4 * Plugin Manager Class Declarations
6 * Portable Windows Library
8 * Contributor(s): Snark at GnomeMeeting
11 * Revision 1.13 2004/05/19 06:54:11 csoutheren
14 * Revision 1.12 2004/05/18 06:01:06 csoutheren
15 * Deferred plugin loading until after main has executed by using abstract factory classes
17 * Revision 1.11 2004/05/17 06:05:20 csoutheren
18 * Changed "make docs" to use doxygen
19 * Added new config file and main page
21 * Revision 1.10 2004/04/22 11:43:47 csoutheren
22 * Factored out functions useful for loading dynamic libraries
24 * Revision 1.9 2004/04/22 07:55:30 csoutheren
25 * Fix problem with generic plugin manager having pure virtual. Thanks to Ben Lear
27 * Revision 1.8 2004/04/14 11:14:10 csoutheren
28 * Final fix for generic plugin manager
30 * Revision 1.7 2004/04/14 10:57:38 csoutheren
31 * Removed multiple definition of statc function in generic plugin functions
33 * Revision 1.6 2004/04/14 10:01:54 csoutheren
34 * Fixed compile problem on Windows
36 * Revision 1.5 2004/04/14 08:12:02 csoutheren
37 * Added support for generic plugin managers
39 * Revision 1.4 2004/03/23 04:43:42 csoutheren
40 * Modified plugin manager to allow code modules to be notified when plugins
41 * are loaded or unloaded
43 * Revision 1.3 2003/11/12 10:24:35 csoutheren
44 * Changes to allow operation of static plugins under Windows
46 * Revision 1.2 2003/11/12 03:26:17 csoutheren
47 * Initial version of plugin code from Snark of GnomeMeeting with changes
48 * by Craig Southeren os Post Increment
56 #define DEFAULT_PLUGINDIR "/usr/lib/pwlib"
58 #include <ptlib/plugin.h>
61 void PLoadPluginDirectory(C
& obj
, const PDirectory
& directory
)
63 PDirectory dir
= directory
;
65 PTRACE(4, "Cannot open plugin directory " << dir
);
68 PTRACE(4, "Enumerating plugin directory " << dir
);
70 PString entry
= dir
+ dir
.GetEntryName();
72 PLoadPluginDirectory
<C
>(obj
, entry
);
73 else if (PFilePath(entry
).GetType() *= PDynaLink::GetExtension())
74 obj
.LoadPlugin(entry
);
78 //////////////////////////////////////////////////////
80 // Manager for plugins
83 class PPluginManager
: public PObject
85 PCLASSINFO(PPluginManager
, PObject
);
91 // functions to load/unload a dynamic plugin
92 BOOL
LoadPlugin (const PString
& fileName
);
93 void LoadPluginDirectory (const PDirectory
& dir
)
94 { PLoadPluginDirectory
<PPluginManager
>(*this, dir
); }
96 // functions to access the plugins' services
97 PStringList
GetPluginTypes() const;
98 PStringList
GetPluginsProviding (const PString
& serviceType
) const;
99 PPluginServiceDescriptor
* GetServiceDescriptor (const PString
& serviceName
, const PString
& serviceType
);
101 // function to register a service (used by the plugins themselves)
102 BOOL
RegisterService (const PString
& serviceName
, const PString
& serviceType
, PPluginServiceDescriptor
* descriptor
);
104 // Get the list of plugin directories
105 static PStringArray
GetPluginDirs();
107 // static functions for accessing global instances of plugin managers
108 static PPluginManager
& GetPluginManager();
110 /**Add a notifier to the plugin manager.
111 The call back function is executed just after loading, or
112 just after unloading, a plugin.
115 PDECLARE_NOTIFIER(PDynaLink, YourClass, YourFunction);
117 void YourClass::YourFunction(PDynaLink & dll, INT code)
119 // code == 0 means loading
120 // code == 1 means unloading
122 and to connect to the plugin manager:
123 PPluginManager & mgr = PPluginManager::GetPluginManager();
124 mgr->AddNotifier((PCREATE_NOTIFIER(YourFunction));
128 const PNotifier
& filterFunction
,
129 BOOL existing
= FALSE
133 const PNotifier
& filterFunction
137 void CallNotifier(PDynaLink
& dll
, INT code
);
139 PMutex pluginListMutex
;
140 PList
<PDynaLink
> pluginList
;
142 PMutex serviceListMutex
;
143 PList
<PPluginService
> serviceList
;
145 PMutex notifierMutex
;
146 PList
<PNotifier
> notifierList
;
149 //////////////////////////////////////////////////////
151 // Manager for plugin modules
154 class PPluginModuleManager
: public PObject
157 typedef PDictionary
<PString
, PDynaLink
> PluginListType
;
159 PPluginModuleManager(const char * _signatureFunctionName
, PPluginManager
* pluginMgr
= NULL
);
161 BOOL
LoadPlugin(const PString
& fileName
)
162 { if (pluginMgr
== NULL
) return FALSE
; else return pluginMgr
->LoadPlugin(fileName
); }
164 void LoadPluginDirectory(const PDirectory
&directory
)
165 { if (pluginMgr
!= NULL
) pluginMgr
->LoadPluginDirectory(directory
); }
167 virtual void OnLoadPlugin(PDynaLink
& /*dll*/, INT
/*code*/)
170 virtual PluginListType
GetPluginList() const
171 { return pluginList
; }
174 PluginListType pluginList
;
175 PDECLARE_NOTIFIER(PDynaLink
, PPluginModuleManager
, OnLoadModule
);
178 const char * signatureFunctionName
;
179 PPluginManager
* pluginMgr
;
182 #endif // ifndef _PLUGINMGR_H