[gmpi] Plugin Factory Update

Hi All,
Your improvements have been added to the GMPI Factory, let me know if I've missed any:


1. Ron.
"For in arguments, I like to use const references.  Pointers are
reserved for out."

2. Ron.
"when comparing values in an 'if', put the constant value on the left side, not the right."


3. Ron + others.
"Also, could plugin_list be a map instead?"

Tim also has some changes, I'll let Tim to post them when he's ready.


GMPI FACTORY (C++ version). Tim has a C version

A dll may contain one or more plugins. When the dll first loads each plugin registers itself with the Factory. The factory is basicly just a list of all the plugins in that dll...
---------your_plugin.cpp----------


// register plugin ID and creation function with factory
namespace
{
GMPI_RESULT r = Factory()->RegisterPlugin( IID_GMPI_Prototype_DSP, &Prototype_Plugin::CreateInstance );
}



Factory adds each plugin to it's list... --------------------factory.cpp----------------------------

// register a plugin with this factory
GMPI_RESULT GMPI_Factory::RegisterPlugin( const GMPI_GUID *iid, PLUGIN_CREATE_FUNCTION create_function )
{
m_available_plugins.insert( pair<const GMPI_GUID ,PLUGIN_CREATE_FUNCTION>(*iid, create_function) );
return GMPI_SUCCESS;
}



When the host wants to instantiate a plugin, it passes the plugin ID to the factory. Factory looks-up the plugin and calls it's Create function...
--------------------factory.cpp----------------------------


// Instantiate a GMPI_Plugin
GMPI_RESULT GMPI_Factory::CreateInstance( const GMPI_GUID &plugin_id, void **object )
{
// search plugin list for requested type
map<GMPI_GUID, PLUGIN_CREATE_FUNCTION >::iterator it = m_available_plugins.find( plugin_id );


    if( it != m_available_plugins.end() )
    {
        // call plugin create function
        GMPI_Plugin *plugin = 0;
        GMPI_RESULT r = (*it).second(&plugin);

        if( GMPI_SUCCESS != r )
        {
            *object = 0;
            return r;// E_OUTOFMEMORY;
        }

        return plugin->QueryInterface( IID_GMPI_IUnknown , object );
    }

    // couln't find requested type, return error
    *object = 0;
    return GMPI_FAIL;
}


Your plugin has a CreateInstance() function like so ---------your_plugin.cpp----------

// instantiate a new plugin
GMPI_RESULT Prototype_Plugin::CreateInstance(GMPI_Plugin **plugin)
{
    *plugin = new Prototype_Plugin();

    if( *plugin )
        return GMPI_SUCCESS;
    else
        return GMPI_FAIL;
}

That's it.  That's pretty much all GMPI does so far.
Jeff McClintock


---------------------------------------------------------------------- Generalized Music Plugin Interface (GMPI) public discussion list Participation in this list is contingent upon your abiding by the following rules: Please stay on topic. You are responsible for your own words. Please respect your fellow subscribers. Please do not redistribute anyone else's words without their permission.

Archive: http://www.freelists.org/archives/gmpi
Email gmpi-request@xxxxxxxxxxxxx w/ subject "unsubscribe" to unsubscribe

Other related posts: