diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-06-22 01:27:19 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-06-22 01:27:19 +0000 |
commit | 35274124dc95ec5d6094e71c18ac7b484d812f13 (patch) | |
tree | 20e192f0b87ed43235e0ade4e0180b4c57be8e5c /src/plugger.h | |
parent | 0acdeb045f1bf6caae786c474d99cea68071f31f (diff) | |
download | libbu++-35274124dc95ec5d6094e71c18ac7b484d812f13.tar.gz libbu++-35274124dc95ec5d6094e71c18ac7b484d812f13.tar.bz2 libbu++-35274124dc95ec5d6094e71c18ac7b484d812f13.tar.xz libbu++-35274124dc95ec5d6094e71c18ac7b484d812f13.zip |
Updated some tests so they don't work but will compile, and made some pleasant
changes to the plugger. Also set it up so that libbu++ code is relocatable.
Diffstat (limited to '')
-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 | ||