Blame include/cppunit/plugin/DynamicLibraryManager.h

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