Skip to content

Commit

Permalink
[dbus] Add dbus send helper variant with controllable reply timeout
Browse files Browse the repository at this point in the history
The mce convenience functions for dealing with dbus method calls do not allow
customizing method call timeouts and lower level functions have been used for
those cases where non-standard timeouts are needed.

Provide dbus_send_ex2() convenience function that is otherwise identical with
dbus_send_ex() function except it allows defining a custom dbus reply timeout.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed May 11, 2017
1 parent 2127af0 commit 1f5c9e9
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
55 changes: 51 additions & 4 deletions mce-dbus.c
Expand Up @@ -536,6 +536,7 @@ gboolean dbus_send_message(DBusMessage *const msg)
static gboolean
dbus_send_message_with_reply_handler(DBusMessage *const msg,
DBusPendingCallNotifyFunction callback,
int timeout,
void *user_data,
DBusFreeFunction user_free,
DBusPendingCall **ppc)
Expand All @@ -546,7 +547,8 @@ dbus_send_message_with_reply_handler(DBusMessage *const msg,
if( !msg )
goto EXIT;

if( !dbus_connection_send_with_reply(dbus_connection, msg, &pc, -1) ) {
if( !dbus_connection_send_with_reply(dbus_connection, msg, &pc,
timeout) ) {
mce_log(LL_CRIT, "Out of memory when sending D-Bus message");
goto EXIT;
}
Expand Down Expand Up @@ -596,6 +598,7 @@ static gboolean dbus_send_va(const char *service,
const char *interface,
const char *name,
DBusPendingCallNotifyFunction callback,
int timeout,
void *user_data, DBusFreeFunction user_free,
DBusPendingCall **ppc,
int first_arg_type, va_list va)
Expand Down Expand Up @@ -634,7 +637,9 @@ static gboolean dbus_send_va(const char *service,
msg = 0;
}
else {
res = dbus_send_message_with_reply_handler(msg, callback,
res = dbus_send_message_with_reply_handler(msg,
callback,
timeout,
user_data,
user_free,
ppc);
Expand Down Expand Up @@ -688,7 +693,49 @@ gboolean dbus_send_ex(const char *service,
va_list va;
va_start(va, first_arg_type);
gboolean res = dbus_send_va(service, path, interface, name,
callback, user_data, user_free,
callback, -1, user_data, user_free,
ppc, first_arg_type, va);
va_end(va);
return res;
}

/** Generic function to send D-Bus messages and signals
* to send a signal, call dbus_send with service == NULL
*
* @todo Make it possible to send D-Bus replies as well
*
* @param service D-Bus service; for signals, set to NULL
* @param path D-Bus path
* @param interface D-Bus interface
* @param name The D-Bus method or signal name to send to
* @param callback A reply callback, or NULL to set no reply;
* for signals, this is unused, but please use NULL
* for consistency
* @param timeout Milliseconds to wait for reply, or -1 for default
* @param user_data Data to pass to callback
* @param user_free Data release callback for user_data
* @param ppc Where to store pending call handle, or NULL
* @param first_arg_type The DBUS_TYPE of the first argument in the list
* @param ... The arguments to append to the D-Bus message;
* terminate with DBUS_TYPE_INVALID
* Note: the arguments MUST be passed by reference
*
* @return TRUE on success, FALSE on failure
*/
gboolean dbus_send_ex2(const char *service,
const char *path,
const char *interface,
const char *name,
DBusPendingCallNotifyFunction callback,
int timeout,
void *user_data, DBusFreeFunction user_free,
DBusPendingCall **ppc,
int first_arg_type, ...)
{
va_list va;
va_start(va, first_arg_type);
gboolean res = dbus_send_va(service, path, interface, name,
callback, timeout, user_data, user_free,
ppc, first_arg_type, va);
va_end(va);
return res;
Expand Down Expand Up @@ -721,7 +768,7 @@ gboolean dbus_send(const gchar *const service, const gchar *const path,
va_list va;
va_start(va, first_arg_type);
gboolean res = dbus_send_va(service, path, interface, name,
callback, 0, 0, 0, first_arg_type, va);
callback, -1, 0, 0, 0, first_arg_type, va);
va_end(va);
return res;
}
Expand Down
10 changes: 10 additions & 0 deletions mce-dbus.h
Expand Up @@ -99,6 +99,16 @@ gboolean dbus_send_ex(const char *service,
DBusPendingCall **ppc,
int first_arg_type, ...);

gboolean dbus_send_ex2(const char *service,
const char *path,
const char *interface,
const char *name,
DBusPendingCallNotifyFunction callback,
int timeout,
void *user_data, DBusFreeFunction user_free,
DBusPendingCall **ppc,
int first_arg_type, ...);

gconstpointer mce_dbus_handler_add_ex(const gchar *const sender,
const gchar *const interface,
const gchar *const name,
Expand Down

0 comments on commit 1f5c9e9

Please sign in to comment.