Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

pluginmgr.h

Go to the documentation of this file.
00001 /* 00002 * pluginmgr.h 00003 * 00004 * Plugin Manager Class Declarations 00005 * 00006 * Portable Windows Library 00007 * 00008 * Contributor(s): Snark at GnomeMeeting 00009 * 00010 * $Log: pluginmgr.h,v $ 00011 * Revision 1.15 2004/06/24 23:10:27 csoutheren 00012 * Require plugins to have _pwplugin suffix 00013 * 00014 * Revision 1.14 2004/06/01 05:44:57 csoutheren 00015 * Added OnShutdown to allow cleanup on exit 00016 * 00017 * Revision 1.13 2004/05/19 06:54:11 csoutheren 00018 * Removed unused code 00019 * 00020 * Revision 1.12 2004/05/18 06:01:06 csoutheren 00021 * Deferred plugin loading until after main has executed by using abstract factory classes 00022 * 00023 * Revision 1.11 2004/05/17 06:05:20 csoutheren 00024 * Changed "make docs" to use doxygen 00025 * Added new config file and main page 00026 * 00027 * Revision 1.10 2004/04/22 11:43:47 csoutheren 00028 * Factored out functions useful for loading dynamic libraries 00029 * 00030 * Revision 1.9 2004/04/22 07:55:30 csoutheren 00031 * Fix problem with generic plugin manager having pure virtual. Thanks to Ben Lear 00032 * 00033 * Revision 1.8 2004/04/14 11:14:10 csoutheren 00034 * Final fix for generic plugin manager 00035 * 00036 * Revision 1.7 2004/04/14 10:57:38 csoutheren 00037 * Removed multiple definition of statc function in generic plugin functions 00038 * 00039 * Revision 1.6 2004/04/14 10:01:54 csoutheren 00040 * Fixed compile problem on Windows 00041 * 00042 * Revision 1.5 2004/04/14 08:12:02 csoutheren 00043 * Added support for generic plugin managers 00044 * 00045 * Revision 1.4 2004/03/23 04:43:42 csoutheren 00046 * Modified plugin manager to allow code modules to be notified when plugins 00047 * are loaded or unloaded 00048 * 00049 * Revision 1.3 2003/11/12 10:24:35 csoutheren 00050 * Changes to allow operation of static plugins under Windows 00051 * 00052 * Revision 1.2 2003/11/12 03:26:17 csoutheren 00053 * Initial version of plugin code from Snark of GnomeMeeting with changes 00054 * by Craig Southeren os Post Increment 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 // Manager for plugins 00095 // 00096 00097 class PPluginManager : public PObject 00098 { 00099 PCLASSINFO(PPluginManager, PObject); 00100 00101 public: 00102 // functions to load/unload a dynamic plugin 00103 BOOL LoadPlugin (const PString & fileName); 00104 void LoadPluginDirectory (const PDirectory & dir); 00105 00106 // functions to access the plugins' services 00107 PStringList GetPluginTypes() const; 00108 PStringList GetPluginsProviding (const PString & serviceType) const; 00109 PPluginServiceDescriptor * GetServiceDescriptor (const PString & serviceName, const PString & serviceType); 00110 00111 // function to register a service (used by the plugins themselves) 00112 BOOL RegisterService (const PString & serviceName, const PString & serviceType, PPluginServiceDescriptor * descriptor); 00113 00114 // Get the list of plugin directories 00115 static PStringArray GetPluginDirs(); 00116 00117 // static functions for accessing global instances of plugin managers 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 // Manager for plugin modules 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 & /*dll*/, INT /*code*/) 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

Generated on Sat Jul 24 15:35:56 2004 for PWLib by doxygen 1.3.7