diff options
Diffstat (limited to 'src/plugger.h')
-rw-r--r-- | src/plugger.h | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/src/plugger.h b/src/plugger.h index 5f7df6d..aad8b9a 100644 --- a/src/plugger.h +++ b/src/plugger.h | |||
@@ -13,35 +13,54 @@ typedef struct PluginInfo | |||
13 | const char *sAuthor; | 13 | const char *sAuthor; |
14 | unsigned short nVersion; | 14 | unsigned short nVersion; |
15 | unsigned short nRevision; | 15 | unsigned short nRevision; |
16 | class Plugin *(*createPlugin)(); | 16 | void *(*createPlugin)(); |
17 | void (*destroyPlugin)( class Plugin * ); | 17 | void (*destroyPlugin)( void * ); |
18 | } PluginInfo; | 18 | } PluginInfo; |
19 | 19 | ||
20 | typedef struct PluginReg | ||
21 | { | ||
22 | bool bBuiltin; | ||
23 | void *dlHandle; | ||
24 | PluginInfo *pInfo; | ||
25 | } PluginReg; | ||
26 | |||
20 | #define PluginInterface( classname, baseclass, name, ver, rev ) \ | 27 | #define PluginInterface( classname, baseclass, name, ver, rev ) \ |
21 | extern "C" { \ | 28 | extern "C" { \ |
22 | class baseclass *create ##classname() \ | 29 | baseclass *create ##classname() \ |
23 | { \ | 30 | { \ |
24 | return new classname(); \ | 31 | return new classname(); \ |
25 | } \ | 32 | } \ |
26 | void destroy ##classname( class baseclass *pCls ) \ | 33 | void destroy ##classname( baseclass *pCls ) \ |
27 | { \ | 34 | { \ |
28 | delete pCls; \ | 35 | delete pCls; \ |
29 | } \ | 36 | } \ |
30 | PluginInfo classname = { #classname, name, ver, rev, \ | 37 | PluginInfo classname = { \ |
38 | #classname, name, ver, rev, \ | ||
31 | create ##classname, destroy ##classname }; \ | 39 | create ##classname, destroy ##classname }; \ |
32 | } | 40 | } |
33 | 41 | ||
34 | typedef struct PluginReg | 42 | #define PluginInterface2( pluginname, classname, baseclass, name, ver, rev ) \ |
35 | { | 43 | extern "C" { \ |
36 | bool bBuiltin; | 44 | baseclass *create ##classname() \ |
37 | void *dlHandle; | 45 | { \ |
38 | PluginInfo *pInfo; | 46 | return new classname(); \ |
39 | } PluginReg; | 47 | } \ |
48 | void destroy ##classname( baseclass *pCls ) \ | ||
49 | { \ | ||
50 | delete pCls; \ | ||
51 | } \ | ||
52 | PluginInfo pluginname = { \ | ||
53 | #pluginname, name, ver, rev, \ | ||
54 | (void *(*)())(create ##classname), \ | ||
55 | (void (*)( void * ))(destroy ##classname) }; \ | ||
56 | } | ||
40 | 57 | ||
41 | template<class T> | 58 | template<class T> |
42 | class Plugger | 59 | class Plugger |
43 | { | 60 | { |
44 | public: | 61 | public: |
62 | |||
63 | public: | ||
45 | Plugger() : | 64 | Plugger() : |
46 | hPlugin( new HashFunctionString(), 11 ), | 65 | hPlugin( new HashFunctionString(), 11 ), |
47 | hObj( new HashFunctionInt(), 11 ) | 66 | hObj( new HashFunctionInt(), 11 ) |
@@ -96,9 +115,9 @@ public: | |||
96 | if( pReg == NULL ) | 115 | if( pReg == NULL ) |
97 | return NULL; | 116 | return NULL; |
98 | 117 | ||
99 | T *p = pReg->pInfo->createPlugin(); | 118 | T *p = (T *)pReg->pInfo->createPlugin(); |
100 | hObj.insert( p, pReg ); | 119 | hObj.insert( p, pReg ); |
101 | printf("pReg: %08X, pPlug: %08X\n", pReg, p ); | 120 | //printf("pReg: %08X, pPlug: %08X\n", pReg, p ); |
102 | 121 | ||
103 | return p; | 122 | return p; |
104 | } | 123 | } |
@@ -106,7 +125,7 @@ public: | |||
106 | void destroy( T *pPlug ) | 125 | void destroy( T *pPlug ) |
107 | { | 126 | { |
108 | PluginReg *pReg = (PluginReg *)hObj[pPlug]; | 127 | PluginReg *pReg = (PluginReg *)hObj[pPlug]; |
109 | printf("pReg: %08X, pPlug: %08X\n", pReg, pPlug ); | 128 | //printf("pReg: %08X, pPlug: %08X\n", pReg, pPlug ); |
110 | if( pReg == NULL ) | 129 | if( pReg == NULL ) |
111 | return; | 130 | return; |
112 | 131 | ||