diff options
author | Stef Walter <stefw@redhat.com> | 2014-02-25 10:29:23 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2014-04-19 10:32:50 +0200 |
commit | dff909d473f43a6bd0f0286fa2d279c0ebe945c6 (patch) | |
tree | 61b2f3e2c33e28b51a8ffed64a73de364093557a /src/sbus/sssd_dbus_request.c | |
parent | 7a9a6ee1b5f5479c3a6958401f9b34c571c3b6bf (diff) | |
download | sssd-dff909d473f43a6bd0f0286fa2d279c0ebe945c6.tar.gz sssd-dff909d473f43a6bd0f0286fa2d279c0ebe945c6.tar.xz sssd-dff909d473f43a6bd0f0286fa2d279c0ebe945c6.zip |
sbus: Add type-safe DBus method handlers and finish functions
Type safe method handlers allow methods not to have to do tedious
unwrapping and wrapping of DBus method call messages or replies.
Arguments of the following DBus types are supported in type-safe
method handlers. In addition arrays of these are supported.
y: uint8_t
b: bool (but no arrays, yet)
n: int16_t
q: uint16_t
i: int32_t
u: uint32_t
x: int64_t
t: uint64_t
d: double
s: char * (utf8 string)
o: char * (object path)
As an exception, arrays of booleans are not supported, but could be
added later. Other more complex types could be added later if desired.
If a method has other argument types, then it must be marked as having
a raw handler (see below).
Internally each method can have a type specific invoker function which
unpacks the incoming arguments and invokes the method handler with the
correct arguments.
Each method also has a finish which accepts the type-safe out arguments
(ie: return values) and builds the reply message. Like other request
'finish' functions, these free the request talloc context, and are to
be used in place of sbus_request_finish() or friends.
Raw method handlers parse their own method arguments, and prepare their
own reply (ideally using sbus_request_finish() helpers). They can also
do strange things like have variable arguments. To mark a DBus method
as having a raw method handler use the following annotation:
<annotation name="org.freedesktop.sssd.RawHandler" value="true"/>
Raw methods do not have invokers or finish functions.
I've left all of the internal peer to peer communication using raw
method handlers. No code changes here.
Diffstat (limited to 'src/sbus/sssd_dbus_request.c')
-rw-r--r-- | src/sbus/sssd_dbus_request.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/sbus/sssd_dbus_request.c b/src/sbus/sssd_dbus_request.c index c45f3a9fd..1546f0ddf 100644 --- a/src/sbus/sssd_dbus_request.c +++ b/src/sbus/sssd_dbus_request.c @@ -20,10 +20,13 @@ #include "util/util.h" #include "sbus/sssd_dbus.h" +#include "sbus/sssd_dbus_private.h" #include <sys/time.h> #include <dbus/dbus.h> +static const DBusError error_internal = { DBUS_ERROR_FAILED, "Internal Error" }; + static int sbus_request_destructor(struct sbus_request *dbus_req) { dbus_message_unref(dbus_req->message); @@ -51,6 +54,33 @@ sbus_new_request(struct sbus_connection *conn, return dbus_req; } +void +sbus_request_invoke_or_finish(struct sbus_request *dbus_req, + sbus_msg_handler_fn handler_fn, + void *handler_data, + sbus_method_invoker_fn invoker_fn) +{ + int ret; + + if (invoker_fn) { + ret = invoker_fn(dbus_req, handler_fn); + } else { + ret = handler_fn(dbus_req, handler_data); + } + + switch(ret) { + case EOK: + return; + case ENOMEM: + DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory handling DBus message\n"); + sbus_request_finish(dbus_req, NULL); + break; + default: + sbus_request_fail_and_finish(dbus_req, &error_internal); + break; + } +} + int sbus_request_finish(struct sbus_request *dbus_req, DBusMessage *reply) { |