~english Class for loading dynamic libraries. More...
#include <loaders/dynamic_lib_loader.h>
Public Member Functions | |
| DynamicLibLoader (void) | |
| DynamicLibLoader (const char *LibraryPath) | |
| DynamicLibLoader (const std::string &LibraryPath) | |
| void | LoadLibrary (const char *LibraryPath) |
| void | LoadLibrary (const std::string &LibraryPath) |
| void * | GetResource (const char *ResourceName) |
| void * | GetResource (const std::string &ResourceName) |
| bool | ResourceExists (const char *ResourceName) |
| bool | ResourceExists (const std::string &ResourceName) |
| void | Release (void) |
| virtual | ~DynamicLibLoader () |
Private Member Functions | |
| DynamicLibLoader (const DynamicLibLoader &) | |
| DynamicLibLoader | operator= (const DynamicLibLoader &) |
Private Attributes | |
| void * | Handle |
~english Class for loading dynamic libraries.
get_interface.cpp, get_new_interface.cpp, interface_exported.cpp, is_plugin.cpp, and release_interface.cpp.
Definition at line 48 of file dynamic_lib_loader.h.
| nitro::DynamicLibLoader::DynamicLibLoader | ( | void | ) |
Constructor.
Definition at line 17 of file dynamic_lib_loader.cpp.
References nitro::exception::code(), Handle, and nitro::exception::what().
{
try
{
Handle = NULL;
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "DynamicLibLoader::DynamicLibLoader( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "DynamicLibLoader::DynamicLibLoader( void )::An error occured" ) , 1 ) );
}
}

| nitro::DynamicLibLoader::DynamicLibLoader | ( | const char * | LibraryPath | ) |
Constructor.
| LibraryPath | - Path to the loading library. |
| std::string | String with the description of the occured error. |
Definition at line 33 of file dynamic_lib_loader.cpp.
References nitro::exception::code(), Handle, LoadLibrary(), and nitro::exception::what().
{
try
{
Handle = NULL;
LoadLibrary( LibraryPath );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "DynamicLibLoader::DynamicLibLoader( const char * LibraryPath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "DynamicLibLoader::DynamicLibLoader( const char * LibraryPath )::An error occured" ) , 0) );
}
}

| nitro::DynamicLibLoader::DynamicLibLoader | ( | const std::string & | LibraryPath | ) |
Constructor.
| LibraryPath | - Path to the loading library. |
| std::string | String with the description of the occured error. |
Definition at line 51 of file dynamic_lib_loader.cpp.
References nitro::exception::code(), Handle, LoadLibrary(), and nitro::exception::what().
{
try
{
Handle = NULL;
LoadLibrary( LibraryPath );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "DynamicLibLoader::DynamicLibLoader( const std::string & LibraryPath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "DynamicLibLoader::DynamicLibLoader( const std::string & LibraryPath )::An error occured" ) , 0) );
}
}

| nitro::DynamicLibLoader::~DynamicLibLoader | ( | ) | [virtual] |
Virtual destructor.
Definition at line 262 of file dynamic_lib_loader.cpp.
References Release().
{
try
{
Release();
}
catch( nitro::exception e )
{
}
catch( ... )
{
}
}

| nitro::DynamicLibLoader::DynamicLibLoader | ( | const DynamicLibLoader & | ) | [inline, private] |
| void * nitro::DynamicLibLoader::GetResource | ( | const char * | ResourceName | ) |
Function loads resource from library (resource is object or function).
| ResourceName | - Name of the loading resource. |
| std::string | String with the description of the occured error. |
Definition at line 121 of file dynamic_lib_loader.cpp.
References nitro::exception::code(), Handle, and nitro::exception::what().
Referenced by nitro::PluginInterface::GetInterface(), nitro::PluginInterface::GetNewInterface(), GetResource(), nitro::PluginInterface::InterfaceExported(), and nitro::PluginInterface::ReleaseInterface().
{
try
{
if( Handle )
{
#if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
FARPROC Address( NULL );
Address = GetProcAddress( *( ( HMODULE * )Handle ) , ResourceName );
#endif
#if defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
void * Address( NULL );
Address = dlsym( Handle , ResourceName );
#endif
if( Address == NULL )
{
throw( nitro::exception( std::string( "An error occured while getting library resource " ) + ResourceName , 1 ) );
}
return( ( void * )Address );
}
else
{
throw( nitro::exception( std::string( "Library was not loaded" ) , 1 ) );
}
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "DynamicLibLoader::GetResource( const char * ResourceName )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "DynamicLibLoader::GetResource( const char * ResourceName )::An error occured" ) , 1 ) );
}
}

| void * nitro::DynamicLibLoader::GetResource | ( | const std::string & | ResourceName | ) |
Function loads resource from library (resource is object or function).
| ResourceName | - Name of the loading resource. |
| std::string | String with the description of the occured error. |
Definition at line 161 of file dynamic_lib_loader.cpp.
References nitro::exception::code(), GetResource(), and nitro::exception::what().
{
try
{
return( GetResource( ResourceName.c_str() ) );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "DynamicLibLoader::GetResource( const std::string & ResourceName )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "DynamicLibLoader::GetResource( const std::string & ResourceName )::An error occured" ) , 1 ) );
}
}

| void nitro::DynamicLibLoader::LoadLibrary | ( | const std::string & | LibraryPath | ) |
Function loads dynamic library.
| LibraryPath | - Path to the loading library. |
| std::string | String with the description of the occured error. |
Definition at line 105 of file dynamic_lib_loader.cpp.
References nitro::exception::code(), LoadLibrary(), and nitro::exception::what().
{
try
{
LoadLibrary( LibraryPath.c_str() );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "DynamicLibLoader::LoadLibrary( const std::string & LibraryPath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "DynamicLibLoader::LoadLibrary( const std::string & LibraryPath )::An error occured" ) , 1 ) );
}
}

| void nitro::DynamicLibLoader::LoadLibrary | ( | const char * | LibraryPath | ) |
Function loads dynamic library.
| LibraryPath | - Path to the loading library. |
| std::string | String with the description of the occured error. |
Definition at line 69 of file dynamic_lib_loader.cpp.
References nitro::exception::code(), Handle, Release(), and nitro::exception::what().
Referenced by DynamicLibLoader(), and LoadLibrary().
{
try
{
Release();
#if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
Handle = ( void * ) new HMODULE;
*( ( HMODULE * )Handle ) = LoadLibraryA( LibraryPath );
if( *( ( HMODULE * )Handle ) == NULL )
{
throw( nitro::exception( std::string( "An error occured while loading library " ) + LibraryPath , 0 ) );
}
#endif
#if defined( NIX_PLARFORM ) || defined( CYGWIN_PLATFORM )
Handle = dlopen( LibraryPath , RTLD_NOW | RTLD_GLOBAL );
if( Handle == NULL )
{
throw( nitro::exception( std::string( "An error occured while loading library " ) + LibraryPath , 0 ) );
}
#endif
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "DynamicLibLoader::LoadLibrary( const char * LibraryPath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "DynamicLibLoader::LoadLibrary( const char * LibraryPath )::An error occured" ) , 1 ) );
}
}

| DynamicLibLoader nitro::DynamicLibLoader::operator= | ( | const DynamicLibLoader & | ) | [inline, private] |
| void nitro::DynamicLibLoader::Release | ( | void | ) |
Function releases loaded library.
| std::string | String with the description of the occured error. |
Definition at line 233 of file dynamic_lib_loader.cpp.
References nitro::exception::code(), Handle, and nitro::exception::what().
Referenced by LoadLibrary(), and ~DynamicLibLoader().
{
try
{
if( Handle )
{
#if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
FreeLibrary( * ( ( HMODULE * )Handle ) );
delete ( HMODULE * )Handle;
#endif
#if defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
dlclose( Handle );
#endif
Handle = NULL;
}
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "DynamicLibLoader::Release( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "DynamicLibLoader::Release( void )::An error occured" ) , 1 ) );
}
}

| bool nitro::DynamicLibLoader::ResourceExists | ( | const std::string & | ResourceName | ) |
Function validates resource's existance.
| ResourceName | - Name of the loading resource. |
| std::string | String with the description of the occured error. |
Definition at line 217 of file dynamic_lib_loader.cpp.
References nitro::exception::code(), ResourceExists(), and nitro::exception::what().
{
try
{
return( ResourceExists( ResourceName.c_str() ) );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "DynamicLibLoader::ResourceExists( const std::string & ResourceName )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "DynamicLibLoader::ResourceExists( const std::string & ResourceName )::An error occured" ) , 1 ) );
}
}

| bool nitro::DynamicLibLoader::ResourceExists | ( | const char * | ResourceName | ) |
Function validates resource's existance.
| ResourceName | - Name of the loading resource. |
| std::string | String with the description of the occured error. |
Definition at line 177 of file dynamic_lib_loader.cpp.
References nitro::exception::code(), Handle, and nitro::exception::what().
Referenced by nitro::PluginInterface::GetInterface(), nitro::PluginInterface::GetNewInterface(), nitro::PluginInterface::InterfaceExported(), nitro::PluginInterface::ReleaseInterface(), and ResourceExists().
{
try
{
if( Handle )
{
#if defined( WIN32_PLATFORM ) || defined( MINGW_PLATFORM )
FARPROC Address( NULL );
Address = GetProcAddress( *( ( HMODULE * )Handle ) , ResourceName );
#endif
#if defined( NIX_PLATFORM ) || defined( CYGWIN_PLATFORM )
void * Address( NULL );
Address = dlsym( Handle , ResourceName );
#endif
if( Address == NULL )
{
return( false );
}
return( true );
}
else
{
throw( nitro::exception( std::string( "Library was not loaded" ) , 1 ) );
}
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "DynamicLibLoader::ResourceExists( const char * ResourceName )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "DynamicLibLoader::ResourceExists( const char * ResourceName )::An error occured" ) , 1 ) );
}
}

void* nitro::DynamicLibLoader::Handle [private] |
Handle of the loaded dynamic library.
Definition at line 285 of file dynamic_lib_loader.h.
Referenced by DynamicLibLoader(), GetResource(), LoadLibrary(), Release(), and ResourceExists().
1.6.1