Add:Core:Support for FRA FRA NLS Setting
[navit-package] / navit / event_glib.c
index f7d67c3..83c0a26 100644 (file)
@@ -22,6 +22,7 @@
 #include "event_glib.h"
 #include "debug.h"
 #include "callback.h"
+#include "plugin.h"
 
 static GMainLoop *loop;
 
@@ -54,22 +55,33 @@ event_glib_call_watch(GIOChannel * iochan, GIOCondition condition, gpointer t)
 }
 
 static struct event_watch *
-event_glib_add_watch(int fd, int w, struct callback *cb)
+event_glib_add_watch(void *fd, enum event_watch_cond cond, struct callback *cb)
 {
        struct event_watch *ret=g_new0(struct event_watch, 1);
-       ret->iochan = g_io_channel_unix_new(fd);
-       ret->source = g_io_add_watch(ret->iochan, G_IO_IN | G_IO_ERR | G_IO_HUP, event_glib_call_watch, (gpointer)cb);
+       int flags=0;
+       ret->iochan = g_io_channel_unix_new(GPOINTER_TO_INT(fd));
+       switch (cond) {
+       case event_watch_cond_read:
+               flags=G_IO_IN;
+               break;
+       case event_watch_cond_write:
+               flags=G_IO_OUT;
+               break;
+       case event_watch_cond_except:
+               flags=G_IO_ERR|G_IO_HUP;
+               break;
+       }       
+       ret->source = g_io_add_watch(ret->iochan, flags, event_glib_call_watch, (gpointer)cb);
        return ret;
 }
 
 static void
 event_glib_remove_watch(struct event_watch *ev)
 {
-       GError *error = NULL;
        if (! ev)
                return;
        g_source_remove(ev->source);
-       g_io_channel_shutdown(ev->iochan, 0, &error);
+       g_io_channel_unref(ev->iochan);
        g_free(ev);
 }
 
@@ -113,15 +125,46 @@ 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
+event_glib_call_callback(struct callback_list *cb)
+{
+/* 
+ Idea for implementation:
+ Create a pipe then use add_watch
+ add callback to a queue
+ from here write to the pipe to wakeup the pool
+ then from the gui thread process the callback queue
+*/
 }
 
 static struct event_methods event_glib_methods = {
@@ -133,12 +176,17 @@ static struct event_methods event_glib_methods = {
        event_glib_remove_timeout,
        event_glib_add_idle,
        event_glib_remove_idle,
+       event_glib_call_callback,
 };
 
-static void
+struct event_priv {
+};
+
+static struct event_priv*
 event_glib_new(struct event_methods *meth)
 {
        *meth=event_glib_methods;
+       return (struct event_priv *)event_glib_new;
 }
 
 void