From 9a5b6994c745480a78ef658148cfd96dd3e12bdb Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Tue, 23 Jan 2018 15:32:26 -0600 Subject: Support properties of type string Properties used within set speed events may be of type string to trigger an action. These should be handled where the defined type attribute is given as 'std::string' and a parsed value is an instance of python str type. Resolves openbmc/openbmc#292 Change-Id: Ib188e7abc212062a1c61950abaa28434a4726521 Signed-off-by: Matthew Barth --- control/gen-fan-zone-defs.py | 36 +++++++++++++++++++++++++++++------- control/types.hpp | 4 +++- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/control/gen-fan-zone-defs.py b/control/gen-fan-zone-defs.py index c071aea..1568137 100755 --- a/control/gen-fan-zone-defs.py +++ b/control/gen-fan-zone-defs.py @@ -243,6 +243,7 @@ def convertToMap(listOfDict): """ Converts a list of dictionary entries to a std::map initialization list. """ + listOfDict = listOfDict.replace('\'', '\"') listOfDict = listOfDict.replace('[', '{') listOfDict = listOfDict.replace(']', '}') listOfDict = listOfDict.replace(':', ',') @@ -285,9 +286,15 @@ def getActions(edata, actions, events): param += ")," param += "}" elif p == 'property': - param += ( - str(edata['property']['type']).lower() + - ">(" + str(eActions[p]).lower() + ")") + if isinstance(eActions[p], str) or \ + "string" in str(edata['property']['type']).lower(): + param += ( + str(edata['property']['type']).lower() + + ">(\"" + str(eActions[p]) + "\")") + else: + param += ( + str(edata['property']['type']).lower() + + ">(" + str(eActions[p]).lower() + ")") else: # Default type to 'size_t' when not given param += ("size_t>(" + str(eActions[p]).lower() + ")") @@ -301,7 +308,13 @@ def getActions(edata, actions, events): else: param += (str(eActions[p]['type']).lower() + ">(") if p != 'map': - param += str(eActions[p]['value']).lower() + ")" + if isinstance(eActions[p]['value'], str) or \ + "string" in str(eActions[p]['type']).lower(): + param += \ + "\"" + str(eActions[p]['value']) + "\")" + else: + param += \ + str(eActions[p]['value']).lower() + ")" else: param += ( str(eActions[p]['type']).lower() + @@ -458,7 +471,11 @@ def addPrecondition(zNum, zCond, event, events_data): members['interface'] = grp['interface'] members['property'] = grp['property']['name'] members['type'] = grp['property']['type'] - members['value'] = grp['property']['value'] + if isinstance(grp['property']['value'], str) or \ + "string" in str(members['type']).lower(): + members['value'] = "\"" + grp['property']['value'] + "\"" + else: + members['value'] = grp['property']['value'] group.append(members) precond['pcgrp'] = group @@ -484,8 +501,13 @@ def addPrecondition(zNum, zCond, event, events_data): str(pcgrp['interface']) + "\",\"" + str(pcgrp['property']) + "\"," + "static_cast<" + - str(pcgrp['type']).lower() + ">" + - "(" + str(pcgrp['value']).lower() + ")}") + str(pcgrp['type']).lower() + ">") + if isinstance(pcgrp['value'], str) or \ + "string" in str(pcgrp['type']).lower(): + value['value'] += ("(" + str(pcgrp['value']) + ")}") + else: + value['value'] += \ + ("(" + str(pcgrp['value']).lower() + ")}") values.append(value) param['values'] = values params.append(param) diff --git a/control/types.hpp b/control/types.hpp index b0b84f3..f7b75aa 100644 --- a/control/types.hpp +++ b/control/types.hpp @@ -30,7 +30,9 @@ constexpr auto conditionPropertyListPos = 1; using Condition = std::tuple>; -using PropertyVariantType = sdbusplus::message::variant; +using PropertyVariantType = sdbusplus::message::variant; constexpr auto fanNamePos = 0; constexpr auto sensorListPos = 1; -- cgit v1.2.1