[Telepathy-commits] [telepathy-glib/master] TpDBusDaemon: add internal _tp_dbus_daemon_request_name() method
Simon McVittie
simon.mcvittie at collabora.co.uk
Fri Jan 30 06:19:46 PST 2009
To avoid unnecessarily broad signal matching (fd.o #14183) we should
avoid instantiating a DBusGProxy for the dbus-daemon (since that
will probably always have to bind to signals from the whole
interface for backwards compatibility). We can reduce the need to
instantiate such a DBusGProxy by replicating basic functionality.
This is only internal API for now, but it could be promoted to
public API later.
---
telepathy-glib/dbus-internal.h | 3 ++
telepathy-glib/dbus.c | 74 +++++++++++++++++++++++++++++++++++++++-
2 files changed, 76 insertions(+), 1 deletions(-)
diff --git a/telepathy-glib/dbus-internal.h b/telepathy-glib/dbus-internal.h
index 8465c6f..1e5f53d 100644
--- a/telepathy-glib/dbus-internal.h
+++ b/telepathy-glib/dbus-internal.h
@@ -29,6 +29,9 @@ G_BEGIN_DECLS
gboolean _tp_dbus_daemon_get_name_owner (TpDBusDaemon *self, gint timeout_ms,
const gchar *well_known_name, gchar **unique_name, GError **error);
+gboolean _tp_dbus_daemon_request_name (TpDBusDaemon *self,
+ const gchar *well_known_name, gboolean idempotent, GError **error);
+
void _tp_register_dbus_glib_marshallers (void);
G_END_DECLS
diff --git a/telepathy-glib/dbus.c b/telepathy-glib/dbus.c
index 88ec078..649b51a 100644
--- a/telepathy-glib/dbus.c
+++ b/telepathy-glib/dbus.c
@@ -57,7 +57,8 @@
#include <stdlib.h>
#include <string.h>
-#include <dbus/dbus-shared.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib-lowlevel.h>
#include <telepathy-glib/errors.h>
#include <telepathy-glib/interfaces.h>
@@ -984,6 +985,77 @@ _tp_dbus_daemon_get_name_owner (TpDBusDaemon *self,
G_TYPE_INVALID);
}
+/**
+ * _tp_dbus_daemon_request_name:
+ * @self: a TpDBusDaemon
+ * @well_known_name: a well-known name to acquire
+ * @idempotent: whether to consider it to be a success if this process
+ * already owns the name
+ * @error: used to raise an error if %FALSE is returned
+ *
+ * Claim the given well-known name without queueing, allowing replacement
+ * or replacing an existing name-owner.
+ *
+ * For internal use by TpBaseConnection, TpBaseConnectionManager.
+ */
+gboolean
+_tp_dbus_daemon_request_name (TpDBusDaemon *self,
+ const gchar *well_known_name,
+ gboolean idempotent,
+ GError **error)
+{
+ TpProxy *as_proxy = (TpProxy *) self;
+ DBusGConnection *gconn = as_proxy->dbus_connection;
+ DBusConnection *dbc = dbus_g_connection_get_connection (gconn);
+ DBusError dbus_error;
+ int result;
+
+ g_return_val_if_fail (TP_IS_DBUS_DAEMON (self), FALSE);
+ g_return_val_if_fail (tp_dbus_check_valid_bus_name (well_known_name,
+ TP_DBUS_NAME_TYPE_WELL_KNOWN, error), FALSE);
+
+ dbus_error_init (&dbus_error);
+ result = dbus_bus_request_name (dbc, well_known_name,
+ DBUS_NAME_FLAG_DO_NOT_QUEUE, &dbus_error);
+
+ switch (result)
+ {
+ case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
+ return TRUE;
+
+ case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
+ if (idempotent)
+ {
+ return TRUE;
+ }
+ else
+ {
+ g_set_error (error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
+ "Name '%s' already in use by this process", well_known_name);
+ return FALSE;
+ }
+
+ case DBUS_REQUEST_NAME_REPLY_EXISTS:
+ case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
+ /* the latter shouldn't actually happen since we said DO_NOT_QUEUE */
+ g_set_error (error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
+ "Name '%s' already in use by another process", well_known_name);
+ return FALSE;
+
+ case -1:
+ g_set_error (error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
+ "%s: %s", dbus_error.name, dbus_error.message);
+ dbus_error_free (&dbus_error);
+ return FALSE;
+
+ default:
+ g_set_error (error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
+ "RequestName('%s') returned %d and I don't know what that means",
+ well_known_name, result);
+ return FALSE;
+ }
+}
+
static GObject *
tp_dbus_daemon_constructor (GType type,
guint n_params,
--
1.5.6.5
More information about the telepathy-commits
mailing list