• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

xap_Module.h

Go to the documentation of this file.
00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
00002 
00003 /* AbiSource Application Framework
00004  * Copyright (C) 2001 Dom Lachowicz <cinamod@hotmail.com>
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019  * 02110-1301 USA.
00020  */
00021 
00022 #ifndef XAP_MODULE_H
00023 #define XAP_MODULE_H
00024 
00025 // This is an abstract class meant for dynamically
00026 // Loading and unloading modules. To load a module,
00027 // Pass the intended file name (dll, so, whatever)
00028 // To a valid child instance of this class.
00029 
00030 #ifdef HAVE_CONFIG_H
00031 #include "config.h"
00032 #endif
00033 
00034 #include <stdio.h>
00035 
00036 /* pre-emptive dismissal; ut_types.h is needed by just about everything,
00037  * so even if it's commented out in-file that's still a lot of work for
00038  * the preprocessor to do...
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 /*ul_reason_for_call*/, LPVOID /*lpReserved*/ ) { s_hModule = hModule; return TRUE; } }
00048 #else
00049   #define ABI_PLUGIN_DECLARE(name)
00050 #endif
00051 
00052 // we want to have C linkage for both
00053 // this and for all of our required functions
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     // load this module into memory. true on success
00079     virtual bool load (const char * name) = 0;
00080 
00081     // unload this module from memory. true on success
00082     virtual bool unload (void) = 0;
00083 
00084 public:
00085     // marks the module as loaded; returns false if module is already loaded
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     // silly names. fscking c/c++ has the keyword 'register' taken #:^)
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     // passed a symbol name and a void ** symbol,
00104     // *symbol refers to the actual representation of @symbol_name
00105     //
00106     // void (*func) (XAP_ModuleInfo *);
00107     // resolveSymbol ("abi_plugin_init", static_cast<void **>(&func));
00108     // int result = func (&m_info);
00109     virtual bool resolveSymbol (const char * symbol_name, void ** symbol) = 0;
00110 
00111     // returns the name of this module, if it has one
00112     // if return is true, you must FREEP dest
00113     virtual bool getModuleName (char ** dest) const = 0;
00114 
00115     // returns the most recent error message from one of these
00116     // calls failing. If return is true, you must FREEP dest
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 /* ! ABI_PLUGIN_SOURCE */
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 /* XAP_MODULE_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1