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 | 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 | |
| 83 | fruLocationCode.emplace( |
| 84 | itemEEPROM["extraInterfaces"][LOCATION_CODE_INF]["LocationCode"] |
| 85 | .get_ref<const nlohmann::json::string_t&>(), |
| 86 | itemEEPROM["inventoryPath"] |
| 87 | .get_ref<const nlohmann::json::string_t&>()); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | void Manager::writeKeyword(const sdbusplus::message::object_path path, |
| 93 | const std::string recordName, |
| 94 | const std::string keyword, const Binary value) |
| 95 | { |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 96 | try |
| 97 | { |
| 98 | if (frus.find(path) == frus.end()) |
| 99 | { |
| 100 | throw std::runtime_error("Inventory path not found"); |
| 101 | } |
| 102 | |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 103 | inventory::Path vpdFilePath = frus.find(path)->second.first; |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 104 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 105 | // instantiate editor class to update the data |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 106 | EditorImpl edit(vpdFilePath, jsonFile, recordName, keyword); |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 107 | edit.updateKeyword(value); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 108 | |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 109 | // if it is a motehrboard FRU need to check for location expansion |
| 110 | if (frus.find(path)->second.second) |
| 111 | { |
| 112 | if (recordName == "VCEN" && (keyword == "FC" || keyword == "SE")) |
| 113 | { |
| 114 | edit.expandLocationCode("fcs"); |
| 115 | } |
| 116 | else if (recordName == "VSYS" && |
| 117 | (keyword == "TM" || keyword == "SE")) |
| 118 | { |
| 119 | edit.expandLocationCode("mts"); |
| 120 | } |
| 121 | } |
| 122 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 123 | return; |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 124 | } |
| 125 | catch (const std::exception& e) |
| 126 | { |
| 127 | std::cerr << e.what() << std::endl; |
| 128 | } |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 129 | } |
| 130 | |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 131 | ListOfPaths |
SunnySrivastava1984 | fb5815a | 2020-04-24 08:03:52 -0500 | [diff] [blame] | 132 | Manager::getFRUsByUnexpandedLocationCode(const LocationCode locationCode, |
| 133 | const NodeNumber nodeNumber) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 134 | { |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 135 | ReaderImpl read; |
| 136 | return read.getFrusAtLocation(locationCode, nodeNumber, fruLocationCode); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 137 | } |
| 138 | |
SunnySrivastava1984 | 1356d7e | 2020-04-24 04:29:35 -0500 | [diff] [blame] | 139 | ListOfPaths |
SunnySrivastava1984 | fb5815a | 2020-04-24 08:03:52 -0500 | [diff] [blame] | 140 | Manager::getFRUsByExpandedLocationCode(const LocationCode locationCode) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 141 | { |
SunnySrivastava1984 | fb5815a | 2020-04-24 08:03:52 -0500 | [diff] [blame] | 142 | ReaderImpl read; |
| 143 | return read.getFRUsByExpandedLocationCode(locationCode, fruLocationCode); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 144 | } |
| 145 | |
SunnySrivastava1984 | fb5815a | 2020-04-24 08:03:52 -0500 | [diff] [blame] | 146 | LocationCode Manager::getExpandedLocationCode(const LocationCode locationCode, |
| 147 | const NodeNumber nodeNumber) |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 148 | { |
SunnySrivastava1984 | bca5aaa | 2020-04-21 05:31:04 -0500 | [diff] [blame] | 149 | ReaderImpl read; |
| 150 | return read.getExpandedLocationCode(locationCode, nodeNumber, |
| 151 | fruLocationCode); |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 152 | } |
SunnySrivastava1984 | de3c60d | 2020-02-03 10:34:33 -0600 | [diff] [blame] | 153 | |
SunnySrivastava1984 | b59fd09 | 2020-02-03 09:58:56 -0600 | [diff] [blame] | 154 | } // namespace manager |
| 155 | } // namespace vpd |
| 156 | } // namespace openpower |