summaryrefslogtreecommitdiffstats
path: root/bus/bus.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-03-14 01:27:58 +0000
committerHavoc Pennington <hp@redhat.com>2003-03-14 01:27:58 +0000
commit3bea935316ff048e68dea6a26c2e8e9fd314477f (patch)
tree498e62121c89d78693070d04e6bc6a6462efe2a7 /bus/bus.c
parent81c30364c291045d556c88f6818033104e627b6e (diff)
2003-03-13 Havoc Pennington <hp@redhat.com>
* dbus/dbus-timeout.c (_dbus_timeout_list_set_functions): handle out of memory * dbus/dbus-watch.c (_dbus_watch_list_set_functions): handle out of memory * dbus/dbus-connection.h: Make AddWatchFunction and AddTimeoutFunction return a bool so they can fail on out-of-memory * bus/bus.c (bus_context_new): set up timeout handlers * bus/connection.c (bus_connections_setup_connection): set up timeout handlers * glib/dbus-gmain.c: adapt to the fact that set_functions stuff can fail * bus/bus.c (bus_context_new): adapt to changes * bus/connection.c: adapt to changes * test/watch.c: adapt to DBusWatch changes * bus/dispatch.c (bus_dispatch_test): started adding this but didn't finish
Diffstat (limited to 'bus/bus.c')
-rw-r--r--bus/bus.c68
1 files changed, 60 insertions, 8 deletions
diff --git a/bus/bus.c b/bus/bus.c
index 7ac0beee..e376ae4d 100644
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -49,12 +49,12 @@ server_watch_callback (DBusWatch *watch,
dbus_server_handle_watch (context->server, watch, condition);
}
-static void
+static dbus_bool_t
add_server_watch (DBusWatch *watch,
BusContext *context)
{
- bus_loop_add_watch (watch, server_watch_callback, context,
- NULL);
+ return bus_loop_add_watch (watch, server_watch_callback, context,
+ NULL);
}
static void
@@ -65,6 +65,27 @@ remove_server_watch (DBusWatch *watch,
}
static void
+server_timeout_callback (DBusTimeout *timeout,
+ void *data)
+{
+ dbus_timeout_handle (timeout);
+}
+
+static dbus_bool_t
+add_server_timeout (DBusTimeout *timeout,
+ BusContext *context)
+{
+ return bus_loop_add_timeout (timeout, server_timeout_callback, context, NULL);
+}
+
+static void
+remove_server_timeout (DBusTimeout *timeout,
+ BusContext *context)
+{
+ bus_loop_remove_timeout (timeout, server_timeout_callback, context);
+}
+
+static void
new_connection_callback (DBusServer *server,
DBusConnection *new_connection,
void *data)
@@ -136,11 +157,24 @@ bus_context_new (const char *address,
new_connection_callback,
context, NULL);
- dbus_server_set_watch_functions (context->server,
- (DBusAddWatchFunction) add_server_watch,
- (DBusRemoveWatchFunction) remove_server_watch,
- context,
- NULL);
+ if (!dbus_server_set_watch_functions (context->server,
+ (DBusAddWatchFunction) add_server_watch,
+ (DBusRemoveWatchFunction) remove_server_watch,
+ context,
+ NULL))
+ {
+ BUS_SET_OOM (error);
+ goto failed;
+ }
+
+ if (!dbus_server_set_timeout_functions (context->server,
+ (DBusAddTimeoutFunction) add_server_timeout,
+ (DBusRemoveTimeoutFunction) remove_server_timeout,
+ context, NULL))
+ {
+ BUS_SET_OOM (error);
+ goto failed;
+ }
return context;
@@ -152,6 +186,22 @@ bus_context_new (const char *address,
void
bus_context_shutdown (BusContext *context)
{
+ if (context->server == NULL ||
+ !dbus_server_get_is_connected (context->server))
+ return;
+
+ if (!dbus_server_set_watch_functions (context->server,
+ NULL, NULL,
+ context,
+ NULL))
+ _dbus_assert_not_reached ("setting watch functions to NULL failed");
+
+ if (!dbus_server_set_timeout_functions (context->server,
+ NULL, NULL,
+ context,
+ NULL))
+ _dbus_assert_not_reached ("setting timeout functions to NULL failed");
+
dbus_server_disconnect (context->server);
}
@@ -170,6 +220,8 @@ bus_context_unref (BusContext *context)
if (context->refcount == 0)
{
+ bus_context_shutdown (context);
+
if (context->registry)
bus_registry_unref (context->registry);
if (context->connections)