forked from openbmc/sdbusplus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sdbus++: events: create json for events
Create JSON for the events containing their metadata and leverage that as the "message" portion of the `sd_bus_error`. This will allow unpacking the message on a client side back to the original exception. Tested: ``` $ busctl --user call net.poettering.Calculator /net/poettering/calculator net.poettering.Calculator Divide xx 5 0 Call failed: {"net.poettering.Calculator.DivisionByZero":{"FOO":"unused"}} ``` Signed-off-by: Patrick Williams <[email protected]> Change-Id: I4edd76d983267f28e51c4aa41902d45f5d6da793
- Loading branch information
1 parent
a4bfefd
commit 14c4797
Showing
7 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[wrap-git] | ||
revision = HEAD | ||
url = https://github.com/nlohmann/json.git | ||
|
||
[provide] | ||
nlohmann_json = nlohmann_json_dep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
int ${event.CamelCase}::set_error(sd_bus_error* e) const | ||
{ | ||
if (jsonString.empty()) | ||
{ | ||
jsonString = to_json().dump(); | ||
} | ||
|
||
return sd_bus_error_set(e, errName, jsonString.c_str()); | ||
} | ||
|
||
int ${event.CamelCase}::set_error(SdBusInterface* i, sd_bus_error* e) const | ||
{ | ||
if (jsonString.empty()) | ||
{ | ||
jsonString = to_json().dump(); | ||
} | ||
|
||
return i->sd_bus_error_set(e, errName, jsonString.c_str()); | ||
} | ||
|
||
auto ${event.CamelCase}::to_json() const -> nlohmann::json | ||
{ | ||
nlohmann::json j = { }; | ||
% for m in event.metadata: | ||
j["${m.SNAKE_CASE}"] = ${m.camelCase}; | ||
% endfor | ||
return nlohmann::json{ { errName, std::move(j) } }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <${events.headerFile("event")}> | ||
#include <nlohmann/json.hpp> | ||
|
||
%if events.errors: | ||
|
||
namespace sdbusplus::error::${events.cppNamespacedClass()} | ||
{ | ||
% for e in events.errors: | ||
|
||
${events.render(loader, "event.cpp.mako", events=events, event=e)}\ | ||
% endfor | ||
|
||
} // namespace sdbusplus::error::${events.cppNamespacedClass()} | ||
%endif | ||
%if events.errors: | ||
|
||
namespace sdbusplus::event::${events.cppNamespacedClass()} | ||
{ | ||
% for e in events.events: | ||
|
||
${events.render(loader, "event.cpp.mako", events=events, event=e)}\ | ||
% endfor | ||
|
||
} // namespace sdbusplus::event::${events.cppNamespacedClass()} | ||
%endif |