/usr/include/ptlib/pluginmgr.h is in libpt-dev 2.10.11~dfsg-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | /*
* 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
};
/**Add a notifier to the plugin manager.
The call back function is executed just after loading, or
just after unloading, a plugin.
To use define:
PDECLARE_NOTIFIER(PDynaLink, YourClass, YourFunction);
and
void YourClass::YourFunction(PDynaLink & dll, INT code)
{
// code == 0 means loading
// code == 1 means unloading
}
and to connect to the plugin manager:
PPluginManager & mgr = PPluginManager::GetPluginManager();
mgr->AddNotifier((PCREATE_NOTIFIER(YourFunction));
*/
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 ///////////////////////////////////////////////////////////////
|