summaryrefslogtreecommitdiff
path: root/navit
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-09-04 16:51:05 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-09-04 16:51:05 +0000
commitc593dd07b38049073c36a5787ad3fbafc80353a2 (patch)
tree169df3d9c0ea38ba4c8a19ad9e6b396e6cddb0d7 /navit
parenta435e3311bae22df0b48dd96fbe8448e5742c15d (diff)
downloadnavit-c593dd07b38049073c36a5787ad3fbafc80353a2.tar.gz
Add:core:Further works on event system abstraction
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@1365 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit')
-rw-r--r--navit/Makefile.am2
-rw-r--r--navit/event.c67
-rw-r--r--navit/event.h25
-rw-r--r--navit/event_glib.c143
-rw-r--r--navit/event_glib.h3
-rw-r--r--navit/plugin.h1
-rw-r--r--navit/plugin_def.h1
-rw-r--r--navit/start.c3
8 files changed, 228 insertions, 17 deletions
diff --git a/navit/Makefile.am b/navit/Makefile.am
index 726cdd1f0..d7cd0cb65 100644
--- a/navit/Makefile.am
+++ b/navit/Makefile.am
@@ -15,7 +15,7 @@ EXTRA_DIST = navit.xml
noinst_LTLIBRARIES = libnavit.la
libnavit_la_SOURCES = attr.c callback.c compass.c coord.c country.c cursor.c data_window.c debug.c \
- event.c file.c graphics.c gui.c item.c layout.c log.c main.c map.c \
+ event.c event_glib.c file.c graphics.c gui.c item.c layout.c log.c main.c map.c \
mapset.c maptype.c menu.c navit.c navigation.c osd.c param.c phrase.c plugin.c popup.c \
profile.c projection.c route.c search.c speech.c transform.c track.c \
util.c vehicle.c xmlconfig.c attr.h attr_def.h callback.h color.h compass.h coord.h country.h \
diff --git a/navit/event.c b/navit/event.c
index efbb499a7..456d1c3c6 100644
--- a/navit/event.c
+++ b/navit/event.c
@@ -17,52 +17,87 @@
* Boston, MA 02110-1301, USA.
*/
-#include <glib.h>
+#include <string.h>
+#include <stdlib.h>
#include "event.h"
+#include "plugin.h"
+#include "debug.h"
-static GMainLoop *loop;
+static struct event_methods event_methods;
+static char *e_requestor;
+static char *e_system;
void event_main_loop_run(void)
{
- loop = g_main_loop_new (NULL, TRUE);
- if (g_main_loop_is_running (loop))
- {
- g_main_loop_run (loop);
+ if (! event_methods.main_loop_run) {
+ dbg(0,"no event system set\n");
+ exit(1);
}
+ event_methods.main_loop_run();
}
void event_main_loop_quit(void)
{
- if (loop)
- g_main_loop_quit(loop);
-}
+ event_methods.main_loop_quit();
+}
-void *
+struct event_watch *
event_add_watch(int fd, int w, struct callback *cb)
{
+ return event_methods.add_watch(fd, w, cb);
}
void
-event_remove_watch(void *data)
+event_remove_watch(struct event_watch *ev)
{
+ event_methods.remove_watch(ev);
}
-void *
-event_add_timeout(int timeout, struct callback *cb)
+struct event_timeout *
+event_add_timeout(int timeout, int multi, struct callback *cb)
{
+ return event_methods.add_timeout(timeout, multi, cb);
}
void
-event_remove_timeout(void *data)
+event_remove_timeout(struct event_timeout *ev)
{
+ event_methods.remove_timeout(ev);
}
-void *
+struct event_idle *
event_add_idle(struct callback *cb)
{
+ return event_methods.add_idle(cb);
}
void
-event_remove_idle(void *data)
+event_remove_idle(struct event_idle *ev)
+{
+ event_methods.remove_idle(ev);
+}
+
+int
+event_request_system(char *system, char *requestor)
{
+ void (*event_type_new)(struct event_methods *meth);
+ if (e_system) {
+ if (strcmp(e_system, system)) {
+ dbg(0,"system '%s' already requested by '%s', can't set to '%s' as requested from '%s'\n", e_system, e_requestor, system, requestor);
+ return 0;
+ }
+ return 1;
+ }
+ event_type_new=plugin_get_event_type(system);
+ if (! event_type_new) {
+ dbg(0,"unsupported event system '%s' requested from '%s'\n", system, requestor);
+ return 0;
+ }
+ event_type_new(&event_methods);
+ e_system=system;
+ e_requestor=requestor;
+
+ return 1;
}
+
+
diff --git a/navit/event.h b/navit/event.h
index 7e141e959..897fdff33 100644
--- a/navit/event.h
+++ b/navit/event.h
@@ -17,5 +17,30 @@
* Boston, MA 02110-1301, USA.
*/
+struct event_idle;
+struct event_timeout;
+struct event_watch;
+struct callback;
+
+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);
+ 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);
+ struct event_idle *(*add_idle)(struct callback *cb);
+ 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);
+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);
+struct event_idle *event_add_idle(struct callback *cb);
+void event_remove_idle(struct event_idle *ev);
+int event_request_system(char *system, char *requestor);
+/* end of prototypes */
diff --git a/navit/event_glib.c b/navit/event_glib.c
new file mode 100644
index 000000000..69e6358d2
--- /dev/null
+++ b/navit/event_glib.c
@@ -0,0 +1,143 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <glib.h>
+#include "event.h"
+#include "event_glib.h"
+#include "debug.h"
+#include "callback.h"
+
+static GMainLoop *loop;
+
+static void event_glib_main_loop_run(void)
+{
+ loop = g_main_loop_new (NULL, TRUE);
+ if (g_main_loop_is_running (loop))
+ {
+ g_main_loop_run (loop);
+ }
+}
+
+static void event_glib_main_loop_quit(void)
+{
+ if (loop)
+ g_main_loop_quit(loop);
+}
+
+struct event_watch {
+ GIOChannel *iochan;
+ guint source;
+};
+
+static gboolean
+event_glib_call_watch(GIOChannel * iochan, GIOCondition condition, gpointer t)
+{
+ struct callback *cb=t;
+ callback_call_0(cb);
+ return TRUE;
+}
+
+static struct event_watch *
+event_glib_add_watch(int fd, int w, 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);
+ return ret;
+}
+
+static void
+event_glib_remove_watch(struct event_watch *ev)
+{
+ GError *error = NULL;
+ g_source_remove(ev->source);
+ g_io_channel_shutdown(ev->iochan, 0, &error);
+ g_free(ev);
+}
+
+struct event_timeout {
+ guint source;
+};
+
+static gboolean
+event_glib_call_timeout_single(gpointer t)
+{
+ struct callback *cb=t;
+ callback_call_0(cb);
+ return FALSE;
+}
+
+static gboolean
+event_glib_call_timeout_multi(gpointer t)
+{
+ struct callback *cb=t;
+ callback_call_0(cb);
+ return TRUE;
+}
+
+
+static struct event_timeout *
+event_glib_add_timeout(int timeout, int multi, struct callback *cb)
+{
+ struct event_timeout *ret=g_new0(struct event_timeout, 1);
+ ret->source = g_timeout_add(timeout, multi ? (GSourceFunc)event_glib_call_timeout_multi : (GSourceFunc)event_glib_call_timeout_single, (gpointer)cb);
+
+ return ret;
+}
+
+static void
+event_glib_remove_timeout(struct event_timeout *ev)
+{
+ g_source_remove(ev->source);
+ g_free(ev);
+}
+
+static struct event_idle *
+event_glib_add_idle(struct callback *cb)
+{
+ return NULL;
+}
+
+static void
+event_glib_remove_idle(struct event_idle *ev)
+{
+}
+
+static struct event_methods event_glib_methods = {
+ event_glib_main_loop_run,
+ event_glib_main_loop_quit,
+ event_glib_add_watch,
+ event_glib_remove_watch,
+ event_glib_add_timeout,
+ event_glib_remove_timeout,
+ event_glib_add_idle,
+ event_glib_remove_idle,
+};
+
+static void
+event_glib_new(struct event_methods *meth)
+{
+ *meth=event_glib_methods;
+}
+
+void
+event_glib_init(void)
+{
+ plugin_register_event_type("glib", event_glib_new);
+}
diff --git a/navit/event_glib.h b/navit/event_glib.h
new file mode 100644
index 000000000..9f9b2f52b
--- /dev/null
+++ b/navit/event_glib.h
@@ -0,0 +1,3 @@
+/* prototypes */
+void event_glib_init(void);
+/* end of prototypes */
diff --git a/navit/plugin.h b/navit/plugin.h
index 666876807..5f60a2e91 100644
--- a/navit/plugin.h
+++ b/navit/plugin.h
@@ -32,6 +32,7 @@ enum plugin_type {
plugin_type_osd,
plugin_type_speech,
plugin_type_vehicle,
+ plugin_type_event,
plugin_type_last,
};
#endif
diff --git a/navit/plugin_def.h b/navit/plugin_def.h
index ce8d89968..d948fb1ee 100644
--- a/navit/plugin_def.h
+++ b/navit/plugin_def.h
@@ -28,3 +28,4 @@ PLUGIN_TYPE(map, (struct map_methods *meth, struct attr **attrs))
PLUGIN_TYPE(osd, (struct navit *nav, struct osd_methods *meth, struct attr **attrs))
PLUGIN_TYPE(speech, (char *data, struct speech_methods *meth))
PLUGIN_TYPE(vehicle, (struct vehicle_methods *meth, struct callback_list *cbl, struct attr **attrs))
+PLUGIN_TYPE(event, (struct event_methods *meth))
diff --git a/navit/start.c b/navit/start.c
index 3f28d6b1e..5c66e3b37 100644
--- a/navit/start.c
+++ b/navit/start.c
@@ -30,6 +30,7 @@
#include "navigation.h"
#include "debug.h"
#include "event.h"
+#include "event_glib.h"
#include "xmlconfig.h"
#include "file.h"
#include "search.h"
@@ -71,6 +72,7 @@ int main(int argc, char **argv)
GList *list = NULL, *li;
+ event_glib_init();
main_init(argv[0]);
main_init_nls();
debug_init(argv[0]);
@@ -153,6 +155,7 @@ int main(int argc, char **argv)
printf(_("No instance has been created, exiting\n"));
exit(1);
}
+ event_request_system("glib","start");
event_main_loop_run();
return 0;