Implemented the idle "spawn" in LmBlockingResolver.
authorMikael Hallendal <micke@imendio.com>
Mon, 14 Jul 2008 00:35:25 +0200
changeset 459 e6e0a95d108a
parent 458 0cd193ceddaa
child 460 4d978afca525
Implemented the idle "spawn" in LmBlockingResolver. In order to simulate the asynchronous API of LmResolver the synchronous LmBlockingResolver runs in an idle callback. That means the lm_resolver_lookup call will return just as it does in the asynchronous version and instead the result will come through the given callback.
loudmouth/lm-blocking-resolver.c
--- a/loudmouth/lm-blocking-resolver.c	Mon Jul 14 00:14:28 2008 +0200
+++ b/loudmouth/lm-blocking-resolver.c	Mon Jul 14 00:35:25 2008 +0200
@@ -27,7 +27,7 @@
 
 typedef struct LmBlockingResolverPriv LmBlockingResolverPriv;
 struct LmBlockingResolverPriv {
-	gint my_prop;
+        guint idle_id;
 };
 
 static void     blocking_resolver_finalize    (GObject       *object);
@@ -56,7 +56,6 @@
 	LmBlockingResolverPriv *priv;
 
 	priv = GET_PRIV (blocking_resolver);
-
 }
 
 static void
@@ -69,13 +68,41 @@
 	(G_OBJECT_CLASS (lm_blocking_resolver_parent_class)->finalize) (object);
 }
 
+static gboolean
+blocking_resolver_idle_lookup (LmBlockingResolver *resolver) 
+{
+        LmBlockingResolverPriv *priv = GET_PRIV (resolver);
+
+        /* Start the DNS querying */
+
+        priv->idle_id = 0;
+        return FALSE;
+}
+
 static void
 blocking_resolver_lookup (LmResolver *resolver)
 {
+        LmBlockingResolverPriv *priv;
+
+        g_return_if_fail (LM_IS_BLOCKING_RESOLVER (resolver));
+
+        priv = GET_PRIV (resolver);
+
+        priv->idle_id = g_idle_add ((GSourceFunc) blocking_resolver_idle_lookup,
+                                    resolver);
 }
 
 static void
 blocking_resolver_cancel (LmResolver *resolver)
 {
+        LmBlockingResolverPriv *priv;
+
+        g_return_if_fail (LM_IS_BLOCKING_RESOLVER (resolver));
+
+        priv = GET_PRIV (resolver);
+
+        if (priv->idle_id > 0) {
+                g_source_remove (priv->idle_id);
+                priv->idle_id = 0;
+        }
 }
-