Class provides plugin creation routine. More...
#include <utilities/plugin_interface.h>
Static Public Member Functions | |
static bool | IsPlugin (nitro::DynamicLibLoader &Module) |
template<class type1 > | |
static bool | InterfaceExported (nitro::DynamicLibLoader &Plugin) |
template<class type1 > | |
static type1 * | GetInterface (nitro::DynamicLibLoader &Plugin, const std::string &ObjectName="") |
template<class type1 > | |
static type1 * | GetNewInterface (nitro::DynamicLibLoader &Plugin) |
template<class type1 > | |
static void | ReleaseInterface (nitro::DynamicLibLoader &Plugin, type1 *Interface) |
Static Private Attributes | |
static std::size_t | ObjectInterfaceCounter = 0 |
Class provides plugin creation routine.
Definition at line 94 of file plugin_interface.h.
type1 * nitro::PluginInterface::GetInterface | ( | nitro::DynamicLibLoader & | Plugin, | |
const std::string & | ObjectName = "" | |||
) | [static] |
Function returnes exporting interface.
Plugin | - Plugin wich exports interface. | |
ObjectName | - Object name. |
nitro::exception | String with the description of the occured error. |
Definition at line 305 of file plugin_interface.h.
References nitro::exception::code(), nitro::DynamicLibLoader::GetResource(), nitro::DynamicLibLoader::ResourceExists(), and nitro::exception::what().
{ try { if( Plugin.ResourceExists( "GetInterface" ) == false ) { throw( nitro::exception( "Loaded module is not a plugin" , 1 ) ); } void * ( * _GetInterface )( const char * , const char * ); _GetInterface = ( void * ( * )( const char * , const char * ) )Plugin.GetResource( "GetInterface" ); return( ( type1 * )_GetInterface( typeid( type1 ).name() , ObjectName.c_str() ) ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "PluginInterface::GetInterface( nitro::DynamicLibLoader & Plugin , const std::string & ObjectName )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "PluginInterface::GetInterface( nitro::DynamicLibLoader & Plugin , const std::string & ObjectName )::An error occured" ) , 1 ) ); } }
type1 * nitro::PluginInterface::GetNewInterface | ( | nitro::DynamicLibLoader & | Plugin | ) | [static] |
Function returnes exporting interface.
Plugin | - Plugin wich exports interface. |
nitro::exception | String with the description of the occured error. |
Definition at line 339 of file plugin_interface.h.
References nitro::exception::code(), nitro::DynamicLibLoader::GetResource(), ObjectInterfaceCounter, nitro::DynamicLibLoader::ResourceExists(), and nitro::exception::what().
{ try { if( Plugin.ResourceExists( "GetInterface" ) == false ) { throw( nitro::exception( "Loaded module is not a plugin" , 1 ) ); } void * ( * _GetInterface )( const char * , const char * ); _GetInterface = ( void * ( * )( const char * , const char * ) )Plugin.GetResource( "GetInterface" ); std::size_t CurrentCursor( PluginInterface::ObjectInterfaceCounter++ ); std::string ObjectInterfaceCursor( nitro::Convertes::itoa( CurrentCursor ) ); std::string ObjectName( "" ); ObjectName += "_new_interface["; ObjectName += ObjectInterfaceCursor; ObjectName += "]"; return( ( type1 * )_GetInterface( typeid( type1 ).name() , ObjectName.c_str() ) ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "PluginInterface::GetNewInterface( nitro::DynamicLibLoader & Plugin )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "PluginInterface::GetNewInterface( nitro::DynamicLibLoader & Plugin )::An error occured" ) , 1 ) ); } }
bool nitro::PluginInterface::InterfaceExported | ( | nitro::DynamicLibLoader & | Plugin | ) | [static] |
Function validates if the interface can be exported.
Plugin | - Plugin wich exports interface. |
nitro::exception | String with the description of the occured error. |
Definition at line 261 of file plugin_interface.h.
References nitro::exception::code(), nitro::DynamicLibLoader::GetResource(), nitro::DynamicLibLoader::ResourceExists(), and nitro::exception::what().
{ void * ( * _GetInterface )( const char * , const char * ); try { if( Plugin.ResourceExists( "GetInterface" ) == false ) { throw( nitro::exception( "Loaded module is not a plugin" , 1 ) ); } _GetInterface = ( void * ( * )( const char * , const char * ) )Plugin.GetResource( "GetInterface" ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "PluginInterface::InterfaceExported( nitro::DynamicLibLoader & Plugin )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "PluginInterface::InterfaceExported( nitro::DynamicLibLoader & Plugin )::An error occured" ) , 1 ) ); } try { _GetInterface( typeid( type1 ).name() , "" ); return( true ); } catch( ... ) { return( false ); } }
bool nitro::PluginInterface::IsPlugin | ( | nitro::DynamicLibLoader & | Module | ) | [static] |
Function validates if the loaded module is a plugin.
Module | - loaded module to be checked. |
std::string | String with the description of the occured error. |
Definition at line 18 of file plugin_interface.cpp.
References nitro::exception::code(), and nitro::exception::what().
{ try { if( Plugin.ResourceExists( "GetInterface" ) == false ) { return( false ); } return( true ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "PluginInterface::IsPlugin( nitro::DynamicLibLoader & Module )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "PluginInterface::IsPlugin( nitro::DynamicLibLoader & Module )::An error occured" ) , 1 ) ); } } }
void nitro::PluginInterface::ReleaseInterface | ( | nitro::DynamicLibLoader & | Plugin, | |
type1 * | Interface | |||
) | [static] |
Function returnes exporting interface.
Plugin | - Plugin wich exports interface. | |
Interface | - Interface. |
nitro::exception | String with the description of the occured error. |
Definition at line 380 of file plugin_interface.h.
References nitro::exception::code(), nitro::DynamicLibLoader::GetResource(), nitro::DynamicLibLoader::ResourceExists(), and nitro::exception::what().
{ try { if( Plugin.ResourceExists( "ReleaseInterface" ) == false ) { throw( nitro::exception( "Loaded module is not a plugin" , 1 ) ); } void ( * _ReleaseInterface )( void * ); _ReleaseInterface = ( void ( * )( void * ) )Plugin.GetResource( "ReleaseInterface" ); _ReleaseInterface( ( void * ) Interface ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "PluginInterface::ReleaseInterface( nitro::DynamicLibLoader & Plugin , type1 * Interface )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "PluginInterface::ReleaseInterface( nitro::DynamicLibLoader & Plugin , type1 * Interface )::An error occured" ) , 1 ) ); } } }
std::size_t nitro::PluginInterface::ObjectInterfaceCounter = 0 [static, private] |
Internal counter.
Definition at line 246 of file plugin_interface.h.
Referenced by GetNewInterface().