source: trunk/contrib/cppunit-1.12.2/include/cppunit/plugin/DynamicLibraryManager.h @ 876

Last change on this file since 876 was 876, checked in by sam, 9 years ago

contrib: add a precompiled Win32 version of CppUnit and update build system
accordingly.

File size: 4.0 KB
Line 
1#ifndef CPPUNIT_PLUGIN_DYNAMICLIBRARYMANAGER_H
2#define CPPUNIT_PLUGIN_DYNAMICLIBRARYMANAGER_H
3
4#include <cppunit/Portability.h>
5#include <string>
6
7#if !defined(CPPUNIT_NO_TESTPLUGIN)
8
9CPPUNIT_NS_BEGIN
10
11
12/*! \brief Manages dynamic libraries.
13 *
14 * The Dynamic Library Manager provides a platform independent way to work with
15 * dynamic library. It load a specific dynamic library, and can returns specific
16 * symbol exported by the dynamic library.
17 *
18 * If an error occurs, a DynamicLibraryManagerException is thrown.
19 *
20 * \internal Implementation of the OS independent methods is in
21 * DynamicLibraryManager.cpp.
22 *
23 * \internal Porting to a new platform:
24 * - Adds platform detection in config/SelectDllLoader.h. Should define a specific
25 *   macro for that platform of the form: CPPUNIT_HAVE_XYZ_DLL_LOADER, where
26 *   XYZ is the platform.
27 * - Makes a copy of UnixDynamicLibraryManager.cpp and named it after the platform.
28 * - Updated the 'guard' in your file (CPPUNIT_HAVE_XYZ_DLL_LOADER) so that it is
29 *   only processed if the matching platform has been detected.
30 * - Change the implementation of methods doLoadLibrary(), doReleaseLibrary(),
31 *   doFindSymbol() in your copy. Those methods usually maps directly to OS calls.
32 * - Adds the file to the project.
33 */
34class DynamicLibraryManager
35{
36public:
37  typedef void *Symbol;
38  typedef void *LibraryHandle;
39
40  /*! \brief Loads the specified library.
41   * \param libraryFileName Name of the library to load.
42   * \exception DynamicLibraryManagerException if a failure occurs while loading
43   *            the library (fail to found or load the library).
44   */
45  DynamicLibraryManager( const std::string &libraryFileName );
46
47  /// Releases the loaded library..
48  ~DynamicLibraryManager();
49
50  /*! \brief Returns a pointer on the specified symbol exported by the library.
51   * \param symbol Name of the symbol exported by the library.
52   * \return Pointer on the symbol. Should be casted to the actual type. Never \c NULL.
53   * \exception DynamicLibraryManagerException if the symbol is not found.
54   */
55  Symbol findSymbol( const std::string &symbol );
56
57private:
58  /*! Loads the specified library.
59   * \param libraryName Name of the library to load.
60   * \exception DynamicLibraryManagerException if a failure occurs while loading
61   *            the library (fail to found or load the library).
62   */
63  void loadLibrary( const std::string &libraryName );
64
65  /*! Releases the loaded library.
66   *
67   * \warning Must NOT throw any exceptions (called from destructor).
68   */
69  void releaseLibrary();
70
71  /*! Loads the specified library.
72   *
73   * May throw any exceptions (indicates failure).
74   * \param libraryName Name of the library to load.
75   * \return Handle of the loaded library. \c NULL indicates failure.
76   */
77  LibraryHandle doLoadLibrary( const std::string &libraryName );
78
79  /*! Releases the loaded library.
80   *
81   * The handle of the library to free is in \c m_libraryHandle. It is never
82   * \c NULL.
83   * \warning Must NOT throw any exceptions (called from destructor).
84   */
85  void doReleaseLibrary();
86
87  /*! Returns a pointer on the specified symbol exported by the library.
88   *
89   * May throw any exceptions (indicates failure).
90   * \param symbol Name of the symbol exported by the library.
91   * \return Pointer on the symbol. \c NULL indicates failure.
92   */
93  Symbol doFindSymbol( const std::string &symbol );
94
95  /*! Returns detailed information about doLoadLibrary() failure.
96   *
97   * Called just after a failed call to doLoadLibrary() to get extra
98   * error information.
99   *
100   * \return Detailed information about the failure of the call to
101   *         doLoadLibrary() that just failed.
102   */
103  std::string getLastErrorDetail() const;
104
105  /// Prevents the use of the copy constructor.
106  DynamicLibraryManager( const DynamicLibraryManager &copy );
107
108  /// Prevents the use of the copy operator.
109  void operator =( const DynamicLibraryManager &copy );
110
111private:
112  LibraryHandle m_libraryHandle;
113  std::string m_libraryName;
114};
115
116
117CPPUNIT_NS_END
118
119#endif // !defined(CPPUNIT_NO_TESTPLUGIN)
120
121#endif  // CPPUNIT_PLUGIN_DYNAMICLIBRARYMANAGER_H
Note: See TracBrowser for help on using the repository browser.