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