blob: 3182126736b9184d4577e15e8847ed5adf648184 [file] [log] [blame]
Kuiying Wang642f4372020-08-12 15:35:46 +08001/*
2// Copyright (c) 2020 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17
Tom Josephf1101df2020-11-06 08:23:34 +053018#include "config.h"
19
Kuiying Wang642f4372020-08-12 15:35:46 +080020#include <sdbusplus/asio/object_server.hpp>
21#include <sdbusplus/server.hpp>
22#include <xyz/openbmc_project/BIOSConfig/Manager/server.hpp>
23
Tom Josephf1101df2020-11-06 08:23:34 +053024#include <filesystem>
Kuiying Wang642f4372020-08-12 15:35:46 +080025#include <string>
26
27namespace bios_config
28{
29
30static constexpr auto service = "xyz.openbmc_project.BIOSConfigManager";
31static constexpr auto objectPath = "/xyz/openbmc_project/bios_config/manager";
Tom Josephf1101df2020-11-06 08:23:34 +053032constexpr auto biosPersistFile = "biosData";
Kuiying Wang642f4372020-08-12 15:35:46 +080033
34using Base = sdbusplus::xyz::openbmc_project::BIOSConfig::server::Manager;
Tom Josephf1101df2020-11-06 08:23:34 +053035namespace fs = std::filesystem;
Kuiying Wang642f4372020-08-12 15:35:46 +080036
37/** @class Manager
38 *
39 * @brief Implements the BIOS Manager
40 */
41class Manager : public Base
42{
43 public:
44 using BaseTable = std::map<
45 std::string,
46 std::tuple<AttributeType, bool, std::string, std::string, std::string,
47 std::variant<int64_t, std::string>,
48 std::variant<int64_t, std::string>,
49 std::vector<std::tuple<
50 BoundType, std::variant<int64_t, std::string>>>>>;
51
52 using PendingAttributes =
53 std::map<std::string,
54 std::tuple<AttributeType, std::variant<int64_t, std::string>>>;
55
56 using PendingAttribute =
57 std::tuple<AttributeType, std::variant<int64_t, std::string>>;
58
59 using AttributeName = std::string;
60 using AttributeValue = std::variant<int64_t, std::string>;
61 using CurrentValue = std::variant<int64_t, std::string>;
62 using PendingValue = std::variant<int64_t, std::string>;
63 using AttributeDetails =
64 std::tuple<AttributeType, CurrentValue, PendingValue>;
65
66 Manager() = delete;
67 ~Manager() = default;
68 Manager(const Manager&) = delete;
69 Manager& operator=(const Manager&) = delete;
70 Manager(Manager&&) = delete;
71 Manager& operator=(Manager&&) = delete;
72
73 /** @brief Constructs Manager object.
74 *
75 * @param[in] objectServer - object server
76 * @param[in] systemBus - bus connection
77 */
78 Manager(sdbusplus::asio::object_server& objectServer,
79 std::shared_ptr<sdbusplus::asio::connection>& systemBus);
80
81 /** @brief Set the BIOS attribute with a new value, the new value is added
82 * to the PendingAttribute.
83 *
84 * @param[in] attribute - attribute name
85 * @param[in] value - new value for the attribute
86 *
87 * @return On error, throw exception
88 */
89 void setAttribute(AttributeName attribute, AttributeValue value) override;
90
91 /** @brief Get the details of the BIOS attribute
92 *
93 * @param[in] attribute - attribute name
94 *
95 * @return On success, return the attribute details: attribute type,
96 * current value, pending value. On error, throw exception
97 */
98 AttributeDetails getAttribute(AttributeName attribute) override;
99
100 /** @brief Set the BaseBIOSTable property and clears the PendingAttributes
101 * property
102 *
103 * @param[in] value - new BaseBIOSTable
104 *
105 * @return The new BaseBIOSTable that is applied.
106 */
107 BaseTable baseBIOSTable(BaseTable value) override;
108
109 /** @brief Set the PendingAttributes property, additionally checks if the
110 * attributes are in the BaseBIOSTable, whether the attributes are
111 * read only and validate the attribute value based on the
112 * attribute type. PendingAttributes is cleared if value is empty.
113 *
114 * @param[in] value - new PendingAttributes to append to the
115 * PendingAttributes property
116 *
117 * @return On success, return the new PendingAttributes property that is
118 * set.Throw exception if the validation fails.
119 */
120 PendingAttributes pendingAttributes(PendingAttributes value) override;
121
122 private:
123 /** @enum Index into the fields in the BaseBIOSTable
124 */
125 enum class Index : uint8_t
126 {
127 attributeType = 0,
128 readOnly,
129 displayName,
130 description,
131 menuPath,
132 currentValue,
133 defaultValue,
134 options,
135 };
136
137 sdbusplus::asio::object_server& objServer;
138 std::shared_ptr<sdbusplus::asio::connection>& systemBus;
Tom Josephf1101df2020-11-06 08:23:34 +0530139 std::filesystem::path biosFile;
Kuiying Wang642f4372020-08-12 15:35:46 +0800140};
141
142} // namespace bios_config