Add:Core:Improved and implemented idle callback
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sat, 13 Dec 2008 22:09:39 +0000 (22:09 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sat, 13 Dec 2008 22:09:39 +0000 (22:09 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@1789 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/callback.h
navit/navit/event.c
navit/navit/event_glib.c

index 3954b36..3d437e2 100644 (file)
@@ -94,6 +94,16 @@ static inline struct callback *callback_new_3(void (*func)(void), void *p1, void
        return callback_new(func, 3, p);
 }
 
+static inline struct callback *callback_new_4(void (*func)(void), void *p1, void *p2, void *p3, void *p4)
+{
+       void *p[4];
+       p[0]=p1;
+       p[1]=p2;
+       p[2]=p3;
+       p[3]=p4;
+       return callback_new(func, 4, p);
+}
+
 static inline void callback_call_0(struct callback *cb)
 {
        callback_call(cb, 0, NULL);
index f75c3f3..96fdde1 100644 (file)
@@ -67,9 +67,9 @@ event_remove_timeout(struct event_timeout *ev)
 }
 
 struct event_idle *
-event_add_idle(struct callback *cb)
+event_add_idle(int priority, struct callback *cb)
 {
-       return event_methods.add_idle(cb);
+       return event_methods.add_idle(priority,cb);
 }
 
 void
index 7a4a1eb..7a3c6f5 100644 (file)
@@ -125,15 +125,34 @@ event_glib_remove_timeout(struct event_timeout *ev)
        g_free(ev);
 }
 
+struct event_idle {
+       guint source;
+       struct callback *cb;
+};
+
+static gboolean
+event_glib_call_idle(struct event_idle *ev)
+{
+       callback_call_0(ev->cb);
+       return TRUE;
+}
+
 static struct event_idle *
-event_glib_add_idle(struct callback *cb)
+event_glib_add_idle(int priority, struct callback *cb)
 {
-       return NULL;
+       struct event_idle *ret=g_new0(struct event_idle, 1);
+       ret->cb=cb;
+       ret->source = g_idle_add_full(priority+100, (GSourceFunc)event_glib_call_idle, (gpointer)ret, NULL);
+       return ret;
 }
 
 static void
 event_glib_remove_idle(struct event_idle *ev)
 {
+       if (! ev)
+               return;
+       g_source_remove(ev->source);
+       g_free(ev);
 }
 
 static void