SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 3 | #include "editor_impl.hpp" |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 4 | #include "types.hpp" |
| 5 | |
| 6 | #include <com/ibm/VPD/Manager/server.hpp> |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 7 | #include <map> |
| 8 | #include <nlohmann/json.hpp> |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 9 | |
| 10 | namespace sdbusplus |
| 11 | { |
| 12 | namespace bus |
| 13 | { |
| 14 | class bus; |
| 15 | } |
| 16 | } // namespace sdbusplus |
| 17 | |
| 18 | namespace openpower |
| 19 | { |
| 20 | namespace vpd |
| 21 | { |
| 22 | namespace manager |
| 23 | { |
| 24 | |
| 25 | template <typename T> |
| 26 | using ServerObject = T; |
| 27 | |
| 28 | using ManagerIface = sdbusplus::com::ibm::VPD::server::Manager; |
| 29 | |
| 30 | /** @class Manager |
| 31 | * @brief OpenBMC VPD Manager implementation. |
| 32 | * |
| 33 | * A concrete implementation for the |
| 34 | * com.ibm.vpd.Manager |
| 35 | */ |
| 36 | class Manager : public ServerObject<ManagerIface> |
| 37 | { |
| 38 | public: |
| 39 | /* Define all of the basic class operations: |
| 40 | * Not allowed: |
| 41 | * - Default constructor to avoid nullptrs. |
| 42 | * - Copy operations due to internal unique_ptr. |
| 43 | * - Move operations due to 'this' being registered as the |
| 44 | * 'context' with sdbus. |
| 45 | * Allowed: |
| 46 | * - Destructor. |
| 47 | */ |
| 48 | Manager() = delete; |
| 49 | Manager(const Manager&) = delete; |
| 50 | Manager& operator=(const Manager&) = delete; |
| 51 | Manager(Manager&&) = delete; |
| 52 | ~Manager() = default; |
| 53 | |
| 54 | /** @brief Constructor to put object onto bus at a dbus path. |
| 55 | * @param[in] bus - Bus connection. |
| 56 | * @param[in] busName - Name to be requested on Bus |
| 57 | * @param[in] objPath - Path to attach at. |
| 58 | * @param[in] iFace - interface to implement |
| 59 | */ |
| 60 | Manager(sdbusplus::bus::bus&& bus, const char* busName, const char* objPath, |
| 61 | const char* iFace); |
| 62 | |
| 63 | /** @brief Implementation for WriteKeyword |
| 64 | * Api to update the keyword value for a given inventory. |
| 65 | * |
| 66 | * @param[in] path - Path to the D-Bus object that represents the FRU. |
| 67 | * @param[in] recordName - name of the record for which the keyword value |
| 68 | * has to be modified |
| 69 | * @param[in] keyword - keyword whose value needs to be updated |
| 70 | * @param[in] value - value that needs to be updated |
| 71 | */ |
| 72 | void writeKeyword(const sdbusplus::message::object_path path, |
| 73 | const std::string recordName, const std::string keyword, |
| 74 | const Binary value); |
| 75 | |
| 76 | /** @brief Implementation for GetFRUsByUnexpandedLocationCode |
| 77 | * A method to get list of FRU D-BUS object paths for a given unexpanded |
| 78 | * location code. Returns empty vector if no FRU found for that location |
| 79 | * code. |
| 80 | * |
| 81 | * @param[in] locationCode - An un-expanded Location code. |
| 82 | * @param[in] nodeNumber - Denotes the node in case of a multi-node |
| 83 | * configuration, ignored on a single node system. |
| 84 | * |
| 85 | * @return inventoryList[std::vector<sdbusplus::message::object_path>] - |
| 86 | * List of all the FRUs D-Bus object paths for the given location code. |
| 87 | */ |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 88 | inventory::ListOfPaths |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 89 | getFRUsByUnexpandedLocationCode(const std::string locationCode, |
| 90 | const uint16_t nodeNumber); |
| 91 | |
| 92 | /** @brief Implementation for GetFRUsByExpandedLocationCode |
| 93 | * A method to get list of FRU D-BUS object paths for a given expanded |
| 94 | * location code. Returns empty vector if no FRU found for that location |
| 95 | * code. |
| 96 | * |
| 97 | * @param[in] locationCode - Location code in expanded format. |
| 98 | * |
| 99 | * @return inventoryList[std::vector<sdbusplus::message::object_path>] - |
| 100 | * List of all the FRUs D-Bus object path for the given location code. |
| 101 | */ |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 102 | inventory::ListOfPaths |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 103 | getFRUsByExpandedLocationCode(const std::string locationCode); |
| 104 | |
| 105 | /** @brief Implementation for GetExpandedLocationCode |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 106 | * An API to get expanded location code corresponding to a given |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 107 | * un-expanded location code. |
| 108 | * |
| 109 | * @param[in] locationCode - Location code in un-expaned format. |
| 110 | * @param[in] nodeNumber - Denotes the node in case of multi-node |
| 111 | * configuration. Ignored in case of single node configuration. |
| 112 | * |
| 113 | * @return locationCode[std::string] - Location code in expanded format. |
| 114 | */ |
| 115 | std::string getExpandedLocationCode(const std::string locationCode, |
| 116 | const uint16_t nodeNumber); |
| 117 | |
| 118 | /** @brief Start processing DBus messages. */ |
| 119 | void run(); |
| 120 | |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 121 | /** @brief Api to perform VPD recollection. |
| 122 | * This api will trigger parser to perform VPD recollection for FRUs that |
| 123 | * can be replaced at standby. |
| 124 | */ |
| 125 | void performVPDRecollection(); |
| 126 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 127 | private: |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 128 | /** @brief process the given JSON file |
| 129 | */ |
| 130 | void processJSON(); |
| 131 | |
Sunny Srivastava | ecb5c7d | 2021-09-02 07:20:24 -0500 | [diff] [blame] | 132 | /** @brief Api to register host state callback. |
| 133 | * This api will register callback to listen for host state property change. |
| 134 | */ |
| 135 | void listenHostState(); |
| 136 | |
| 137 | /** @brief Callback to listen for Host state change |
| 138 | * @param[in] msg - callback message. |
| 139 | */ |
| 140 | void hostStateCallBack(sdbusplus::message::message& msg); |
| 141 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 142 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 143 | sdbusplus::bus::bus _bus; |
| 144 | |
| 145 | /** @brief sdbusplus org.freedesktop.DBus.ObjectManager reference. */ |
| 146 | sdbusplus::server::manager::manager _manager; |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 147 | |
| 148 | // file to store parsed json |
| 149 | nlohmann::json jsonFile; |
| 150 | |
| 151 | // map to hold mapping to inventory path to vpd file path |
| 152 | // we need as map here as it is in reverse order to that of json |
| 153 | inventory::FrusMap frus; |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 154 | |
| 155 | // map to hold the mapping of location code and inventory path |
| 156 | inventory::LocationCodeMap fruLocationCode; |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 157 | |
| 158 | // map to hold FRUs which can be replaced at standby |
| 159 | inventory::ReplaceableFrus replaceableFrus; |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | } // namespace manager |
| 163 | } // namespace vpd |
| 164 | } // namespace openpower |