sdbus++: simplify namespace generation
Use nested namespaces in the server interface definitions to
simplify the mako template.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I6f17dd4069c818f9836cd47eb56926adeaa41b6e
diff --git a/tools/sdbusplus/interface.py b/tools/sdbusplus/interface.py
index 3f6d9b3..9f85f03 100644
--- a/tools/sdbusplus/interface.py
+++ b/tools/sdbusplus/interface.py
@@ -35,7 +35,10 @@
self.classname = self.namespaces.pop()
def cppNamespace(self):
- return "::".join(self.namespaces) + "::server::" + self.classname
+ return "::".join(self.namespaces) + "::server"
+
+ def cppNamespacedClass(self):
+ return self.cppNamespace() + "::" + self.classname
def enum_includes(self, inc_list):
includes = []
diff --git a/tools/sdbusplus/templates/interface.server.cpp.mako b/tools/sdbusplus/templates/interface.server.cpp.mako
index 94f5040..fe91780 100644
--- a/tools/sdbusplus/templates/interface.server.cpp.mako
+++ b/tools/sdbusplus/templates/interface.server.cpp.mako
@@ -18,13 +18,7 @@
def interface_instance():
return "_".join(interface.name.split('.') + ['interface'])
%>
-namespace sdbusplus
-{
- % for s in namespaces:
-namespace ${s}
-{
- % endfor
-namespace server
+namespace sdbusplus::${interface.cppNamespace()}
{
${classname}::${classname}(bus_t& bus, const char* path)
@@ -175,8 +169,4 @@
vtable::end()
};
-} // namespace server
- % for s in reversed(namespaces):
-} // namespace ${s}
- % endfor
-} // namespace sdbusplus
+} // namespace sdbusplus::${interface.cppNamespace()}
diff --git a/tools/sdbusplus/templates/interface.server.hpp.mako b/tools/sdbusplus/templates/interface.server.hpp.mako
index 234fff8..771c6ac 100644
--- a/tools/sdbusplus/templates/interface.server.hpp.mako
+++ b/tools/sdbusplus/templates/interface.server.hpp.mako
@@ -20,13 +20,7 @@
interface.properties);
%>
-namespace sdbusplus
-{
- % for s in namespaces:
-namespace ${s}
-{
- % endfor
-namespace server
+namespace sdbusplus::${interface.cppNamespace()}
{
class ${classname}
@@ -208,31 +202,27 @@
}
% endfor
-} // namespace server
- % for s in reversed(namespaces):
-} // namespace ${s}
- % endfor
+} // namespace sdbusplus::${interface.cppNamespace()}
-namespace message::details
+namespace sdbusplus::message::details
{
% for e in interface.enums:
template <>
-struct convert_from_string<${interface.cppNamespace()}::${e.name}>
+struct convert_from_string<${interface.cppNamespacedClass()}::${e.name}>
{
static auto op(const std::string& value) noexcept
{
- return ${interface.cppNamespace()}::convertStringTo${e.name}(value);
+ return ${interface.cppNamespacedClass()}::convertStringTo${e.name}(value);
}
};
template <>
-struct convert_to_string<${interface.cppNamespace()}::${e.name}>
+struct convert_to_string<${interface.cppNamespacedClass()}::${e.name}>
{
- static std::string op(${interface.cppNamespace()}::${e.name} value)
+ static std::string op(${interface.cppNamespacedClass()}::${e.name} value)
{
- return ${interface.cppNamespace()}::convert${e.name}ToString(value);
+ return ${interface.cppNamespacedClass()}::convert${e.name}ToString(value);
}
};
% endfor
-} // namespace message::details
-} // namespace sdbusplus
+} // namespace sdbusplus::message::details