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 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 6 | #include "ipz_parser.hpp" |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 7 | #include "reader_impl.hpp" |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 8 | #include "utils.hpp" |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 9 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 10 | using namespace openpower::vpd::constants; |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 11 | using namespace openpower::vpd::inventory; |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 12 | using namespace openpower::vpd::manager::editor; |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 13 | using namespace openpower::vpd::manager::reader; |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 14 | |
| 15 | namespace openpower |
| 16 | { |
| 17 | namespace vpd |
| 18 | { |
| 19 | namespace manager |
| 20 | { |
| 21 | Manager::Manager(sdbusplus::bus::bus&& bus, const char* busName, |
| 22 | const char* objPath, const char* iFace) : |
| 23 | ServerObject<ManagerIface>(bus, objPath), |
| 24 | _bus(std::move(bus)), _manager(_bus, objPath) |
| 25 | { |
| 26 | _bus.request_name(busName); |
| 27 | } |
| 28 | |
| 29 | void Manager::run() |
| 30 | { |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 31 | try |
| 32 | { |
| 33 | processJSON(); |
| 34 | } |
| 35 | catch (const std::exception& e) |
| 36 | { |
| 37 | std::cerr << e.what() << "\n"; |
| 38 | } |
| 39 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 40 | while (true) |
| 41 | { |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 42 | _bus.process_discard(); |
| 43 | |
| 44 | // wait for event |
| 45 | _bus.wait(); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | void Manager::processJSON() |
| 50 | { |
| 51 | std::ifstream json(INVENTORY_JSON, std::ios::binary); |
| 52 | |
| 53 | if (!json) |
| 54 | { |
| 55 | throw std::runtime_error("json file not found"); |
| 56 | } |
| 57 | |
| 58 | jsonFile = nlohmann::json::parse(json); |
| 59 | if (jsonFile.find("frus") == jsonFile.end()) |
| 60 | { |
| 61 | throw std::runtime_error("frus group not found in json"); |
| 62 | } |
| 63 | |
| 64 | const nlohmann::json& groupFRUS = |
| 65 | jsonFile["frus"].get_ref<const nlohmann::json::object_t&>(); |
| 66 | for (const auto& itemFRUS : groupFRUS.items()) |
| 67 | { |
| 68 | const std::vector<nlohmann::json>& groupEEPROM = |
| 69 | itemFRUS.value().get_ref<const nlohmann::json::array_t&>(); |
| 70 | for (const auto& itemEEPROM : groupEEPROM) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 71 | { |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 72 | bool isMotherboard = false; |
| 73 | if (itemEEPROM["extraInterfaces"].find( |
| 74 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard") != |
| 75 | itemEEPROM["extraInterfaces"].end()) |
| 76 | { |
| 77 | isMotherboard = true; |
| 78 | } |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 79 | frus.emplace(itemEEPROM["inventoryPath"] |
| 80 | .get_ref<const nlohmann::json::string_t&>(), |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 81 | std::make_pair(itemFRUS.key(), isMotherboard)); |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 82 | |
Alpana Kumari | 920408d | 2020-05-14 00:07:03 -0500 | [diff] [blame] | 83 | if (itemEEPROM["extraInterfaces"].find(LOCATION_CODE_INF) != |
| 84 | itemEEPROM["extraInterfaces"].end()) |
| 85 | { |
| 86 | fruLocationCode.emplace( |
| 87 | itemEEPROM["extraInterfaces"][LOCATION_CODE_INF] |
| 88 | ["LocationCode"] |
| 89 | .get_ref<const nlohmann::json::string_t&>(), |
| 90 | itemEEPROM["inventoryPath"] |
| 91 | .get_ref<const nlohmann::json::string_t&>()); |
| 92 | } |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | void Manager::writeKeyword(const sdbusplus::message::object_path path, |
| 98 | const std::string recordName, |
| 99 | const std::string keyword, const Binary value) |
| 100 | { |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 101 | try |
| 102 | { |
| 103 | if (frus.find(path) == frus.end()) |
| 104 | { |
| 105 | throw std::runtime_error("Inventory path not found"); |
| 106 | } |
| 107 | |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 108 | inventory::Path vpdFilePath = frus.find(path)->second.first; |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 109 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 110 | // instantiate editor class to update the data |
Alpana Kumari | 920408d | 2020-05-14 00:07:03 -0500 | [diff] [blame] | 111 | EditorImpl edit(vpdFilePath, jsonFile, recordName, keyword, path); |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 112 | edit.updateKeyword(value); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 113 | |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 114 | // if it is a motehrboard FRU need to check for location expansion |
| 115 | if (frus.find(path)->second.second) |
| 116 | { |
| 117 | if (recordName == "VCEN" && (keyword == "FC" || keyword == "SE")) |
| 118 | { |
| 119 | edit.expandLocationCode("fcs"); |
| 120 | } |
| 121 | else if (recordName == "VSYS" && |
| 122 | (keyword == "TM" || keyword == "SE")) |
| 123 | { |
| 124 | edit.expandLocationCode("mts"); |
| 125 | } |
| 126 | } |
| 127 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 128 | return; |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 129 | } |
| 130 | catch (const std::exception& e) |
| 131 | { |
| 132 | std::cerr << e.what() << std::endl; |
| 133 | } |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 134 | } |
| 135 | |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 136 | ListOfPaths |
SunnySrivastava1984 | fb5815a | 2020-04-24 08:03:52 -0500 | [diff] [blame] | 137 | Manager::getFRUsByUnexpandedLocationCode(const LocationCode locationCode, |
| 138 | const NodeNumber nodeNumber) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 139 | { |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 140 | ReaderImpl read; |
| 141 | return read.getFrusAtLocation(locationCode, nodeNumber, fruLocationCode); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 142 | } |
| 143 | |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 144 | ListOfPaths |
SunnySrivastava1984 | fb5815a | 2020-04-24 08:03:52 -0500 | [diff] [blame] | 145 | Manager::getFRUsByExpandedLocationCode(const LocationCode locationCode) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 146 | { |
SunnySrivastava1984 | fb5815a | 2020-04-24 08:03:52 -0500 | [diff] [blame] | 147 | ReaderImpl read; |
| 148 | return read.getFRUsByExpandedLocationCode(locationCode, fruLocationCode); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 149 | } |
| 150 | |
SunnySrivastava1984 | fb5815a | 2020-04-24 08:03:52 -0500 | [diff] [blame] | 151 | LocationCode Manager::getExpandedLocationCode(const LocationCode locationCode, |
| 152 | const NodeNumber nodeNumber) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 153 | { |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 154 | ReaderImpl read; |
| 155 | return read.getExpandedLocationCode(locationCode, nodeNumber, |
| 156 | fruLocationCode); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 157 | } |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 158 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 159 | } // namespace manager |
| 160 | } // namespace vpd |
| 161 | } // namespace openpower |