summaryrefslogtreecommitdiffstats
path: root/bus
diff options
context:
space:
mode:
authorOlivier Andrieu <oliv__a@users.sourceforge.net>2004-04-15 22:08:05 +0000
committerOlivier Andrieu <oliv__a@users.sourceforge.net>2004-04-15 22:08:05 +0000
commita470eaa0789662d3d3e1f0a23e75c7be2ab574cc (patch)
treee8db28dbafeb1af3d93459bc2fe76f88e940808b /bus
parent61b294f1a9e41c68486bc9340cd42d94224a4080 (diff)
2004-04-15 Olivier Andrieu <oliv__a@users.sourceforge.net>
* bus/driver.c (bus_driver_handle_get_service_owner): implement a GetServiceOwner method. * doc/dbus-specification.xml: document it. * dbus/dbus-errors.h: add a 'ServiceHasNoOwner' error. * glib/dbus-gproxy.c (dbus_gproxy_new_for_service_owner): implement, using the bus GetServiceOwner method. * test/glib/test-dbus-glib.c: use dbus_gproxy_new_for_service_owner so that we can receive the signal.
Diffstat (limited to 'bus')
-rw-r--r--bus/driver.c76
1 files changed, 75 insertions, 1 deletions
diff --git a/bus/driver.c b/bus/driver.c
index 3ffae2e0..a9dddd19 100644
--- a/bus/driver.c
+++ b/bus/driver.c
@@ -756,6 +756,79 @@ bus_driver_handle_remove_match (DBusConnection *connection,
return FALSE;
}
+static dbus_bool_t
+bus_driver_handle_get_service_owner (DBusConnection *connection,
+ BusTransaction *transaction,
+ DBusMessage *message,
+ DBusError *error)
+{
+ char *text;
+ const char *base_name;
+ DBusString str;
+ BusRegistry *registry;
+ BusService *service;
+ DBusMessage *reply;
+
+ _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+ registry = bus_connection_get_registry (connection);
+
+ text = NULL;
+ reply = NULL;
+
+ if (! dbus_message_get_args (message, error,
+ DBUS_TYPE_STRING, &text,
+ DBUS_TYPE_INVALID))
+ goto failed;
+
+ _dbus_string_init_const (&str, text);
+ service = bus_registry_lookup (registry, &str);
+ if (service == NULL)
+ {
+ dbus_set_error (error,
+ DBUS_ERROR_SERVICE_HAS_NO_OWNER,
+ "Could not get owner of service '%s': no such service", text);
+ goto failed;
+ }
+
+ base_name = bus_connection_get_name (bus_service_get_primary_owner (service));
+ if (base_name == NULL)
+ {
+ dbus_set_error (error,
+ DBUS_ERROR_FAILED,
+ "Could not determine base service for '%s'", text);
+ goto failed;
+ }
+ _dbus_assert (*base_name == ':');
+
+ reply = dbus_message_new_method_return (message);
+ if (reply == NULL)
+ goto oom;
+
+ if (! dbus_message_append_args (reply,
+ DBUS_TYPE_STRING, base_name,
+ DBUS_TYPE_INVALID))
+ goto oom;
+
+ if (! bus_transaction_send_from_driver (transaction, connection, reply))
+ goto oom;
+
+ dbus_message_unref (reply);
+ dbus_free (text);
+
+ return TRUE;
+
+ oom:
+ BUS_SET_OOM (error);
+
+ failed:
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ if (reply)
+ dbus_message_unref (reply);
+ dbus_free (text);
+ 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)
@@ -774,7 +847,8 @@ struct
{ "ServiceExists", bus_driver_handle_service_exists },
{ "ListServices", bus_driver_handle_list_services },
{ "AddMatch", bus_driver_handle_add_match },
- { "RemoveMatch", bus_driver_handle_remove_match }
+ { "RemoveMatch", bus_driver_handle_remove_match },
+ { "GetServiceOwner", bus_driver_handle_get_service_owner }
};
dbus_bool_t