Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

plugin.h

Go to the documentation of this file.
00001 /* 00002 * plugin.h 00003 * 00004 * Plugin Class Declarations 00005 * 00006 * Portable Windows Library 00007 * 00008 * Contributor(s): Snark at GnomeMeeting 00009 * 00010 * $Log: plugin.h,v $ 00011 * Revision 1.8 2004/06/21 10:40:02 csoutheren 00012 * Fixed problem with dynamic plugins 00013 * 00014 * Revision 1.7 2004/06/21 00:57:40 csoutheren 00015 * Changed service plugin static registration to use attribute (( constructor )) 00016 * 00017 * Revision 1.6 2003/12/19 00:34:27 csoutheren 00018 * Ensured that older compilers do not get confused about functions wth empty 00019 * parameter lists. Thanks to Kilian Krause 00020 * 00021 * Revision 1.5 2003/11/19 09:29:19 csoutheren 00022 * Added super hack to avoid problems with multiple plugins in a single file 00023 * 00024 * Revision 1.4 2003/11/12 10:24:35 csoutheren 00025 * Changes to allow operation of static plugins under Windows 00026 * 00027 * Revision 1.3 2003/11/12 06:58:21 csoutheren 00028 * Changes to help in making static plugins autoregister under Windows 00029 * 00030 * Revision 1.2 2003/11/12 03:26:17 csoutheren 00031 * Initial version of plugin code from Snark of GnomeMeeting with changes 00032 * by Craig Southeren os Post Increment 00033 * 00034 * 00035 */ 00036 00037 #ifndef _PLUGIN_H 00038 #define _PLUGIN_H 00039 00040 #define PWLIB_PLUGIN_API_VERSION 0 00041 00043 // 00044 // Ancestor Service descriptor for plugins 00045 // 00046 00047 class PPluginServiceDescriptor 00048 { 00049 public: 00050 PPluginServiceDescriptor(unsigned (*_GetPluginAPIVersion)()) 00051 : GetPluginAPIVersion(_GetPluginAPIVersion) 00052 { } 00053 00054 unsigned (*GetPluginAPIVersion)(); 00055 }; 00056 00057 00059 // 00060 // Define a service provided by a plugin, which consists of the following: 00061 // 00062 // serviceType - the base class name of the service which is used to identify 00063 // the service type, such as PSoundChannel, 00064 // 00065 // serviceName - the name of the service provided by the plugin. This will usually 00066 // be related to the class implementing the service, such as: 00067 // service name = OSS, class name = PSoundChannelOSS 00068 // 00069 // descriptor - a pointer to a class containing pointers to any static functions 00070 // for this class 00071 // 00072 // 00073 00074 class PPluginService: public PObject 00075 { 00076 public: 00077 PPluginService(const PString & _serviceName, 00078 const PString & _serviceType, 00079 PPluginServiceDescriptor *_descriptor) 00080 { 00081 serviceName = _serviceName; 00082 serviceType = _serviceType; 00083 descriptor = _descriptor; 00084 } 00085 00086 PString serviceName; 00087 PString serviceType; 00088 PPluginServiceDescriptor * descriptor; 00089 }; 00090 00092 00093 #define PCREATE_PLUGIN_VERSION_DECLARE 00094 00095 #define PCREATE_STATIC_PLUGIN_VERSION_FN(serviceName, serviceType) \ 00096 unsigned PPlugin_##serviceType##_##serviceName##_GetVersion() \ 00097 { return PWLIB_PLUGIN_API_VERSION; } 00098 00099 #define PCREATE_DYNAMIC_PLUGIN_VERSION_FN(serviceName, serviceType) \ 00100 extern "C" unsigned PWLibPlugin_GetAPIVersion (void) \ 00101 { return PWLIB_PLUGIN_API_VERSION; } 00102 00104 // 00105 // These crazy macros are needed to cause automatic registration of 00106 // static plugins. They are made more complex by the arcane behaviour 00107 // of the Windows link system that requires an external reference in the 00108 // object module before it will instantiate any globals in in it 00109 // The non-Windows version is much simpler - just use declare a 00110 // function with attribute (( constructor )) and it will get called on startup 00111 // 00112 00113 #define PCREATE_PLUGIN_REGISTERER(serviceName, serviceType, descriptor) \ 00114 class PPlugin_##serviceType##_##serviceName##_Registration { \ 00115 public: \ 00116 PPlugin_##serviceType##_##serviceName##_Registration(PPluginManager * pluginMgr) \ 00117 { pluginMgr->RegisterService(#serviceName, #serviceType, descriptor); } \ 00118 int kill_warning; \ 00119 }; \ 00120 00121 #ifdef _WIN32 00122 00123 #define PCREATE_PLUGIN_STATIC(serviceName, serviceType, descriptor) \ 00124 PCREATE_PLUGIN_REGISTERER(serviceName, serviceType, descriptor) \ 00125 PPlugin_##serviceType##_##serviceName##_Registration \ 00126 PPlugin_##serviceType##_##serviceName##_Registration_Instance(&PPluginManager::GetPluginManager()); \ 00127 00128 #define PWLIB_STATIC_LOAD_PLUGIN(cls) \ 00129 class PPlugin_##cls##_Registration; \ 00130 extern PPlugin_##cls##_Registration PPlugin_##cls##_Registration_Instance; \ 00131 static PPlugin_##cls##_Registration * PPlugin_##cls##_Registration_Static_Library_Loader = &PPlugin_##cls##_Registration_Instance 00132 00133 #else 00134 00135 #define PCREATE_PLUGIN_STATIC(serviceName, serviceType, descriptor) \ 00136 static void __attribute__ (( constructor )) PWLIB_StaticLoader_##serviceName##_##serviceType() \ 00137 { PPluginManager::GetPluginManager().RegisterService(#serviceName, #serviceType, descriptor); } \ 00138 00139 #define PWLIB_STATIC_LOAD_PLUGIN(cls) 00140 00141 #endif 00142 00143 #define PCREATE_PLUGIN_DYNAMIC(serviceName, serviceType, descriptor) \ 00144 PCREATE_PLUGIN_REGISTERER(serviceName, serviceType, descriptor) \ 00145 extern "C" void PWLibPlugin_TriggerRegister (PPluginManager * pluginMgr) { \ 00146 PPlugin_##serviceType##_##serviceName##_Registration \ 00147 pplugin_##serviceType##_##serviceName##_Registration_Instance(pluginMgr); \ 00148 pplugin_##serviceType##_##serviceName##_Registration_Instance.kill_warning = 0; \ 00149 } 00150 00152 00153 #if defined(P_HAS_PLUGINS) && ! defined(P_FORCE_STATIC_PLUGIN) 00154 # define PCREATE_PLUGIN(serviceName, serviceType, descriptor) \ 00155 PCREATE_PLUGIN_DYNAMIC(serviceName, serviceType, descriptor) 00156 00157 # define PCREATE_PLUGIN_VERSION_FN(serviceName, serviceType) \ 00158 PCREATE_DYNAMIC_PLUGIN_VERSION_FN(serviceName, serviceType) 00159 00160 # define PPLUGIN_VERSION_FN(serviceName, serviceType) \ 00161 PWLibPlugin_GetAPIVersion 00162 00163 #else 00164 00165 # define PCREATE_PLUGIN(serviceName, serviceType, descriptor) \ 00166 PCREATE_PLUGIN_STATIC(serviceName, serviceType, descriptor) 00167 00168 # define PCREATE_PLUGIN_VERSION_FN(serviceName, serviceType) \ 00169 PCREATE_STATIC_PLUGIN_VERSION_FN(serviceName, serviceType) 00170 00171 # define PPLUGIN_VERSION_FN(serviceName, serviceType) \ 00172 PPlugin_##serviceType##_##serviceName##_GetVersion 00173 00174 #endif 00175 00177 00178 #endif

Generated on Sat Jul 24 15:35:56 2004 for PWLib by doxygen 1.3.7