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 |
static int has_quit;
|
31 |
|
32 |
void event_main_loop_run(void)
|
33 |
{
|
34 |
if (! event_methods.main_loop_run) {
|
35 |
dbg(0,"no event system set\n");
|
36 |
return;
|
37 |
}
|
38 |
event_methods.main_loop_run();
|
39 |
}
|
40 |
|
41 |
void event_main_loop_quit(void)
|
42 |
{
|
43 |
if (event_methods.main_loop_quit)
|
44 |
event_methods.main_loop_quit();
|
45 |
has_quit=1;
|
46 |
}
|
47 |
|
48 |
int
|
49 |
event_main_loop_has_quit(void)
|
50 |
{
|
51 |
return has_quit;
|
52 |
}
|
53 |
|
54 |
struct event_watch *
|
55 |
event_add_watch(void *fd, enum event_watch_cond cond, struct callback *cb)
|
56 |
{
|
57 |
return event_methods.add_watch(fd, cond, cb);
|
58 |
}
|
59 |
|
60 |
void
|
61 |
event_remove_watch(struct event_watch *ev)
|
62 |
{
|
63 |
event_methods.remove_watch(ev);
|
64 |
}
|
65 |
|
66 |
struct event_timeout *
|
67 |
event_add_timeout(int timeout, int multi, struct callback *cb)
|
68 |
{
|
69 |
return event_methods.add_timeout(timeout, multi, cb);
|
70 |
}
|
71 |
|
72 |
void
|
73 |
event_remove_timeout(struct event_timeout *ev)
|
74 |
{
|
75 |
event_methods.remove_timeout(ev);
|
76 |
}
|
77 |
|
78 |
struct event_idle *
|
79 |
event_add_idle(int priority, struct callback *cb)
|
80 |
{
|
81 |
return event_methods.add_idle(priority,cb);
|
82 |
}
|
83 |
|
84 |
void
|
85 |
event_remove_idle(struct event_idle *ev)
|
86 |
{
|
87 |
event_methods.remove_idle(ev);
|
88 |
}
|
89 |
|
90 |
void
|
91 |
event_call_callback(struct callback_list *cb)
|
92 |
{
|
93 |
event_methods.call_callback(cb);
|
94 |
}
|
95 |
|
96 |
char const *
|
97 |
event_system(void)
|
98 |
{
|
99 |
return e_system;
|
100 |
}
|
101 |
|
102 |
int
|
103 |
event_request_system(const char *system, const char *requestor)
|
104 |
{
|
105 |
void (*event_type_new)(struct event_methods *meth);
|
106 |
if (e_system)
|
107 |
{
|
108 |
if (strcmp(e_system, system))
|
109 |
{
|
110 |
dbg(0,"system '%s' already requested by '%s', can't set to '%s' as requested from '%s'\n", e_system, e_requestor, system, requestor);
|
111 |
return 0;
|
112 |
}
|
113 |
return 1;
|
114 |
}
|
115 |
event_type_new=plugin_get_event_type(system);
|
116 |
if (! event_type_new)
|
117 |
{
|
118 |
dbg(0,"unsupported event system '%s' requested from '%s'\n", system, requestor);
|
119 |
return 0;
|
120 |
}
|
121 |
event_type_new(&event_methods);
|
122 |
e_system=system;
|
123 |
e_requestor=requestor;
|
124 |
|
125 |
return 1;
|
126 |
}
|
127 |
|
128 |
|