sdbus++: error: move error to front of namespace
To be consistent with the new 'server' and 'client' namespaces,
refactor the 'error' namespace in the same way. Move 'error' to
the front and use snake_case for namespace and struct identifiers.
Leave the same backwards compatibility, which can be disabled with
the SDBUSPP_REMOVE_DEPRECATED_NAMESPACE guard.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I1a147a153798c84eaac3f6bf9581c6ca31ecaf4f
diff --git a/docs/yaml/error.md b/docs/yaml/error.md
index 292b0ef..f8dcba0 100644
--- a/docs/yaml/error.md
+++ b/docs/yaml/error.md
@@ -4,7 +4,7 @@
this YAML file, both documentation and binding code may be generated. The
generated bindings are C++ exception types corresponding to the D-Bus error
name. Ex. `org.freedesktop.Example.Error.SomeError` will create a generated
-exception type of `sdbusplus::org::freedesktop::Example::Error::SomeError` which
+exception type of `sdbusplus::error::org::freedesktop::example::SomeError` which
may be thrown or caught as appropriate. If the error is thrown from an interface
method which has specified it may return that error, then the bindings will
generate a catch clause that returns a D-Bus error like
diff --git a/example/calculator-aserver.cpp b/example/calculator-aserver.cpp
index 62a3ebe..f70e7ab 100644
--- a/example/calculator-aserver.cpp
+++ b/example/calculator-aserver.cpp
@@ -19,7 +19,7 @@
auto method_call(divide_t, auto x, auto y)
-> sdbusplus::async::task<divide_t::return_type>
{
- using sdbusplus::net::poettering::Calculator::Error::DivisionByZero;
+ using sdbusplus::error::net::poettering::calculator::DivisionByZero;
if (y == 0)
{
status(State::Error);
diff --git a/example/calculator-server.cpp b/example/calculator-server.cpp
index aa60662..b0603a3 100644
--- a/example/calculator-server.cpp
+++ b/example/calculator-server.cpp
@@ -29,7 +29,7 @@
*/
int64_t divide(int64_t x, int64_t y) override
{
- using sdbusplus::net::poettering::Calculator::Error::DivisionByZero;
+ using sdbusplus::error::net::poettering::calculator::DivisionByZero;
if (y == 0)
{
status(State::Error);
diff --git a/tools/sdbusplus/error.py b/tools/sdbusplus/error.py
index e30a59a..7af1809 100644
--- a/tools/sdbusplus/error.py
+++ b/tools/sdbusplus/error.py
@@ -30,6 +30,15 @@
super(Error, self).__init__(**kwargs)
+ self.old_namespaces = self.name.split(".")
+ self.namespaces = [
+ NamedElement(name=x).snake_case for x in self.old_namespaces
+ ]
+ self.old_namespaces = "::".join(
+ ["sdbusplus"] + self.old_namespaces + ["Error"]
+ )
+ self.namespaces = "::".join(["sdbusplus", "error"] + self.namespaces)
+
def markdown(self, loader):
return self.render(loader, "error.md.mako", error=self)
diff --git a/tools/sdbusplus/templates/error.hpp.mako b/tools/sdbusplus/templates/error.hpp.mako
index 9200fc7..4892bb6 100644
--- a/tools/sdbusplus/templates/error.hpp.mako
+++ b/tools/sdbusplus/templates/error.hpp.mako
@@ -1,14 +1,13 @@
-<% namespaces = error.name.split('.') %>\
#pragma once
#include <sdbusplus/exception.hpp>
#include <cerrno>
-namespace sdbusplus::${"::".join(namespaces)}::Error
+namespace ${error.namespaces}
{
% for e in error.errors:
-struct ${e.name} final : public sdbusplus::exception::generated_exception
+struct ${e.CamelCase} final : public sdbusplus::exception::generated_exception
{
static constexpr auto errName =
"${error.name}.Error.${e.name}";
@@ -40,5 +39,13 @@
% endif
};
% endfor
+} // namespace ${error.namespaces}
-} // namespace sdbusplus::${"::".join(namespaces)}::Error\
+#ifndef SDBUSPP_REMOVE_DEPRECATED_NAMESPACE
+namespace ${error.old_namespaces}
+{
+ % for e in error.errors:
+ using ${e.name} = ${error.namespaces}::${e.CamelCase};
+ % endfor
+} // namespace ${error.old_namespaces}
+#endif\