[grilo] wc: test app



commit 020c1846c35ef7cc6c81e776c47e2617b534e0a3
Author: Víctor Manuel Jáquez Leal <vjaquez igalia com>
Date:   Mon Sep 20 12:21:28 2010 +0200

    wc: test app
    
    Signed-off-by: Víctor Manuel Jáquez Leal <vjaquez igalia com>

 libs/net/wc-test.c |   86 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 86 insertions(+), 0 deletions(-)
---
diff --git a/libs/net/wc-test.c b/libs/net/wc-test.c
new file mode 100644
index 0000000..4bb8d8e
--- /dev/null
+++ b/libs/net/wc-test.c
@@ -0,0 +1,86 @@
+#include "grl-net-wc.h"
+#include <stdio.h>
+
+GMainLoop *loop;
+const gchar *uri;
+
+static gboolean
+quit (gpointer data)
+{
+  g_object_unref (G_OBJECT (data));
+  g_main_loop_quit (loop);
+
+  return FALSE;
+}
+
+static void
+fetch_result (GObject *source,
+	      GAsyncResult *result,
+	      gpointer user_data)
+{
+  gchar *content;
+  gsize length;
+  GError *error = NULL;
+
+  if (!grl_net_wc_request_finish (GRL_NET_WC (source),
+                                  result,
+                                  &content,
+                                  &length,
+                                  &error)) {
+    g_print ("Error: %s\n", error->message);
+  } else {
+    write (fileno (stdout), content, length);
+  }
+
+  g_idle_add (quit, source);
+}
+
+static gboolean
+cancel_request (gpointer data)
+{
+  GCancellable *cancellable;
+
+  cancellable = G_CANCELLABLE (data);
+  g_cancellable_cancel (cancellable);
+
+  return FALSE;
+}
+
+static gboolean
+request (gpointer data)
+{
+  GCancellable *cancellable;
+  GrlNetWc *wc;
+  const gchar *u;
+
+  wc = GRL_NET_WC (data);
+  u = uri ? uri : "http://www.yahoo.com";;
+
+  cancellable = g_cancellable_new ();
+  grl_net_wc_request_async (wc, u, cancellable, fetch_result, NULL);
+  g_timeout_add_seconds (2, cancel_request, cancellable);
+
+  return FALSE;
+}
+
+int
+main (int argc, const char **argv)
+{
+  GrlNetWc *wc;
+
+  g_thread_init (NULL);
+  g_type_init ();
+
+  if (argc == 2)
+    uri = argv[1];
+
+  wc = grl_net_wc_new ();
+
+  g_object_set (wc, "loglevel", 1, NULL);
+
+  loop = g_main_loop_new (NULL, FALSE);
+
+  g_idle_add (request, wc);
+
+  g_main_loop_run (loop);
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]