Navit SVN

/work/compile/navit/src/navit/plugin.h

00001 
00020 #ifndef PLUGIN_C
00021 
00022 #ifdef __cplusplus
00023 extern "C" {
00024 #endif
00025 
00026 struct plugin;
00027 
00028 enum plugin_type {
00029         plugin_type_graphics,
00030         plugin_type_gui,
00031         plugin_type_map,
00032         plugin_type_osd,
00033         plugin_type_speech,
00034         plugin_type_vehicle,
00035         plugin_type_event,
00036         plugin_type_font,
00037         plugin_type_last,
00038 };
00039 #endif
00040 
00041 struct container;
00042 struct popup;
00043 struct popup_item;
00044 #undef PLUGIN_FUNC1
00045 #undef PLUGIN_FUNC3
00046 #undef PLUGIN_FUNC4
00047 #undef PLUGIN_TYPE
00048 #define PLUGIN_PROTO(name,...) void name(__VA_ARGS__)
00049 
00050 #ifdef PLUGIN_C
00051 #define PLUGIN_REGISTER(name,...)                                               \
00052 void                                                                            \
00053 plugin_register_##name(PLUGIN_PROTO((*func),__VA_ARGS__))                               \
00054 {                                                                               \
00055         plugin_##name##_func=func;                                              \
00056 }
00057 
00058 #define PLUGIN_CALL(name,...)                                           \
00059 {                                                                               \
00060         if (plugin_##name##_func)                                               \
00061                 (*plugin_##name##_func)(__VA_ARGS__);                                   \
00062 }                                                                               
00063 
00064 #define PLUGIN_FUNC1(name,t1,p1)                                \
00065 PLUGIN_PROTO((*plugin_##name##_func),t1 p1);                    \
00066 void plugin_call_##name(t1 p1) PLUGIN_CALL(name,p1)             \
00067 PLUGIN_REGISTER(name,t1 p1)                                     
00068 
00069 #define PLUGIN_FUNC3(name,t1,p1,t2,p2,t3,p3)                                    \
00070 PLUGIN_PROTO((*plugin_##name##_func),t1 p1,t2 p2,t3 p3);                                \
00071 void plugin_call_##name(t1 p1,t2 p2, t3 p3) PLUGIN_CALL(name,p1,p2,p3)  \
00072 PLUGIN_REGISTER(name,t1 p1,t2 p2,t3 p3)                                 
00073 
00074 #define PLUGIN_FUNC4(name,t1,p1,t2,p2,t3,p3,t4,p4)                                      \
00075 PLUGIN_PROTO((*plugin_##name##_func),t1 p1,t2 p2,t3 p3,t4 p4);                          \
00076 void plugin_call_##name(t1 p1,t2 p2, t3 p3, t4 p4) PLUGIN_CALL(name,p1,p2,p3,p4)        \
00077 PLUGIN_REGISTER(name,t1 p1,t2 p2,t3 p3,t4 p4)                                   
00078 
00079 struct name_val {
00080         char *name;
00081         void *val;
00082 };
00083 
00084 GList *plugin_types[plugin_type_last];
00085 
00086 #define PLUGIN_TYPE(type,newargs) \
00087 struct type##_priv; \
00088 struct type##_methods; \
00089 void \
00090 plugin_register_##type##_type(const char *name, struct type##_priv *(*new_) newargs) \
00091 { \
00092         struct name_val *nv; \
00093         nv=g_new(struct name_val, 1); \
00094         nv->name=g_strdup(name); \
00095         nv->val=new_; \
00096         plugin_types[plugin_type_##type]=g_list_append(plugin_types[plugin_type_##type], nv); \
00097 } \
00098  \
00099 void * \
00100 plugin_get_##type##_type(const char *name) \
00101 { \
00102         return plugin_get_type(plugin_type_##type, #type, name); \
00103 } 
00104 
00105 #else
00106 #define PLUGIN_FUNC1(name,t1,p1)                        \
00107 void plugin_register_##name(void(*func)(t1 p1));        \
00108 void plugin_call_##name(t1 p1);
00109 
00110 #define PLUGIN_FUNC3(name,t1,p1,t2,p2,t3,p3)                    \
00111 void plugin_register_##name(void(*func)(t1 p1,t2 p2,t3 p3));    \
00112 void plugin_call_##name(t1 p1,t2 p2,t3 p3);
00113 
00114 #define PLUGIN_FUNC4(name,t1,p1,t2,p2,t3,p3,t4,p4)                      \
00115 void plugin_register_##name(void(*func)(t1 p1,t2 p2,t3 p3,t4 p4));      \
00116 void plugin_call_##name(t1 p1,t2 p2,t3 p3,t4 p4);
00117 
00118 #define PLUGIN_TYPE(type,newargs) \
00119 struct type##_priv; \
00120 struct type##_methods; \
00121 void plugin_register_##type##_type(const char *name, struct type##_priv *(*new_) newargs); \
00122 void *plugin_get_##type##_type(const char *name);
00123 
00124 #endif
00125 
00126 #include "plugin_def.h"
00127 
00128 #ifndef USE_PLUGINS
00129 #define plugin_module_cat3(pre,mod,post) pre##mod##post
00130 #define plugin_module_cat2(pre,mod,post) plugin_module_cat3(pre,mod,post)
00131 #define plugin_module_cat(pre,post) plugin_module_cat2(pre,MODULE,post)
00132 #define plugin_init plugin_module_cat(module_,_init)
00133 #endif
00134 
00135 struct attr;
00136 
00137 /* prototypes */
00138 void plugin_init(void);
00139 int plugin_load(struct plugin *pl);
00140 char *plugin_get_name(struct plugin *pl);
00141 int plugin_get_active(struct plugin *pl);
00142 void plugin_set_active(struct plugin *pl, int active);
00143 void plugin_set_lazy(struct plugin *pl, int lazy);
00144 void plugin_call_init(struct plugin *pl);
00145 void plugin_unload(struct plugin *pl);
00146 void plugin_destroy(struct plugin *pl);
00147 struct plugins *plugins_new(void);
00148 struct plugin *plugin_new(struct attr *parent, struct attr ** attrs);
00149 void plugins_init(struct plugins *pls);
00150 void plugins_destroy(struct plugins *pls);
00151 void *plugin_get_type(enum plugin_type type, const char *type_name, const char *name);
00152 /* end of prototypes */
00153 
00154 #ifdef __cplusplus
00155 }
00156 #endif
00157 
00158