Fix:Core:Cleanup event watch api
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Fri, 24 Oct 2008 20:51:37 +0000 (20:51 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Fri, 24 Oct 2008 20:51:37 +0000 (20:51 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@1558 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/event.c
navit/event.h
navit/event_glib.c
navit/file.c

index 9ac73c9..87e1798 100644 (file)
@@ -43,9 +43,9 @@ void event_main_loop_quit(void)
 }
 
 struct event_watch *
-event_add_watch(int fd, int w, struct callback *cb)
+event_add_watch(struct file *file, enum event_watch_cond cond, struct callback *cb)
 {
-       return event_methods.add_watch(fd, w, cb);
+       return event_methods.add_watch(file, cond, cb);
 }
 
 void
index df0647d..0f02278 100644 (file)
@@ -25,11 +25,18 @@ struct event_idle;
 struct event_timeout;
 struct event_watch;
 struct callback;
+struct file;
+
+enum event_watch_cond {
+       event_watch_cond_read=1,
+       event_watch_cond_write,
+       event_watch_cond_except,
+};
 
 struct event_methods {
        void (*main_loop_run)(void);
        void (*main_loop_quit)(void);
-       struct event_watch *(*add_watch)(int fd, int w, struct callback *cb);
+       struct event_watch *(*add_watch)(struct file *file, enum event_watch_cond cond, struct callback *cb);
        void (*remove_watch)(struct event_watch *ev);
        struct event_timeout *(*add_timeout)(int timeout, int multi, struct callback *cb);
        void (*remove_timeout)(struct event_timeout *ev);
@@ -37,10 +44,11 @@ struct event_methods {
        void (*remove_idle)(struct event_idle *ev);
 };
 
+
 /* prototypes */
 void event_main_loop_run(void);
 void event_main_loop_quit(void);
-struct event_watch *event_add_watch(int fd, int w, struct callback *cb);
+struct event_watch *event_add_watch(struct file *file, enum event_watch_cond cond, struct callback *cb);
 void event_remove_watch(struct event_watch *ev);
 struct event_timeout *event_add_timeout(int timeout, int multi, struct callback *cb);
 void event_remove_timeout(struct event_timeout *ev);
index f7d67c3..730d908 100644 (file)
@@ -54,11 +54,23 @@ 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(struct file *file, enum event_watch_cond cond, struct callback *cb)
 {
        struct event_watch *ret=g_new0(struct event_watch, 1);
+       int flags=0,fd=(int)file_get_os_handle(file);
        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);
+       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, cond, event_glib_call_watch, (gpointer)cb);
        return ret;
 }
 
index a17ed4c..c8d7176 100644 (file)
@@ -397,6 +397,12 @@ file_version(struct file *file, int byname)
 #endif
 }
 
+void *
+file_get_os_handle(struct file *file)
+{
+       return (void *)(file->fd);
+}
+
 void
 file_init(void)
 {