blob: 61a392a7fa240ffc15c14059a160b7caffc4ee03 [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 {
SunnySrivastava198443306542020-04-01 02:50:20 -050068 bool isMotherboard = false;
69 if (itemEEPROM["extraInterfaces"].find(
70 "xyz.openbmc_project.Inventory.Item.Board.Motherboard") !=
71 itemEEPROM["extraInterfaces"].end())
72 {
73 isMotherboard = true;
74 }
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -060075 frus.emplace(itemEEPROM["inventoryPath"]
76 .get_ref<const nlohmann::json::string_t&>(),
SunnySrivastava198443306542020-04-01 02:50:20 -050077 std::make_pair(itemFRUS.key(), isMotherboard));
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060078 }
79 }
80}
81
82void Manager::writeKeyword(const sdbusplus::message::object_path path,
83 const std::string recordName,
84 const std::string keyword, const Binary value)
85{
SunnySrivastava1984f6d541e2020-02-04 12:50:40 -060086 try
87 {
88 if (frus.find(path) == frus.end())
89 {
90 throw std::runtime_error("Inventory path not found");
91 }
92
SunnySrivastava198443306542020-04-01 02:50:20 -050093 inventory::Path vpdFilePath = frus.find(path)->second.first;
SunnySrivastava1984f6d541e2020-02-04 12:50:40 -060094
SunnySrivastava19846d8314d2020-05-15 09:34:58 -050095 // instantiate editor class to update the data
SunnySrivastava1984b421bfd2020-03-02 08:59:32 -060096 EditorImpl edit(vpdFilePath, jsonFile, recordName, keyword);
SunnySrivastava19846d8314d2020-05-15 09:34:58 -050097 edit.updateKeyword(value);
SunnySrivastava1984f6d541e2020-02-04 12:50:40 -060098
SunnySrivastava198443306542020-04-01 02:50:20 -050099 // if it is a motehrboard FRU need to check for location expansion
100 if (frus.find(path)->second.second)
101 {
102 if (recordName == "VCEN" && (keyword == "FC" || keyword == "SE"))
103 {
104 edit.expandLocationCode("fcs");
105 }
106 else if (recordName == "VSYS" &&
107 (keyword == "TM" || keyword == "SE"))
108 {
109 edit.expandLocationCode("mts");
110 }
111 }
112
SunnySrivastava19846d8314d2020-05-15 09:34:58 -0500113 return;
SunnySrivastava1984f6d541e2020-02-04 12:50:40 -0600114 }
115 catch (const std::exception& e)
116 {
117 std::cerr << e.what() << std::endl;
118 }
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600119}
120
121std::vector<sdbusplus::message::object_path>
122 Manager::getFRUsByUnexpandedLocationCode(const std::string locationCode,
123 const uint16_t nodeNumber)
124{
125 // implement the interface
126}
127
128std::vector<sdbusplus::message::object_path>
129 Manager::getFRUsByExpandedLocationCode(const std::string locationCode)
130{
131 // implement the interface
132}
133
134std::string Manager::getExpandedLocationCode(const std::string locationCode,
135 const uint16_t nodeNumber)
136{
137 // implement the interface
138}
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -0600139
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600140} // namespace manager
141} // namespace vpd
142} // namespace openpower