summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2011-04-26 17:38:33 +0100
committerJonny Lamb <jonny.lamb@collabora.co.uk>2011-04-26 17:38:33 +0100
commit81a11a12028f05882968762106a2c594f555ea13 (patch)
treeefab58ce49dfc2e26ce9d127ca0c4acab874b3d9
parentf96007f88c6e94654acc2eea7bef836cc55c362d (diff)
client: add support for poking in the handler capability tokens for Ytstenut clients
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r--docs/reference/telepathy-ytstenut-glib-sections.txt8
-rw-r--r--telepathy-ytstenut-glib/client.c217
-rw-r--r--telepathy-ytstenut-glib/client.h15
3 files changed, 235 insertions, 5 deletions
diff --git a/docs/reference/telepathy-ytstenut-glib-sections.txt b/docs/reference/telepathy-ytstenut-glib-sections.txt
index 50bd94f..0a7b7e7 100644
--- a/docs/reference/telepathy-ytstenut-glib-sections.txt
+++ b/docs/reference/telepathy-ytstenut-glib-sections.txt
@@ -190,6 +190,12 @@ tp_yts_svc_channel_get_type
TpYtsClient
TpYtsClientClass
tp_yts_client_new
+tp_yts_client_add_names
+tp_yts_client_add_name
+tp_yts_client_add_capabilities
+tp_yts_client_add_capability
+tp_yts_client_add_interests
+tp_yts_client_add_interest
tp_yts_client_register
tp_yts_client_accept_channel
tp_yts_client_request_channel_async
@@ -217,4 +223,4 @@ TP_YTS_IFACE_QUARK_ACCOUNT_MANAGER
tp_yts_iface_quark_account_manager
tp_yts_iface_quark_status
tp_yts_iface_quark_channel
-</SECTION> \ No newline at end of file
+</SECTION>
diff --git a/telepathy-ytstenut-glib/client.c b/telepathy-ytstenut-glib/client.c
index 3b34143..154a1f9 100644
--- a/telepathy-ytstenut-glib/client.c
+++ b/telepathy-ytstenut-glib/client.c
@@ -295,17 +295,25 @@ tp_yts_client_class_init (TpYtsClientClass *klass)
* @service_name: The Ytstenut service name for this client.
* @account: The Ytstenut account for this client.
*
- * Create a new #TpYtsClient object for the given Ytstenut service name
- * and account. You should
+ * Create a new #TpYtsClient object for the given Ytstenut name and
+ * account. After getting the new client object, you should add
+ * localized names, capabilities and interests with
+ * tp_yts_client_add_names(), tp_yts_client_add_capabilities() and
+ * tp_yts_client_add_interests() respectively.
+
+ * After setting these values, You should call
+ * tp_yts_client_register() to register the client. g_object_unref()
+ * should be used to free the object.
*
* Returns: A newly allocated client object.
*/
TpYtsClient *
-tp_yts_client_new (const gchar *service_name, TpAccount *account)
+tp_yts_client_new (const gchar *service_name,
+ TpAccount *account)
{
TpYtsClient *out = NULL;
TpDBusDaemon *bus;
- gchar *name;
+ gchar *name, *tmp;
g_return_val_if_fail (tp_dbus_check_valid_interface_name (service_name, NULL),
NULL);
@@ -324,10 +332,211 @@ tp_yts_client_new (const gchar *service_name, TpAccount *account)
g_object_unref (bus);
g_free (name);
+ /* add uid handler capability token */
+ tmp = g_strdup_printf (TP_YTS_IFACE_CHANNEL "/uid/%s", service_name);
+ tp_base_client_add_handler_capability (TP_BASE_CLIENT (out), tmp);
+ g_free (tmp);
+
return out;
}
/**
+ * tp_yts_client_add_names:
+ * @client: a #TpYtsClient
+ * @lang: the IETF language tag of the first name
+ * @...: the value of the first name and subsequent names, terminated
+ * by %NULL
+ *
+ * Adds a list of localized names to @client. See
+ * tp_yts_client_add_name() for more details on the singular version
+ * of this function.
+ *
+ * <example>
+ * <title>using tp_yts_client_add_names</title>
+ * <programlisting>
+ * tp_yts_client_add_names (client,
+ * "en_GB", "banana",
+ * "fr", "la banane",
+ * "de", "banane",
+ * NULL);
+ * </programlisting>
+ * </example>
+ */
+void
+tp_yts_client_add_names (TpYtsClient *client,
+ const gchar *lang,
+ ...)
+{
+ const gchar *key;
+ va_list ap;
+
+ va_start (ap, lang);
+
+ for (key = lang; key != NULL; key = va_arg (ap, const gchar *))
+ {
+ const gchar *val;
+
+ val = va_arg (ap, const gchar *);
+
+ if (val == NULL)
+ break;
+
+ tp_yts_client_add_name (client, key, val);
+ }
+
+ va_end (ap);
+
+}
+
+/**
+ * tp_yts_client_add_name:
+ * @client: a #TpYtsClient
+ * @lang: the IETF language tag
+ * @name: the localized name
+ *
+ * Adds @name as a localized name to @client. This will be advertised
+ * to other Ytstenut clients when @client is registered.
+ *
+ * This must be called before tp_yts_client_register() is called.
+ */
+void
+tp_yts_client_add_name (TpYtsClient *client,
+ const gchar *lang,
+ const gchar *name)
+{
+ gchar *tmp;
+
+ tmp = g_strdup_printf (TP_YTS_IFACE_CHANNEL "/name/%s/%s",
+ lang, name);
+
+ tp_base_client_add_handler_capability (TP_BASE_CLIENT (client), tmp);
+
+ g_free (tmp);
+}
+
+/**
+ * tp_yts_client_add_capabilities:
+ * @client: a #TpYtsClient
+ * @cap: the first capability to add
+ * @...: the subsequenet capabilities to add, followed by %NULL
+ *
+ * The plural version of tp_yts_client_add_capability().
+ *
+ * <example>
+ * <title>using tp_yts_client_add_capabilities</title>
+ * <programlisting>
+ * tp_yts_client_add_capabilities (client,
+ * "urn:ytstenut:capabilities:yts-caps-video",
+ * "urn:ytstenut:capabilities:yts-caps-audio",
+ * NULL);
+ * </programlisting>
+ * </example>
+ */
+void
+tp_yts_client_add_capabilities (TpYtsClient *client,
+ const gchar *first_cap,
+ ...)
+{
+ va_list ap;
+ const gchar *cap;
+
+ va_start (ap, first_cap);
+
+ for (cap = first_cap; cap != NULL; cap = va_arg (ap, const gchar *))
+ {
+ tp_yts_client_add_capability (client, cap);
+ }
+
+ va_end (ap);
+}
+
+/**
+ * tp_yts_client_add_capability:
+ * @client: a #TpYtsClient
+ * @cap: a capability to add
+ *
+ * Adds @cap as capability to @client. This will be advertised to
+ * other Ytstenut clients when @client is registered.
+ *
+ * This must be called before tp_yts_client_register() is called.
+ */
+void
+tp_yts_client_add_capability (TpYtsClient *client,
+ const gchar *cap)
+{
+ gchar *tmp;
+
+ tmp = g_strdup_printf (TP_YTS_IFACE_CHANNEL "/caps/%s", cap);
+
+ tp_base_client_add_handler_capability (TP_BASE_CLIENT (client), tmp);
+
+ g_free (tmp);
+}
+
+/**
+ * tp_yts_client_add_interests:
+ * @client: a #TpYtsClient
+ * @interest: the first interest to add
+ * @...: the subsequent interests to add, followed by %NULL
+ *
+ * The plural version of tp_yts_client_add_interest().
+ *
+ * <example>
+ * <title>using tp_yts_client_add_interests</title>
+ * <programlisting>
+ * tp_yts_client_add_interests (client,
+ * "urn:ytstenut:capabilities:falling-over",
+ * "urn:ytstenut:capabilities:taking-pictures-of-cats",
+ * NULL);
+ * </programlisting>
+ * </example>
+ */
+void
+tp_yts_client_add_interests (TpYtsClient *client,
+ const gchar *first_interest,
+ ...)
+{
+ va_list ap;
+ const gchar *interest;
+
+ va_start (ap, first_interest);
+
+ for (interest = first_interest;
+ interest != NULL;
+ interest = va_arg (ap, const gchar *))
+ {
+ tp_yts_client_add_interest (client, interest);
+ }
+
+ va_end (ap);
+}
+
+/**
+ * tp_yts_client_add_interest:
+ * @client: a #TpYtsClient
+ * @interest: an interest to add
+ *
+ * Adds @interest as an interest to @client. This will be advertised
+ * to other Ytstenut clients when @client is registered and as a
+ * result will mean that StatusChanged will be emitted for this
+ * interest from other services.
+ *
+ * This must be called before tp_yts_client_register() is called.
+ */
+void
+tp_yts_client_add_interest (TpYtsClient *client,
+ const gchar *interest)
+{
+ gchar *tmp;
+
+ tmp = g_strdup_printf (TP_YTS_IFACE_CHANNEL "/interested/%s", interest);
+
+ tp_base_client_add_handler_capability (TP_BASE_CLIENT (client), tmp);
+
+ g_free (tmp);
+}
+
+/**
* tp_yts_client_register:
* @self: The client object.
* @error: If not %NULL, raise an error here when %FALSE is returned.
diff --git a/telepathy-ytstenut-glib/client.h b/telepathy-ytstenut-glib/client.h
index 3149c94..b389066 100644
--- a/telepathy-ytstenut-glib/client.h
+++ b/telepathy-ytstenut-glib/client.h
@@ -61,6 +61,21 @@ GType tp_yts_client_get_type (void);
TpYtsClient *tp_yts_client_new (const gchar *service_name,
TpAccount *account);
+void tp_yts_client_add_names (TpYtsClient *client,
+ const gchar *lang, ...);
+void tp_yts_client_add_name (TpYtsClient *client,
+ const gchar *lang, const gchar *name);
+
+void tp_yts_client_add_capabilities (TpYtsClient *client,
+ const gchar *cap, ...);
+void tp_yts_client_add_capability (TpYtsClient *client,
+ const gchar *cap);
+
+void tp_yts_client_add_interests (TpYtsClient *client,
+ const gchar *interest, ...);
+void tp_yts_client_add_interest (TpYtsClient *client,
+ const gchar *interest);
+
gboolean tp_yts_client_register (TpYtsClient *self, GError **error);
TpYtsChannel *tp_yts_client_accept_channel (TpYtsClient *self);