[telepathy-gabble/master] add wocky_pep_service_get_{async,finish}

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Mon Sep 21 06:06:52 PDT 2009


---
 src/wocky-pep-service.c |   70 +++++++++++++++++++++++++++++++++++++++++++++++
 src/wocky-pep-service.h |   11 +++++++
 2 files changed, 81 insertions(+), 0 deletions(-)

diff --git a/src/wocky-pep-service.c b/src/wocky-pep-service.c
index f670987..0f27f98 100644
--- a/src/wocky-pep-service.c
+++ b/src/wocky-pep-service.c
@@ -264,3 +264,73 @@ wocky_pep_service_start (WockyPepService *self,
 
   /* TODO: subscribe to node if needed */
 }
+
+static void
+send_query_cb (GObject *source,
+    GAsyncResult *res,
+    gpointer user_data)
+{
+  GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data);
+  GError *error = NULL;
+  WockyXmppStanza *reply;
+
+  reply = wocky_porter_send_iq_finish (WOCKY_PORTER (source), res, &error);
+  if (reply == NULL)
+    {
+      g_simple_async_result_set_from_error (result, error);
+      g_error_free (error);
+    }
+
+  g_simple_async_result_set_op_res_gpointer (result, reply, NULL);
+  g_simple_async_result_complete (result);
+  g_object_unref (result);
+}
+
+void
+wocky_pep_service_get_async (WockyPepService *self,
+    WockyBareContact *contact,
+    GCancellable *cancellable,
+    GAsyncReadyCallback callback,
+    gpointer user_data)
+{
+  WockyPepServicePrivate *priv = WOCKY_PEP_SERVICE_GET_PRIVATE (self);
+  WockyXmppStanza *msg;
+  GSimpleAsyncResult *result;
+  const gchar *jid;
+
+  jid = wocky_bare_contact_get_jid (contact);
+
+  msg = wocky_xmpp_stanza_build (
+      WOCKY_STANZA_TYPE_IQ, WOCKY_STANZA_SUB_TYPE_GET,
+      NULL, jid,
+      WOCKY_NODE, "pubsub",
+        WOCKY_NODE_XMLNS, WOCKY_XMPP_NS_PUBSUB,
+        WOCKY_NODE, "items",
+          WOCKY_NODE_ATTRIBUTE, "node", priv->node,
+        WOCKY_NODE_END,
+      WOCKY_NODE_END, WOCKY_STANZA_END);
+
+  result = g_simple_async_result_new (G_OBJECT (self),
+    callback, user_data, wocky_pep_service_get_finish);
+
+  wocky_porter_send_iq_async (priv->porter, msg, cancellable, send_query_cb,
+      result);
+
+  g_object_unref (msg);
+}
+
+WockyXmppStanza *
+wocky_pep_service_get_finish (WockyPepService *self,
+    GAsyncResult *result,
+    GError **error)
+{
+  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
+      error))
+    return NULL;
+
+  g_return_val_if_fail (g_simple_async_result_is_valid (result,
+    G_OBJECT (self), wocky_pep_service_get_finish), NULL);
+
+  return g_simple_async_result_get_op_res_gpointer (
+      G_SIMPLE_ASYNC_RESULT (result));
+}
diff --git a/src/wocky-pep-service.h b/src/wocky-pep-service.h
index c59550d..aa4e857 100644
--- a/src/wocky-pep-service.h
+++ b/src/wocky-pep-service.h
@@ -21,6 +21,7 @@
 #define __WOCKY_PEP_SERVICE_H__
 
 #include <glib-object.h>
+#include <gio/gio.h>
 #include <wocky/wocky-xmpp-stanza.h>
 #include <wocky/wocky-session.h>
 
@@ -61,6 +62,16 @@ WockyPepService * wocky_pep_service_new (const gchar *node,
 void wocky_pep_service_start (WockyPepService *pep_service,
     WockySession *session);
 
+void wocky_pep_service_get_async (WockyPepService *pep,
+    WockyBareContact *contact,
+    GCancellable *cancellable,
+    GAsyncReadyCallback callback,
+    gpointer user_data);
+
+WockyXmppStanza * wocky_pep_service_get_finish (WockyPepService *pep,
+    GAsyncResult *result,
+    GError **error);
+
 G_END_DECLS
 
 #endif /* __WOCKY_PEP_SERVICE_H__ */
-- 
1.5.6.5




More information about the telepathy-commits mailing list