Leosac  0.8.0
Open Source Access Control
DynamicLibrary Class Reference

Wraps a dynamic library handler and provide methods to interact with it. More...

#include <dynamiclibrary.hpp>

+ Collaboration diagram for DynamicLibrary:

Public Types

enum  RelocationMode : int { RelocationMode::Lazy = RTLD_LAZY, RelocationMode::Now = RTLD_NOW }
 

Public Member Functions

 DynamicLibrary (const std::string &file)
 Construct a dynamic library wrapper for the shared object referenced by name. More...
 
 ~DynamicLibrary ()=default
 
 DynamicLibrary (const DynamicLibrary &other)=delete
 
DynamicLibraryoperator= (const DynamicLibrary &other)=delete
 
void open (RelocationMode mode=RelocationMode::Lazy)
 Attempts to open the shared library file so that we can access its symbols. More...
 
void close ()
 Close the already opened library handler. More...
 
void * getSymbol (const std::string &symbol)
 Lookup a symbol by name and return a pointer to it. More...
 
const std::string & getFilePath () const
 Returns the full path from which the library was loaded. More...
 

Private Attributes

std::string _file
 
void * _handle
 

Detailed Description

Wraps a dynamic library handler and provide methods to interact with it.

Definition at line 38 of file dynamiclibrary.hpp.

Member Enumeration Documentation

◆ RelocationMode

enum DynamicLibrary::RelocationMode : int
strong
Enumerator
Lazy 
Now 

Definition at line 41 of file dynamiclibrary.hpp.

Constructor & Destructor Documentation

◆ DynamicLibrary() [1/2]

DynamicLibrary::DynamicLibrary ( const std::string &  file)
explicit

Construct a dynamic library wrapper for the shared object referenced by name.

Parameters
fileis the path to the dynamic library file.

Definition at line 29 of file dynamiclibrary.cpp.

◆ ~DynamicLibrary()

DynamicLibrary::~DynamicLibrary ( )
default

◆ DynamicLibrary() [2/2]

DynamicLibrary::DynamicLibrary ( const DynamicLibrary other)
delete

Member Function Documentation

◆ close()

void DynamicLibrary::close ( )

Close the already opened library handler.

Exceptions
DynLibExceptionif something went wrong.

Definition at line 48 of file dynamiclibrary.cpp.

◆ getFilePath()

const std::string & DynamicLibrary::getFilePath ( ) const

Returns the full path from which the library was loaded.

Definition at line 65 of file dynamiclibrary.cpp.

◆ getSymbol()

void * DynamicLibrary::getSymbol ( const std::string &  symbol)

Lookup a symbol by name and return a pointer to it.

You need to open() the library first.

Exceptions
DynLibExceptionif we cannot access the symbol.

Definition at line 54 of file dynamiclibrary.cpp.

◆ open()

void DynamicLibrary::open ( RelocationMode  mode = RelocationMode::Lazy)

Attempts to open the shared library file so that we can access its symbols.

You must call open() before calling getSymbol().

Exceptions
DynLibExceptionif something went wrong.

Definition at line 35 of file dynamiclibrary.cpp.

◆ operator=()

DynamicLibrary& DynamicLibrary::operator= ( const DynamicLibrary other)
delete

Member Data Documentation

◆ _file

std::string DynamicLibrary::_file
private

Definition at line 85 of file dynamiclibrary.hpp.

◆ _handle

void* DynamicLibrary::_handle
private

Definition at line 86 of file dynamiclibrary.hpp.


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