sdbus++: fix enumeration property default values
Current generation emits for enumerations:
Enum property = EnumValue
Fix this to be:
Enum property = Enum::EnumValue
Change-Id: Iae1e8e4ad73bf8623ed9f3b2d3ec57803c7f18bd
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/tools/sdbusplus/property.py b/tools/sdbusplus/property.py
index bcb50d9..0297e79 100644
--- a/tools/sdbusplus/property.py
+++ b/tools/sdbusplus/property.py
@@ -11,11 +11,18 @@
super(Property, self).__init__(**kwargs)
+ def is_enum(self):
+ if not self.cppTypeName:
+ return False
+ if self.cppTypeName.startswith("enum<"):
+ return True
+ return False
+
""" Return a conversion of the cppTypeName valid as a function parameter.
Currently only 'enum' requires conversion.
"""
def cppTypeParam(self, interface, server=True):
- if self.cppTypeName.startswith("enum<"):
+ if self.is_enum():
# strip off 'enum<' and '>'
r = self.cppTypeName.split('>')[0].split('<')[1]
@@ -33,7 +40,7 @@
message. Currently only 'enum' requires conversion.
"""
def cppTypeMessage(self, interface):
- if self.cppTypeName.startswith("enum<"):
+ if self.is_enum():
return "std::string"
return self.cppTypeName
diff --git a/tools/sdbusplus/templates/interface.mako.server.hpp b/tools/sdbusplus/templates/interface.mako.server.hpp
index 5a67a43..1fab15b 100644
--- a/tools/sdbusplus/templates/interface.mako.server.hpp
+++ b/tools/sdbusplus/templates/interface.mako.server.hpp
@@ -88,7 +88,11 @@
% for p in interface.properties:
% if p.defaultValue:
- ${p.cppTypeParam(interface.name)} _${p.camelCase} = ${p.defaultValue};
+ ${p.cppTypeParam(interface.name)} _${p.camelCase} = \
+ % if p.is_enum():
+${p.cppTypeParam(interface.name)}::\
+ % endif
+${p.defaultValue};
% else:
${p.cppTypeParam(interface.name)} _${p.camelCase}{};
% endif