blob: 37a8055f976628a8092456e9a76d1df4cede13a6 [file] [log] [blame]
SunnySrivastava1984b59fd092020-02-03 09:58:56 -06001#include "config.h"
2
3#include "manager.hpp"
4
SunnySrivastava1984d076da82020-03-05 05:33:35 -06005#include "editor_impl.hpp"
SunnySrivastava1984b59fd092020-02-03 09:58:56 -06006#include "parser.hpp"
7
SunnySrivastava1984f6d541e2020-02-04 12:50:40 -06008using namespace openpower::vpd::constants;
9using namespace openpower::vpd::manager::editor;
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060010
11namespace openpower
12{
13namespace vpd
14{
15namespace manager
16{
17Manager::Manager(sdbusplus::bus::bus&& bus, const char* busName,
18 const char* objPath, const char* iFace) :
19 ServerObject<ManagerIface>(bus, objPath),
20 _bus(std::move(bus)), _manager(_bus, objPath)
21{
22 _bus.request_name(busName);
23}
24
25void Manager::run()
26{
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -060027 try
28 {
29 processJSON();
30 }
31 catch (const std::exception& e)
32 {
33 std::cerr << e.what() << "\n";
34 }
35
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060036 while (true)
37 {
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -060038 _bus.process_discard();
39
40 // wait for event
41 _bus.wait();
42 }
43}
44
45void Manager::processJSON()
46{
47 std::ifstream json(INVENTORY_JSON, std::ios::binary);
48
49 if (!json)
50 {
51 throw std::runtime_error("json file not found");
52 }
53
54 jsonFile = nlohmann::json::parse(json);
55 if (jsonFile.find("frus") == jsonFile.end())
56 {
57 throw std::runtime_error("frus group not found in json");
58 }
59
60 const nlohmann::json& groupFRUS =
61 jsonFile["frus"].get_ref<const nlohmann::json::object_t&>();
62 for (const auto& itemFRUS : groupFRUS.items())
63 {
64 const std::vector<nlohmann::json>& groupEEPROM =
65 itemFRUS.value().get_ref<const nlohmann::json::array_t&>();
66 for (const auto& itemEEPROM : groupEEPROM)
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060067 {
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -060068 frus.emplace(itemEEPROM["inventoryPath"]
69 .get_ref<const nlohmann::json::string_t&>(),
70 itemFRUS.key());
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060071 }
72 }
73}
74
75void Manager::writeKeyword(const sdbusplus::message::object_path path,
76 const std::string recordName,
77 const std::string keyword, const Binary value)
78{
SunnySrivastava1984f6d541e2020-02-04 12:50:40 -060079 try
80 {
81 if (frus.find(path) == frus.end())
82 {
83 throw std::runtime_error("Inventory path not found");
84 }
85
86 inventory::Path vpdFilePath = frus.find(path)->second;
SunnySrivastava1984f6d541e2020-02-04 12:50:40 -060087
SunnySrivastava19846d8314d2020-05-15 09:34:58 -050088 // instantiate editor class to update the data
SunnySrivastava1984b421bfd2020-03-02 08:59:32 -060089 EditorImpl edit(vpdFilePath, jsonFile, recordName, keyword);
SunnySrivastava19846d8314d2020-05-15 09:34:58 -050090 edit.updateKeyword(value);
SunnySrivastava1984f6d541e2020-02-04 12:50:40 -060091
SunnySrivastava19846d8314d2020-05-15 09:34:58 -050092 return;
SunnySrivastava1984f6d541e2020-02-04 12:50:40 -060093 }
94 catch (const std::exception& e)
95 {
96 std::cerr << e.what() << std::endl;
97 }
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060098}
99
100std::vector<sdbusplus::message::object_path>
101 Manager::getFRUsByUnexpandedLocationCode(const std::string locationCode,
102 const uint16_t nodeNumber)
103{
104 // implement the interface
105}
106
107std::vector<sdbusplus::message::object_path>
108 Manager::getFRUsByExpandedLocationCode(const std::string locationCode)
109{
110 // implement the interface
111}
112
113std::string Manager::getExpandedLocationCode(const std::string locationCode,
114 const uint16_t nodeNumber)
115{
116 // implement the interface
117}
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -0600118
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600119} // namespace manager
120} // namespace vpd
121} // namespace openpower