11//
22// ClassLoader.h
33//
4- // $Id: //poco/Main/Foundation/include/Poco/ClassLoader.h#2 $
4+ // $Id: //poco/Main/Foundation/include/Poco/ClassLoader.h#3 $
55//
66// Library: Foundation
77// Package: SharedLibrary
@@ -62,6 +62,15 @@ class ClassLoader
6262 // / The Manifest for a shared library can be easily built
6363 // / with the help of the macros in the header file
6464 // / "Foundation/ClassLibrary.h".
65+ // /
66+ // / Starting with POCO release 1.3, a class library can
67+ // / export multiple manifests. In addition to the default
68+ // / (unnamed) manifest, multiple named manifests can
69+ // / be exported, each having a different base class.
70+ // /
71+ // / There is one important restriction: one instance of
72+ // / ClassLoader can only load one manifest from a class
73+ // / library.
6574{
6675public:
6776 typedef AbstractMetaObject<Base> Meta;
@@ -152,9 +161,9 @@ class ClassLoader
152161 }
153162 }
154163
155- void loadLibrary (const std::string& path)
156- // / Loads a library from the given path. Does nothing
157- // / if the library is already loaded.
164+ void loadLibrary (const std::string& path, const std::string& manifest )
165+ // / Loads a library from the given path, using the given manifest.
166+ // / Does nothing if the library is already loaded.
158167 // / Throws a LibraryLoadException if the library
159168 // / cannot be loaded or does not have a Manifest.
160169 // / If the library exports a function named "pocoInitializeLibrary",
@@ -174,20 +183,22 @@ class ClassLoader
174183 li.refCount = 1 ;
175184 try
176185 {
186+ std::string pocoBuildManifestSymbol (" pocoBuildManifest" );
187+ pocoBuildManifestSymbol.append (manifest);
177188 if (li.pLibrary ->hasSymbol (" pocoInitializeLibrary" ))
178189 {
179190 InitializeLibraryFunc initializeLibrary = (InitializeLibraryFunc) li.pLibrary ->getSymbol (" pocoInitializeLibrary" );
180191 initializeLibrary ();
181192 }
182- if (li.pLibrary ->hasSymbol (" pocoBuildManifest " ))
193+ if (li.pLibrary ->hasSymbol (pocoBuildManifestSymbol ))
183194 {
184- BuildManifestFunc buildManifest = (BuildManifestFunc) li.pLibrary ->getSymbol (" pocoBuildManifest " );
195+ BuildManifestFunc buildManifest = (BuildManifestFunc) li.pLibrary ->getSymbol (pocoBuildManifestSymbol );
185196 if (buildManifest (const_cast <Manif*>(li.pManifest )))
186197 _map[path] = li;
187198 else
188- throw LibraryLoadException (std::string (" Manifest class mismatch in " ) + path);
199+ throw LibraryLoadException (std::string (" Manifest class mismatch in " ) + path, manifest );
189200 }
190- else throw LibraryLoadException (std::string (" No manifest in " ) + path);
201+ else throw LibraryLoadException (std::string (" No manifest in " ) + path, manifest );
191202 }
192203 catch (...)
193204 {
@@ -202,6 +213,22 @@ class ClassLoader
202213 }
203214 }
204215
216+ void loadLibrary (const std::string& path)
217+ // / Loads a library from the given path. Does nothing
218+ // / if the library is already loaded.
219+ // / Throws a LibraryLoadException if the library
220+ // / cannot be loaded or does not have a Manifest.
221+ // / If the library exports a function named "pocoInitializeLibrary",
222+ // / this function is executed.
223+ // / If called multiple times for the same library,
224+ // / the number of calls to unloadLibrary() must be the same
225+ // / for the library to become unloaded.
226+ // /
227+ // / Equivalent to loadLibrary(path, "").
228+ {
229+ loadLibrary (path, " " );
230+ }
231+
205232 void unloadLibrary (const std::string& path)
206233 // / Unloads the given library.
207234 // / Be extremely cautious when unloading shared libraries.
0 commit comments