summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorPatrick Williams <patrick@stwcx.xyz>2016-11-16 16:23:07 -0600
committerPatrick Williams <patrick@stwcx.xyz>2016-11-18 14:26:34 +0000
commit9b373f0dd12b638d322baaee92c5db0c0f1fe2e3 (patch)
tree37c1d1439a2706f372612a3e6d7037942c8a1788 /tools
parent0ad505ca7afa6bc917f9d13c9998113a73fa3915 (diff)
downloadsdbusplus-9b373f0dd12b638d322baaee92c5db0c0f1fe2e3.tar.gz
sdbusplus-9b373f0dd12b638d322baaee92c5db0c0f1fe2e3.zip
sdbus++: exception handling for property callbacks
Change-Id: I4230d5ebc7d2a470d9ae2d3bb03a9918a29ba919 Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Diffstat (limited to 'tools')
-rw-r--r--tools/sdbusplus/templates/interface.mako.server.cpp34
1 files changed, 25 insertions, 9 deletions
diff --git a/tools/sdbusplus/templates/interface.mako.server.cpp b/tools/sdbusplus/templates/interface.mako.server.cpp
index faaed4d..93e66d1 100644
--- a/tools/sdbusplus/templates/interface.mako.server.cpp
+++ b/tools/sdbusplus/templates/interface.mako.server.cpp
@@ -49,10 +49,18 @@ int ${classname}::_callback_get_${p.name}(
{
using sdbusplus::server::binding::details::convertForMessage;
- auto m = message::message(sd_bus_message_ref(reply));
+ try
+ {
+ auto m = message::message(sd_bus_message_ref(reply));
- auto o = static_cast<${classname}*>(context);
- m.append(convertForMessage(o->${p.camelCase}()));
+ auto o = static_cast<${classname}*>(context);
+ m.append(convertForMessage(o->${p.camelCase}()));
+ }
+ catch(sdbusplus::internal_exception_t& e)
+ {
+ sd_bus_error_set_const(error, e.name(), e.description());
+ return -EINVAL;
+ }
return true;
}
@@ -74,18 +82,26 @@ int ${classname}::_callback_set_${p.name}(
const char* property, sd_bus_message* value, void* context,
sd_bus_error* error)
{
- auto m = message::message(sd_bus_message_ref(value));
+ try
+ {
+ auto m = message::message(sd_bus_message_ref(value));
- auto o = static_cast<${classname}*>(context);
+ auto o = static_cast<${classname}*>(context);
- ${p.cppTypeMessage(interface.name)} v{};
- m.read(v);
+ ${p.cppTypeMessage(interface.name)} v{};
+ m.read(v);
% if p.is_enum():
- o->${p.camelCase}(${p.enum_namespace(interface.name)}\
+ o->${p.camelCase}(${p.enum_namespace(interface.name)}\
convert${p.enum_name(interface.name)}FromString(v));
% else:
- o->${p.camelCase}(v);
+ o->${p.camelCase}(v);
% endif
+ }
+ catch(sdbusplus::internal_exception_t& e)
+ {
+ sd_bus_error_set_const(error, e.name(), e.description());
+ return -EINVAL;
+ }
return true;
}
OpenPOWER on IntegriCloud