1*8457f821SDeepak Kodihalli ## This file is a template.  The comment below is emitted
2*8457f821SDeepak Kodihalli ## into the rendered file; feel free to edit this file.
3*8457f821SDeepak Kodihalli // WARNING: Generated header. Do not edit!
4*8457f821SDeepak Kodihalli 
5*8457f821SDeepak Kodihalli 
6*8457f821SDeepak Kodihalli #pragma once
7*8457f821SDeepak Kodihalli 
8*8457f821SDeepak Kodihalli #include <map>
9*8457f821SDeepak Kodihalli #include <iostream>
10*8457f821SDeepak Kodihalli #include "defines.hpp"
11*8457f821SDeepak Kodihalli #include "store.hpp"
12*8457f821SDeepak Kodihalli 
13*8457f821SDeepak Kodihalli namespace openpower
14*8457f821SDeepak Kodihalli {
15*8457f821SDeepak Kodihalli namespace vpd
16*8457f821SDeepak Kodihalli {
17*8457f821SDeepak Kodihalli namespace inventory
18*8457f821SDeepak Kodihalli {
19*8457f821SDeepak Kodihalli 
20*8457f821SDeepak Kodihalli using Inner = Parsed::mapped_type;
21*8457f821SDeepak Kodihalli using Outer = std::map<std::string, Inner>;
22*8457f821SDeepak Kodihalli 
23*8457f821SDeepak Kodihalli // TODO: Remove once the call to inventory manager is added
24*8457f821SDeepak Kodihalli auto print = [](Outer&& object, const std::string& path)
25*8457f821SDeepak Kodihalli {
26*8457f821SDeepak Kodihalli     std::cout << "\n";
27*8457f821SDeepak Kodihalli     std::cout << path << "\n";
28*8457f821SDeepak Kodihalli     std::cout << "\n";
29*8457f821SDeepak Kodihalli     for(const auto& o : object)
30*8457f821SDeepak Kodihalli     {
31*8457f821SDeepak Kodihalli         std::cout << o.first << "\n";
32*8457f821SDeepak Kodihalli         for(const auto& i : o.second)
33*8457f821SDeepak Kodihalli         {
34*8457f821SDeepak Kodihalli             std::cout << i.first << " : " << i.second << "\n";
35*8457f821SDeepak Kodihalli         }
36*8457f821SDeepak Kodihalli         std::cout << "\n";
37*8457f821SDeepak Kodihalli     }
38*8457f821SDeepak Kodihalli };
39*8457f821SDeepak Kodihalli 
40*8457f821SDeepak Kodihalli /** @brief API to write parsed VPD to inventory,
41*8457f821SDeepak Kodihalli  *      for a specifc FRU
42*8457f821SDeepak Kodihalli  *
43*8457f821SDeepak Kodihalli  *  @param [in] vpdStore - Store object containing
44*8457f821SDeepak Kodihalli  *      parsed VPD
45*8457f821SDeepak Kodihalli  *  @param [in] path - FRU object path
46*8457f821SDeepak Kodihalli  */
47*8457f821SDeepak Kodihalli template<Fru F>
48*8457f821SDeepak Kodihalli void writeFru(const Store& vpdStore, const std::string& path);
49*8457f821SDeepak Kodihalli 
50*8457f821SDeepak Kodihalli % for key in fruDict.iterkeys():
51*8457f821SDeepak Kodihalli <%
52*8457f821SDeepak Kodihalli     fru = fruDict[key]
53*8457f821SDeepak Kodihalli %>\
54*8457f821SDeepak Kodihalli // Specialization of ${key}
55*8457f821SDeepak Kodihalli template<>
56*8457f821SDeepak Kodihalli void writeFru<Fru::${key}>(const Store& vpdStore,
57*8457f821SDeepak Kodihalli                            const std::string& path)
58*8457f821SDeepak Kodihalli {
59*8457f821SDeepak Kodihalli     Outer object;
60*8457f821SDeepak Kodihalli 
61*8457f821SDeepak Kodihalli     // Inventory manager needs object path, list of interface names to be
62*8457f821SDeepak Kodihalli     // implemented, and property:value pairs contained in said interfaces
63*8457f821SDeepak Kodihalli 
64*8457f821SDeepak Kodihalli     % for interfaces, properties in fru.iteritems():
65*8457f821SDeepak Kodihalli <%
66*8457f821SDeepak Kodihalli         interface = interfaces.split(".")
67*8457f821SDeepak Kodihalli         intfName = interface[0] + interface[-1]
68*8457f821SDeepak Kodihalli %>\
69*8457f821SDeepak Kodihalli     Inner ${intfName};
70*8457f821SDeepak Kodihalli         % for name, value in properties.iteritems():
71*8457f821SDeepak Kodihalli             % if fru and interfaces and name and value:
72*8457f821SDeepak Kodihalli <%
73*8457f821SDeepak Kodihalli                 record, keyword = value.split(",")
74*8457f821SDeepak Kodihalli %>\
75*8457f821SDeepak Kodihalli     ${intfName}["${name}"] =
76*8457f821SDeepak Kodihalli         vpdStore.get<Record::${record}, record::Keyword::${keyword}>();
77*8457f821SDeepak Kodihalli             % endif
78*8457f821SDeepak Kodihalli         % endfor
79*8457f821SDeepak Kodihalli     object.emplace("${interfaces}",
80*8457f821SDeepak Kodihalli                    std::move(${intfName}));
81*8457f821SDeepak Kodihalli     % endfor
82*8457f821SDeepak Kodihalli 
83*8457f821SDeepak Kodihalli     // TODO: Need integration with inventory manager, print serialized dbus
84*8457f821SDeepak Kodihalli     // object for now.
85*8457f821SDeepak Kodihalli     print(std::move(object), path);
86*8457f821SDeepak Kodihalli }
87*8457f821SDeepak Kodihalli 
88*8457f821SDeepak Kodihalli % endfor
89*8457f821SDeepak Kodihalli } // namespace inventory
90*8457f821SDeepak Kodihalli } // namespace vpd
91*8457f821SDeepak Kodihalli } // namespace openpower
92