blob: 7066f9a7d515029482cb48f6376c9d8e583a210c [file] [log] [blame]
Deepak Kodihalli8457f822016-11-29 06:05:39 -06001## 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 Kodihalli4cf89a12017-02-06 05:06:48 -060010#include <sdbusplus/server.hpp>
11#include <log.hpp>
Deepak Kodihalli8457f822016-11-29 06:05:39 -060012#include "defines.hpp"
13#include "store.hpp"
14
15namespace openpower
16{
17namespace vpd
18{
19namespace inventory
20{
21
Deepak Kodihalli4cf89a12017-02-06 05:06:48 -060022using Property = std::string;
23using Value = sdbusplus::message::variant<bool, int64_t, std::string>;
24using PropertyMap = std::map<Property, Value>;
Deepak Kodihalli8457f822016-11-29 06:05:39 -060025
Deepak Kodihalli4cf89a12017-02-06 05:06:48 -060026using Interface = std::string;
27using InterfaceMap = std::map<Interface, PropertyMap>;
28
29using Object = sdbusplus::message::object_path;
30using ObjectMap = std::map<Object, InterfaceMap>;
31
32using namespace std::string_literals;
33static const auto pimPath = "/xyz/openbmc_project/Inventory"s;
34static const auto pimIntf = "xyz.openbmc_project.Inventory.Manager"s;
35
36/** @brief Get inventory-manager's d-bus service
37 */
38auto getPIMService()
Deepak Kodihalli8457f822016-11-29 06:05:39 -060039{
Deepak Kodihalli4cf89a12017-02-06 05:06:48 -060040 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 Kodihalli8457f822016-11-29 06:05:39 -060053 {
Deepak Kodihalli4cf89a12017-02-06 05:06:48 -060054 throw std::runtime_error("ObjectMapper GetObject failed");
Deepak Kodihalli8457f822016-11-29 06:05:39 -060055 }
Deepak Kodihalli4cf89a12017-02-06 05:06:48 -060056
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
67auto 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 Kodihalli8457f822016-11-29 06:05:39 -060093
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 */
101template<Fru F>
102void 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}
109template<>
110void writeFru<Fru::${key}>(const Store& vpdStore,
111 const std::string& path)
112{
Deepak Kodihalli4cf89a12017-02-06 05:06:48 -0600113 ObjectMap objects;
114 InterfaceMap interfaces;
Deepak Kodihalli8457f822016-11-29 06:05:39 -0600115
116 // Inventory manager needs object path, list of interface names to be
117 // implemented, and property:value pairs contained in said interfaces
118
Deepak Kodihalli4cf89a12017-02-06 05:06:48 -0600119 % for interface, properties in fru.iteritems():
Deepak Kodihalli8457f822016-11-29 06:05:39 -0600120<%
Deepak Kodihalli4cf89a12017-02-06 05:06:48 -0600121 names = interface.split(".")
122 intfName = names[0] + names[-1]
Deepak Kodihalli8457f822016-11-29 06:05:39 -0600123%>\
Deepak Kodihalli4cf89a12017-02-06 05:06:48 -0600124 PropertyMap ${intfName}Props;
Deepak Kodihalli8457f822016-11-29 06:05:39 -0600125 % for name, value in properties.iteritems():
Deepak Kodihalli4cf89a12017-02-06 05:06:48 -0600126 % if fru and interface and name and value:
Deepak Kodihalli8457f822016-11-29 06:05:39 -0600127<%
128 record, keyword = value.split(",")
129%>\
Deepak Kodihalli4cf89a12017-02-06 05:06:48 -0600130 ${intfName}Props["${name}"] =
Deepak Kodihalli8457f822016-11-29 06:05:39 -0600131 vpdStore.get<Record::${record}, record::Keyword::${keyword}>();
132 % endif
133 % endfor
Deepak Kodihalli4cf89a12017-02-06 05:06:48 -0600134 interfaces.emplace("${interface}",
135 std::move(${intfName}Props));
Deepak Kodihalli8457f822016-11-29 06:05:39 -0600136 % endfor
137
Deepak Kodihalli4cf89a12017-02-06 05:06:48 -0600138 sdbusplus::message::object_path object(path);
139 objects.emplace(std::move(object), std::move(interfaces));
140
141 callPIM(std::move(objects));
Deepak Kodihalli8457f822016-11-29 06:05:39 -0600142}
143
144% endfor
145} // namespace inventory
146} // namespace vpd
147} // namespace openpower