Version: 8.3.0
YACS::BASES::DynLibLoaderGNU Class Reference

#include <DynLibLoaderGNU.hxx>

Collaboration diagram for YACS::BASES::DynLibLoaderGNU:

Public Member Functions

 DynLibLoaderGNU (const std::string &libNameWithoutExtension)
 
 ~DynLibLoaderGNU ()
 
bool isLibFileFindable () const
 
std::string getLibNameWithoutExt () const
 
int appendDirInSearchPath (const std::string &dirName)
 
int removeDirInSearchPath (const std::string &dirName)
 
void * getHandleOnSymbolWithName (const std::string &symbName, bool stopOnError=true)
 
bool load ()
 
bool reload ()
 
bool unload ()
 

Static Public Member Functions

static const char * getExtensionForDynLib ()
 

Private Member Functions

void loadLib ()
 
void * resolveSymb (const std::string &symbName, bool stopOnError)
 load lib without regarding that _libName is reachable More...
 
 DynLibLoaderGNU (const DynLibLoaderGNU &orig)
 
DynLibLoaderGNUoperator= (const DynLibLoaderGNU &orig)
 

Private Attributes

void * _handleOnLoadedLib
 
std::string _libName
 

Static Private Attributes

static const char _extForDynLib [] =".so"
 

Detailed Description

Definition at line 29 of file DynLibLoaderGNU.hxx.

Constructor & Destructor Documentation

DynLibLoaderGNU::DynLibLoaderGNU ( const std::string &  libNameWithoutExtension)

Definition at line 33 of file DynLibLoaderGNU.cxx.

33  :_libName(libNameWithoutExtension),
35 {
36 }
DynLibLoaderGNU::~DynLibLoaderGNU ( )

Definition at line 38 of file DynLibLoaderGNU.cxx.

References _handleOnLoadedLib.

39 {
41  dlclose(_handleOnLoadedLib);
42 }
YACS::BASES::DynLibLoaderGNU::DynLibLoaderGNU ( const DynLibLoaderGNU orig)
inlineprivate

Definition at line 54 of file DynLibLoaderGNU.hxx.

54 {}

Member Function Documentation

int DynLibLoaderGNU::appendDirInSearchPath ( const std::string &  dirName)

Append a directory with name dirName to the searching paths.

Returns
If append succeeds 0 is returned. If the directory does not exists 1 is returned. If the addition of directory causes some troubles due to seach paths name 2 is returned.

Definition at line 60 of file DynLibLoaderGNU.cxx.

61 {
62  return 0;
63 }
const char * DynLibLoaderGNU::getExtensionForDynLib ( )
static

Definition at line 136 of file DynLibLoaderGNU.cxx.

References _extForDynLib.

137 {
138  return _extForDynLib+1;
139 }
void * DynLibLoaderGNU::getHandleOnSymbolWithName ( const std::string &  symbName,
bool  stopOnError = true 
)

Definition at line 76 of file DynLibLoaderGNU.cxx.

References _extForDynLib, _handleOnLoadedLib, isLibFileFindable(), loadLib(), and resolveSymb().

77 {
79  if(!isLibFileFindable())
80  {
81  std::cerr << "Dynamic library with name " << symbName << _extForDynLib;
82  std::cerr << " not existing in paths specified" << std::endl;
83  return 0;
84  }
85  else
86  loadLib();
87  return resolveSymb(symbName, stopOnError);
88 }
std::string DynLibLoaderGNU::getLibNameWithoutExt ( ) const

Definition at line 49 of file DynLibLoaderGNU.cxx.

References _libName.

50 {
51  return _libName;
52 }
bool DynLibLoaderGNU::isLibFileFindable ( ) const

Definition at line 44 of file DynLibLoaderGNU.cxx.

Referenced by getHandleOnSymbolWithName().

45 {
46  return true;
47 }
bool DynLibLoaderGNU::load ( )

Definition at line 90 of file DynLibLoaderGNU.cxx.

References _extForDynLib, _handleOnLoadedLib, and _libName.

Referenced by loadLib(), and reload().

91 {
92  std::string fullLibName(_libName);
93  fullLibName+=_extForDynLib;
94  dlerror();
95  _handleOnLoadedLib=dlopen(fullLibName.c_str(),RTLD_LAZY | RTLD_GLOBAL);
96  char *message=dlerror();
97  if (message != NULL)
98  {
99  std::string error = "Error while trying to load library with name " + fullLibName +
100  " with the following internal message: " + message;
101  throw YACS::Exception(error);
102  }
103  return _handleOnLoadedLib != NULL;
104 }
void YACS::BASES::DynLibLoaderGNU::loadLib ( )
inlineprivate

Definition at line 49 of file DynLibLoaderGNU.hxx.

References load().

Referenced by getHandleOnSymbolWithName().

49 { load(); }
DynLibLoaderGNU& YACS::BASES::DynLibLoaderGNU::operator= ( const DynLibLoaderGNU orig)
inlineprivate

Definition at line 55 of file DynLibLoaderGNU.hxx.

55 { return *this; }
bool DynLibLoaderGNU::reload ( )

Definition at line 115 of file DynLibLoaderGNU.cxx.

References load(), and unload().

116 {
117  unload();
118  return load();
119 }
int DynLibLoaderGNU::removeDirInSearchPath ( const std::string &  dirName)

Removes a directory with name dirName from the searching paths.

Returns
If removal succeeds 0 is returned. If the directory does not exists 1 is returned. If the path were not already in existing paths 2 is returned.

Definition at line 71 of file DynLibLoaderGNU.cxx.

72 {
73  return 0;
74 }
void * DynLibLoaderGNU::resolveSymb ( const std::string &  symbName,
bool  stopOnError 
)
private

load lib without regarding that _libName is reachable

Definition at line 121 of file DynLibLoaderGNU.cxx.

References _extForDynLib, _handleOnLoadedLib, _libName, and PMMLBasicsTestLauncher::ret.

Referenced by getHandleOnSymbolWithName().

122 {
123  dlerror();
124  void *ret=dlsym(_handleOnLoadedLib,symbName.c_str());
125  char *message=dlerror();
126  if(stopOnError && (NULL != message))
127  {
128  std::string error="Error detected on symbol ";
129  error=error+symbName +" search in library with name "+_libName+_extForDynLib+" with the following internal message "+message;
130  throw YACS::Exception(error);
131  }
132  else
133  return ret;
134 }
bool DynLibLoaderGNU::unload ( )

Definition at line 106 of file DynLibLoaderGNU.cxx.

References _handleOnLoadedLib.

Referenced by reload().

107 {
108  if (_handleOnLoadedLib)
109  {
110  dlclose(_handleOnLoadedLib);
111  _handleOnLoadedLib = NULL;
112  }
113 }

Member Data Documentation

const char DynLibLoaderGNU::_extForDynLib =".so"
staticprivate
void* YACS::BASES::DynLibLoaderGNU::_handleOnLoadedLib
private
std::string YACS::BASES::DynLibLoaderGNU::_libName
private

Definition at line 33 of file DynLibLoaderGNU.hxx.

Referenced by getLibNameWithoutExt(), load(), and resolveSymb().


The documentation for this class was generated from the following files: