From 529501022989500cffb73eba060f04c34fca9b91 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Thu, 14 Jul 2011 12:34:30 +0200 Subject: [PATCH] Add tp_simple_client_factory_dup_channel_request() --- docs/reference/telepathy-glib-sections.txt | 1 + telepathy-glib/channel-request.c | 21 +++++++++ telepathy-glib/simple-client-factory-internal.h | 8 ++++ telepathy-glib/simple-client-factory.c | 51 +++++++++++++++++++++++ telepathy-glib/simple-client-factory.h | 6 +++ 5 files changed, 87 insertions(+), 0 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 12da4cb..e5af863 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -5701,6 +5701,7 @@ tp_simple_client_factory_add_channel_features tp_simple_client_factory_dup_contact tp_simple_client_factory_dup_contact_features tp_simple_client_factory_add_contact_features +tp_simple_client_factory_dup_channel_request TP_IS_SIMPLE_CLIENT_FACTORY TP_IS_SIMPLE_CLIENT_FACTORY_CLASS diff --git a/telepathy-glib/channel-request.c b/telepathy-glib/channel-request.c index c8785e6..7559da0 100644 --- a/telepathy-glib/channel-request.c +++ b/telepathy-glib/channel-request.c @@ -35,6 +35,7 @@ #define DEBUG_FLAG TP_DEBUG_DISPATCHER #include "telepathy-glib/dbus-internal.h" #include "telepathy-glib/debug-internal.h" +#include "telepathy-glib/simple-client-factory-internal.h" #include "telepathy-glib/_gen/tp-cli-channel-request-body.h" @@ -573,6 +574,17 @@ tp_channel_request_new (TpDBusDaemon *bus_daemon, GHashTable *immutable_properties, GError **error) { + return _tp_channel_request_new_with_factory (bus_daemon, object_path, + immutable_properties, error, NULL); +} + +TpChannelRequest * +_tp_channel_request_new_with_factory (TpDBusDaemon *bus_daemon, + const gchar *object_path, + GHashTable *immutable_properties, + GError **error, + TpSimpleClientFactory *factory) +{ TpChannelRequest *self; gchar *unique_name; @@ -593,6 +605,7 @@ tp_channel_request_new (TpDBusDaemon *bus_daemon, "bus-name", unique_name, "object-path", object_path, "immutable-properties", immutable_properties, + "factory", factory, NULL)); g_free (unique_name); @@ -638,6 +651,14 @@ tp_channel_request_get_immutable_properties (TpChannelRequest *self) return self->priv->immutable_properties; } +void +_tp_channel_request_ensure_immutable_properties (TpChannelRequest *self, + GHashTable *immutable_properties) +{ + if (self->priv->immutable_properties == NULL && immutable_properties != NULL) + self->priv->immutable_properties = g_hash_table_ref (immutable_properties); +} + /** * tp_channel_request_get_account: * @self: a #tpchannelrequest diff --git a/telepathy-glib/simple-client-factory-internal.h b/telepathy-glib/simple-client-factory-internal.h index 72daa90..00c67ff 100644 --- a/telepathy-glib/simple-client-factory-internal.h +++ b/telepathy-glib/simple-client-factory-internal.h @@ -42,6 +42,14 @@ TpChannel *_tp_channel_new_with_factory (TpConnection *conn, const gchar *object_path, const GHashTable *immutable_properties, GError **error, TpSimpleClientFactory *factory); +TpChannelRequest *_tp_channel_request_new_with_factory ( + TpDBusDaemon *bus_daemon, const gchar *object_path, + GHashTable *immutable_properties, GError **error, + TpSimpleClientFactory *factory); +void _tp_channel_request_ensure_immutable_properties (TpChannelRequest *self, + GHashTable *immutable_properties); + + G_END_DECLS #endif diff --git a/telepathy-glib/simple-client-factory.c b/telepathy-glib/simple-client-factory.c index 8d33499..1bfa627 100644 --- a/telepathy-glib/simple-client-factory.c +++ b/telepathy-glib/simple-client-factory.c @@ -856,3 +856,54 @@ tp_simple_client_factory_add_contact_features (TpSimpleClientFactory *self, g_array_append_val (self->priv->desired_contact_features, features[i]); } } + +/** + * tp_simple_client_factory_dup_channel_request: + * @self: a #TpSimpleClientFactory object + * @object_path: the non-NULL object path of this connection + * @immutable_properties: (transfer none) (element-type utf8 GObject.Value): + * the immutable properties of the channel request + * @error: Used to raise an error if @object_path is not valid + * + * If a #TpChannelRequest proxy has already been created using this method for + * the given @object_path, it will be returned. Otherwise a new one will be + * created. + * + * @self keeps only a weak-ref on the returned object, so it is the caller's + * responsability to keep a strong ref as long as needed. + * + * Returns: (transfer full): a new or existing #TpChannelRequest proxy; + * see tp_channel_request_new(). + * + * Since: 0.UNRELEASED + */ +TpChannelRequest * +tp_simple_client_factory_dup_channel_request (TpSimpleClientFactory *self, + const gchar *object_path, + GHashTable *immutable_properties, + GError **error) +{ + TpChannelRequest *request; + + g_return_val_if_fail (TP_IS_SIMPLE_CLIENT_FACTORY (self), NULL); + g_return_val_if_fail (g_variant_is_object_path (object_path), NULL); + + request = lookup_proxy (self, object_path); + if (request != NULL) + { + /* A common usage is request_and_handle, in that case EnsureChannel + * returns only the object-path of the ChannelRequest but not properties. + * The TpChannelRequest will be created with no properties, then when + * handling we get the properties and we reuse the same TpChannelRequest + * object, and we can give it the immutable-properties. */ + _tp_channel_request_ensure_immutable_properties (request, + immutable_properties); + return g_object_ref (request); + } + + request = _tp_channel_request_new_with_factory (self->priv->dbus, object_path, + immutable_properties, error, self); + insert_proxy (self, request); + + return request; +} diff --git a/telepathy-glib/simple-client-factory.h b/telepathy-glib/simple-client-factory.h index 239fad8..0f6e50b 100644 --- a/telepathy-glib/simple-client-factory.h +++ b/telepathy-glib/simple-client-factory.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -136,6 +137,11 @@ GArray *tp_simple_client_factory_dup_contact_features ( void tp_simple_client_factory_add_contact_features (TpSimpleClientFactory *self, guint n_features, const TpContactFeature *features); +/* TpChannelRequest */ +TpChannelRequest *tp_simple_client_factory_dup_channel_request ( + TpSimpleClientFactory *self, const gchar *object_path, + GHashTable *immutable_properties, GError **error); + G_END_DECLS #endif -- 1.7.4.1