sdbus++: server: simplify header include templates
There are various callbacks within the mako templates for methods,
properties, and signals. This makes the mako template fairly difficult
to read (since there are big if-else trees for each callback type),
impossible to reuse, and poorer performing. Eliminate the
`callback-hpp-includes` type and move the code into Python directly.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Id51f9a78bc57b718732172a3b6634f33740afd09
diff --git a/tools/sdbusplus/interface.py b/tools/sdbusplus/interface.py
index fd5cccb..ce740a8 100644
--- a/tools/sdbusplus/interface.py
+++ b/tools/sdbusplus/interface.py
@@ -58,3 +58,12 @@
def common_header(self, loader):
self.typename = "common"
return self.render(loader, "interface.common.hpp.mako", interface=self)
+
+ def cpp_includes(self):
+ return set.union(
+ set(),
+ *[
+ set(m.cpp_includes(self))
+ for m in self.methods + self.properties + self.signals
+ ]
+ )
diff --git a/tools/sdbusplus/method.py b/tools/sdbusplus/method.py
index bb8460c..6bc76b4 100644
--- a/tools/sdbusplus/method.py
+++ b/tools/sdbusplus/method.py
@@ -26,6 +26,9 @@
post=str.rstrip,
)
+ def cpp_includes(self, interface):
+ return interface.enum_includes(self.returns + self.parameters)
+
def returns_as_list(self, interface, full=False):
return ", ".join(
[r.cppTypeParam(interface.name, full=full) for r in self.returns]
diff --git a/tools/sdbusplus/property.py b/tools/sdbusplus/property.py
index 58b92f9..9ac86fb 100644
--- a/tools/sdbusplus/property.py
+++ b/tools/sdbusplus/property.py
@@ -304,6 +304,9 @@
post=str.rstrip,
)
+ def cpp_includes(self, interface):
+ return interface.enum_includes([self])
+
def or_cpp_flags(self, flags):
"""Return the corresponding ORed cpp flags."""
flags_dict = {
diff --git a/tools/sdbusplus/signal.py b/tools/sdbusplus/signal.py
index 51d3abc..4dcba7f 100644
--- a/tools/sdbusplus/signal.py
+++ b/tools/sdbusplus/signal.py
@@ -21,3 +21,6 @@
ptype=ptype,
post=str.rstrip,
)
+
+ def cpp_includes(self, interface):
+ return interface.enum_includes(self.properties)
diff --git a/tools/sdbusplus/templates/interface.server.hpp.mako b/tools/sdbusplus/templates/interface.server.hpp.mako
index 3ba5224..6e5691d 100644
--- a/tools/sdbusplus/templates/interface.server.hpp.mako
+++ b/tools/sdbusplus/templates/interface.server.hpp.mako
@@ -7,8 +7,8 @@
#include <string>
#include <systemd/sd-bus.h>
-% for m in interface.methods + interface.properties + interface.signals:
-${ m.cpp_prototype(loader, interface=interface, ptype='callback-hpp-includes') }
+% for h in interface.cpp_includes():
+#include <${h}>
% endfor
#include <${interface.headerFile("common")}> \
<%
diff --git a/tools/sdbusplus/templates/method.prototype.hpp.mako b/tools/sdbusplus/templates/method.prototype.hpp.mako
index 16f0312..569bf2c 100644
--- a/tools/sdbusplus/templates/method.prototype.hpp.mako
+++ b/tools/sdbusplus/templates/method.prototype.hpp.mako
@@ -118,8 +118,4 @@
% for e in method.errors:
#include <${error_include(e)}>
% endfor
- % elif ptype == 'callback-hpp-includes':
- % for i in interface.enum_includes(method.returns + method.parameters):
-#include <${i}>
- % endfor
% endif
diff --git a/tools/sdbusplus/templates/property.prototype.hpp.mako b/tools/sdbusplus/templates/property.prototype.hpp.mako
index 48692db..86cd8dd 100644
--- a/tools/sdbusplus/templates/property.prototype.hpp.mako
+++ b/tools/sdbusplus/templates/property.prototype.hpp.mako
@@ -114,8 +114,4 @@
% for e in property.errors:
#include <${error_include(e)}>
% endfor
-% elif ptype == 'callback-hpp-includes':
- % for i in interface.enum_includes([property]):
-#include <${i}>
- % endfor
% endif
diff --git a/tools/sdbusplus/templates/signal.prototype.hpp.mako b/tools/sdbusplus/templates/signal.prototype.hpp.mako
index b0bd891..78c838c 100644
--- a/tools/sdbusplus/templates/signal.prototype.hpp.mako
+++ b/tools/sdbusplus/templates/signal.prototype.hpp.mako
@@ -73,8 +73,4 @@
% endif
}
}
- % elif ptype == 'callback-hpp-includes':
- % for i in interface.enum_includes(signal.properties):
-#include <${i}>
- % endfor
% endif