From 54b943432c7c947db88066751dd36a372cc9a618 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Mon, 18 Jun 2007 19:32:51 +0000 Subject: 2007-06-18 Havoc Pennington * doc/dbus-specification.xml: document org.freedesktop.DBus.GetId() * bus/driver.c (bus_driver_handle_get_id): implement org.freedesktop.DBus.GetId() * bus/bus.c (bus_context_new): generate a unique ID for each bus context * dbus/dbus-connection.c (dbus_connection_get_server_id): new function * dbus/dbus-bus.c (dbus_bus_get_id): new function * dbus/dbus-server.c (dbus_server_get_id): new function --- bus/bus.c | 10 +++++++++ bus/bus.h | 2 ++ bus/driver.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 76 insertions(+), 5 deletions(-) (limited to 'bus') diff --git a/bus/bus.c b/bus/bus.c index a6abc455..394436aa 100644 --- a/bus/bus.c +++ b/bus/bus.c @@ -38,6 +38,7 @@ struct BusContext { int refcount; + DBusGUID uuid; char *config_file; char *type; char *address; @@ -552,6 +553,8 @@ bus_context_new (const DBusString *config_file, } context->refcount = 1; + _dbus_generate_uuid (&context->uuid); + if (!_dbus_string_copy_data (config_file, &context->config_file)) { BUS_SET_OOM (error); @@ -784,6 +787,13 @@ bus_context_new (const DBusString *config_file, return NULL; } +dbus_bool_t +bus_context_get_id (BusContext *context, + DBusString *uuid) +{ + return _dbus_uuid_encode (&context->uuid, uuid); +} + dbus_bool_t bus_context_reload_config (BusContext *context, DBusError *error) diff --git a/bus/bus.h b/bus/bus.h index e17de060..1f96aed9 100644 --- a/bus/bus.h +++ b/bus/bus.h @@ -78,6 +78,8 @@ dbus_bool_t bus_context_reload_config (BusContext void bus_context_shutdown (BusContext *context); BusContext* bus_context_ref (BusContext *context); void bus_context_unref (BusContext *context); +dbus_bool_t bus_context_get_id (BusContext *context, + DBusString *uuid); const char* bus_context_get_type (BusContext *context); const char* bus_context_get_address (BusContext *context); BusRegistry* bus_context_get_registry (BusContext *context); diff --git a/bus/driver.c b/bus/driver.c index 69084330..ebe355cd 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -1382,6 +1382,61 @@ bus_driver_handle_reload_config (DBusConnection *connection, return FALSE; } +static dbus_bool_t +bus_driver_handle_get_id (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + BusContext *context; + DBusMessage *reply; + DBusString uuid; + const char *v_STRING; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (!_dbus_string_init (&uuid)) + { + BUS_SET_OOM (error); + return FALSE; + } + + reply = NULL; + + context = bus_connection_get_context (connection); + if (!bus_context_get_id (context, &uuid)) + goto oom; + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + goto oom; + + v_STRING = _dbus_string_get_const_data (&uuid); + if (!dbus_message_append_args (reply, + DBUS_TYPE_STRING, &v_STRING, + DBUS_TYPE_INVALID)) + goto oom; + + _dbus_assert (dbus_message_has_signature (reply, "s")); + + if (! bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + _dbus_string_free (&uuid); + dbus_message_unref (reply); + return TRUE; + + oom: + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + BUS_SET_OOM (error); + + if (reply) + dbus_message_unref (reply); + _dbus_string_free (&uuid); + return FALSE; +} + /* For speed it might be useful to sort this in order of * frequency of use (but doesn't matter with only a few items * anyhow) @@ -1396,6 +1451,10 @@ struct DBusMessage *message, DBusError *error); } message_handlers[] = { + { "Hello", + "", + DBUS_TYPE_STRING_AS_STRING, + bus_driver_handle_hello }, { "RequestName", DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING, DBUS_TYPE_UINT32_AS_STRING, @@ -1408,10 +1467,6 @@ struct DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING, DBUS_TYPE_UINT32_AS_STRING, bus_driver_handle_activate_service }, - { "Hello", - "", - DBUS_TYPE_STRING_AS_STRING, - bus_driver_handle_hello }, { "NameHasOwner", DBUS_TYPE_STRING_AS_STRING, DBUS_TYPE_BOOLEAN_AS_STRING, @@ -1455,7 +1510,11 @@ struct { "ReloadConfig", "", "", - bus_driver_handle_reload_config } + bus_driver_handle_reload_config }, + { "GetId", + "", + DBUS_TYPE_STRING_AS_STRING, + bus_driver_handle_get_id } }; static dbus_bool_t -- cgit