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>
10 #include "defines.hpp"
11 #include "store.hpp"
12 #include "types.hpp"
13 #include "common_utility.hpp"
14 #include "extra-properties-gen.hpp"
15 
16 namespace openpower
17 {
18 namespace vpd
19 {
20 namespace inventory
21 {
22 using namespace openpower::vpd::common::utility;
23 
24 /** @brief API to write parsed VPD to inventory,
25  *      for a specific FRU
26  *
27  *  @param [in] vpdStore - Store object containing
28  *      parsed VPD
29  *  @param [in] path - FRU object path
30  */
31 template<Fru F>
writeFru(const Store &,const std::string &)32 void writeFru(const Store& /*vpdStore*/, const std::string& /*path*/) {
33     throw std::runtime_error("Not implemented");
34 }
35 
36 % for key in fruDict.keys():
37 <%
38     fru = fruDict[key]
39 %>\
40 // Specialization of ${key}
41 template<>
42 void writeFru<Fru::${key}>(const Store& vpdStore,
43                            const std::string& path)
44 {
45     ObjectMap objects;
46     InterfaceMap interfaces;
47     auto iter = extra::objects.find(path);
48 
49     // Inventory manager needs object path, list of interface names to be
50     // implemented, and property:value pairs contained in said interfaces
51 
52     % for interface, properties in fru.items():
53 <%
54         names = interface.split(".")
55         intfName = names[0] + names[-1]
56 %>\
57     PropertyMap ${intfName}Props;
58         % if properties:
59             % for name, value in properties.items():
60                 % if fru and interface and name and value:
61 <%
62                 record, keyword = name.split(",")
63 %>\
64     if (vpdStore.exists<Record::${record}, record::Keyword::${keyword}>())
65     {
66         ${intfName}Props["${value}"] =
67             vpdStore.get<Record::${record}, record::Keyword::${keyword}>();
68     }
69                 % endif
70             % endfor
71         % endif
72     // Check and update extra properties
73     if(extra::objects.end() != iter)
74     {
75         auto propIter = (iter->second).find("${interface}");
76         if((iter->second).end() != propIter)
77         {
78             for(const auto& map : propIter->second)
79             {
80                 ${intfName}Props[map.first] = map.second;
81             }
82         }
83     }
84     interfaces.emplace("${interface}",
85                        std::move(${intfName}Props));
86     % endfor
87 
88     sdbusplus::message::object_path object(path);
89     // Check and update extra properties
90     if(extra::objects.end() != iter)
91     {
92         for(const auto& entry : iter->second)
93         {
94             if(interfaces.end() == interfaces.find(entry.first))
95             {
96                 interfaces.emplace(entry.first, entry.second);
97             }
98         }
99     }
100     objects.emplace(std::move(object), std::move(interfaces));
101 
102     callPIM(std::move(objects));
103 }
104 
105 % endfor
106 } // namespace inventory
107 } // namespace vpd
108 } // namespace openpower
109