From ff8348650ab13cd736fb6ce92ca6e552d7b5c955 Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Thu, 2 Dec 2010 05:21:51 +0200 Subject: [PATCH] Move the dbus call default timeout define out of the interface header The default timeout is a property of the implementation, not the interface --- dbus/helpers.c | 41 +++++++++++++++++++++++++++++------------ dbus/helpers.h | 7 +++++-- proxies/jack_proxy.c | 44 ++++---------------------------------------- 3 files changed, 38 insertions(+), 54 deletions(-) diff --git a/dbus/helpers.c b/dbus/helpers.c index 2474f870..84e481af 100644 --- a/dbus/helpers.c +++ b/dbus/helpers.c @@ -38,6 +38,8 @@ #include "../assert.h" #include "../common/klist.h" +#define DBUS_CALL_DEFAULT_TIMEOUT 3000 // in milliseconds + DBusConnection * g_dbus_connection; DBusError g_dbus_error; @@ -332,6 +334,32 @@ bool dbus_add_dict_entry_bool(DBusMessageIter * dict_iter_ptr, const char * key, return true; } +DBusMessage * +dbus_call_raw( + unsigned int timeout, + DBusMessage * request_ptr) +{ + DBusMessage * reply_ptr; + + if (timeout == 0) + { + timeout = DBUS_CALL_DEFAULT_TIMEOUT; + } + + reply_ptr = dbus_connection_send_with_reply_and_block( + g_dbus_connection, + request_ptr, + timeout, + &g_dbus_error); + if (reply_ptr == NULL) + { + //log_error("calling method '%s' failed, error is '%s'", method, g_dbus_error.message); + dbus_error_free(&g_dbus_error); + } + + return reply_ptr; +} + bool dbus_call( unsigned int timeout, @@ -355,11 +383,6 @@ dbus_call( //log_info("dbus_call('%s', '%s', '%s', '%s')", service, object, iface, method); - if (timeout == 0) - { - timeout = DBUS_CALL_DEFAULT_TIMEOUT; - } - ret = false; va_start(ap, input_signature); @@ -410,11 +433,7 @@ dbus_call( output_signature = va_arg(ap, const char *); - reply_ptr = dbus_connection_send_with_reply_and_block( - g_dbus_connection, - request_ptr, - timeout, - &g_dbus_error); + reply_ptr = dbus_call_raw(timeout, request_ptr); if (input_signature != NULL) { @@ -423,8 +442,6 @@ dbus_call( if (reply_ptr == NULL) { - //log_error("calling method '%s' failed, error is '%s'", method, g_dbus_error.message); - dbus_error_free(&g_dbus_error); goto fail; } diff --git a/dbus/helpers.h b/dbus/helpers.h index 7b9a0144..48529515 100644 --- a/dbus/helpers.h +++ b/dbus/helpers.h @@ -43,6 +43,11 @@ bool dbus_maybe_add_dict_entry_string(DBusMessageIter *dict_iter_ptr, const char bool dbus_add_dict_entry_uint32(DBusMessageIter * dict_iter_ptr, const char * key, dbus_uint32_t value); bool dbus_add_dict_entry_bool(DBusMessageIter * dict_iter_ptr, const char * key, dbus_bool_t value); +DBusMessage * +dbus_call_raw( + unsigned int timeout, /* in milliseconds */ + DBusMessage * request_ptr); + bool dbus_call( unsigned int timeout, /* in milliseconds */ @@ -106,8 +111,6 @@ dbus_unregister_service_lifetime_hook( DBusConnection * connection, const char * service); -#define DBUS_CALL_DEFAULT_TIMEOUT 3000 // in milliseconds - #include "method.h" #include "signal.h" #include "interface.h" diff --git a/proxies/jack_proxy.c b/proxies/jack_proxy.c index 1ff03805..df12bec0 100644 --- a/proxies/jack_proxy.c +++ b/proxies/jack_proxy.c @@ -226,19 +226,10 @@ jack_proxy_read_conf_container( return false; } - // send message and get a handle for a reply - reply_ptr = dbus_connection_send_with_reply_and_block( - g_dbus_connection, - request_ptr, - DBUS_CALL_DEFAULT_TIMEOUT, - &g_dbus_error); - + reply_ptr = dbus_call_raw(0, request_ptr); dbus_message_unref(request_ptr); - if (reply_ptr == NULL) { - log_error("no reply from JACK server, error is '%s'", g_dbus_error.message); - dbus_error_free(&g_dbus_error); return false; } @@ -358,19 +349,10 @@ jack_proxy_get_parameter_value( return false; } - // send message and get a handle for a reply - reply_ptr = dbus_connection_send_with_reply_and_block( - g_dbus_connection, - request_ptr, - DBUS_CALL_DEFAULT_TIMEOUT, - &g_dbus_error); - + reply_ptr = dbus_call_raw(0, request_ptr); dbus_message_unref(request_ptr); - if (reply_ptr == NULL) { - log_error("no reply from JACK server, error is '%s'", g_dbus_error.message); - dbus_error_free(&g_dbus_error); return false; } @@ -476,19 +458,10 @@ jack_proxy_set_parameter_value( return false; } - // send message and get a handle for a reply - reply_ptr = dbus_connection_send_with_reply_and_block( - g_dbus_connection, - request_ptr, - DBUS_CALL_DEFAULT_TIMEOUT, - &g_dbus_error); - + reply_ptr = dbus_call_raw(0, request_ptr); dbus_message_unref(request_ptr); - if (reply_ptr == NULL) { - log_error("no reply from JACK server, error is '%s'", g_dbus_error.message); - dbus_error_free(&g_dbus_error); return false; } @@ -529,19 +502,10 @@ jack_proxy_reset_parameter_value( return false; } - // send message and get a handle for a reply - reply_ptr = dbus_connection_send_with_reply_and_block( - g_dbus_connection, - request_ptr, - DBUS_CALL_DEFAULT_TIMEOUT, - &g_dbus_error); - + reply_ptr = dbus_call_raw(0, request_ptr); dbus_message_unref(request_ptr); - if (reply_ptr == NULL) { - log_error("no reply from JACK server, error is '%s'", g_dbus_error.message); - dbus_error_free(&g_dbus_error); return false; }