PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
plugin.h
Go to the documentation of this file.
1 /*
2  * plugin.h
3  *
4  * Plugin Class Declarations
5  *
6  * Portable Windows Library
7  *
8  * Contributor(s): Snark at GnomeMeeting
9  *
10  * $Revision: 30779 $
11  * $Author: rjongbloed $
12  * $Date: 2013-10-29 18:10:28 +1100 (Tue, 29 Oct 2013) $
13  */
14 
15 #ifndef PTLIB_PLUGIN_H
16 #define PTLIB_PLUGIN_H
17 
19 //
20 // these templates implement an adapter to make the old style device plugins appear in the new factory system
21 //
22 
23 #include <ptlib/pfactory.h>
24 
25 #ifdef PWLIB_PLUGIN_API_VERSION
26  #ifdef PTLIB_PLUGIN_API_VERSION
27  #warning Ignoring PWLIB_PLUGIN_API_VERSION as PTLIB_PLUGIN_API_VERSION is defined!
28  #undef PWLIB_PLUGIN_API_VERSION
29  #else
30  #define PTLIB_PLUGIN_API_VERSION PWLIB_PLUGIN_API_VERSION
31  #endif
32 #else
33  #ifndef PTLIB_PLUGIN_API_VERSION
34  #define PTLIB_PLUGIN_API_VERSION 1
35  #endif
36 #endif
37 
38 
40 //
41 // Ancestor Service descriptor for plugins
42 //
43 
45 {
46  public:
47  static const char SeparatorChar;
48 
51  { }
52 
54 
55  virtual unsigned GetPluginAPIVersion() const { return m_version; }
56  virtual const char * GetServiceType() const = 0;
57  virtual const char * GetServiceName() const = 0;
58  virtual const char * GetFriendlyName() const { return GetServiceName(); }
59  virtual bool ValidateServiceName(const PString & name, P_INT_PTR userData) const;
60  virtual PObject * CreateInstance(P_INT_PTR userData) const = 0;
61 
62  protected:
63  unsigned m_version;
64 };
65 
66 
68 
69 
71 {
72  public:
73  virtual bool ValidateServiceName(const PString & name, P_INT_PTR userData) const;
74 
75  virtual PStringArray GetDeviceNames(P_INT_PTR userData) const;
76  virtual bool ValidateDeviceName(const PString & deviceName, P_INT_PTR userData) const;
77  virtual bool GetDeviceCapabilities(const PString & deviceName, void * capabilities) const;
78 };
79 
80 typedef PPluginDeviceDescriptor PDevicePluginServiceDescriptor; // Backward compatibility
81 
82 
84 
85 #define PCREATE_PLUGIN_SERVICE_EX(serviceType, BaseClass, extra) \
86  class PPlugin_##serviceType : public BaseClass { \
87  public: \
88  static const char * ServiceType() { return #serviceType; } \
89  virtual const char * GetServiceType() const { return ServiceType(); } \
90  extra \
91  }
92 
93 #define PCREATE_PLUGIN_SERVICE(serviceType) \
94  PCREATE_PLUGIN_SERVICE_EX(serviceType, PPluginServiceDescriptor, )
95 
96 #define PCREATE_PLUGIN_DEVICE(serviceType) \
97  PCREATE_PLUGIN_SERVICE_EX(serviceType, PPluginDeviceDescriptor, )
98 
99 
101 
102 #define PCREATE_PLUGIN_ARG_5(serviceName, serviceType, InstanceClass, DescriptorClass, extra) \
103  class PPlugin_##serviceType##_##serviceName : public DescriptorClass { \
104  public: \
105  static const char * ServiceName() { return #serviceName; } \
106  virtual const char * GetServiceName() const { return ServiceName(); } \
107  virtual PObject * CreateInstance(P_INT_PTR) const { return new InstanceClass; } \
108  extra \
109  }; \
110  PFACTORY_CREATE(PPluginFactory, PPlugin_##serviceType##_##serviceName, #serviceType #serviceName, true)
111 
112 #define PCREATE_PLUGIN_ARG_4(serviceName, serviceType, InstanceClass, DescriptorClass) \
113  PCREATE_PLUGIN_ARG_5(serviceName, serviceType, InstanceClass, DescriptorClass, )
114 
115 #define PCREATE_PLUGIN_ARG_3(serviceName, serviceType, InstanceClass) \
116  PCREATE_PLUGIN_ARG_4(serviceName, serviceType, InstanceClass, PPlugin_##serviceType)
117 
118 #define PCREATE_PLUGIN_ARG_2(serviceName, serviceType) \
119  PCREATE_PLUGIN_ARG_3(serviceName, serviceType, serviceType##_##serviceName)
120 
121 #define PCREATE_PLUGIN_PART1(narg, args) PCREATE_PLUGIN_PART2(narg, args)
122 #define PCREATE_PLUGIN_PART2(narg, args) PCREATE_PLUGIN_ARG_##narg args
123 
124 #define PCREATE_PLUGIN_STATIC(...) PCREATE_PLUGIN_PART1(PARG_COUNT(__VA_ARGS__), (__VA_ARGS__))
125 
126 
127 #define PPLUGIN_STATIC_LOAD(serviceName, serviceType) PFACTORY_LOAD(PPlugin_##serviceType##_##serviceName)
128 
129 
130 #if defined(_WIN32) && !defined(P_FORCE_STATIC_PLUGIN)
131  #define P_FORCE_STATIC_PLUGIN 1 // always define static plugins in Windows, since otherwise they seem not to work
132 #endif
133 
134 #if defined(P_PLUGINS) && !defined(P_FORCE_STATIC_PLUGIN)
135 
136  #define PCREATE_PLUGIN(serviceName, serviceType, ...) \
137  PCREATE_PLUGIN_STATIC(serviceName, serviceType, __VA_ARGS__) \
138  extern "C" void PWLibPlugin_TriggerRegister(PPluginManager * pluginMgr) \
139  { pluginMgr->RegisterService(#serviceType #serviceName); } \
140  extern "C" unsigned PWLibPlugin_GetAPIVersion (void) \
141  { return PTLIB_PLUGIN_API_VERSION; }
142 
143 #else
144 
145  #define PCREATE_PLUGIN(...) \
146  PCREATE_PLUGIN_STATIC(__VA_ARGS__)
147 
148 #endif
149 
150 
152 
153 
154 #endif // PTLIB_PLUGIN_H
155 
156 
157 // End Of File ///////////////////////////////////////////////////////////////