Version: 9.16.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() [1/2]

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

Definition at line 33 of file DynLibLoaderGNU.cxx.

33 :_libName(libNameWithoutExtension),
35{
36}

◆ ~DynLibLoaderGNU()

DynLibLoaderGNU::~DynLibLoaderGNU ( )

Definition at line 38 of file DynLibLoaderGNU.cxx.

39{
41 dlclose(_handleOnLoadedLib);
42}

References _handleOnLoadedLib.

◆ DynLibLoaderGNU() [2/2]

YACS::BASES::DynLibLoaderGNU::DynLibLoaderGNU ( const DynLibLoaderGNU orig)
inlineprivate

Definition at line 54 of file DynLibLoaderGNU.hxx.

54{}

Member Function Documentation

◆ appendDirInSearchPath()

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}

◆ getExtensionForDynLib()

const char * DynLibLoaderGNU::getExtensionForDynLib ( )
static

Definition at line 137 of file DynLibLoaderGNU.cxx.

138{
139 return _extForDynLib+1;
140}
static const char _extForDynLib[]

References _extForDynLib.

◆ getHandleOnSymbolWithName()

void * DynLibLoaderGNU::getHandleOnSymbolWithName ( const std::string &  symbName,
bool  stopOnError = true 
)

Definition at line 76 of file DynLibLoaderGNU.cxx.

77{
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}
void * resolveSymb(const std::string &symbName, bool stopOnError)
load lib without regarding that _libName is reachable

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

◆ getLibNameWithoutExt()

std::string DynLibLoaderGNU::getLibNameWithoutExt ( ) const

Definition at line 49 of file DynLibLoaderGNU.cxx.

50{
51 return _libName;
52}

References _libName.

◆ isLibFileFindable()

bool DynLibLoaderGNU::isLibFileFindable ( ) const

Definition at line 44 of file DynLibLoaderGNU.cxx.

45{
46 return true;
47}

Referenced by getHandleOnSymbolWithName().

◆ load()

bool DynLibLoaderGNU::load ( )

Definition at line 90 of file DynLibLoaderGNU.cxx.

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}

References _extForDynLib, _handleOnLoadedLib, and _libName.

Referenced by loadLib(), and reload().

◆ loadLib()

void YACS::BASES::DynLibLoaderGNU::loadLib ( )
inlineprivate

Definition at line 49 of file DynLibLoaderGNU.hxx.

References load().

Referenced by getHandleOnSymbolWithName().

◆ operator=()

DynLibLoaderGNU & YACS::BASES::DynLibLoaderGNU::operator= ( const DynLibLoaderGNU orig)
inlineprivate

Definition at line 55 of file DynLibLoaderGNU.hxx.

55{ return *this; }

◆ reload()

bool DynLibLoaderGNU::reload ( )

Definition at line 116 of file DynLibLoaderGNU.cxx.

117{
118 unload();
119 return load();
120}

References load(), and unload().

◆ removeDirInSearchPath()

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}

◆ resolveSymb()

void * DynLibLoaderGNU::resolveSymb ( const std::string &  symbName,
bool  stopOnError 
)
private

load lib without regarding that _libName is reachable

Definition at line 122 of file DynLibLoaderGNU.cxx.

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

References _extForDynLib, _handleOnLoadedLib, and _libName.

Referenced by getHandleOnSymbolWithName().

◆ unload()

bool DynLibLoaderGNU::unload ( )

Definition at line 106 of file DynLibLoaderGNU.cxx.

107{
109 {
110 dlclose(_handleOnLoadedLib);
111 _handleOnLoadedLib = NULL;
112 }
113 return false;
114}

References _handleOnLoadedLib.

Referenced by reload().

Member Data Documentation

◆ _extForDynLib

const char DynLibLoaderGNU::_extForDynLib =".so"
staticprivate

◆ _handleOnLoadedLib

void* YACS::BASES::DynLibLoaderGNU::_handleOnLoadedLib
private

◆ _libName

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: