blob: fd1a306333a6515feae1f5995e0a8e9966aa43ff [file] [log] [blame]
SunnySrivastava1984b59fd092020-02-03 09:58:56 -06001#pragma once
2
SunnySrivastava1984f6d541e2020-02-04 12:50:40 -06003#include "editor_impl.hpp"
SunnySrivastava1984b59fd092020-02-03 09:58:56 -06004#include "types.hpp"
5
6#include <com/ibm/VPD/Manager/server.hpp>
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -06007#include <map>
8#include <nlohmann/json.hpp>
SunnySrivastava1984b59fd092020-02-03 09:58:56 -06009
10namespace sdbusplus
11{
12namespace bus
13{
14class bus;
15}
16} // namespace sdbusplus
17
18namespace openpower
19{
20namespace vpd
21{
22namespace manager
23{
24
25template <typename T>
26using ServerObject = T;
27
28using 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 */
36class 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 */
SunnySrivastava19841356d7e2020-04-24 04:29:35 -050088 inventory::ListOfPaths
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060089 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 */
SunnySrivastava19841356d7e2020-04-24 04:29:35 -0500102 inventory::ListOfPaths
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600103 getFRUsByExpandedLocationCode(const std::string locationCode);
104
105 /** @brief Implementation for GetExpandedLocationCode
SunnySrivastava1984bca5aaa2020-04-21 05:31:04 -0500106 * An API to get expanded location code corresponding to a given
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600107 * 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
SunnySrivastava19849a195542020-09-07 06:04:50 -0500121 /** @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
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600127 private:
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -0600128 /** @brief process the given JSON file
129 */
130 void processJSON();
131
Sunny Srivastavaecb5c7d2021-09-02 07:20:24 -0500132 /** @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
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600142 /** @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;
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -0600147
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;
SunnySrivastava1984bca5aaa2020-04-21 05:31:04 -0500154
155 // map to hold the mapping of location code and inventory path
156 inventory::LocationCodeMap fruLocationCode;
SunnySrivastava19849a195542020-09-07 06:04:50 -0500157
158 // map to hold FRUs which can be replaced at standby
159 inventory::ReplaceableFrus replaceableFrus;
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600160};
161
162} // namespace manager
163} // namespace vpd
164} // namespace openpower