1 ## This file is a template.  The comment below is emitted
2 ## into the rendered file; feel free to edit this file.
3 // !!! WARNING: This is a GENERATED Code..Please do NOT Edit !!!
4 <%
5 interfaceDict = {}
6 sensorNameMaxLength = 16
7 %>\
8 %for key in sensorDict.keys():
9 <%
10     sensor = sensorDict[key]
11     serviceInterface = sensor["serviceInterface"]
12     if serviceInterface == "org.freedesktop.DBus.Properties":
13         updateFunc = "set::"
14         getFunc = "get::"
15     elif serviceInterface == "xyz.openbmc_project.Inventory.Manager":
16         updateFunc = "notify::"
17         getFunc = "inventory::get::"
18     else:
19         assert "Un-supported interface: " + serviceInterface
20     endif
21     if serviceInterface not in interfaceDict:
22         interfaceDict[serviceInterface] = {}
23         interfaceDict[serviceInterface]["updateFunc"] = updateFunc
24         interfaceDict[serviceInterface]["getFunc"] = getFunc
25 %>\
26 % endfor
27 
28 #include "sensordatahandler.hpp"
29 
30 #include <ipmid/types.hpp>
31 
32 namespace ipmi {
33 namespace sensor {
34 
35 extern const IdInfoMap __attribute__((init_priority(101))) sensors = {
36 % for key in sensorDict.keys():
37    % if key:
38 {${key},{
39 <%
40        sensor = sensorDict[key]
41        interfaces = sensor["interfaces"]
42        path = sensor["path"]
43        serviceInterface = sensor["serviceInterface"]
44        sensorType = sensor["sensorType"]
45        entityID = sensor.get("entityID", 0)
46        instance = sensor.get("entityInstance", 0)
47        readingType = sensor["sensorReadingType"]
48        multiplier = sensor.get("multiplierM", 1)
49        offsetB = sensor.get("offsetB", 0)
50        bExp = sensor.get("bExp", 0)
51        rExp = sensor.get("rExp", 0)
52        sensorUnits1 = sensor.get("sensorUnits1", 0)
53        unit = sensor.get("unit", "")
54        scale = sensor.get("scale", 0)
55        hasScale = "true" if "scale" in sensor.keys() else "false"
56        valueReadingType = sensor["readingType"]
57        updateFunc = interfaceDict[serviceInterface]["updateFunc"]
58        updateFunc += sensor["readingType"]
59        getFunc = interfaceDict[serviceInterface]["getFunc"]
60        getFunc += sensor["readingType"]
61        sensorName = sensor.get("sensorName", None)
62        if sensorName:
63            assert len(sensorName) <= sensorNameMaxLength, \
64                    "sensor name '%s' is too long (%d bytes max)" % \
65                    (sensorName, sensorNameMaxLength)
66        else:
67            sensorNameFunc = "get::" + sensor.get("sensorNamePattern",
68                    "nameLeaf")
69 
70        if "readingAssertion" == valueReadingType or "readingData" == valueReadingType:
71            for interface,properties in interfaces.items():
72                for dbus_property,property_value in properties.items():
73                    for offset,values in property_value["Offsets"].items():
74                        valueType = values["type"]
75            updateFunc = "set::" + valueReadingType + "<" + valueType + ">"
76            getFunc = "get::" + valueReadingType + "<" + valueType + ">"
77        sensorInterface = serviceInterface
78        if serviceInterface == "org.freedesktop.DBus.Properties":
79            sensorInterface = next(iter(interfaces))
80        mutability = sensor.get("mutability", "Mutability::Read")
81 %>
82         .entityType = ${entityID},
83         .instance = ${instance},
84         .sensorType = ${sensorType},
85         .sensorPath = "${path}",
86         .sensorInterface = "${sensorInterface}",
87         .sensorReadingType = ${readingType},
88         .coefficientM = ${multiplier},
89         .coefficientB = ${offsetB},
90         .exponentB = ${bExp},
91         .scaledOffset = ${offsetB * pow(10,bExp)},
92         .exponentR = ${rExp},
93         .hasScale = ${hasScale},
94         .scale = ${scale},
95         .sensorUnits1 = ${sensorUnits1},
96         .unit = "${unit}",
97         .updateFunc = ${updateFunc},
98         .getFunc = ${getFunc},
99         .mutability = Mutability(${mutability}),
100     % if sensorName:
101         .sensorName = "${sensorName}",
102         .sensorNameFunc = nullptr,
103     % else:
104         .sensorName = "",
105         .sensorNameFunc = ${sensorNameFunc},
106     % endif
107         .propertyInterfaces = {
108     % for interface,properties in interfaces.items():
109             {"${interface}",{
110             % if properties:
111                 % for dbus_property,property_value in properties.items():
112                     {"${dbus_property}",{
113 <%
114 try:
115     preReq = property_value["Prereqs"]
116 except KeyError:
117     preReq = dict()
118 %>\
119                     {
120                         % for preOffset,preValues in preReq.items():
121                         { ${preOffset},{
122                             % for name,value in preValues.items():
123                                 % if name == "type":
124 <%                              continue %>\
125                                 % endif
126 <%                          value = str(value).lower() %>\
127                                 ${value},
128                             % endfor
129                             }
130                         },
131                         % endfor
132                     },
133                     {
134                     % for offset,values in property_value["Offsets"].items():
135                         { ${offset},{
136                             % if offset == 0xFF:
137                                 }},
138 <%                          continue %>\
139                             % endif
140 <%                          valueType = values["type"] %>\
141 <%
142 try:
143     skip = values["skipOn"]
144     if skip == "assert":
145         skipVal = "SkipAssertion::ASSERT"
146     elif skip == "deassert":
147         skipVal = "SkipAssertion::DEASSERT"
148     else:
149         assert "Unknown skip value " + str(skip)
150 except KeyError:
151     skipVal = "SkipAssertion::NONE"
152 %>\
153                                 ${skipVal},
154                         % for name,value in values.items():
155                             % if name == "type" or name == "skipOn":
156 <%                          continue %>\
157                             % endif
158                             % if valueType == "string":
159                             std::string("${value}"),
160                             % elif valueType == "bool":
161 <%                         value = str(value).lower() %>\
162                             ${value},
163                             % else:
164                             ${value},
165                             % endif
166                         % endfor
167                             }
168                         },
169                     % endfor
170                     }}},
171                 % endfor
172             % endif
173             }},
174     % endfor
175      },
176 }},
177    % endif
178 % endfor
179 };
180 
181 } // namespace sensor
182 } // namespace ipmi
183