Static Public Member Functions | Static Private Attributes

nitro::PluginInterface Class Reference

Class provides plugin creation routine. More...

#include <utilities/plugin_interface.h>

List of all members.

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

Detailed Description

Class provides plugin creation routine.

Definition at line 94 of file plugin_interface.h.


Member Function Documentation

template<class type1 >
type1 * nitro::PluginInterface::GetInterface ( nitro::DynamicLibLoader Plugin,
const std::string &  ObjectName = "" 
) [static]

Function returnes exporting interface.

Parameters:
Plugin - Plugin wich exports interface.
ObjectName - Object name.
Returns:
Pointer on the exporting interface.
Note:
This function have a singleton behaviour.
Exceptions:
nitro::exception String with the description of the occured error.
Author:
Dodonov A.A.

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

Here is the call graph for this function:

template<class type1 >
type1 * nitro::PluginInterface::GetNewInterface ( nitro::DynamicLibLoader Plugin  )  [static]

Function returnes exporting interface.

Parameters:
Plugin - Plugin wich exports interface.
Returns:
Pointer on the exporting interface.
Note:
This function always returns a new interface.
Exceptions:
nitro::exception String with the description of the occured error.
Author:
Dodonov A.A.

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

Here is the call graph for this function:

template<class type1 >
bool nitro::PluginInterface::InterfaceExported ( nitro::DynamicLibLoader Plugin  )  [static]

Function validates if the interface can be exported.

Parameters:
Plugin - Plugin wich exports interface.
Returns:
true if it does.
Exceptions:
nitro::exception String with the description of the occured error.
Author:
Dodonov A.A.

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

Here is the call graph for this function:

bool nitro::PluginInterface::IsPlugin ( nitro::DynamicLibLoader Module  )  [static]

Function validates if the loaded module is a plugin.

Parameters:
Module - loaded module to be checked.
Returns:
true if it does.
Exceptions:
std::string String with the description of the occured error.
Author:
Dodonov A.A.
Examples:
is_plugin.cpp.

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

Here is the call graph for this function:

template<class type1 >
void nitro::PluginInterface::ReleaseInterface ( nitro::DynamicLibLoader Plugin,
type1 *  Interface 
) [static]

Function returnes exporting interface.

Parameters:
Plugin - Plugin wich exports interface.
Interface - Interface.
Returns:
Pointer on the exporting interface.
Exceptions:
nitro::exception String with the description of the occured error.
Author:
Dodonov A.A.
Examples:
release_interface.cpp.

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

Here is the call graph for this function:


Member Data Documentation

std::size_t nitro::PluginInterface::ObjectInterfaceCounter = 0 [static, private]

Internal counter.

Author:
Dodonov A.A.

Definition at line 246 of file plugin_interface.h.

Referenced by GetNewInterface().


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

Generated by  doxygen 1.6.1