15 #ifndef PTLIB_PLUGIN_H 16 #define PTLIB_PLUGIN_H 25 template <
class AbstractClass,
typename KeyType = PString>
32 Worker(
const KeyType & key,
bool singleton =
false)
41 typedef std::map<KeyType, WorkerBase_T *>
KeyMap_T;
46 typename KeyMap_T::const_iterator entry;
47 for (entry = km.begin(); entry != km.end(); ++entry) {
48 if (entry->second ==
this) {
58 virtual AbstractClass *
Create(
const KeyType & key)
const;
69 virtual void CreateFactory(
const PString & device) = 0;
72 template <
typename DeviceBase>
80 if (!(Factory_T::IsRegistered(device)))
81 new Worker_T(device,
false);
86 #ifndef PWLIB_PLUGIN_API_VERSION 87 #define PWLIB_PLUGIN_API_VERSION 0 115 virtual PStringArray GetDeviceNames(
int userData)
const = 0;
116 virtual bool ValidateDeviceName(
const PString & deviceName,
int userData)
const;
117 virtual bool GetDeviceCapabilities(
const PString & deviceName,
void * capabilities)
const;
163 #define PCREATE_PLUGIN_REGISTERER(serviceName, serviceType, descriptor) \ 164 class PPlugin_##serviceType##_##serviceName##_Registration { \ 166 PPlugin_##serviceType##_##serviceName##_Registration(PPluginManager * pluginMgr) \ 168 static PDevicePluginFactory<serviceType>::Worker factory(#serviceName); \ 169 pluginMgr->RegisterService(#serviceName, #serviceType, descriptor); \ 176 #define PCREATE_PLUGIN_STATIC(serviceName, serviceType, descriptor) \ 177 PCREATE_PLUGIN_REGISTERER(serviceName, serviceType, descriptor) \ 178 PPlugin_##serviceType##_##serviceName##_Registration \ 179 PPlugin_##serviceType##_##serviceName##_Registration_Instance(&PPluginManager::GetPluginManager()); \ 180 int PPlugin_##serviceType##_##serviceName##_link() { return 0; } 182 #define PPLUGIN_STATIC_LOAD(serviceName, serviceType) \ 183 extern int PPlugin_##serviceType##_##serviceName##_link(); \ 184 int const PPlugin_##serviceType##_##serviceName##_loader = PPlugin_##serviceType##_##serviceName##_link(); 187 #ifndef P_FORCE_STATIC_PLUGIN 188 #define P_FORCE_STATIC_PLUGIN 1 194 #define PCREATE_PLUGIN_STATIC(serviceName, serviceType, descriptor) \ 195 static void __attribute__ (( constructor )) PWLIB_StaticLoader_##serviceName##_##serviceType() \ 196 { PPluginManager::GetPluginManager().RegisterService(#serviceName, #serviceType, descriptor); } \ 197 int PPlugin_##serviceType##_##serviceName##_link() { return 0; } 200 #define PCREATE_PLUGIN_STATIC(serviceName, serviceType, descriptor) \ 201 extern int PWLIB_gStaticLoader__##serviceName##_##serviceType; \ 202 static int PWLIB_StaticLoader_##serviceName##_##serviceType() \ 203 { PPluginManager::GetPluginManager().RegisterService(#serviceName, #serviceType, descriptor); return 1; } \ 204 int PWLIB_gStaticLoader__##serviceName##_##serviceType = PWLIB_StaticLoader_##serviceName##_##serviceType(); \ 205 int PPlugin_##serviceType##_##serviceName##_link() { return 0; } 208 #define PPLUGIN_STATIC_LOAD(serviceName, serviceType) \ 209 extern int PPlugin_##serviceType##_##serviceName##_link(); \ 210 int const PPlugin_##serviceType##_##serviceName##_loader = PPlugin_##serviceType##_##serviceName##_link(); 213 #ifndef P_FORCE_STATIC_PLUGIN 214 #define P_FORCE_STATIC_PLUGIN 1 223 #if defined(P_PLUGINS) && ! defined(P_FORCE_STATIC_PLUGIN) 225 # define PCREATE_PLUGIN(serviceName, serviceType, descriptor) \ 226 PCREATE_PLUGIN_REGISTERER(serviceName, serviceType, descriptor) \ 227 extern "C" void PWLibPlugin_TriggerRegister (PPluginManager * pluginMgr) { \ 228 PPlugin_##serviceType##_##serviceName##_Registration \ 229 pplugin_##serviceType##_##serviceName##_Registration_Instance(pluginMgr); \ 230 pplugin_##serviceType##_##serviceName##_Registration_Instance.kill_warning = 0; \ 232 extern "C" unsigned PWLibPlugin_GetAPIVersion (void) \ 233 { return PWLIB_PLUGIN_API_VERSION; } 237 # define PCREATE_PLUGIN(serviceName, serviceType, descriptor) \ 238 PCREATE_PLUGIN_STATIC(serviceName, serviceType, descriptor) 245 #endif // PTLIB_PLUGIN_H std::map< Key_T, WorkerBase * > KeyMap_T
Definition: pfactory.h:223
virtual ~PDevicePluginAdapterBase()
Definition: plugin.h:67
static const char SeparatorChar
Definition: plugin.h:112
Worker(const KeyType &key, bool singleton=false)
Definition: plugin.h:32
static KeyMap_T & GetKeyMap()
Definition: pfactory.h:281
void CreateFactory(const PString &device)
Definition: plugin.h:78
static void Unregister(const Key_T &key)
Definition: pfactory.h:245
PPluginServiceDescriptor * descriptor
Definition: plugin.h:151
PPluginServiceDescriptor()
Definition: plugin.h:99
virtual AbstractClass * Create(const KeyType &key) const
~Worker()
Definition: plugin.h:38
#define PWLIB_PLUGIN_API_VERSION
Definition: plugin.h:87
This is an array collection class of PString objects.
Definition: pstring.h:2024
Factory_T::Worker Worker_T
Definition: plugin.h:77
PString serviceName
Definition: plugin.h:149
unsigned version
Definition: plugin.h:105
PDevicePluginAdapterBase()
Definition: plugin.h:65
PPluginService(const PString &name, const PString &type, PPluginServiceDescriptor *desc)
Definition: plugin.h:140
static bool Register(const Key_T &key, WorkerBase *worker)
Definition: pfactory.h:226
The character string class.
Definition: pstring.h:108
virtual ~PPluginServiceDescriptor()
Definition: plugin.h:100
Template class for generic factories of an abstract class.
Definition: pfactory.h:144
Abstract_T * CreateInstance(const Key_T &key)
Definition: pfactory.h:176
virtual unsigned GetPluginAPIVersion() const
Definition: plugin.h:102
Definition: pfactory.h:150
PDevicePluginFactory< DeviceBase > Factory_T
Definition: plugin.h:76
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PString serviceType
Definition: plugin.h:150