Add:Core:Added svn version in navit -v output
[navit-package] / navit / event.c
1 /**
2  * Navit, a modular navigation system.
3  * Copyright (C) 2005-2008 Navit Team
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * version 2 as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA  02110-1301, USA.
18  */
19
20 #include <string.h>
21 #include <stdlib.h>
22 #include "event.h"
23 #include "plugin.h"
24 #include "debug.h"
25
26 static struct event_methods event_methods;
27 static char *e_requestor;
28 static char *e_system;
29
30 void event_main_loop_run(void)
31 {
32         if (! event_methods.main_loop_run) {
33                 dbg(0,"no event system set\n");
34                 exit(1);
35         }
36         event_methods.main_loop_run();
37 }
38
39 void event_main_loop_quit(void)
40 {
41         event_methods.main_loop_quit();
42 }
43
44 struct event_watch *
45 event_add_watch(int fd, int w, struct callback *cb)
46 {
47         return event_methods.add_watch(fd, w, cb);
48 }
49
50 void
51 event_remove_watch(struct event_watch *ev)
52 {
53         event_methods.remove_watch(ev);
54 }
55
56 struct event_timeout *
57 event_add_timeout(int timeout, int multi, struct callback *cb)
58 {
59         return event_methods.add_timeout(timeout, multi, cb);
60 }
61
62 void
63 event_remove_timeout(struct event_timeout *ev)
64 {
65         event_methods.remove_timeout(ev);
66 }
67
68 struct event_idle *
69 event_add_idle(struct callback *cb)
70 {
71         return event_methods.add_idle(cb);
72 }
73
74 void
75 event_remove_idle(struct event_idle *ev)
76 {
77         event_methods.remove_idle(ev);
78 }
79
80 int
81 event_request_system(char *system, char *requestor)
82 {
83         void (*event_type_new)(struct event_methods *meth);
84         if (e_system) {
85                 if (strcmp(e_system, system)) {
86                         dbg(0,"system '%s' already requested by '%s', can't set to '%s' as requested from '%s'\n", e_system, e_requestor, system, requestor);
87                         return 0;
88                 }
89                 return 1;
90         }
91         event_type_new=plugin_get_event_type(system);
92         if (! event_type_new) {
93                 dbg(0,"unsupported event system '%s' requested from '%s'\n", system, requestor);
94                 return 0;
95         }
96         event_type_new(&event_methods);
97         e_system=system;
98         e_requestor=requestor;
99         
100         return 1;
101 }
102
103