[next] telepathy-glib: add tp_client_factory_ensure_protocol()
Guillaume Desmottes
gdesmott at kemper.freedesktop.org
Mon Mar 17 07:25:42 PDT 2014
Module: telepathy-glib
Branch: next
Commit: 777a952629036bcee843f95b23f35bc3f9d8fa34
URL: http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=777a952629036bcee843f95b23f35bc3f9d8fa34
Author: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Date: Thu Mar 6 14:55:16 2014 +0100
add tp_client_factory_ensure_protocol()
No caching yet, just a wrapper around tp_protocol_new() for now.
---
.../telepathy-glib/telepathy-glib-sections.txt | 2 +
telepathy-glib/client-factory.c | 39 ++++++++++++++++++++
telepathy-glib/client-factory.h | 9 +++++
tests/dbus/protocol-objects.c | 18 +++++----
4 files changed, 61 insertions(+), 7 deletions(-)
diff --git a/docs/reference/telepathy-glib/telepathy-glib-sections.txt b/docs/reference/telepathy-glib/telepathy-glib-sections.txt
index 588034c..0e0dcce 100644
--- a/docs/reference/telepathy-glib/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib/telepathy-glib-sections.txt
@@ -5785,6 +5785,8 @@ tp_client_factory_ensure_contact_by_id_finish
tp_client_factory_dup_contact_features
tp_client_factory_add_contact_features
tp_client_factory_add_contact_features_varargs
+<SUBSECTION>
+tp_client_factory_ensure_protocol
<SUBSECTION Standard>
TP_IS_CLIENT_FACTORY
TP_IS_CLIENT_FACTORY_CLASS
diff --git a/telepathy-glib/client-factory.c b/telepathy-glib/client-factory.c
index 041cbcf..38cf4a8 100644
--- a/telepathy-glib/client-factory.c
+++ b/telepathy-glib/client-factory.c
@@ -1259,3 +1259,42 @@ _tp_client_factory_ensure_channel_dispatch_operation (
return dispatch;
}
+
+/**
+ * tp_client_factory_ensure_protocol:
+ * @self: a #TpClientFactory
+ * @cm_name: the connection manager name (such as "gabble")
+ * @protocol_name: the protocol name (such as "jabber")
+ * @immutable_properties: (allow-none) a #G_VARIANT_TYPE_VARDICT containing
+ * the immutable properties of the protocol, or %NULL.
+ * @error: Used to raise an error if @cm_name or @protocol_name is invalid
+ *
+ * Returns a #TpProtocol proxy for the protocol @protocol_name on connection
+ * manager @cm_name.
+ * The returned #TpProtocol is cached; the same #TpProtocol object
+ * will be returned by this function repeatedly, as long as at least one
+ * reference exists.
+ *
+ * Note that the returned #TpProtocol is not guaranteed to be ready; the
+ * caller is responsible for calling tp_proxy_prepare_async() with the desired
+ * features (as given by tp_client_factory_dup_protocol_features()).
+ *
+ * @immutable_properties is consumed if it is floating.
+ *
+ * Returns: (transfer full): a reference to a #TpProtocol,
+ * or %NULL on invalid arguments
+ *
+ * Since: UNRELEASED
+ */
+TpProtocol *
+tp_client_factory_ensure_protocol (TpClientFactory *self,
+ const gchar *cm_name,
+ const gchar *protocol_name,
+ GVariant *immutable_properties,
+ GError **error)
+{
+ g_return_val_if_fail (TP_IS_CLIENT_FACTORY (self), NULL);
+
+ return tp_protocol_new (self->priv->dbus, cm_name, protocol_name,
+ immutable_properties, error);
+}
diff --git a/telepathy-glib/client-factory.h b/telepathy-glib/client-factory.h
index 1a79da8..b79cbdc 100644
--- a/telepathy-glib/client-factory.h
+++ b/telepathy-glib/client-factory.h
@@ -32,6 +32,7 @@
#include <telepathy-glib/connection.h>
#include <telepathy-glib/contact.h>
#include <telepathy-glib/dbus-daemon.h>
+#include <telepathy-glib/protocol.h>
G_BEGIN_DECLS
@@ -183,6 +184,14 @@ void tp_client_factory_add_contact_features_varargs (TpClientFactory *self,
GQuark feature,
...);
+/* TpProtocol */
+_TP_AVAILABLE_IN_UNRELEASED
+TpProtocol *tp_client_factory_ensure_protocol (TpClientFactory *self,
+ const gchar *cm_name,
+ const gchar *protocol_name,
+ GVariant *immutable_properties,
+ GError **error);
+
G_END_DECLS
#endif
diff --git a/tests/dbus/protocol-objects.c b/tests/dbus/protocol-objects.c
index 0335303..bf1c7dd 100644
--- a/tests/dbus/protocol-objects.c
+++ b/tests/dbus/protocol-objects.c
@@ -25,6 +25,7 @@ typedef struct
{
GMainLoop *mainloop;
TpDBusDaemon *dbus;
+ TpClientFactory *factory;
GError *error /* statically initialized to NULL */ ;
ExampleEcho2ConnectionManager *service_cm;
@@ -49,6 +50,8 @@ setup (Test *test,
test->dbus = tp_dbus_daemon_dup (NULL);
g_assert (test->dbus != NULL);
+ test->factory = tp_automatic_client_factory_new (test->dbus);
+
test->service_cm = EXAMPLE_ECHO_2_CONNECTION_MANAGER (g_object_new (
EXAMPLE_TYPE_ECHO_2_CONNECTION_MANAGER,
NULL));
@@ -83,6 +86,7 @@ teardown (Test *test,
tp_clear_object (&test->file_cm);
tp_clear_object (&test->file_protocol);
+ tp_clear_object (&test->factory);
tp_clear_object (&test->dbus);
g_main_loop_unref (test->mainloop);
test->mainloop = NULL;
@@ -125,8 +129,8 @@ test_protocol_properties (Test *test,
GValueArray *va;
GHashTable *fixed;
- test->protocol = tp_protocol_new (test->dbus, "example_echo_2",
- "example", NULL, NULL);
+ test->protocol = tp_client_factory_ensure_protocol (test->factory,
+ "example_echo_2", "example", NULL, NULL);
g_assert (test->protocol != NULL);
tp_cli_dbus_properties_run_get_all (test->protocol, -1,
@@ -175,8 +179,8 @@ test_protocol_avatar_properties (Test *test,
gboolean is_set;
guint num;
- test->protocol = tp_protocol_new (test->dbus, "example_echo_2",
- "example", NULL, NULL);
+ test->protocol = tp_client_factory_ensure_protocol (test->factory,
+ "example_echo_2", "example", NULL, NULL);
g_assert (test->protocol != NULL);
tp_cli_dbus_properties_run_get_all (test->protocol, -1,
@@ -222,8 +226,8 @@ test_protocol_addressing_properties (Test *test,
{
GHashTable *properties = NULL;
- test->protocol = tp_protocol_new (test->dbus, "example_echo_2",
- "example", NULL, NULL);
+ test->protocol = tp_client_factory_ensure_protocol (test->factory,
+ "example_echo_2", "example", NULL, NULL);
g_assert (test->protocol != NULL);
tp_cli_dbus_properties_run_get_all (test->protocol, -1,
@@ -404,7 +408,7 @@ test_protocol_object (Test *test,
"protocol-properties", &props,
NULL);
- protocol = tp_protocol_new (test->dbus, "example_echo_2",
+ protocol = tp_client_factory_ensure_protocol (test->factory, "example_echo_2",
"example", props, &test->error);
g_assert_no_error (test->error);
g_assert (TP_IS_PROTOCOL (protocol));
More information about the telepathy-commits
mailing list