blob: 702e30f345e992c6f7b552f8e6686e4f22ca65c4 [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
18#include <sdbusplus/asio/object_server.hpp>
19#include <sdbusplus/server.hpp>
20#include <xyz/openbmc_project/BIOSConfig/Manager/server.hpp>
21
22#include <string>
23
24namespace bios_config
25{
26
27static constexpr auto service = "xyz.openbmc_project.BIOSConfigManager";
28static constexpr auto objectPath = "/xyz/openbmc_project/bios_config/manager";
29
30using Base = sdbusplus::xyz::openbmc_project::BIOSConfig::server::Manager;
31
32/** @class Manager
33 *
34 * @brief Implements the BIOS Manager
35 */
36class Manager : public Base
37{
38 public:
39 using BaseTable = std::map<
40 std::string,
41 std::tuple<AttributeType, bool, std::string, std::string, std::string,
42 std::variant<int64_t, std::string>,
43 std::variant<int64_t, std::string>,
44 std::vector<std::tuple<
45 BoundType, std::variant<int64_t, std::string>>>>>;
46
47 using PendingAttributes =
48 std::map<std::string,
49 std::tuple<AttributeType, std::variant<int64_t, std::string>>>;
50
51 using PendingAttribute =
52 std::tuple<AttributeType, std::variant<int64_t, std::string>>;
53
54 using AttributeName = std::string;
55 using AttributeValue = std::variant<int64_t, std::string>;
56 using CurrentValue = std::variant<int64_t, std::string>;
57 using PendingValue = std::variant<int64_t, std::string>;
58 using AttributeDetails =
59 std::tuple<AttributeType, CurrentValue, PendingValue>;
60
61 Manager() = delete;
62 ~Manager() = default;
63 Manager(const Manager&) = delete;
64 Manager& operator=(const Manager&) = delete;
65 Manager(Manager&&) = delete;
66 Manager& operator=(Manager&&) = delete;
67
68 /** @brief Constructs Manager object.
69 *
70 * @param[in] objectServer - object server
71 * @param[in] systemBus - bus connection
72 */
73 Manager(sdbusplus::asio::object_server& objectServer,
74 std::shared_ptr<sdbusplus::asio::connection>& systemBus);
75
76 /** @brief Set the BIOS attribute with a new value, the new value is added
77 * to the PendingAttribute.
78 *
79 * @param[in] attribute - attribute name
80 * @param[in] value - new value for the attribute
81 *
82 * @return On error, throw exception
83 */
84 void setAttribute(AttributeName attribute, AttributeValue value) override;
85
86 /** @brief Get the details of the BIOS attribute
87 *
88 * @param[in] attribute - attribute name
89 *
90 * @return On success, return the attribute details: attribute type,
91 * current value, pending value. On error, throw exception
92 */
93 AttributeDetails getAttribute(AttributeName attribute) override;
94
95 /** @brief Set the BaseBIOSTable property and clears the PendingAttributes
96 * property
97 *
98 * @param[in] value - new BaseBIOSTable
99 *
100 * @return The new BaseBIOSTable that is applied.
101 */
102 BaseTable baseBIOSTable(BaseTable value) override;
103
104 /** @brief Set the PendingAttributes property, additionally checks if the
105 * attributes are in the BaseBIOSTable, whether the attributes are
106 * read only and validate the attribute value based on the
107 * attribute type. PendingAttributes is cleared if value is empty.
108 *
109 * @param[in] value - new PendingAttributes to append to the
110 * PendingAttributes property
111 *
112 * @return On success, return the new PendingAttributes property that is
113 * set.Throw exception if the validation fails.
114 */
115 PendingAttributes pendingAttributes(PendingAttributes value) override;
116
117 private:
118 /** @enum Index into the fields in the BaseBIOSTable
119 */
120 enum class Index : uint8_t
121 {
122 attributeType = 0,
123 readOnly,
124 displayName,
125 description,
126 menuPath,
127 currentValue,
128 defaultValue,
129 options,
130 };
131
132 sdbusplus::asio::object_server& objServer;
133 std::shared_ptr<sdbusplus::asio::connection>& systemBus;
134};
135
136} // namespace bios_config