Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef XAP_MODULE_H
00023 #define XAP_MODULE_H
00024
00025
00026
00027
00028
00029
00030 #ifdef HAVE_CONFIG_H
00031 #include "config.h"
00032 #endif
00033
00034 #include <stdio.h>
00035
00036
00037
00038
00039
00040 #ifndef UT_TYPES_H
00041 #include "ut_types.h"
00042 #endif
00043
00044 #ifdef TOOLKIT_WIN
00045 #define WIN32_LEAN_AND_MEAN
00046 #include <windows.h>
00047 #define ABI_PLUGIN_DECLARE(name) static HANDLE s_hModule = static_cast<HANDLE>(NULL); extern "C" {BOOL APIENTRY DllMain( HANDLE hModule, DWORD , LPVOID ) { s_hModule = hModule; return TRUE; } }
00048 #else
00049 #define ABI_PLUGIN_DECLARE(name)
00050 #endif
00051
00052
00053
00054 extern "C" {
00055 typedef struct {
00056 const char * name;
00057 const char * desc;
00058 const char * version;
00059 const char * author;
00060 const char * usage;
00061 } XAP_ModuleInfo;
00062 }
00063
00064 class XAP_ModuleManager;
00065
00066 typedef int (*XAP_Plugin_Registration) (XAP_ModuleInfo * mi);
00067 typedef int (*XAP_Plugin_VersionCheck) (UT_uint32 major, UT_uint32 minor, UT_uint32 release);
00068
00069 class ABI_EXPORT XAP_Module {
00070
00071 friend class XAP_ModuleManager;
00072
00073 protected:
00074 XAP_Module ();
00075
00076 virtual ~XAP_Module (void);
00077
00078
00079 virtual bool load (const char * name) = 0;
00080
00081
00082 virtual bool unload (void) = 0;
00083
00084 public:
00085
00086 bool setSymbols (XAP_Plugin_Registration fnRegister,
00087 XAP_Plugin_Registration fnDeregister,
00088 XAP_Plugin_VersionCheck fnSupportsVersion);
00089
00090 bool registered ();
00091 private:
00092 bool registerPending ();
00093
00094 bool registerThySelf ();
00095 bool unregisterThySelf ();
00096 bool supportsAbiVersion (UT_uint32 major, UT_uint32 minor,
00097 UT_uint32 release);
00098 inline void setCreator (XAP_ModuleManager * creator) {m_creator = creator;}
00099 inline void setLoaded (bool bLoaded) {m_bLoaded = bLoaded;}
00100
00101 public:
00102
00103
00104
00105
00106
00107
00108
00109 virtual bool resolveSymbol (const char * symbol_name, void ** symbol) = 0;
00110
00111
00112
00113 virtual bool getModuleName (char ** dest) const = 0;
00114
00115
00116
00117 virtual bool getErrorMsg (char ** dest) const = 0;
00118
00119 inline XAP_ModuleManager * getCreator () const {return m_creator;}
00120
00121 inline const XAP_ModuleInfo *getModuleInfo (void) const {return &m_info;}
00122
00123 private:
00124
00125 XAP_Plugin_Registration m_fnRegister;
00126 XAP_Plugin_Registration m_fnDeregister;
00127 XAP_Plugin_VersionCheck m_fnSupportsVersion;
00128
00129 XAP_ModuleManager * m_creator;
00130 bool m_bLoaded;
00131 bool m_bRegistered;
00132 int m_iStatus;
00133 const char * m_szSPI;
00134 XAP_ModuleInfo m_info;
00135 };
00136
00137 #if 0 // TODO: make me 100% and turn me on again one day
00138 #ifndef ABI_PLUGIN_SOURCE
00139 static inline bool
00140 _isCurrentAbiVersion(int a, int b, int c)
00141 {
00142 int _a, _b, _c, _n;
00143
00144 _n = sscanf( ABI_BUILD_VERSION , "%d.%d.%d", &_a, &_b, &_c);
00145
00146 if (_n <= 1 || _a != a || _b != b)
00147 return false;
00148
00149 if (3 == _n && _c != c)
00150 return false;
00151
00152 return true;
00153 }
00154 #endif
00155
00156 #define isCurrentAbiVersion(a,b,c) _isCurrentAbiVersion(a, b, c)
00157
00158 #else
00159 #define isCurrentAbiVersion(a,b,c) true
00160 #endif
00161
00162 #ifdef ABI_PLUGIN_SOURCE
00163 #define ABI_VERSION_STRING ABI_PLUGIN_VERSION
00164 #else
00165 #define ABI_VERSION_STRING ABI_BUILD_VERSION
00166 #endif
00167
00168 #endif