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" |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame^] | 7 | #include "reader_impl.hpp" |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 8 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 9 | using namespace openpower::vpd::constants; |
| 10 | using namespace openpower::vpd::manager::editor; |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame^] | 11 | using namespace openpower::vpd::manager::reader; |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 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 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 70 | bool isMotherboard = false; |
| 71 | if (itemEEPROM["extraInterfaces"].find( |
| 72 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard") != |
| 73 | itemEEPROM["extraInterfaces"].end()) |
| 74 | { |
| 75 | isMotherboard = true; |
| 76 | } |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 77 | frus.emplace(itemEEPROM["inventoryPath"] |
| 78 | .get_ref<const nlohmann::json::string_t&>(), |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 79 | std::make_pair(itemFRUS.key(), isMotherboard)); |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame^] | 80 | |
| 81 | fruLocationCode.emplace( |
| 82 | itemEEPROM["extraInterfaces"][LOCATION_CODE_INF]["LocationCode"] |
| 83 | .get_ref<const nlohmann::json::string_t&>(), |
| 84 | itemEEPROM["inventoryPath"] |
| 85 | .get_ref<const nlohmann::json::string_t&>()); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | void Manager::writeKeyword(const sdbusplus::message::object_path path, |
| 91 | const std::string recordName, |
| 92 | const std::string keyword, const Binary value) |
| 93 | { |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 94 | try |
| 95 | { |
| 96 | if (frus.find(path) == frus.end()) |
| 97 | { |
| 98 | throw std::runtime_error("Inventory path not found"); |
| 99 | } |
| 100 | |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 101 | inventory::Path vpdFilePath = frus.find(path)->second.first; |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 102 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 103 | // instantiate editor class to update the data |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 104 | EditorImpl edit(vpdFilePath, jsonFile, recordName, keyword); |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 105 | edit.updateKeyword(value); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 106 | |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 107 | // if it is a motehrboard FRU need to check for location expansion |
| 108 | if (frus.find(path)->second.second) |
| 109 | { |
| 110 | if (recordName == "VCEN" && (keyword == "FC" || keyword == "SE")) |
| 111 | { |
| 112 | edit.expandLocationCode("fcs"); |
| 113 | } |
| 114 | else if (recordName == "VSYS" && |
| 115 | (keyword == "TM" || keyword == "SE")) |
| 116 | { |
| 117 | edit.expandLocationCode("mts"); |
| 118 | } |
| 119 | } |
| 120 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 121 | return; |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 122 | } |
| 123 | catch (const std::exception& e) |
| 124 | { |
| 125 | std::cerr << e.what() << std::endl; |
| 126 | } |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | std::vector<sdbusplus::message::object_path> |
| 130 | Manager::getFRUsByUnexpandedLocationCode(const std::string locationCode, |
| 131 | const uint16_t nodeNumber) |
| 132 | { |
| 133 | // implement the interface |
| 134 | } |
| 135 | |
| 136 | std::vector<sdbusplus::message::object_path> |
| 137 | Manager::getFRUsByExpandedLocationCode(const std::string locationCode) |
| 138 | { |
| 139 | // implement the interface |
| 140 | } |
| 141 | |
| 142 | std::string Manager::getExpandedLocationCode(const std::string locationCode, |
| 143 | const uint16_t nodeNumber) |
| 144 | { |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame^] | 145 | ReaderImpl read; |
| 146 | return read.getExpandedLocationCode(locationCode, nodeNumber, |
| 147 | fruLocationCode); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 148 | } |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 149 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 150 | } // namespace manager |
| 151 | } // namespace vpd |
| 152 | } // namespace openpower |