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