00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #ifndef _PLUGIN_H
00047 #define _PLUGIN_H
00048
00050
00051
00052
00053
00054 #include <ptlib/pfactory.h>
00055
00056 template <class _Abstract_T, typename _Key_T = PString>
00057 class PDevicePluginFactory : public PFactory<_Abstract_T, _Key_T>
00058 {
00059 public:
00060 class Worker : public PFactory<_Abstract_T, _Key_T>::WorkerBase
00061 {
00062 public:
00063 Worker(const _Key_T & key, bool singleton = false)
00064 : PFactory<_Abstract_T, _Key_T>::WorkerBase(singleton)
00065 {
00066 PFactory<_Abstract_T, _Key_T>::Register(key, this);
00067 }
00068
00069 protected:
00070 virtual _Abstract_T * Create(const _Key_T & key) const;
00071 };
00072 };
00073
00074 class PDevicePluginAdapterBase
00075 {
00076 public:
00077 PDevicePluginAdapterBase()
00078 { }
00079 virtual ~PDevicePluginAdapterBase()
00080 { }
00081 virtual void CreateFactory(const PString & device) = 0;
00082 };
00083
00084 template <typename DeviceBase>
00085 class PDevicePluginAdapter : public PDevicePluginAdapterBase
00086 {
00087 public:
00088 typedef PDevicePluginFactory<DeviceBase> Factory_T;
00089 typedef typename Factory_T::Worker Worker_T;
00090 void CreateFactory(const PString & device)
00091 { new Worker_T(device, TRUE); }
00092 };
00093
00094 #define PWLIB_PLUGIN_API_VERSION 0
00095
00097
00098
00099
00100
00101 class PPluginServiceDescriptor
00102 {
00103 public:
00104 PPluginServiceDescriptor(unsigned (*_GetPluginAPIVersion)())
00105 : GetPluginAPIVersion(_GetPluginAPIVersion)
00106 { }
00107
00108 unsigned (*GetPluginAPIVersion)();
00109 };
00110
00111
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 class PPluginService: public PObject
00129 {
00130 public:
00131 PPluginService(const PString & _serviceName,
00132 const PString & _serviceType,
00133 PPluginServiceDescriptor *_descriptor)
00134 {
00135 serviceName = _serviceName;
00136 serviceType = _serviceType;
00137 descriptor = _descriptor;
00138 }
00139
00140 PString serviceName;
00141 PString serviceType;
00142 PPluginServiceDescriptor * descriptor;
00143 };
00144
00146
00147 #define PCREATE_PLUGIN_VERSION_DECLARE
00148
00149 #define PCREATE_STATIC_PLUGIN_VERSION_FN(serviceName, serviceType) \
00150 unsigned PPlugin_##serviceType##_##serviceName##_GetVersion() \
00151 { return PWLIB_PLUGIN_API_VERSION; }
00152
00153 #define PCREATE_DYNAMIC_PLUGIN_VERSION_FN(serviceName, serviceType) \
00154 extern "C" unsigned PWLibPlugin_GetAPIVersion (void) \
00155 { return PWLIB_PLUGIN_API_VERSION; }
00156
00158
00159
00160
00161
00162
00163
00164
00165 #define PCREATE_PLUGIN_REGISTERER(serviceName, serviceType, descriptor) \
00166 class PPlugin_##serviceType##_##serviceName##_Registration { \
00167 public: \
00168 PPlugin_##serviceType##_##serviceName##_Registration(PPluginManager * pluginMgr) \
00169 { \
00170 static PDevicePluginFactory<serviceType>::Worker factory(#serviceName); \
00171 pluginMgr->RegisterService(#serviceName, #serviceType, descriptor); \
00172 } \
00173 int kill_warning; \
00174 }; \
00175
00176 #ifdef _WIN32
00177
00178 #define PCREATE_PLUGIN_STATIC(serviceName, serviceType, descriptor) \
00179 PCREATE_PLUGIN_REGISTERER(serviceName, serviceType, descriptor) \
00180 PPlugin_##serviceType##_##serviceName##_Registration \
00181 PPlugin_##serviceType##_##serviceName##_Registration_Instance(&PPluginManager::GetPluginManager()); \
00182
00183 #define PWLIB_STATIC_LOAD_PLUGIN(cls) \
00184 class PPlugin_##cls##_Registration; \
00185 extern PPlugin_##cls##_Registration PPlugin_##cls##_Registration_Instance; \
00186 static PPlugin_##cls##_Registration * PPlugin_##cls##_Registration_Static_Library_Loader = &PPlugin_##cls##_Registration_Instance
00187
00188 #else
00189
00190 #define PCREATE_PLUGIN_STATIC(serviceName, serviceType, descriptor) \
00191 static void __attribute__ (( constructor )) PWLIB_StaticLoader_##serviceName##_##serviceType() \
00192 { PPluginManager::GetPluginManager().RegisterService(#serviceName, #serviceType, descriptor); } \
00193
00194 #define PWLIB_STATIC_LOAD_PLUGIN(cls)
00195
00196 #endif
00197
00198 #define PCREATE_PLUGIN_DYNAMIC(serviceName, serviceType, descriptor) \
00199 PCREATE_PLUGIN_REGISTERER(serviceName, serviceType, descriptor) \
00200 extern "C" void PWLibPlugin_TriggerRegister (PPluginManager * pluginMgr) { \
00201 PPlugin_##serviceType##_##serviceName##_Registration \
00202 pplugin_##serviceType##_##serviceName##_Registration_Instance(pluginMgr); \
00203 pplugin_##serviceType##_##serviceName##_Registration_Instance.kill_warning = 0; \
00204 }
00205
00207
00208 #if defined(P_HAS_PLUGINS) && ! defined(P_FORCE_STATIC_PLUGIN)
00209 # define PCREATE_PLUGIN(serviceName, serviceType, descriptor) \
00210 PCREATE_PLUGIN_DYNAMIC(serviceName, serviceType, descriptor)
00211
00212 # define PCREATE_PLUGIN_VERSION_FN(serviceName, serviceType) \
00213 PCREATE_DYNAMIC_PLUGIN_VERSION_FN(serviceName, serviceType)
00214
00215 # define PPLUGIN_VERSION_FN(serviceName, serviceType) \
00216 PWLibPlugin_GetAPIVersion
00217
00218 #else
00219
00220 # define PCREATE_PLUGIN(serviceName, serviceType, descriptor) \
00221 PCREATE_PLUGIN_STATIC(serviceName, serviceType, descriptor)
00222
00223 # define PCREATE_PLUGIN_VERSION_FN(serviceName, serviceType) \
00224 PCREATE_STATIC_PLUGIN_VERSION_FN(serviceName, serviceType)
00225
00226 # define PPLUGIN_VERSION_FN(serviceName, serviceType) \
00227 PPlugin_##serviceType##_##serviceName##_GetVersion
00228
00229 #endif
00230
00232
00233 #endif