sdbus++: simplify enum typename usage
Now that we have a common header file for the interface enums, the
enum typename and header calculation can be significantly simplified.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I088543375824c42230c32acabc2531427904cd9e
diff --git a/tools/sdbusplus/interface.py b/tools/sdbusplus/interface.py
index e766a86..ed3e2d7 100644
--- a/tools/sdbusplus/interface.py
+++ b/tools/sdbusplus/interface.py
@@ -51,26 +51,22 @@
def enum_includes(self, inc_list):
includes = []
for e in inc_list:
- includes.extend(e.enum_headers(self.name, self.typename))
+ includes.extend(e.enum_headers(self.name))
return sorted(set(includes))
def markdown(self, loader):
return self.render(loader, "interface.md.mako", interface=self)
def server_header(self, loader):
- self.typename = "server"
return self.render(loader, "interface.server.hpp.mako", interface=self)
def server_cpp(self, loader):
- self.typename = "server"
return self.render(loader, "interface.server.cpp.mako", interface=self)
def client_header(self, loader):
- self.typename = "client"
return self.render(loader, "interface.client.hpp.mako", interface=self)
def common_header(self, loader):
- self.typename = "common"
return self.render(loader, "interface.common.hpp.mako", interface=self)
def cpp_includes(self):
diff --git a/tools/sdbusplus/namedelement.py b/tools/sdbusplus/namedelement.py
index f91815c..2f332cb 100644
--- a/tools/sdbusplus/namedelement.py
+++ b/tools/sdbusplus/namedelement.py
@@ -45,7 +45,7 @@
def old_cppNamespacedClass(self, typename="server"):
return self.old_cppNamespace(typename) + "::" + self.old_classname
- def headerFile(self, typename):
+ def headerFile(self, typename="common"):
return self.name.replace(".", "/") + f"/{typename}.hpp"
def cppNamespace(self):
diff --git a/tools/sdbusplus/property.py b/tools/sdbusplus/property.py
index a1478d7..63d7282 100644
--- a/tools/sdbusplus/property.py
+++ b/tools/sdbusplus/property.py
@@ -83,7 +83,7 @@
Currently only 'enum' requires conversion.
"""
- def cppTypeParam(self, interface, full=False, typename="server"):
+ def cppTypeParam(self, interface, full=False, typename="common"):
return self.__cppTypeParam(interface, self.cppTypeName, full, typename)
def default_value(self):
@@ -93,7 +93,7 @@
return ""
def __cppTypeParam(
- self, interface, cppTypeName, full=False, typename="server"
+ self, interface, cppTypeName, full=False, typename="common"
):
iface = NamedElement(name=interface).cppNamespacedClass()
r = cppTypeName
@@ -112,11 +112,11 @@
""" Determine the C++ header of an enumeration-type property.
"""
- def enum_headers(self, interface, typename="server"):
+ def enum_headers(self, interface):
typeTuple = self.__type_tuple()
- return self.__enum_headers(interface, typeTuple, typename)
+ return self.__enum_headers(interface, typeTuple)
- def __enum_headers(self, interface, typeTuple, typename):
+ def __enum_headers(self, interface, typeTuple):
# Enums can be processed directly.
if "enum" == typeTuple[0]:
# Get enum type from typeTuple.
@@ -127,7 +127,7 @@
return []
enumType = ".".join(enumType.split(".")[0:-1])
- return [NamedElement(name=enumType).headerFile(typename)]
+ return [NamedElement(name=enumType).headerFile()]
# If the details part of the tuple has zero entries, no enums are
# present
@@ -138,7 +138,7 @@
# them recursively.
r = []
for t in typeTuple[1]:
- r.extend(self.__enum_headers(interface, t, typename))
+ r.extend(self.__enum_headers(interface, t))
return r
""" Convert the property type into a C++ type.
@@ -267,7 +267,7 @@
if result.startswith("self."):
return result.replace("self.", self.LOCAL_ENUM_MAGIC + "::")
- # Insert place-holder for header-type namespace (ex. "server")
+ # Insert place-holder for header-type namespace (ex. "common")
result = result.split(".")
result = "::".join(
[
diff --git a/tools/sdbusplus/templates/interface.client.hpp.mako b/tools/sdbusplus/templates/interface.client.hpp.mako
index ae49f10..8c111bc 100644
--- a/tools/sdbusplus/templates/interface.client.hpp.mako
+++ b/tools/sdbusplus/templates/interface.client.hpp.mako
@@ -5,7 +5,7 @@
% for h in interface.cpp_includes():
#include <${h}>
% endfor
-#include <${interface.headerFile("common")}>
+#include <${interface.headerFile()}>
#ifndef SDBUSPP_REMOVE_DEPRECATED_NAMESPACE
namespace sdbusplus::${interface.old_cppNamespacedClass("client")}
diff --git a/tools/sdbusplus/templates/interface.server.hpp.mako b/tools/sdbusplus/templates/interface.server.hpp.mako
index 079b441..2d807fb 100644
--- a/tools/sdbusplus/templates/interface.server.hpp.mako
+++ b/tools/sdbusplus/templates/interface.server.hpp.mako
@@ -10,7 +10,7 @@
% for h in interface.cpp_includes():
#include <${h}>
% endfor
-#include <${interface.headerFile("common")}> \
+#include <${interface.headerFile()}> \
<%
def setOfPropertyTypes():
return set(p.cppTypeParam(interface.name) for p in