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