From 75ff3e190199c645bfa9ab3ae72b16f6374e43d3 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Fri, 9 May 2014 16:23:55 +0200 Subject: [PATCH 02/11] base-client: use gdbus-codegen's skeleton to implement Client --- telepathy-glib/Makefile.am | 2 ++ telepathy-glib/base-client.c | 66 +++++++++++++++++++++++--------------------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/telepathy-glib/Makefile.am b/telepathy-glib/Makefile.am index 84ab59e..7c93ac2 100644 --- a/telepathy-glib/Makefile.am +++ b/telepathy-glib/Makefile.am @@ -355,6 +355,8 @@ gdbus_codegen = \ _gdbus/Connection_Interface_Presence1.h \ _gdbus/Connection_Interface_Requests.c \ _gdbus/Connection_Interface_Requests.h \ + _gdbus/Client.c \ + _gdbus/Client.h \ $(NULL) _gdbus/%.c: _gdbus/%-stamp diff --git a/telepathy-glib/base-client.c b/telepathy-glib/base-client.c index 3235041..6439418 100644 --- a/telepathy-glib/base-client.c +++ b/telepathy-glib/base-client.c @@ -193,6 +193,8 @@ #include #include +#include + #define DEBUG_FLAG TP_DEBUG_CLIENT #include "telepathy-glib/connection-internal.h" #include "telepathy-glib/debug-internal.h" @@ -207,7 +209,6 @@ static void requests_iface_init (gpointer, gpointer); G_DEFINE_ABSTRACT_TYPE_WITH_CODE(TpBaseClient, tp_base_client, G_TYPE_DBUS_OBJECT_SKELETON, - G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_CLIENT, NULL); G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_CLIENT_OBSERVER, observer_iface_init); G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_CLIENT_APPROVER, approver_iface_init); G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_CLIENT_HANDLER, handler_iface_init); @@ -271,6 +272,8 @@ struct _TpBaseClientPrivate TpBaseClientDelegatedChannelsCb delegated_channels_cb; gpointer delegated_channels_data; GDestroyNotify delegated_channels_destroy; + + _TpGDBusClient *client_skeleton; }; /* @@ -469,6 +472,7 @@ tp_base_client_set_observer_recover (TpBaseClient *self, self->priv->flags |= CLIENT_IS_OBSERVER; self->priv->flags &= ~CLIENT_OBSERVER_RECOVER; } + } /** @@ -907,6 +911,26 @@ clients_quark (void) return q; } +static void +update_interfaces (TpBaseClient *self) +{ + GPtrArray *arr = g_ptr_array_new (); + + if (self->priv->flags & CLIENT_IS_OBSERVER) + g_ptr_array_add (arr, TP_IFACE_CLIENT_OBSERVER); + if (self->priv->flags & CLIENT_IS_APPROVER) + g_ptr_array_add (arr, TP_IFACE_CLIENT_APPROVER); + if (self->priv->flags & CLIENT_IS_HANDLER) + g_ptr_array_add (arr, TP_IFACE_CLIENT_HANDLER); + if (self->priv->flags & CLIENT_HANDLER_WANTS_REQUESTS) + g_ptr_array_add (arr, TP_IFACE_CLIENT_INTERFACE_REQUESTS); + + g_ptr_array_add (arr, NULL); + _tp_gdbus_client_set_interfaces (self->priv->client_skeleton, + (const gchar * const *) arr->pdata); + g_ptr_array_unref (arr); +} + /** * tp_base_client_register: * @self: a #TpBaseClient, which must not have been registered with @@ -937,6 +961,8 @@ tp_base_client_register (TpBaseClient *self, DEBUG ("request name %s", self->priv->bus_name); + update_interfaces (self); + if (!tp_dbus_connection_try_register_object (self->priv->dbus, self->priv->object_path, G_OBJECT (self), error)) { @@ -1058,6 +1084,8 @@ tp_base_client_init (TpBaseClient *self) self->priv->my_chans = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); + + self->priv->client_skeleton = _tp_gdbus_client_skeleton_new (); } static void @@ -1090,6 +1118,8 @@ tp_base_client_dispose (GObject *object) self->priv->delegated_channels_destroy = NULL; } + g_clear_object (&self->priv->client_skeleton); + if (dispose != NULL) dispose (object); } @@ -1211,7 +1241,9 @@ tp_base_client_constructed (GObject *object) if (chain_up != NULL) chain_up (object); - object_skeleton_take_svc_interface (skel, TP_TYPE_SVC_CLIENT); + g_dbus_object_skeleton_add_interface (skel, + G_DBUS_INTERFACE_SKELETON (self->priv->client_skeleton)); + object_skeleton_take_svc_interface (skel, TP_TYPE_SVC_CLIENT_OBSERVER); object_skeleton_take_svc_interface (skel, TP_TYPE_SVC_CLIENT_APPROVER); object_skeleton_take_svc_interface (skel, TP_TYPE_SVC_CLIENT_HANDLER); @@ -1254,7 +1286,6 @@ tp_base_client_constructed (GObject *object) } typedef enum { - DP_INTERFACES, DP_APPROVER_CHANNEL_FILTER, DP_HANDLER_CHANNEL_FILTER, DP_BYPASS_APPROVAL, @@ -1277,28 +1308,6 @@ tp_base_client_get_dbus_properties (GObject *object, switch (which) { - case DP_INTERFACES: - { - GPtrArray *arr = g_ptr_array_sized_new (5); - - if (self->priv->flags & CLIENT_IS_OBSERVER) - g_ptr_array_add (arr, g_strdup (TP_IFACE_CLIENT_OBSERVER)); - - if (self->priv->flags & CLIENT_IS_APPROVER) - g_ptr_array_add (arr, g_strdup (TP_IFACE_CLIENT_APPROVER)); - - if (self->priv->flags & CLIENT_IS_HANDLER) - g_ptr_array_add (arr, g_strdup (TP_IFACE_CLIENT_HANDLER)); - - if (self->priv->flags & CLIENT_HANDLER_WANTS_REQUESTS) - g_ptr_array_add (arr, g_strdup ( - TP_IFACE_CLIENT_INTERFACE_REQUESTS)); - - g_ptr_array_add (arr, NULL); - g_value_take_boxed (value, g_ptr_array_free (arr, FALSE)); - } - break; - case DP_OBSERVER_CHANNEL_FILTER: g_value_set_boxed (value, self->priv->observer_filters); break; @@ -1355,10 +1364,6 @@ static void tp_base_client_class_init (TpBaseClientClass *cls) { GParamSpec *param_spec; - static TpDBusPropertiesMixinPropImpl client_properties[] = { - { "Interfaces", GINT_TO_POINTER (DP_INTERFACES) }, - { NULL } - }; static TpDBusPropertiesMixinPropImpl handler_properties[] = { { "HandlerChannelFilter", GINT_TO_POINTER (DP_HANDLER_CHANNEL_FILTER) }, @@ -1506,9 +1511,6 @@ tp_base_client_class_init (TpBaseClientClass *cls) tp_dbus_properties_mixin_class_init (object_class, 0); tp_dbus_properties_mixin_implement_interface (object_class, - TP_IFACE_QUARK_CLIENT, tp_base_client_get_dbus_properties, - NULL, client_properties); - tp_dbus_properties_mixin_implement_interface (object_class, TP_IFACE_QUARK_CLIENT_OBSERVER, tp_base_client_get_dbus_properties, NULL, observer_properties); tp_dbus_properties_mixin_implement_interface (object_class, -- 1.9.0