[PATCH core 02/10] wc: test app



Signed-off-by: Víctor Manuel Jáquez Leal <vjaquez igalia com>
---
 libs/net/wc-test.c |   80 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 80 insertions(+), 0 deletions(-)
 create mode 100644 libs/net/wc-test.c

diff --git a/libs/net/wc-test.c b/libs/net/wc-test.c
new file mode 100644
index 0000000..2721bc6
--- /dev/null
+++ b/libs/net/wc-test.c
@@ -0,0 +1,80 @@
+#include "grl-net-wc.h"
+#include <stdio.h>
+
+GMainLoop *loop;
+const gchar *uri;
+
+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);
+    goto end_func;
+  }
+
+  fwrite (content, 1, length, stdout);
+
+end_func:
+  g_object_unref (source);
+  g_main_loop_quit (loop);
+}
+
+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);
+}
-- 
1.7.1



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