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
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
#ifndef _PLUGINMGR_H
00060
#define _PLUGINMGR_H
00061
00062 #define DEFAULT_PLUGINDIR "/usr/lib/pwlib"
00063
00064
#include <ptlib/plugin.h>
00065
00066
template <
class C>
00067 void PLoadPluginDirectory(C & obj,
const PDirectory & directory,
const char * suffix = NULL)
00068 {
00069
PDirectory dir = directory;
00070
if (!dir.
Open()) {
00071
PTRACE(4,
"Cannot open plugin directory " << dir);
00072
return;
00073 }
00074
PTRACE(4,
"Enumerating plugin directory " << dir);
00075
do {
00076
PString entry = dir + dir.
GetEntryName();
00077
if (dir.
IsSubDir())
00078 PLoadPluginDirectory<C>(obj, entry);
00079
else {
00080
PFilePath fn(entry);
00081
if (
00082 (fn.
GetType() *=
PDynaLink::GetExtension()) &&
00083 (
00084 (suffix == NULL) || (fn.
GetTitle().
Right(strlen(suffix)) *= suffix)
00085 )
00086 )
00087 obj.LoadPlugin(entry);
00088 }
00089 }
while (dir.
Next());
00090 }
00091
00093
00094
00095
00096
00097 class PPluginManager :
public PObject
00098 {
00099
PCLASSINFO(
PPluginManager,
PObject);
00100
00101
public:
00102
00103 BOOL
LoadPlugin (
const PString & fileName);
00104
void LoadPluginDirectory (
const PDirectory & dir);
00105
00106
00107
PStringList GetPluginTypes()
const;
00108
PStringList GetPluginsProviding (
const PString & serviceType)
const;
00109
PPluginServiceDescriptor *
GetServiceDescriptor (
const PString & serviceName,
const PString & serviceType);
00110
00111
00112 BOOL
RegisterService (
const PString & serviceName,
const PString & serviceType,
PPluginServiceDescriptor * descriptor);
00113
00114
00115
static PStringArray GetPluginDirs();
00116
00117
00118
static PPluginManager &
GetPluginManager();
00119
00137
void AddNotifier(
00138
const PNotifier & filterFunction,
00139 BOOL existing = FALSE
00140 );
00141
00142
void RemoveNotifier(
00143
const PNotifier & filterFunction
00144 );
00145
00146
protected:
00147
void CallNotifier(
PDynaLink & dll, INT code);
00148
00149 PMutex pluginListMutex;
00150 PList<PDynaLink>
pluginList;
00151
00152 PMutex serviceListMutex;
00153 PList<PPluginService>
serviceList;
00154
00155 PMutex notifierMutex;
00156 PList<PNotifier>
notifierList;
00157 };
00158
00160
00161
00162
00163
00164 class PPluginModuleManager :
public PObject
00165 {
00166
public:
00167 typedef PDictionary<PString, PDynaLink>
PluginListType;
00168
00169
PPluginModuleManager(
const char * _signatureFunctionName,
PPluginManager * pluginMgr = NULL);
00170
00171 BOOL
LoadPlugin(
const PString & fileName)
00172 {
if (
pluginMgr == NULL)
return FALSE;
else return pluginMgr->
LoadPlugin(fileName); }
00173
00174 void LoadPluginDirectory(
const PDirectory &directory)
00175 {
if (
pluginMgr != NULL)
pluginMgr->
LoadPluginDirectory(directory); }
00176
00177 virtual void OnLoadPlugin(
PDynaLink & , INT )
00178 { }
00179
00180 virtual PluginListType GetPluginList()
const
00181
{
return pluginList; }
00182
00183 virtual void OnShutdown()
00184 { }
00185
00186
protected:
00187 PluginListType pluginList;
00188
PDECLARE_NOTIFIER(
PDynaLink,
PPluginModuleManager, OnLoadModule);
00189
00190
protected:
00191 const char *
signatureFunctionName;
00192 PPluginManager *
pluginMgr;
00193 };
00194
00195
#endif // ifndef _PLUGINMGR_H