18457f821SDeepak Kodihalli ## This file is a template.  The comment below is emitted
28457f821SDeepak Kodihalli ## into the rendered file; feel free to edit this file.
38457f821SDeepak Kodihalli // WARNING: Generated header. Do not edit!
48457f821SDeepak Kodihalli 
58457f821SDeepak Kodihalli 
68457f821SDeepak Kodihalli #pragma once
78457f821SDeepak Kodihalli 
88457f821SDeepak Kodihalli #include <map>
98457f821SDeepak Kodihalli #include <iostream>
108457f821SDeepak Kodihalli #include "defines.hpp"
118457f821SDeepak Kodihalli #include "store.hpp"
1276794495SDeepak Kodihalli #include "types.hpp"
1376794495SDeepak Kodihalli #include "utils.hpp"
14128512b2SDeepak Kodihalli #include "extra-properties-gen.hpp"
158457f821SDeepak Kodihalli 
168457f821SDeepak Kodihalli namespace openpower
178457f821SDeepak Kodihalli {
188457f821SDeepak Kodihalli namespace vpd
198457f821SDeepak Kodihalli {
208457f821SDeepak Kodihalli namespace inventory
218457f821SDeepak Kodihalli {
228457f821SDeepak Kodihalli 
238457f821SDeepak Kodihalli /** @brief API to write parsed VPD to inventory,
248457f821SDeepak Kodihalli  *      for a specifc FRU
258457f821SDeepak Kodihalli  *
268457f821SDeepak Kodihalli  *  @param [in] vpdStore - Store object containing
278457f821SDeepak Kodihalli  *      parsed VPD
288457f821SDeepak Kodihalli  *  @param [in] path - FRU object path
298457f821SDeepak Kodihalli  */
308457f821SDeepak Kodihalli template<Fru F>
318457f821SDeepak Kodihalli void writeFru(const Store& vpdStore, const std::string& path);
328457f821SDeepak Kodihalli 
338457f821SDeepak Kodihalli % for key in fruDict.iterkeys():
348457f821SDeepak Kodihalli <%
358457f821SDeepak Kodihalli     fru = fruDict[key]
368457f821SDeepak Kodihalli %>\
378457f821SDeepak Kodihalli // Specialization of ${key}
388457f821SDeepak Kodihalli template<>
398457f821SDeepak Kodihalli void writeFru<Fru::${key}>(const Store& vpdStore,
408457f821SDeepak Kodihalli                            const std::string& path)
418457f821SDeepak Kodihalli {
424cf89a10SDeepak Kodihalli     ObjectMap objects;
434cf89a10SDeepak Kodihalli     InterfaceMap interfaces;
440cc20121SDeepak Kodihalli     auto iter = extra::objects.find(path);
458457f821SDeepak Kodihalli 
468457f821SDeepak Kodihalli     // Inventory manager needs object path, list of interface names to be
478457f821SDeepak Kodihalli     // implemented, and property:value pairs contained in said interfaces
488457f821SDeepak Kodihalli 
494cf89a10SDeepak Kodihalli     % for interface, properties in fru.iteritems():
508457f821SDeepak Kodihalli <%
514cf89a10SDeepak Kodihalli         names = interface.split(".")
524cf89a10SDeepak Kodihalli         intfName = names[0] + names[-1]
538457f821SDeepak Kodihalli %>\
544cf89a10SDeepak Kodihalli     PropertyMap ${intfName}Props;
558457f821SDeepak Kodihalli         % for name, value in properties.iteritems():
564cf89a10SDeepak Kodihalli             % if fru and interface and name and value:
578457f821SDeepak Kodihalli <%
58*db12d763SDeepak Kodihalli                 record, keyword = name.split(",")
598457f821SDeepak Kodihalli %>\
60*db12d763SDeepak Kodihalli     if (vpdStore.exists<Record::${record}, record::Keyword::${keyword}>())
61*db12d763SDeepak Kodihalli     {
62*db12d763SDeepak Kodihalli         ${intfName}Props["${value}"] =
638457f821SDeepak Kodihalli             vpdStore.get<Record::${record}, record::Keyword::${keyword}>();
64*db12d763SDeepak Kodihalli     }
658457f821SDeepak Kodihalli             % endif
668457f821SDeepak Kodihalli         % endfor
670cc20121SDeepak Kodihalli     // Check and update extra properties
680cc20121SDeepak Kodihalli     if(extra::objects.end() != iter)
690cc20121SDeepak Kodihalli     {
700cc20121SDeepak Kodihalli         auto propIter = (iter->second).find("${interface}");
710cc20121SDeepak Kodihalli         if((iter->second).end() != propIter)
720cc20121SDeepak Kodihalli         {
730cc20121SDeepak Kodihalli             for(const auto& map : propIter->second)
740cc20121SDeepak Kodihalli             {
750cc20121SDeepak Kodihalli                 ${intfName}Props[map.first] = map.second;
760cc20121SDeepak Kodihalli             }
770cc20121SDeepak Kodihalli         }
780cc20121SDeepak Kodihalli     }
794cf89a10SDeepak Kodihalli     interfaces.emplace("${interface}",
804cf89a10SDeepak Kodihalli                        std::move(${intfName}Props));
818457f821SDeepak Kodihalli     % endfor
828457f821SDeepak Kodihalli 
834cf89a10SDeepak Kodihalli     sdbusplus::message::object_path object(path);
84128512b2SDeepak Kodihalli     // Check and update extra properties
850cc20121SDeepak Kodihalli     if(extra::objects.end() != iter)
86128512b2SDeepak Kodihalli     {
870cc20121SDeepak Kodihalli         for(const auto& entry : iter->second)
880cc20121SDeepak Kodihalli         {
890cc20121SDeepak Kodihalli             if(interfaces.end() == interfaces.find(entry.first))
90128512b2SDeepak Kodihalli             {
91128512b2SDeepak Kodihalli                 interfaces.emplace(entry.first, entry.second);
92128512b2SDeepak Kodihalli             }
93128512b2SDeepak Kodihalli         }
940cc20121SDeepak Kodihalli     }
954cf89a10SDeepak Kodihalli     objects.emplace(std::move(object), std::move(interfaces));
964cf89a10SDeepak Kodihalli 
974cf89a10SDeepak Kodihalli     callPIM(std::move(objects));
988457f821SDeepak Kodihalli }
998457f821SDeepak Kodihalli 
1008457f821SDeepak Kodihalli % endfor
1018457f821SDeepak Kodihalli } // namespace inventory
1028457f821SDeepak Kodihalli } // namespace vpd
1038457f821SDeepak Kodihalli } // namespace openpower
104