[gmpi] Linux C++ question

  • From: Jeff McClintock <jeffmcc@xxxxxxxxxx>
  • To: gmpi@xxxxxxxxxxxxx
  • Date: Thu, 24 Feb 2005 10:14:05 +1300

A question for someone familier (very familier) with C++ on Linux.

A GMPI dll may contain several plugins. In the GMPI prototype. An object called the factory maintains a list. There is only ever one factory. I used a singleton to implement such. However Tim reports that it crashes while unloading the dll. Any help appreciated.

details:

The technique comes from "Modern C++ Design - Andrei Alexandrescu", author of the Loki library.

This is the essential code. Ignore the GMPIness of this...If you want to see the entire file, let me know.

/* factory is a singleton, this retrieves a pointer to it */
GMPI_Factory *Factory(void)
{
        static GMPI_Factory the_factory;
        return &the_factory;
}

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


/* Instantiate a GMPI_Plugin */
GMPI_RESULT GMPI_Factory::CreateInstance( GMPI_GUID *plugin_id, void **object )
{
/* search plugin list for requested type */
for( list< pair<const GMPI_GUID *,PLUGIN_CREATE_FUNCTION> >::iterator it = plugin_list.begin() ; it != plugin_list.end() ; it++ )
{
if( GIMPI_IsEqualIID( plugin_id, (*it).first ) )
{
/* call plugin create function */
GMPI_Plugin *plugin = ((*it).second)();


                        if (plugin == 0)
                        {
                                *object = 0;
                                return GMPI_FAIL;// E_OUTOFMEMORY;
                        }

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


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


---------------------------------------------------------------------- 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: //www.freelists.org/archives/gmpi
Email gmpi-request@xxxxxxxxxxxxx w/ subject "unsubscribe" to unsubscribe

Other related posts: