Public Member Functions | Private Member Functions | Private Attributes

nitro::DynamicLibLoader Class Reference

~english Class for loading dynamic libraries. More...

#include <loaders/dynamic_lib_loader.h>

List of all members.

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

Detailed Description

~english Class for loading dynamic libraries.

Author:
Dodonov A.A.
Examples:

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.


Constructor & Destructor Documentation

nitro::DynamicLibLoader::DynamicLibLoader ( void   ) 

Constructor.

Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

nitro::DynamicLibLoader::DynamicLibLoader ( const char *  LibraryPath  ) 

Constructor.

Parameters:
LibraryPath - Path to the loading library.
Exceptions:
std::string String with the description of the occured error.
Author:
Dodonov A.A.

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) );
                }
        }

Here is the call graph for this function:

nitro::DynamicLibLoader::DynamicLibLoader ( const std::string &  LibraryPath  ) 

Constructor.

Parameters:
LibraryPath - Path to the loading library.
Exceptions:
std::string String with the description of the occured error.
Author:
Dodonov A.A.

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) );
                }
        }

Here is the call graph for this function:

nitro::DynamicLibLoader::~DynamicLibLoader (  )  [virtual]

Virtual destructor.

Author:
Dodonov A.A.

Definition at line 262 of file dynamic_lib_loader.cpp.

References Release().

        {
                try
                {
                        Release();
                }
                catch( nitro::exception e )
                {
                }
                catch( ... )
                {
                }
        }

Here is the call graph for this function:

nitro::DynamicLibLoader::DynamicLibLoader ( const DynamicLibLoader  )  [inline, private]

Private copy-constructor.

Author:
Dodonov A.A.

Definition at line 297 of file dynamic_lib_loader.h.

{}


Member Function Documentation

void * nitro::DynamicLibLoader::GetResource ( const char *  ResourceName  ) 

Function loads resource from library (resource is object or function).

Parameters:
ResourceName - Name of the loading resource.
Returns:
Pointer on the resource.
Exceptions:
std::string String with the description of the occured error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

void * nitro::DynamicLibLoader::GetResource ( const std::string &  ResourceName  ) 

Function loads resource from library (resource is object or function).

Parameters:
ResourceName - Name of the loading resource.
Returns:
Pointer on the resource.
Exceptions:
std::string String with the description of the occured error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

void nitro::DynamicLibLoader::LoadLibrary ( const std::string &  LibraryPath  ) 

Function loads dynamic library.

Parameters:
LibraryPath - Path to the loading library.
Exceptions:
std::string String with the description of the occured error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

void nitro::DynamicLibLoader::LoadLibrary ( const char *  LibraryPath  ) 

Function loads dynamic library.

Parameters:
LibraryPath - Path to the loading library.
Exceptions:
std::string String with the description of the occured error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

DynamicLibLoader nitro::DynamicLibLoader::operator= ( const DynamicLibLoader  )  [inline, private]

Private assign operator.

Author:
Dodonov A.A.

Definition at line 309 of file dynamic_lib_loader.h.

{return( *this );}

void nitro::DynamicLibLoader::Release ( void   ) 

Function releases loaded library.

Exceptions:
std::string String with the description of the occured error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

bool nitro::DynamicLibLoader::ResourceExists ( const std::string &  ResourceName  ) 

Function validates resource's existance.

Parameters:
ResourceName - Name of the loading resource.
Returns:
true if exists.
Exceptions:
std::string String with the description of the occured error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

bool nitro::DynamicLibLoader::ResourceExists ( const char *  ResourceName  ) 

Function validates resource's existance.

Parameters:
ResourceName - Name of the loading resource.
Returns:
true if exists.
Exceptions:
std::string String with the description of the occured error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:


Member Data Documentation

Handle of the loaded dynamic library.

Author:
Dodonov A.A.

Definition at line 285 of file dynamic_lib_loader.h.

Referenced by DynamicLibLoader(), GetResource(), LoadLibrary(), Release(), and ResourceExists().


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

Generated by  doxygen 1.6.1