Fix:Core:Renamed src to navit for cleanup of includes
[navit-package] / navit / plugin.h
1 #ifndef PLUGIN_C
2
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6
7 struct plugin;
8
9 enum plugin_type {
10         plugin_type_graphics,
11         plugin_type_gui,
12         plugin_type_map,
13         plugin_type_osd,
14         plugin_type_speech,
15         plugin_type_vehicle,
16         plugin_type_last,
17 };
18 #endif
19
20 struct container;
21 struct popup;
22 struct popup_item;
23 #undef PLUGIN_FUNC1
24 #undef PLUGIN_FUNC3
25 #undef PLUGIN_FUNC4
26 #undef PLUGIN_TYPE
27 #define PLUGIN_PROTO(name,args...) void name(args)
28
29 #ifdef PLUGIN_C
30 #define PLUGIN_REGISTER(name,args...)                                           \
31 void                                                                            \
32 plugin_register_##name(PLUGIN_PROTO((*func),args))                              \
33 {                                                                               \
34         plugin_##name##_func=func;                                              \
35 }
36
37 #define PLUGIN_CALL(name,args...)                                               \
38 {                                                                               \
39         if (plugin_##name##_func)                                               \
40                 (*plugin_##name##_func)(args);                                  \
41 }                                                                               
42
43 #define PLUGIN_FUNC1(name,t1,p1)                                \
44 PLUGIN_PROTO((*plugin_##name##_func),t1 p1);                    \
45 void plugin_call_##name(t1 p1) PLUGIN_CALL(name,p1)             \
46 PLUGIN_REGISTER(name,t1 p1)                                     
47
48 #define PLUGIN_FUNC3(name,t1,p1,t2,p2,t3,p3)                                    \
49 PLUGIN_PROTO((*plugin_##name##_func),t1 p1,t2 p2,t3 p3);                                \
50 void plugin_call_##name(t1 p1,t2 p2, t3 p3) PLUGIN_CALL(name,p1,p2,p3)  \
51 PLUGIN_REGISTER(name,t1 p1,t2 p2,t3 p3)                                 
52
53 #define PLUGIN_FUNC4(name,t1,p1,t2,p2,t3,p3,t4,p4)                                      \
54 PLUGIN_PROTO((*plugin_##name##_func),t1 p1,t2 p2,t3 p3,t4 p4);                          \
55 void plugin_call_##name(t1 p1,t2 p2, t3 p3, t4 p4) PLUGIN_CALL(name,p1,p2,p3,p4)        \
56 PLUGIN_REGISTER(name,t1 p1,t2 p2,t3 p3,t4 p4)                                   
57
58 struct name_val {
59         char *name;
60         void *val;
61 };
62
63 GList *plugin_types[plugin_type_last];
64
65 #define PLUGIN_TYPE(type,newargs) \
66 struct type##_priv; \
67 struct type##_methods; \
68 void \
69 plugin_register_##type##_type(const char *name, struct type##_priv *(*new_) newargs) \
70 { \
71         struct name_val *nv; \
72         nv=g_new(struct name_val, 1); \
73         nv->name=g_strdup(name); \
74         nv->val=new_; \
75         plugin_types[plugin_type_##type]=g_list_append(plugin_types[plugin_type_##type], nv); \
76 } \
77  \
78 void * \
79 plugin_get_##type##_type(const char *name) \
80 { \
81         return plugin_get_type(plugin_type_##type, name); \
82
83
84 #else
85 #define PLUGIN_FUNC1(name,t1,p1)                        \
86 void plugin_register_##name(void(*func)(t1 p1));        \
87 void plugin_call_##name(t1 p1);
88
89 #define PLUGIN_FUNC3(name,t1,p1,t2,p2,t3,p3)                    \
90 void plugin_register_##name(void(*func)(t1 p1,t2 p2,t3 p3));    \
91 void plugin_call_##name(t1 p1,t2 p2,t3 p3);
92
93 #define PLUGIN_FUNC4(name,t1,p1,t2,p2,t3,p3,t4,p4)                      \
94 void plugin_register_##name(void(*func)(t1 p1,t2 p2,t3 p3,t4 p4));      \
95 void plugin_call_##name(t1 p1,t2 p2,t3 p3,t4 p4);
96
97 #define PLUGIN_TYPE(type,newargs) \
98 struct type##_priv; \
99 struct type##_methods; \
100 void plugin_register_##type##_type(const char *name, struct type##_priv *(*new_) newargs); \
101 void *plugin_get_##type##_type(const char *name);
102
103 #endif
104
105 #include "plugin_def.h"
106
107 #ifndef USE_PLUGINS
108 #define plugin_module_cat3(pre,mod,post) pre##mod##post
109 #define plugin_module_cat2(pre,mod,post) plugin_module_cat3(pre,mod,post)
110 #define plugin_module_cat(pre,post) plugin_module_cat2(pre,MODULE,post)
111 #define plugin_init plugin_module_cat(module_,_init)
112 #endif
113
114 void plugin_init(void);
115
116 /* prototypes */
117 struct plugin *plugin_new(char *plugin);
118 int plugin_load(struct plugin *pl);
119 char *plugin_get_name(struct plugin *pl);
120 int plugin_get_active(struct plugin *pl);
121 void plugin_set_active(struct plugin *pl, int active);
122 void plugin_set_lazy(struct plugin *pl, int lazy);
123 void plugin_call_init(struct plugin *pl);
124 void plugin_unload(struct plugin *pl);
125 void plugin_destroy(struct plugin *pl);
126 struct plugins *plugins_new(void);
127 void plugins_add_path(struct plugins *pls, const char *path, int active, int lazy);
128 void plugins_init(struct plugins *pls);
129 void plugins_destroy(struct plugins *pls);
130 void *plugin_get_type(enum plugin_type type, const char *name);
131 /* end of prototypes */
132
133 #ifdef __cplusplus
134 }
135 #endif
136
137