The Open Master Hearing Aid (openMHA)  openMHA
Open community platform for hearing aid algorithm research
dynamiclib_t Class Reference

Wrapper class around a shared library. More...

Inheritance diagram for dynamiclib_t:
Inheritance graph

Public Member Functions

 dynamiclib_t (const std::string &name_)
 C'tor of the wrapper class. More...
 
virtual void * resolve (const std::string &name_)
 Resolves the function specified by name_ and returns a pointer to it or a nullptr if the function was not found in the wrapped library. More...
 
virtual void * resolve_checked (const std::string &name_)
 Resolves the function specified by name_ and returns a pointer to it or throws an exception if the function was not found. More...
 
virtual ~dynamiclib_t ()
 D'tor. More...
 
virtual const std::string & getmodulename () const
 Returns unqualified filename of the wrapped library sans file suffix. More...
 
virtual const std::string & getname () const
 

Protected Member Functions

 dynamiclib_t ()
 Default constructor. More...
 
void load_lib (const std::string &name_)
 Loads the library specified in name_ and saves a handle in h. More...
 

Protected Attributes

std::string fullname
 Fully qualified file name of the library. More...
 
std::string modulename
 Unqualified file name of the library. More...
 
mha_libhandle_t h
 Handle to the shared library. More...
 

Detailed Description

Wrapper class around a shared library.

Encapsulates the OS-specific stuff of loading the shared library, resolving functions, etc... Uses the dload API on Linux/macOS and the win32 API on Windows

Constructor & Destructor Documentation

◆ dynamiclib_t() [1/2]

dynamiclib_t::dynamiclib_t ( const std::string &  name_)

C'tor of the wrapper class.

Takes a the the file name of a shared libary w/o the suffix as argument, searches for the library in the system-dependent standard paths for libraries and in MHA_LIBRARY_PATH. Calls load_lib for the actual work.

Parameters
name_File name of the shared library, without suffix
Exceptions
MHA_Errorif the library can not be found or can not be loaded

◆ ~dynamiclib_t()

dynamiclib_t::~dynamiclib_t ( )
virtual

D'tor.

Closes the library handle.

◆ dynamiclib_t() [2/2]

dynamiclib_t::dynamiclib_t ( )
protected

Default constructor.

Member Function Documentation

◆ resolve()

void * dynamiclib_t::resolve ( const std::string &  name_)
virtual

Resolves the function specified by name_ and returns a pointer to it or a nullptr if the function was not found in the wrapped library.

Parameters
name_Name of the function to be resolved
Returns
Pointer to the function

Reimplemented in pluginlib_t.

◆ resolve_checked()

void * dynamiclib_t::resolve_checked ( const std::string &  name_)
virtual

Resolves the function specified by name_ and returns a pointer to it or throws an exception if the function was not found.

Parameters
name_Name of the function to be resolved
Returns
Pointer to the function

◆ getmodulename()

virtual const std::string& dynamiclib_t::getmodulename ( ) const
inlinevirtual

Returns unqualified filename of the wrapped library sans file suffix.

Returns
Unqualified filename of the wrapped library

◆ getname()

virtual const std::string& dynamiclib_t::getname ( ) const
inlinevirtual

◆ load_lib()

void dynamiclib_t::load_lib ( const std::string &  name_)
protected

Loads the library specified in name_ and saves a handle in h.

Parameters
name_unqualified file name of the shared library w/o suffix

Member Data Documentation

◆ fullname

std::string dynamiclib_t::fullname
protected

Fully qualified file name of the library.

◆ modulename

std::string dynamiclib_t::modulename
protected

Unqualified file name of the library.

◆ h

mha_libhandle_t dynamiclib_t::h
protected

Handle to the shared library.


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