Fix:maptool:Another name for faroe islands
[navit-package] / navit / plugin.h
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 Library 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 Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License 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 #ifndef PLUGIN_C
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 struct plugin;
27
28 enum plugin_type {
29         plugin_type_graphics,
30         plugin_type_gui,
31         plugin_type_map,
32         plugin_type_osd,
33         plugin_type_speech,
34         plugin_type_vehicle,
35         plugin_type_event,
36         plugin_type_font,
37         plugin_type_last,
38 };
39 #endif
40
41 struct container;
42 struct popup;
43 struct popup_item;
44 #undef PLUGIN_FUNC1
45 #undef PLUGIN_FUNC3
46 #undef PLUGIN_FUNC4
47 #undef PLUGIN_TYPE
48 #define PLUGIN_PROTO(name,args...) void name(args)
49
50 #ifdef PLUGIN_C
51 #define PLUGIN_REGISTER(name,args...)                                           \
52 void                                                                            \
53 plugin_register_##name(PLUGIN_PROTO((*func),args))                              \
54 {                                                                               \
55         plugin_##name##_func=func;                                              \
56 }
57
58 #define PLUGIN_CALL(name,args...)                                               \
59 {                                                                               \
60         if (plugin_##name##_func)                                               \
61                 (*plugin_##name##_func)(args);                                  \
62 }                                                                               
63
64 #define PLUGIN_FUNC1(name,t1,p1)                                \
65 PLUGIN_PROTO((*plugin_##name##_func),t1 p1);                    \
66 void plugin_call_##name(t1 p1) PLUGIN_CALL(name,p1)             \
67 PLUGIN_REGISTER(name,t1 p1)                                     
68
69 #define PLUGIN_FUNC3(name,t1,p1,t2,p2,t3,p3)                                    \
70 PLUGIN_PROTO((*plugin_##name##_func),t1 p1,t2 p2,t3 p3);                                \
71 void plugin_call_##name(t1 p1,t2 p2, t3 p3) PLUGIN_CALL(name,p1,p2,p3)  \
72 PLUGIN_REGISTER(name,t1 p1,t2 p2,t3 p3)                                 
73
74 #define PLUGIN_FUNC4(name,t1,p1,t2,p2,t3,p3,t4,p4)                                      \
75 PLUGIN_PROTO((*plugin_##name##_func),t1 p1,t2 p2,t3 p3,t4 p4);                          \
76 void plugin_call_##name(t1 p1,t2 p2, t3 p3, t4 p4) PLUGIN_CALL(name,p1,p2,p3,p4)        \
77 PLUGIN_REGISTER(name,t1 p1,t2 p2,t3 p3,t4 p4)                                   
78
79 struct name_val {
80         char *name;
81         void *val;
82 };
83
84 GList *plugin_types[plugin_type_last];
85
86 #define PLUGIN_TYPE(type,newargs) \
87 struct type##_priv; \
88 struct type##_methods; \
89 void \
90 plugin_register_##type##_type(const char *name, struct type##_priv *(*new_) newargs) \
91 { \
92         struct name_val *nv; \
93         nv=g_new(struct name_val, 1); \
94         nv->name=g_strdup(name); \
95         nv->val=new_; \
96         plugin_types[plugin_type_##type]=g_list_append(plugin_types[plugin_type_##type], nv); \
97 } \
98  \
99 void * \
100 plugin_get_##type##_type(const char *name) \
101 { \
102         return plugin_get_type(plugin_type_##type, #type, name); \
103
104
105 #else
106 #define PLUGIN_FUNC1(name,t1,p1)                        \
107 void plugin_register_##name(void(*func)(t1 p1));        \
108 void plugin_call_##name(t1 p1);
109
110 #define PLUGIN_FUNC3(name,t1,p1,t2,p2,t3,p3)                    \
111 void plugin_register_##name(void(*func)(t1 p1,t2 p2,t3 p3));    \
112 void plugin_call_##name(t1 p1,t2 p2,t3 p3);
113
114 #define PLUGIN_FUNC4(name,t1,p1,t2,p2,t3,p3,t4,p4)                      \
115 void plugin_register_##name(void(*func)(t1 p1,t2 p2,t3 p3,t4 p4));      \
116 void plugin_call_##name(t1 p1,t2 p2,t3 p3,t4 p4);
117
118 #define PLUGIN_TYPE(type,newargs) \
119 struct type##_priv; \
120 struct type##_methods; \
121 void plugin_register_##type##_type(const char *name, struct type##_priv *(*new_) newargs); \
122 void *plugin_get_##type##_type(const char *name);
123
124 #endif
125
126 #include "plugin_def.h"
127
128 #ifndef USE_PLUGINS
129 #define plugin_module_cat3(pre,mod,post) pre##mod##post
130 #define plugin_module_cat2(pre,mod,post) plugin_module_cat3(pre,mod,post)
131 #define plugin_module_cat(pre,post) plugin_module_cat2(pre,MODULE,post)
132 #define plugin_init plugin_module_cat(module_,_init)
133 #endif
134
135 struct attr;
136
137 /* prototypes */
138 void plugin_init(void);
139 int plugin_load(struct plugin *pl);
140 char *plugin_get_name(struct plugin *pl);
141 int plugin_get_active(struct plugin *pl);
142 void plugin_set_active(struct plugin *pl, int active);
143 void plugin_set_lazy(struct plugin *pl, int lazy);
144 void plugin_call_init(struct plugin *pl);
145 void plugin_unload(struct plugin *pl);
146 void plugin_destroy(struct plugin *pl);
147 struct plugins *plugins_new(void);
148 struct plugin *plugin_new(struct attr *parent, struct attr ** attrs);
149 void plugins_init(struct plugins *pls);
150 void plugins_destroy(struct plugins *pls);
151 void *plugin_get_type(enum plugin_type type, const char *type_name, const char *name);
152 /* end of prototypes */
153
154 #ifdef __cplusplus
155 }
156 #endif
157
158