events: add non-template base class
In order to allow non-template implementations that interact with
the `sdbusplus::excception::generated_event<T>` class, it is useful
to have a non-template base class. Add the `to_json` there for use
by phosphor-logging.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ibed2c7c4fc0e23f1c82c4c003e16a6f438f7e68f
diff --git a/include/sdbusplus/exception.hpp b/include/sdbusplus/exception.hpp
index a8707f6..347418e 100644
--- a/include/sdbusplus/exception.hpp
+++ b/include/sdbusplus/exception.hpp
@@ -46,10 +46,17 @@
int get_errno() const noexcept override;
};
+/** Non-templated base for all new errors and events created by the sdbus++
+ * generator */
+struct generated_event_base : public generated_exception
+{
+ virtual auto to_json() const -> nlohmann::json = 0;
+};
+
/** base exception for all new errors and events created by the sdbus++
* generator */
template <typename Event>
-struct generated_event : public generated_exception
+struct generated_event : public generated_event_base
{
const char* name() const noexcept override
{
diff --git a/tools/sdbusplus/templates/event.hpp.mako b/tools/sdbusplus/templates/event.hpp.mako
index 5425d0a..c74efc9 100644
--- a/tools/sdbusplus/templates/event.hpp.mako
+++ b/tools/sdbusplus/templates/event.hpp.mako
@@ -18,7 +18,7 @@
%endif
int set_error(sd_bus_error*) const override;
int set_error(SdBusInterface*, sd_bus_error*) const override;
- auto to_json() const -> nlohmann::json;
+ auto to_json() const -> nlohmann::json override;
static constexpr auto errName =
"${events.name}.${event.name}";