From 6a3ed80650a4a95e1c945b129ad93f22c23b845a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 21 Oct 2013 19:06:43 +0100 Subject: [PATCH 09/16] TpBaseConnectionManager: add dup_cm_dbus_name() virtual method Subclasses written in PyGI can't override a field, but they can override a virtual method. --- docs/reference/telepathy-glib-sections.txt | 1 + telepathy-glib/base-connection-manager.c | 69 +++++++++++++++++++++++++----- telepathy-glib/base-connection-manager.h | 6 ++- 3 files changed, 65 insertions(+), 11 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 6452e26..3911521 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -116,6 +116,7 @@ TpBaseConnectionManager TpBaseConnectionManagerClass TpBaseConnectionManagerNewConnFunc TpBaseConnectionManagerGetInterfacesFunc +tp_base_connection_manager_dup_cm_dbus_name tp_base_connection_manager_get_dbus_daemon tp_base_connection_manager_register tp_base_connection_manager_add_protocol diff --git a/telepathy-glib/base-connection-manager.c b/telepathy-glib/base-connection-manager.c index a533bb2..faab1e4 100644 --- a/telepathy-glib/base-connection-manager.c +++ b/telepathy-glib/base-connection-manager.c @@ -208,13 +208,18 @@ _tp_legacy_protocol_new (TpBaseConnectionManager *cm, * @cm_dbus_name: The name of this connection manager, as used to construct * D-Bus object paths and bus names. Must contain only letters, digits * and underscores, and may not start with a digit. Must be filled in by - * subclasses in their class_init function. + * subclasses in their class_init function, unless @dup_cm_dbus_name + * is implemented. * @get_interfaces: Returns a #GPtrArray of static strings of extra * D-Bus interfaces implemented by instances of this class, which may be * filled in by subclasses. The default is to list no additional interfaces. * Implementations must first chainup on parent class implementation and then * add extra interfaces to the #GPtrArray. Replaces @interfaces. Since: * 0.19.4 + * @dup_cm_dbus_name: Returns the name of this connection manager, as used + * to construct D-Bus object paths and bus names. It must contain only + * letters, digits and underscores, and may not start with a digit. + * Since: 0.UNRELEASED * * The class structure for #TpBaseConnectionManager. * @@ -393,7 +398,8 @@ tp_base_connection_manager_constructor (GType type, TP_BASE_CONNECTION_MANAGER_GET_CLASS (self); GError *error = NULL; - g_assert (tp_connection_manager_check_valid_name (cls->cm_dbus_name, NULL)); + g_assert (cls->cm_dbus_name == NULL || + tp_connection_manager_check_valid_name (cls->cm_dbus_name, NULL)); /* if one of these is NULL, the other must be too */ g_assert (cls->new_connection == NULL || cls->protocol_params != NULL); @@ -510,6 +516,16 @@ tp_base_connection_manager_get_interfaces (TpBaseConnectionManager *self) return interfaces; } +static gchar * +tp_base_connection_manager_default_dup_cm_dbus_name ( + TpBaseConnectionManager *self) +{ + TpBaseConnectionManagerClass *cls = + TP_BASE_CONNECTION_MANAGER_GET_CLASS (self); + + return g_strdup (cls->cm_dbus_name); +} + static void tp_base_connection_manager_class_init (TpBaseConnectionManagerClass *klass) { @@ -528,6 +544,7 @@ tp_base_connection_manager_class_init (TpBaseConnectionManagerClass *klass) object_class->finalize = tp_base_connection_manager_finalize; klass->get_interfaces = tp_base_connection_manager_get_interfaces; + klass->dup_cm_dbus_name = tp_base_connection_manager_default_dup_cm_dbus_name; /** * TpBaseConnectionManager:dbus-daemon: @@ -1018,10 +1035,9 @@ tp_base_connection_manager_request_connection (TpSvcConnectionManager *iface, DBusGMethodInvocation *context) { TpBaseConnectionManager *self = TP_BASE_CONNECTION_MANAGER (iface); - TpBaseConnectionManagerClass *cls = - TP_BASE_CONNECTION_MANAGER_GET_CLASS (self); TpBaseConnectionManagerPrivate *priv = self->priv; TpBaseConnection *conn; + gchar *cm_dbus_name = NULL; gchar *bus_name; gchar *object_path; GError *error = NULL; @@ -1045,8 +1061,10 @@ tp_base_connection_manager_request_connection (TpSvcConnectionManager *iface, if (conn == NULL) goto ERROR; + cm_dbus_name = tp_base_connection_manager_dup_cm_dbus_name (self); + /* register on bus and save bus name and object path */ - if (!tp_base_connection_register (conn, cls->cm_dbus_name, + if (!tp_base_connection_register (conn, cm_dbus_name, &bus_name, &object_path, &error)) { DEBUG ("failed: %s", error->message); @@ -1072,11 +1090,13 @@ tp_base_connection_manager_request_connection (TpSvcConnectionManager *iface, g_free (bus_name); g_free (object_path); + g_free (cm_dbus_name); return; ERROR: dbus_g_method_return_error (context, error); g_error_free (error); + g_free (cm_dbus_name); } /** @@ -1084,8 +1104,9 @@ ERROR: * @self: The connection manager implementation * * Register the connection manager with an appropriate object path as - * determined from its @cm_dbus_name, and register the appropriate well-known - * bus name. + * determined from its + * tp_base_connection_manager_dup_cm_dbus_name(), + * and register the appropriate well-known bus name. * * Returns: %TRUE on success, %FALSE (having emitted a warning to stderr) * on failure @@ -1097,6 +1118,7 @@ tp_base_connection_manager_register (TpBaseConnectionManager *self) GError *error = NULL; TpBaseConnectionManagerClass *cls; GString *string = NULL; + gchar *cm_dbus_name = NULL; guint i; GHashTableIter iter; gpointer name, protocol; @@ -1121,15 +1143,17 @@ tp_base_connection_manager_register (TpBaseConnectionManager *self) g_assert (self->priv->dbus_daemon != NULL); + cm_dbus_name = tp_base_connection_manager_dup_cm_dbus_name (self); + string = g_string_new (TP_CM_BUS_NAME_BASE); - g_string_append (string, cls->cm_dbus_name); + g_string_append (string, cm_dbus_name); if (!tp_dbus_daemon_request_name (self->priv->dbus_daemon, string->str, TRUE, &error)) goto except; g_string_assign (string, TP_CM_OBJECT_PATH_BASE); - g_string_append (string, cls->cm_dbus_name); + g_string_append (string, cm_dbus_name); tp_dbus_daemon_register_object (self->priv->dbus_daemon, string->str, self); g_hash_table_iter_init (&iter, self->priv->protocols); @@ -1150,7 +1174,7 @@ tp_base_connection_manager_register (TpBaseConnectionManager *self) continue; g_string_assign (string, TP_CM_OBJECT_PATH_BASE); - g_string_append (string, cls->cm_dbus_name); + g_string_append (string, cm_dbus_name); g_string_append_c (string, '/'); g_string_append (string, name); @@ -1161,6 +1185,7 @@ tp_base_connection_manager_register (TpBaseConnectionManager *self) } g_string_free (string, TRUE); + g_free (cm_dbus_name); self->priv->registered = TRUE; @@ -1171,6 +1196,7 @@ except: "connection manager, disable all accounts and kill any running " "copies of this CM, then try again. %s", error->message); g_error_free (error); + g_free (cm_dbus_name); if (string != NULL) g_string_free (string, TRUE); @@ -1232,3 +1258,26 @@ tp_base_connection_manager_add_protocol (TpBaseConnectionManager *self, g_strdup (tp_base_protocol_get_name (protocol)), g_object_ref (protocol)); } + +/** + * tp_base_connection_manager_dup_cm_dbus_name: + * @self: a connection manager object + * + * + * + * Returns: (transfer full): the short D-Bus name of this connection manager, + * such as "gabble" or "haze" + * Since: 0.UNRELEASED + */ +gchar * +tp_base_connection_manager_dup_cm_dbus_name ( + TpBaseConnectionManager *self) +{ + TpBaseConnectionManagerClass *cls; + + g_return_val_if_fail (TP_IS_BASE_CONNECTION_MANAGER (self), NULL); + cls = TP_BASE_CONNECTION_MANAGER_GET_CLASS (self); + g_return_val_if_fail (TP_IS_BASE_CONNECTION_MANAGER_CLASS (cls), NULL); + + return cls->dup_cm_dbus_name (self); +} diff --git a/telepathy-glib/base-connection-manager.h b/telepathy-glib/base-connection-manager.h index fe15b70..c1f7c86 100644 --- a/telepathy-glib/base-connection-manager.h +++ b/telepathy-glib/base-connection-manager.h @@ -79,9 +79,9 @@ struct _TpBaseConnectionManagerClass { const gchar * const *_TP_SEAL (interfaces); /**/ TpBaseConnectionManagerGetInterfacesFunc get_interfaces; + gchar *(*dup_cm_dbus_name) (TpBaseConnectionManager *self); /**/ - gpointer _future3; gpointer _future4; TpBaseConnectionManagerClassPrivate *priv; @@ -105,6 +105,10 @@ TpDBusDaemon *tp_base_connection_manager_get_dbus_daemon ( void tp_base_connection_manager_add_protocol (TpBaseConnectionManager *self, TpBaseProtocol *protocol); +_TP_AVAILABLE_IN_UNRELEASED +gchar *tp_base_connection_manager_dup_cm_dbus_name ( + TpBaseConnectionManager *self); + /* TYPE MACROS */ #define TP_TYPE_BASE_CONNECTION_MANAGER \ (tp_base_connection_manager_get_type ()) -- 1.8.4.rc3