blob: d70ccde46291a0726709fe42430fb31e2b29504b (
plain)
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
|
#ifndef CPPUNIT_PLUGIN_DYNAMICLIBRARYMANAGER_H
#define CPPUNIT_PLUGIN_DYNAMICLIBRARYMANAGER_H
#include <cppunit/Portability.h>
#include <string>
#if !defined(CPPUNIT_NO_TESTPLUGIN)
CPPUNIT_NS_BEGIN
/*! \brief Manages dynamic libraries.
*
* The Dynamic Library Manager provides a platform independent way to work with
* dynamic library. It load a specific dynamic library, and can returns specific
* symbol exported by the dynamic library.
*
* If an error occurs, a DynamicLibraryManagerException is thrown.
*
* \internal Implementation of the OS independent methods is in
* DynamicLibraryManager.cpp.
*
* \internal Porting to a new platform:
* - Adds platform detection in config/SelectDllLoader.h. Should define a specific
* macro for that platform of the form: CPPUNIT_HAVE_XYZ_DLL_LOADER, where
* XYZ is the platform.
* - Makes a copy of UnixDynamicLibraryManager.cpp and named it after the platform.
* - Updated the 'guard' in your file (CPPUNIT_HAVE_XYZ_DLL_LOADER) so that it is
* only processed if the matching platform has been detected.
* - Change the implementation of methods doLoadLibrary(), doReleaseLibrary(),
* doFindSymbol() in your copy. Those methods usually maps directly to OS calls.
* - Adds the file to the project.
*/
class DynamicLibraryManager
{
public:
typedef void *Symbol;
typedef void *LibraryHandle;
/*! \brief Loads the specified library.
* \param libraryFileName Name of the library to load.
* \exception DynamicLibraryManagerException if a failure occurs while loading
* the library (fail to found or load the library).
*/
DynamicLibraryManager( const std::string &libraryFileName );
/// Releases the loaded library..
~DynamicLibraryManager();
/*! \brief Returns a pointer on the specified symbol exported by the library.
* \param symbol Name of the symbol exported by the library.
* \return Pointer on the symbol. Should be casted to the actual type. Never \c NULL.
* \exception DynamicLibraryManagerException if the symbol is not found.
*/
Symbol findSymbol( const std::string &symbol );
private:
/*! Loads the specified library.
* \param libraryName Name of the library to load.
* \exception DynamicLibraryManagerException if a failure occurs while loading
* the library (fail to found or load the library).
*/
void loadLibrary( const std::string &libraryName );
/*! Releases the loaded library.
*
* \warning Must NOT throw any exceptions (called from destructor).
*/
void releaseLibrary();
/*! Loads the specified library.
*
* May throw any exceptions (indicates failure).
* \param libraryName Name of the library to load.
* \return Handle of the loaded library. \c NULL indicates failure.
*/
LibraryHandle doLoadLibrary( const std::string &libraryName );
/*! Releases the loaded library.
*
* The handle of the library to free is in \c m_libraryHandle. It is never
* \c NULL.
* \warning Must NOT throw any exceptions (called from destructor).
*/
void doReleaseLibrary();
/*! Returns a pointer on the specified symbol exported by the library.
*
* May throw any exceptions (indicates failure).
* \param symbol Name of the symbol exported by the library.
* \return Pointer on the symbol. \c NULL indicates failure.
*/
Symbol doFindSymbol( const std::string &symbol );
/*! Returns detailed information about doLoadLibrary() failure.
*
* Called just after a failed call to doLoadLibrary() to get extra
* error information.
*
* \return Detailed information about the failure of the call to
* doLoadLibrary() that just failed.
*/
std::string getLastErrorDetail() const;
/// Prevents the use of the copy constructor.
DynamicLibraryManager( const DynamicLibraryManager © );
/// Prevents the use of the copy operator.
void operator =( const DynamicLibraryManager © );
private:
LibraryHandle m_libraryHandle;
std::string m_libraryName;
};
CPPUNIT_NS_END
#endif // !defined(CPPUNIT_NO_TESTPLUGIN)
#endif // CPPUNIT_PLUGIN_DYNAMICLIBRARYMANAGER_H
|