[Telepathy-commits] [telepathy-glib/master] tp_dbus_daemon_dup(): add new API to get a cached starter-bus TpDBusDaemon

Simon McVittie simon.mcvittie at collabora.co.uk
Fri Jan 30 05:59:08 PST 2009


---
 docs/reference/telepathy-glib-sections.txt |    1 +
 telepathy-glib/dbus.c                      |   50 +++++++++++++++++++++++++++-
 telepathy-glib/dbus.h                      |    2 +
 3 files changed, 52 insertions(+), 1 deletions(-)

diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 50d823e..6799742 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -1439,6 +1439,7 @@ tp_dbus_check_valid_object_path
 <SUBSECTION>
 TpDBusDaemon
 TpDBusDaemonClass
+tp_dbus_daemon_dup
 tp_dbus_daemon_new
 TpDBusDaemonNameOwnerChangedCb
 tp_dbus_daemon_watch_name_owner
diff --git a/telepathy-glib/dbus.c b/telepathy-glib/dbus.c
index e840d23..11a63f8 100644
--- a/telepathy-glib/dbus.c
+++ b/telepathy-glib/dbus.c
@@ -122,6 +122,7 @@ starter_bus_conn (GError **error)
  * be useful even in the absence of D-Bus - it is designed for use in
  * connection managers, which are not at all useful without a D-Bus
  * connection. See <https://bugs.freedesktop.org/show_bug.cgi?id=18832>.
+ * Most processes should use tp_dbus_daemon_dup() instead.
  *
  * Returns: a connection to the starter or session D-Bus daemon.
  */
@@ -606,11 +607,58 @@ struct _TpDBusDaemonPrivate
 
 G_DEFINE_TYPE (TpDBusDaemon, tp_dbus_daemon, TP_TYPE_PROXY);
 
+static gpointer starter_bus_daemon = NULL;
+
+/**
+ * tp_dbus_daemon_dup:
+ * @error: Used to indicate error if %NULL is returned
+ *
+ * Returns a proxy for signals and method calls on the D-Bus daemon on which
+ * this process was activated (if it was launched by D-Bus service
+ * activation), or the session bus (otherwise).
+ *
+ * If it is not possible to connect to the appropriate bus, raise an error
+ * and return %NULL.
+ *
+ * The returned #TpDBusDaemon is cached; the same #TpDBusDaemon object will
+ * be returned by this function repeatedly, as long as at least one reference
+ * exists.
+ *
+ * Returns: a reference to a proxy for signals and method calls on the bus
+ *  daemon, or %NULL
+ *
+ * Since: 0.7.UNRELEASED
+ */
+TpDBusDaemon *
+tp_dbus_daemon_dup (GError **error)
+{
+  DBusGConnection *conn;
+
+  if (starter_bus_daemon != NULL)
+    return g_object_ref (starter_bus_daemon);
+
+  conn = starter_bus_conn (error);
+
+  if (conn == NULL)
+    return NULL;
+
+  starter_bus_daemon = tp_dbus_daemon_new (conn);
+  g_assert (starter_bus_daemon != NULL);
+  g_object_add_weak_pointer (starter_bus_daemon, &starter_bus_daemon);
+
+  return starter_bus_daemon;
+}
+
 /**
  * tp_dbus_daemon_new:
  * @connection: a connection to D-Bus
  *
- * <!-- -->
+ * Returns a proxy for signals and method calls on a particular bus
+ * connection.
+ *
+ * Use tp_dbus_daemon_dup() instead if you just want a connection to the
+ * starter or session bus (which is almost always the right thing for
+ * Telepathy).
  *
  * Returns: a new proxy for signals and method calls on the bus daemon
  *  to which @connection is connected
diff --git a/telepathy-glib/dbus.h b/telepathy-glib/dbus.h
index dbcc0a8..6104817 100644
--- a/telepathy-glib/dbus.h
+++ b/telepathy-glib/dbus.h
@@ -51,6 +51,8 @@ GType tp_dbus_daemon_get_type (void);
   (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TYPE_DBUS_DAEMON, \
                               TpDBusDaemonClass))
 
+TpDBusDaemon *tp_dbus_daemon_dup (GError **error);
+
 TpDBusDaemon *tp_dbus_daemon_new (DBusGConnection *connection);
 
 typedef void (*TpDBusDaemonNameOwnerChangedCb) (TpDBusDaemon *bus_daemon,
-- 
1.5.6.5




More information about the telepathy-commits mailing list