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