blob: e5882b53066886a69a8087d1d31a30b01c3b2770 [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#include <sdbusplus/server.hpp>
10
11namespace sdbusplus
12{
13namespace bus
14{
15class bus;
16}
17} // namespace sdbusplus
18
19namespace openpower
20{
21namespace vpd
22{
23namespace manager
24{
25
26template <typename T>
27using ServerObject = T;
28
29using ManagerIface = sdbusplus::com::ibm::VPD::server::Manager;
30
31/** @class Manager
32 * @brief OpenBMC VPD Manager implementation.
33 *
34 * A concrete implementation for the
35 * com.ibm.vpd.Manager
36 */
37class Manager : public ServerObject<ManagerIface>
38{
39 public:
40 /* Define all of the basic class operations:
41 * Not allowed:
42 * - Default constructor to avoid nullptrs.
43 * - Copy operations due to internal unique_ptr.
44 * - Move operations due to 'this' being registered as the
45 * 'context' with sdbus.
46 * Allowed:
47 * - Destructor.
48 */
49 Manager() = delete;
50 Manager(const Manager&) = delete;
51 Manager& operator=(const Manager&) = delete;
52 Manager(Manager&&) = delete;
53 ~Manager() = default;
54
55 /** @brief Constructor to put object onto bus at a dbus path.
56 * @param[in] bus - Bus connection.
57 * @param[in] busName - Name to be requested on Bus
58 * @param[in] objPath - Path to attach at.
59 * @param[in] iFace - interface to implement
60 */
61 Manager(sdbusplus::bus::bus&& bus, const char* busName, const char* objPath,
62 const char* iFace);
63
64 /** @brief Implementation for WriteKeyword
65 * Api to update the keyword value for a given inventory.
66 *
67 * @param[in] path - Path to the D-Bus object that represents the FRU.
68 * @param[in] recordName - name of the record for which the keyword value
69 * has to be modified
70 * @param[in] keyword - keyword whose value needs to be updated
71 * @param[in] value - value that needs to be updated
72 */
73 void writeKeyword(const sdbusplus::message::object_path path,
74 const std::string recordName, const std::string keyword,
75 const Binary value);
76
77 /** @brief Implementation for GetFRUsByUnexpandedLocationCode
78 * A method to get list of FRU D-BUS object paths for a given unexpanded
79 * location code. Returns empty vector if no FRU found for that location
80 * code.
81 *
82 * @param[in] locationCode - An un-expanded Location code.
83 * @param[in] nodeNumber - Denotes the node in case of a multi-node
84 * configuration, ignored on a single node system.
85 *
86 * @return inventoryList[std::vector<sdbusplus::message::object_path>] -
87 * List of all the FRUs D-Bus object paths for the given location code.
88 */
89 std::vector<sdbusplus::message::object_path>
90 getFRUsByUnexpandedLocationCode(const std::string locationCode,
91 const uint16_t nodeNumber);
92
93 /** @brief Implementation for GetFRUsByExpandedLocationCode
94 * A method to get list of FRU D-BUS object paths for a given expanded
95 * location code. Returns empty vector if no FRU found for that location
96 * code.
97 *
98 * @param[in] locationCode - Location code in expanded format.
99 *
100 * @return inventoryList[std::vector<sdbusplus::message::object_path>] -
101 * List of all the FRUs D-Bus object path for the given location code.
102 */
103 std::vector<sdbusplus::message::object_path>
104 getFRUsByExpandedLocationCode(const std::string locationCode);
105
106 /** @brief Implementation for GetExpandedLocationCode
107 * An api to get expanded location code corresponding to a given
108 * un-expanded location code.
109 *
110 * @param[in] locationCode - Location code in un-expaned format.
111 * @param[in] nodeNumber - Denotes the node in case of multi-node
112 * configuration. Ignored in case of single node configuration.
113 *
114 * @return locationCode[std::string] - Location code in expanded format.
115 */
116 std::string getExpandedLocationCode(const std::string locationCode,
117 const uint16_t nodeNumber);
118
119 /** @brief Start processing DBus messages. */
120 void run();
121
122 private:
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -0600123 /** @brief process the given JSON file
124 */
125 void processJSON();
126
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600127 /** @brief Persistent sdbusplus DBus bus connection. */
128 sdbusplus::bus::bus _bus;
129
130 /** @brief sdbusplus org.freedesktop.DBus.ObjectManager reference. */
131 sdbusplus::server::manager::manager _manager;
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -0600132
133 // file to store parsed json
134 nlohmann::json jsonFile;
135
136 // map to hold mapping to inventory path to vpd file path
137 // we need as map here as it is in reverse order to that of json
138 inventory::FrusMap frus;
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600139};
140
141} // namespace manager
142} // namespace vpd
143} // namespace openpower