blob: ce8bea5548d710800b9c1896a2dd974999a5d70f [file] [log] [blame]
SunnySrivastava1984b59fd092020-02-03 09:58:56 -06001#include "config.h"
2
3#include "manager.hpp"
4
SunnySrivastava198419be6d32020-03-03 07:21:45 -06005#include "const.hpp"
SunnySrivastava1984b59fd092020-02-03 09:58:56 -06006#include "parser.hpp"
7
8#include <exception>
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -06009#include <fstream>
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060010#include <iostream>
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -060011#include <nlohmann/json.hpp>
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060012#include <vector>
13
14namespace openpower
15{
16namespace vpd
17{
18namespace manager
19{
20Manager::Manager(sdbusplus::bus::bus&& bus, const char* busName,
21 const char* objPath, const char* iFace) :
22 ServerObject<ManagerIface>(bus, objPath),
23 _bus(std::move(bus)), _manager(_bus, objPath)
24{
25 _bus.request_name(busName);
26}
27
28void Manager::run()
29{
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -060030 try
31 {
32 processJSON();
33 }
34 catch (const std::exception& e)
35 {
36 std::cerr << e.what() << "\n";
37 }
38
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060039 while (true)
40 {
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -060041 _bus.process_discard();
42
43 // wait for event
44 _bus.wait();
45 }
46}
47
48void Manager::processJSON()
49{
50 std::ifstream json(INVENTORY_JSON, std::ios::binary);
51
52 if (!json)
53 {
54 throw std::runtime_error("json file not found");
55 }
56
57 jsonFile = nlohmann::json::parse(json);
58 if (jsonFile.find("frus") == jsonFile.end())
59 {
60 throw std::runtime_error("frus group not found in json");
61 }
62
63 const nlohmann::json& groupFRUS =
64 jsonFile["frus"].get_ref<const nlohmann::json::object_t&>();
65 for (const auto& itemFRUS : groupFRUS.items())
66 {
67 const std::vector<nlohmann::json>& groupEEPROM =
68 itemFRUS.value().get_ref<const nlohmann::json::array_t&>();
69 for (const auto& itemEEPROM : groupEEPROM)
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060070 {
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -060071 frus.emplace(itemEEPROM["inventoryPath"]
72 .get_ref<const nlohmann::json::string_t&>(),
73 itemFRUS.key());
SunnySrivastava1984b59fd092020-02-03 09:58:56 -060074 }
75 }
76}
77
78void Manager::writeKeyword(const sdbusplus::message::object_path path,
79 const std::string recordName,
80 const std::string keyword, const Binary value)
81{
82 // implement the interface to write keyword VPD data
83}
84
85std::vector<sdbusplus::message::object_path>
86 Manager::getFRUsByUnexpandedLocationCode(const std::string locationCode,
87 const uint16_t nodeNumber)
88{
89 // implement the interface
90}
91
92std::vector<sdbusplus::message::object_path>
93 Manager::getFRUsByExpandedLocationCode(const std::string locationCode)
94{
95 // implement the interface
96}
97
98std::string Manager::getExpandedLocationCode(const std::string locationCode,
99 const uint16_t nodeNumber)
100{
101 // implement the interface
102}
SunnySrivastava1984de3c60d2020-02-03 10:34:33 -0600103
SunnySrivastava1984b59fd092020-02-03 09:58:56 -0600104} // namespace manager
105} // namespace vpd
106} // namespace openpower