SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "manager.hpp" |
| 4 | |
SunnySrivastava1984 | 19be6d3 | 2020-03-03 07:21:45 -0600 | [diff] [blame^] | 5 | #include "const.hpp" |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 6 | #include "parser.hpp" |
| 7 | |
| 8 | #include <exception> |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 9 | #include <fstream> |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 10 | #include <iostream> |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 11 | #include <nlohmann/json.hpp> |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 12 | #include <vector> |
| 13 | |
| 14 | namespace openpower |
| 15 | { |
| 16 | namespace vpd |
| 17 | { |
| 18 | namespace manager |
| 19 | { |
| 20 | Manager::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 | |
| 28 | void Manager::run() |
| 29 | { |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 30 | try |
| 31 | { |
| 32 | processJSON(); |
| 33 | } |
| 34 | catch (const std::exception& e) |
| 35 | { |
| 36 | std::cerr << e.what() << "\n"; |
| 37 | } |
| 38 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 39 | while (true) |
| 40 | { |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 41 | _bus.process_discard(); |
| 42 | |
| 43 | // wait for event |
| 44 | _bus.wait(); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | void 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) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 70 | { |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 71 | frus.emplace(itemEEPROM["inventoryPath"] |
| 72 | .get_ref<const nlohmann::json::string_t&>(), |
| 73 | itemFRUS.key()); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | void 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 | |
| 85 | std::vector<sdbusplus::message::object_path> |
| 86 | Manager::getFRUsByUnexpandedLocationCode(const std::string locationCode, |
| 87 | const uint16_t nodeNumber) |
| 88 | { |
| 89 | // implement the interface |
| 90 | } |
| 91 | |
| 92 | std::vector<sdbusplus::message::object_path> |
| 93 | Manager::getFRUsByExpandedLocationCode(const std::string locationCode) |
| 94 | { |
| 95 | // implement the interface |
| 96 | } |
| 97 | |
| 98 | std::string Manager::getExpandedLocationCode(const std::string locationCode, |
| 99 | const uint16_t nodeNumber) |
| 100 | { |
| 101 | // implement the interface |
| 102 | } |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 103 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 104 | } // namespace manager |
| 105 | } // namespace vpd |
| 106 | } // namespace openpower |