summaryrefslogtreecommitdiffstats
path: root/bus/connection.c
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@codefactory.se>2003-01-21 12:42:33 +0000
committerAnders Carlsson <andersca@codefactory.se>2003-01-21 12:42:33 +0000
commitaff24a72c18a43dbb6f2d85e6d2226a3c2ea8f10 (patch)
tree7ff762f5de8d2c0234ea5a8a2f35aa0c01660e39 /bus/connection.c
parent4a85d321b4516c6a663e8bdd530ba59018c974df (diff)
2003-01-21 Anders Carlsson <andersca@codefactory.se>
* bus/Makefile.am: Add driver.[ch] * bus/connection.c: (connection_disconnect_handler): Remove the connection from the bus driver's list. (connection_watch_callback): Dispatch messages. (free_connection_data): Free connection name. (bus_connection_setup): Add connection to the bus driver's list. (bus_connection_remove_owned_service): (bus_connection_set_name), (bus_connection_get_name): Add functions for setting and getting the connection's name. * bus/connection.h: Add function headers. * bus/driver.c: (create_unique_client_name), (bus_driver_handle_hello_message), (bus_driver_send_welcome_message), (bus_driver_message_handler), (bus_driver_add_connection), (bus_driver_remove_connection): * bus/driver.h: * bus/main.c: * bus/services.c: (bus_service_free): * bus/services.h: New file that handles communication and registreation with the bus itself.
Diffstat (limited to 'bus/connection.c')
-rw-r--r--bus/connection.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/bus/connection.c b/bus/connection.c
index a80e46d4..4a805731 100644
--- a/bus/connection.c
+++ b/bus/connection.c
@@ -21,6 +21,7 @@
*
*/
#include "connection.h"
+#include "driver.h"
#include "loop.h"
#include "services.h"
#include <dbus/dbus-list.h>
@@ -32,6 +33,7 @@ typedef struct
{
DBusList *services_owned;
+ char *name;
} BusConnectionData;
#define BUS_CONNECTION_DATA(connection) (dbus_connection_get_data ((connection), connection_data_slot))
@@ -52,6 +54,9 @@ connection_disconnect_handler (DBusConnection *connection,
while ((service = _dbus_list_get_last (&d->services_owned)))
bus_service_remove_owner (service, connection);
+ /* Tell bus driver that we want to get off */
+ bus_driver_remove_connection (connection);
+
/* no more watching */
dbus_connection_set_watch_functions (connection,
NULL, NULL,
@@ -74,6 +79,8 @@ connection_watch_callback (DBusWatch *watch,
DBusConnection *connection = data;
dbus_connection_handle_watch (connection, watch, condition);
+
+ while (dbus_connection_dispatch_message (connection));
}
static void
@@ -98,6 +105,8 @@ free_connection_data (void *data)
/* services_owned should be NULL since we should be disconnected */
_dbus_assert (d->services_owned == NULL);
+
+ dbus_free (d->name);
dbus_free (d);
}
@@ -150,6 +159,9 @@ bus_connection_setup (DBusConnection *connection)
connection_disconnect_handler,
NULL, NULL);
+ if (!bus_driver_add_connection (connection))
+ return FALSE;
+
return TRUE;
}
@@ -180,3 +192,35 @@ bus_connection_remove_owned_service (DBusConnection *connection,
_dbus_list_remove_last (&d->services_owned, service);
}
+
+dbus_bool_t
+bus_connection_set_name (DBusConnection *connection,
+ const DBusString *name)
+{
+ const char *c_name;
+ BusConnectionData *d;
+
+ d = BUS_CONNECTION_DATA (connection);
+ _dbus_assert (d != NULL);
+ _dbus_assert (d->name == NULL);
+
+ _dbus_string_get_const_data (name, &c_name);
+
+ d->name = _dbus_strdup (c_name);
+
+ if (d->name == NULL)
+ return FALSE;
+
+ return TRUE;
+}
+
+const char *
+bus_connection_get_name (DBusConnection *connection)
+{
+ BusConnectionData *d;
+
+ d = BUS_CONNECTION_DATA (connection);
+ _dbus_assert (d != NULL);
+
+ return d->name;
+}