Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 1 | ## This file is a template. The comment below is emitted |
| 2 | ## into the rendered file; feel free to edit this file. |
| 3 | // WARNING: Generated header. Do not edit! |
| 4 | |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include <map> |
| 9 | #include <iostream> |
Deepak Kodihalli | 4cf89a1 | 2017-02-06 05:06:48 -0600 | [diff] [blame] | 10 | #include <sdbusplus/server.hpp> |
| 11 | #include <log.hpp> |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 12 | #include "defines.hpp" |
| 13 | #include "store.hpp" |
| 14 | |
| 15 | namespace openpower |
| 16 | { |
| 17 | namespace vpd |
| 18 | { |
| 19 | namespace inventory |
| 20 | { |
| 21 | |
Deepak Kodihalli | 4cf89a1 | 2017-02-06 05:06:48 -0600 | [diff] [blame] | 22 | using Property = std::string; |
| 23 | using Value = sdbusplus::message::variant<bool, int64_t, std::string>; |
| 24 | using PropertyMap = std::map<Property, Value>; |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 25 | |
Deepak Kodihalli | 4cf89a1 | 2017-02-06 05:06:48 -0600 | [diff] [blame] | 26 | using Interface = std::string; |
| 27 | using InterfaceMap = std::map<Interface, PropertyMap>; |
| 28 | |
| 29 | using Object = sdbusplus::message::object_path; |
| 30 | using ObjectMap = std::map<Object, InterfaceMap>; |
| 31 | |
| 32 | using namespace std::string_literals; |
| 33 | static const auto pimPath = "/xyz/openbmc_project/Inventory"s; |
| 34 | static const auto pimIntf = "xyz.openbmc_project.Inventory.Manager"s; |
| 35 | |
| 36 | /** @brief Get inventory-manager's d-bus service |
| 37 | */ |
| 38 | auto getPIMService() |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 39 | { |
Deepak Kodihalli | 4cf89a1 | 2017-02-06 05:06:48 -0600 | [diff] [blame] | 40 | auto bus = sdbusplus::bus::new_default(); |
| 41 | auto mapper = |
| 42 | bus.new_method_call( |
| 43 | "xyz.openbmc_project.ObjectMapper", |
| 44 | "/xyz/openbmc_project/ObjectMapper", |
| 45 | "xyz.openbmc_project.ObjectMapper", |
| 46 | "GetObject"); |
| 47 | |
| 48 | mapper.append(pimPath); |
| 49 | mapper.append(std::vector<std::string>({pimIntf})); |
| 50 | |
| 51 | auto result = bus.call(mapper); |
| 52 | if(result.is_method_error()) |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 53 | { |
Deepak Kodihalli | 4cf89a1 | 2017-02-06 05:06:48 -0600 | [diff] [blame] | 54 | throw std::runtime_error("ObjectMapper GetObject failed"); |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 55 | } |
Deepak Kodihalli | 4cf89a1 | 2017-02-06 05:06:48 -0600 | [diff] [blame] | 56 | |
| 57 | std::map<std::string, std::vector<std::string>> response; |
| 58 | result.read(response); |
| 59 | if(response.empty()) |
| 60 | { |
| 61 | throw std::runtime_error("ObjectMapper GetObject bad response"); |
| 62 | } |
| 63 | |
| 64 | return response.begin()->first; |
| 65 | } |
| 66 | |
| 67 | auto callPIM(ObjectMap&& objects) |
| 68 | { |
| 69 | std::string service; |
| 70 | |
| 71 | try |
| 72 | { |
| 73 | service = getPIMService(); |
| 74 | auto bus = sdbusplus::bus::new_default(); |
| 75 | auto pimMsg = bus.new_method_call( |
| 76 | service.c_str(), |
| 77 | pimPath.c_str(), |
| 78 | pimIntf.c_str(), |
| 79 | "Notify"); |
| 80 | pimMsg.append(std::move(objects)); |
| 81 | auto result = bus.call(pimMsg); |
| 82 | if(result.is_method_error()) |
| 83 | { |
| 84 | std::cerr << "PIM Notify() failed\n"; |
| 85 | } |
| 86 | } |
| 87 | catch (const std::runtime_error& e) |
| 88 | { |
| 89 | using namespace phosphor::logging; |
| 90 | log<level::ERR>(e.what()); |
| 91 | } |
| 92 | } |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 93 | |
| 94 | /** @brief API to write parsed VPD to inventory, |
| 95 | * for a specifc FRU |
| 96 | * |
| 97 | * @param [in] vpdStore - Store object containing |
| 98 | * parsed VPD |
| 99 | * @param [in] path - FRU object path |
| 100 | */ |
| 101 | template<Fru F> |
| 102 | void writeFru(const Store& vpdStore, const std::string& path); |
| 103 | |
| 104 | % for key in fruDict.iterkeys(): |
| 105 | <% |
| 106 | fru = fruDict[key] |
| 107 | %>\ |
| 108 | // Specialization of ${key} |
| 109 | template<> |
| 110 | void writeFru<Fru::${key}>(const Store& vpdStore, |
| 111 | const std::string& path) |
| 112 | { |
Deepak Kodihalli | 4cf89a1 | 2017-02-06 05:06:48 -0600 | [diff] [blame] | 113 | ObjectMap objects; |
| 114 | InterfaceMap interfaces; |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 115 | |
| 116 | // Inventory manager needs object path, list of interface names to be |
| 117 | // implemented, and property:value pairs contained in said interfaces |
| 118 | |
Deepak Kodihalli | 4cf89a1 | 2017-02-06 05:06:48 -0600 | [diff] [blame] | 119 | % for interface, properties in fru.iteritems(): |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 120 | <% |
Deepak Kodihalli | 4cf89a1 | 2017-02-06 05:06:48 -0600 | [diff] [blame] | 121 | names = interface.split(".") |
| 122 | intfName = names[0] + names[-1] |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 123 | %>\ |
Deepak Kodihalli | 4cf89a1 | 2017-02-06 05:06:48 -0600 | [diff] [blame] | 124 | PropertyMap ${intfName}Props; |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 125 | % for name, value in properties.iteritems(): |
Deepak Kodihalli | 4cf89a1 | 2017-02-06 05:06:48 -0600 | [diff] [blame] | 126 | % if fru and interface and name and value: |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 127 | <% |
| 128 | record, keyword = value.split(",") |
| 129 | %>\ |
Deepak Kodihalli | 4cf89a1 | 2017-02-06 05:06:48 -0600 | [diff] [blame] | 130 | ${intfName}Props["${name}"] = |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 131 | vpdStore.get<Record::${record}, record::Keyword::${keyword}>(); |
| 132 | % endif |
| 133 | % endfor |
Deepak Kodihalli | 4cf89a1 | 2017-02-06 05:06:48 -0600 | [diff] [blame] | 134 | interfaces.emplace("${interface}", |
| 135 | std::move(${intfName}Props)); |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 136 | % endfor |
| 137 | |
Deepak Kodihalli | 4cf89a1 | 2017-02-06 05:06:48 -0600 | [diff] [blame] | 138 | sdbusplus::message::object_path object(path); |
| 139 | objects.emplace(std::move(object), std::move(interfaces)); |
| 140 | |
| 141 | callPIM(std::move(objects)); |
Deepak Kodihalli | 8457f82 | 2016-11-29 06:05:39 -0600 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | % endfor |
| 145 | } // namespace inventory |
| 146 | } // namespace vpd |
| 147 | } // namespace openpower |