All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pluginmgr.h
Go to the documentation of this file.
/*
* pluginmgr.h
*
* Plugin Manager Class Declarations
*
* Portable Windows Library
*
* Contributor(s): Snark at GnomeMeeting
*
* $Revision: 26636 $
* $Author: rjongbloed $
* $Date: 2011-11-03 18:57:12 -0500 (Thu, 03 Nov 2011) $
*/
#ifndef PTLIB_PLUGINMGR_H
#define PTLIB_PLUGINMGR_H
#include <ptlib/plugin.h>
class PPluginSuffix {
private:
int dummy;
};
template <class C>
void PLoadPluginDirectory(C & obj, const PDirectory & directory, const char * suffix = NULL)
{
PDirectory dir = directory;
if (!dir.Open()) {
PTRACE(4, "Cannot open plugin directory " << dir);
return;
}
PTRACE(4, "Enumerating plugin directory " << dir);
do {
PString entry = dir + dir.GetEntryName();
PDirectory subdir = entry;
if (subdir.Open())
PLoadPluginDirectory<C>(obj, entry, suffix);
else {
PFilePath fn(entry);
if (
(fn.GetType() *= PDynaLink::GetExtension()) &&
(
(suffix == NULL) || (fn.GetTitle().Right(strlen(suffix)) *= suffix)
)
)
obj.LoadPlugin(entry);
}
} while (dir.Next());
}
//
// Manager for plugins
//
class PPluginManager : public PObject
{
PCLASSINFO(PPluginManager, PObject);
public:
// functions to load/unload a dynamic plugin
PBoolean LoadPlugin (const PString & fileName);
void LoadPluginDirectory (const PDirectory & dir);
void OnShutdown();
// functions to access the plugins' services
PStringArray GetPluginTypes() const;
PStringArray GetPluginsProviding(const PString & serviceType) const;
PPluginServiceDescriptor * GetServiceDescriptor(const PString & serviceName, const PString & serviceType) const;
PObject * CreatePluginsDevice(const PString & serviceName, const PString & serviceType, int userData = 0) const;
PObject * CreatePluginsDeviceByName(const PString & deviceName, const PString & serviceType, int userData = 0, const PString & serviceName = PString::Empty()) const;
PStringArray GetPluginsDeviceNames(const PString & serviceName, const PString & serviceType, int userData = 0) const;
PBoolean GetPluginsDeviceCapabilities(const PString & serviceType,const PString & serviceName,const PString & deviceName,void * capabilities) const;
// function to register a service (used by the plugins themselves)
PBoolean RegisterService (const PString & serviceName, const PString & serviceType, PPluginServiceDescriptor * descriptor);
// Add a directory to the list of plugin directories (used by OPAL)
static bool AddPluginDirs(const PString & dirs);
// Get the list of plugin directories
static PStringArray GetPluginDirs();
// static functions for accessing global instances of plugin managers
static PPluginManager & GetPluginManager();
enum NotificationCode {
LoadingPlugIn,
UnloadingPlugIn
};
void AddNotifier(
const PNotifier & filterFunction,
PBoolean existing = false
);
void RemoveNotifier(
const PNotifier & filterFunction
);
protected:
void LoadPluginDirectory (const PDirectory & directory, const PStringList & suffixes);
void CallNotifier(PDynaLink & dll, NotificationCode code);
PMutex m_pluginsMutex;
PArray<PDynaLink> m_plugins;
PMutex m_servicesMutex;
PArray<PPluginService> m_services;
PMutex m_notifiersMutex;
PList<PNotifier> m_notifiers;
};
//
// Manager for plugin modules
//
class PPluginModuleManager : public PObject
{
public:
typedef PDictionary<PString, PDynaLink> PluginListType;
PPluginModuleManager(const char * signatureFunctionName, PPluginManager * pluginMgr = NULL);
PBoolean LoadPlugin(const PString & fileName)
{ if (pluginMgr == NULL) return false; else return pluginMgr->LoadPlugin(fileName); }
void LoadPluginDirectory(const PDirectory &directory)
{ if (pluginMgr != NULL) pluginMgr->LoadPluginDirectory(directory); }
virtual void OnLoadPlugin(PDynaLink & /*dll*/, INT /*code*/)
{ }
virtual PluginListType GetPluginList() const
{ return pluginDLLs; }
virtual void OnStartup()
{ }
virtual void OnShutdown()
{ }
protected:
PluginListType pluginDLLs;
PDECLARE_NOTIFIER(PDynaLink, PPluginModuleManager, OnLoadModule);
protected:
const char * signatureFunctionName;
PPluginManager * pluginMgr;
};
#define PLUGIN_LOADER_STARTUP_NAME "PluginLoaderStartup"
PFACTORY_LOAD(PluginLoaderStartup);
#endif // PTLIB_PLUGINMGR_H
// End Of File ///////////////////////////////////////////////////////////////
PLoadPluginDirectory
void PLoadPluginDirectory(C &obj, const PDirectory &directory, const char *suffix=NULL)
Definition: pluginmgr.h:26
PPluginManager::GetServiceDescriptor
PPluginServiceDescriptor * GetServiceDescriptor(const PString &serviceName, const PString &serviceType) const
PDirectory::Next
PBoolean Next()
Move to the next file in the directory scan.
PNotifier
Class specialisation for PNotifierTemplate<INT>
PDynaLink::GetExtension
static PString GetExtension()
Get the extension used by this platform for dynamic link libraries.
PPluginManager
Definition: pluginmgr.h:57
PPluginManager::OnShutdown
void OnShutdown()
PDictionary< PString, PDynaLink >
PPluginManager::GetPluginManager
static PPluginManager & GetPluginManager()
PPluginManager::CreatePluginsDevice
PObject * CreatePluginsDevice(const PString &serviceName, const PString &serviceType, int userData=0) const
plugin.h
PPluginModuleManager
Definition: pluginmgr.h:139
PFilePath::GetTitle
PFilePathString GetTitle() const
Get the title component of the full file specification, eg for the DOS file "C:\SRC\PWLIB\FRED.DAT" this would be "FRED".
PDirectory::GetEntryName
virtual PFilePathString GetEntryName() const
Get the name (without the volume or directory path) of the current entry in the directory scan...
PFilePath
This class describes a full description for a file on the particular platform.
Definition: filepath.h:65
PPluginManager::LoadingPlugIn
Definition: pluginmgr.h:90
PPluginManager::LoadPlugin
PBoolean LoadPlugin(const PString &fileName)
PPluginManager::m_notifiersMutex
PMutex m_notifiersMutex
Definition: pluginmgr.h:130
PPluginManager::m_pluginsMutex
PMutex m_pluginsMutex
Definition: pluginmgr.h:124
PPluginManager::CreatePluginsDeviceByName
PObject * CreatePluginsDeviceByName(const PString &deviceName, const PString &serviceType, int userData=0, const PString &serviceName=PString::Empty()) const
PStringArray
This is an array collection class of PString objects.
Definition: pstring.h:2024
PString::Right
PString Right(PINDEX len) const
Extract a portion of the string into a new string.
PTRACE
#define PTRACE(level, args)
Output trace.
Definition: object.h:530
PPluginManager::AddPluginDirs
static bool AddPluginDirs(const PString &dirs)
PPluginModuleManager::PluginListType
PDictionary< PString, PDynaLink > PluginListType
Definition: pluginmgr.h:142
PList< PNotifier >
PDirectory::Open
virtual PBoolean Open(int scanMask=PFileInfo::AllFiles)
Open the directory for scanning its list of files.
PPluginModuleManager::GetPluginList
virtual PluginListType GetPluginList() const
Definition: pluginmgr.h:155
PBoolean
BOOL PBoolean
Definition: object.h:102
PDirectory
Class to represent a directory in the operating system file system.
Definition: pdirect.h:182
PPluginManager::LoadPluginDirectory
void LoadPluginDirectory(const PDirectory &dir)
PPluginModuleManager::PPluginModuleManager
PPluginModuleManager(const char *signatureFunctionName, PPluginManager *pluginMgr=NULL)
PPluginModuleManager::OnShutdown
virtual void OnShutdown()
Definition: pluginmgr.h:160
PPluginModuleManager::pluginMgr
PPluginManager * pluginMgr
Definition: pluginmgr.h:169
PPluginManager::GetPluginsDeviceCapabilities
PBoolean GetPluginsDeviceCapabilities(const PString &serviceType, const PString &serviceName, const PString &deviceName, void *capabilities) const
PPluginModuleManager::signatureFunctionName
const char * signatureFunctionName
Definition: pluginmgr.h:168
PPluginManager::GetPluginsProviding
PStringArray GetPluginsProviding(const PString &serviceType) const
PPluginManager::GetPluginTypes
PStringArray GetPluginTypes() const
PString
The character string class.
Definition: pstring.h:108
PPluginManager::m_services
PArray< PPluginService > m_services
Definition: pluginmgr.h:128
PPluginModuleManager::LoadPluginDirectory
void LoadPluginDirectory(const PDirectory &directory)
Definition: pluginmgr.h:149
PPluginModuleManager::pluginDLLs
PluginListType pluginDLLs
Definition: pluginmgr.h:164
PPluginManager::UnloadingPlugIn
Definition: pluginmgr.h:91
PDynaLink
A dynamic link library.
Definition: dynalink.h:51
PPluginManager::RemoveNotifier
void RemoveNotifier(const PNotifier &filterFunction)
PString::Empty
static PString Empty()
Return an empty string.
PPluginModuleManager::OnStartup
virtual void OnStartup()
Definition: pluginmgr.h:158
PPluginManager::CallNotifier
void CallNotifier(PDynaLink &dll, NotificationCode code)
PPluginSuffix
Definition: pluginmgr.h:20
PStringList
This is a list collection class of PString objects.
Definition: pstring.h:2184
PFACTORY_LOAD
PFACTORY_LOAD(PluginLoaderStartup)
PFilePath::GetType
PFilePathString GetType() const
Get the file type of the file.
PPluginModuleManager::PDECLARE_NOTIFIER
PDECLARE_NOTIFIER(PDynaLink, PPluginModuleManager, OnLoadModule)
PPluginManager::m_servicesMutex
PMutex m_servicesMutex
Definition: pluginmgr.h:127
PPluginManager::NotificationCode
NotificationCode
Definition: pluginmgr.h:89
PPluginManager::m_plugins
PArray< PDynaLink > m_plugins
Definition: pluginmgr.h:125
PPluginServiceDescriptor
Definition: plugin.h:96
PPluginManager::GetPluginDirs
static PStringArray GetPluginDirs()
PPluginModuleManager::LoadPlugin
PBoolean LoadPlugin(const PString &fileName)
Definition: pluginmgr.h:146
PArray< PDynaLink >
PMutex
Synonym for PTimedMutex.
PPluginManager::m_notifiers
PList< PNotifier > m_notifiers
Definition: pluginmgr.h:131
PPluginManager::AddNotifier
void AddNotifier(const PNotifier &filterFunction, PBoolean existing=false)
Add a notifier to the plugin manager.
PPluginModuleManager::OnLoadPlugin
virtual void OnLoadPlugin(PDynaLink &, INT)
Definition: pluginmgr.h:152
PObject
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PPluginManager::RegisterService
PBoolean RegisterService(const PString &serviceName, const PString &serviceType, PPluginServiceDescriptor *descriptor)
PPluginManager::GetPluginsDeviceNames
PStringArray GetPluginsDeviceNames(const PString &serviceName, const PString &serviceType, int userData=0) const