summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-10-24 20:51:37 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-10-24 20:51:37 +0000
commit37fbca67790882c1f7377a0fcc71b588725e65fd (patch)
treec7a126b20a4e80e140c539e3e666445eb7c16870
parent13895dee0a96fae550019265136c1d67800c97fe (diff)
downloadnavit-37fbca67790882c1f7377a0fcc71b588725e65fd.tar.gz
Fix:Core:Cleanup event watch api
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@1558 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r--navit/event.c4
-rw-r--r--navit/event.h12
-rw-r--r--navit/event_glib.c16
-rw-r--r--navit/file.c6
4 files changed, 32 insertions, 6 deletions
diff --git a/navit/event.c b/navit/event.c
index 9ac73c989..87e1798b0 100644
--- a/navit/event.c
+++ b/navit/event.c
@@ -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
diff --git a/navit/event.h b/navit/event.h
index df0647d10..0f02278fd 100644
--- a/navit/event.h
+++ b/navit/event.h
@@ -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);
diff --git a/navit/event_glib.c b/navit/event_glib.c
index f7d67c3cf..730d9082a 100644
--- a/navit/event_glib.c
+++ b/navit/event_glib.c
@@ -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;
}
diff --git a/navit/file.c b/navit/file.c
index a17ed4ce1..c8d7176f9 100644
--- a/navit/file.c
+++ b/navit/file.c
@@ -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)
{