summaryrefslogtreecommitdiff
path: root/dbind
diff options
context:
space:
mode:
authorMike Gorse <mgorse@novell.com>2010-11-12 13:17:41 -0500
committerMike Gorse <mgorse@novell.com>2010-11-12 13:17:41 -0500
commitacfcea02b3d24e20ed9b6276cd1861774e01fa4b (patch)
treec90574d755371a0560532dd00980b0b7284d262e /dbind
parent23af25b18fe03202e4fe130e8479936fed6cfec0 (diff)
downloadat-spi2-core-acfcea02b3d24e20ed9b6276cd1861774e01fa4b.tar.gz
Various fixes
Diffstat (limited to 'dbind')
-rw-r--r--dbind/dbind.c55
-rw-r--r--dbind/dbind.h1
2 files changed, 44 insertions, 12 deletions
diff --git a/dbind/dbind.c b/dbind/dbind.c
index 5c49d665..0f301b5f 100644
--- a/dbind/dbind.c
+++ b/dbind/dbind.c
@@ -7,6 +7,8 @@
#include "config.h"
#include "dbind/dbind.h"
+static int dbind_timeout = -1;
+
/*
* FIXME: compare types - to ensure they match &
* do dynamic padding of structures etc.
@@ -14,30 +16,53 @@
/*---------------------------------------------------------------------------*/
+typedef struct _SpiReentrantCallClosure
+{
+ GMainLoop *loop;
+ DBusMessage *reply;
+} SpiReentrantCallClosure;
+
static void
-set_reply (DBusPendingCall *pending, void *user_data)
+set_reply (DBusPendingCall * pending, void *user_data)
{
- void **replyptr = (void **)user_data;
+ SpiReentrantCallClosure* closure = (SpiReentrantCallClosure *) user_data;
- *replyptr = dbus_pending_call_steal_reply (pending);
+ closure->reply = dbus_pending_call_steal_reply (pending);
+ g_main_loop_quit (closure->loop);
}
DBusMessage *
-dbind_send_and_allow_reentry (DBusConnection *bus, DBusMessage *message, DBusError *error)
+dbind_send_and_allow_reentry (DBusConnection * bus, DBusMessage * message, DBusError *error)
{
- DBusPendingCall *pending;
- DBusMessage *reply = NULL;
+ DBusPendingCall *pending;
+ SpiReentrantCallClosure closure;
+
+ if (strcmp (dbus_message_get_destination (message),
+ dbus_bus_get_unique_name (bus)) != 0)
+ return dbus_connection_send_with_reply_and_block (bus, message, dbind_timeout, error);
- if (!dbus_connection_send_with_reply (bus, message, &pending, -1))
+ if (!dbus_connection_send_with_reply (bus, message, &pending, dbind_timeout))
+ return NULL;
+ dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL);
+ closure.loop = g_main_loop_new (NULL, FALSE);
+ dbus_connection_setup_with_g_main(bus, NULL);
+
+ if (1)
{
- return NULL;
+ g_main_loop_run (closure.loop);
}
- dbus_pending_call_set_notify (pending, set_reply, (void *)&reply, NULL);
- while (!reply)
+ else
{
- if (!dbus_connection_read_write_dispatch (bus, -1)) return NULL;
+ closure.reply = NULL;
+ while (!closure.reply)
+ {
+ if (!dbus_connection_read_write_dispatch (bus, dbind_timeout))
+ return NULL;
+ }
}
- return reply;
+
+ g_main_loop_unref (closure.loop);
+ return closure.reply;
}
dbus_bool_t
@@ -226,5 +251,11 @@ dbind_emit_signal (DBusConnection *cnx,
return success;
}
+void
+dbind_set_timeout (int timeout)
+{
+ dbind_timeout = timeout;
+}
+
/*END------------------------------------------------------------------------*/
diff --git a/dbind/dbind.h b/dbind/dbind.h
index 3a8b209b..408099c1 100644
--- a/dbind/dbind.h
+++ b/dbind/dbind.h
@@ -46,4 +46,5 @@ dbind_emit_signal (DBusConnection *cnx,
const char *arg_types,
...);
+void dbind_set_timeout (int timeout);
#endif /* _DBIND_H_ */