SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "manager.hpp" |
| 4 | |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 5 | #include "editor_impl.hpp" |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 6 | #include "parser.hpp" |
| 7 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 8 | using namespace openpower::vpd::constants; |
| 9 | using namespace openpower::vpd::manager::editor; |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 10 | |
| 11 | namespace openpower |
| 12 | { |
| 13 | namespace vpd |
| 14 | { |
| 15 | namespace manager |
| 16 | { |
| 17 | Manager::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 | |
| 25 | void Manager::run() |
| 26 | { |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 27 | try |
| 28 | { |
| 29 | processJSON(); |
| 30 | } |
| 31 | catch (const std::exception& e) |
| 32 | { |
| 33 | std::cerr << e.what() << "\n"; |
| 34 | } |
| 35 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 36 | while (true) |
| 37 | { |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 38 | _bus.process_discard(); |
| 39 | |
| 40 | // wait for event |
| 41 | _bus.wait(); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | void 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) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 67 | { |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 68 | frus.emplace(itemEEPROM["inventoryPath"] |
| 69 | .get_ref<const nlohmann::json::string_t&>(), |
| 70 | itemFRUS.key()); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | void Manager::writeKeyword(const sdbusplus::message::object_path path, |
| 76 | const std::string recordName, |
| 77 | const std::string keyword, const Binary value) |
| 78 | { |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 79 | try |
| 80 | { |
| 81 | if (frus.find(path) == frus.end()) |
| 82 | { |
| 83 | throw std::runtime_error("Inventory path not found"); |
| 84 | } |
| 85 | |
| 86 | inventory::Path vpdFilePath = frus.find(path)->second; |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 87 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 88 | // instantiate editor class to update the data |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 89 | EditorImpl edit(vpdFilePath, jsonFile, recordName, keyword); |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 90 | edit.updateKeyword(value); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 91 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 92 | return; |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 93 | } |
| 94 | catch (const std::exception& e) |
| 95 | { |
| 96 | std::cerr << e.what() << std::endl; |
| 97 | } |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | std::vector<sdbusplus::message::object_path> |
| 101 | Manager::getFRUsByUnexpandedLocationCode(const std::string locationCode, |
| 102 | const uint16_t nodeNumber) |
| 103 | { |
| 104 | // implement the interface |
| 105 | } |
| 106 | |
| 107 | std::vector<sdbusplus::message::object_path> |
| 108 | Manager::getFRUsByExpandedLocationCode(const std::string locationCode) |
| 109 | { |
| 110 | // implement the interface |
| 111 | } |
| 112 | |
| 113 | std::string Manager::getExpandedLocationCode(const std::string locationCode, |
| 114 | const uint16_t nodeNumber) |
| 115 | { |
| 116 | // implement the interface |
| 117 | } |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 118 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 119 | } // namespace manager |
| 120 | } // namespace vpd |
| 121 | } // namespace openpower |