Blame include/cppunit/plugin/DynamicLibraryManager.h

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