Fix:Core:Correct parameters
[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 const char *e_requestor;
28 static const 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         if (event_methods.main_loop_quit)
42                 event_methods.main_loop_quit();
43         exit(0);
44 }
45
46 struct event_watch *
47 event_add_watch(void *fd, enum event_watch_cond cond, struct callback *cb)
48 {
49         return event_methods.add_watch(fd, cond, cb);
50 }
51
52 void
53 event_remove_watch(struct event_watch *ev)
54 {
55         event_methods.remove_watch(ev);
56 }
57
58 struct event_timeout *
59 event_add_timeout(int timeout, int multi, struct callback *cb)
60 {
61         return event_methods.add_timeout(timeout, multi, cb);
62 }
63
64 void
65 event_remove_timeout(struct event_timeout *ev)
66 {
67         event_methods.remove_timeout(ev);
68 }
69
70 struct event_idle *
71 event_add_idle(int priority, struct callback *cb)
72 {
73         return event_methods.add_idle(priority,cb);
74 }
75
76 void
77 event_remove_idle(struct event_idle *ev)
78 {
79         event_methods.remove_idle(ev);
80 }
81
82 void
83 event_call_callback(struct callback_list *cb)
84 {
85         event_methods.call_callback(cb);
86 }
87
88 int
89 event_request_system(const char *system, const char *requestor)
90 {
91         void (*event_type_new)(struct event_methods *meth);
92         if (e_system) {
93                 if (strcmp(e_system, system)) {
94                         dbg(0,"system '%s' already requested by '%s', can't set to '%s' as requested from '%s'\n", e_system, e_requestor, system, requestor);
95                         return 0;
96                 }
97                 return 1;
98         }
99         event_type_new=plugin_get_event_type(system);
100         if (! event_type_new) {
101                 dbg(0,"unsupported event system '%s' requested from '%s'\n", system, requestor);
102                 return 0;
103         }
104         event_type_new(&event_methods);
105         e_system=system;
106         e_requestor=requestor;
107         
108         return 1;
109 }
110
111