Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

snx::SoundFactory Class Reference

#include <SoundFactory.h>

List of all members.

Public Methods

void errorOutput (vpr::LibraryPtr lib, const char *test)
bool isPlugin (vpr::LibraryPtr lib)
void loadPlugins (vpr::LibraryFinder::LibraryList libs)
void unloadPlugins ()
void createImplementation (const std::string &apiName, snx::ISoundImplementation *&mImplementation)
 @input name of api to create @output an implementation is returned for you to use. More...

void reg (const std::string &apiName, snx::ISoundImplementation *impl)

Public Attributes

std::map< std::string, snx::ISoundImplementation * > mRegisteredImplementations
std::vector< vpr::LibraryPtr > mPlugins


Member Function Documentation

void snx::SoundFactory::errorOutput vpr::LibraryPtr    lib,
const char *    test
 

Definition at line 171 of file SoundFactory.cpp.

References snxDBG.

Referenced by isPlugin.

00172 {
00173    vprDEBUG(snxDBG, vprDBG_WARNING_LVL)
00174       << "ERROR: Plugin '" << lib->getName() << "' does not export symbol '"
00175       << test << "'\n" << vprDEBUG_FLUSH;
00176 }

bool snx::SoundFactory::isPlugin vpr::LibraryPtr    lib
 

Definition at line 178 of file SoundFactory.cpp.

References errorOutput, and snxDBG.

Referenced by loadPlugins.

00179 {
00180    if (lib->findSymbol( "newPlugin" ) == NULL)
00181    {
00182       errorOutput(lib, "newPlugin");
00183       return false;
00184    }
00185    if (lib->findSymbol( "getVersion" ) == NULL)
00186    {
00187       errorOutput(lib, "getVersion");
00188       return false;
00189    }
00190    if (lib->findSymbol( "getName" ) == NULL)
00191    {
00192       errorOutput(lib, "getName");
00193       return false;
00194    }
00195 
00196    // @todo give sonix an internal version number string!
00197    //getVersionFunc getVersion = (getVersionFunc)lib.lookup( "getVersion" );
00198    //if (getVersion != NULL && getVersion() != snx::version) return false;
00199    vprDEBUG(snxDBG, vprDBG_CONFIG_STATUS_LVL) << "Plugin '" << lib->getName()
00200                                               << "' is a valid Sonix plugin.\n"
00201                                               << vprDEBUG_FLUSH;
00202    return true;
00203 }

void snx::SoundFactory::loadPlugins vpr::LibraryFinder::LibraryList    libs
 

Definition at line 205 of file SoundFactory.cpp.

References snx::getNameFunc, isPlugin, mPlugins, mRegisteredImplementations, snx::newPluginFunc, reg, and snxDBG.

00206 {
00207    for (unsigned int x = 0; x < libs.size(); ++x)
00208    {
00209       // open the library
00210       vpr::ReturnStatus didLoad = libs[x]->load();
00211 
00212       if (didLoad == vpr::ReturnStatus::Succeed)
00213       {
00214         //If the plug-in implements the nessiasry interface
00215         if ( this->isPlugin(libs[x]) )
00216         {
00217             // get the name..
00218             getNameFunc getName = (getNameFunc)libs[x]->findSymbol( "getName" );
00219             std::string name;
00220             if (getName != NULL)
00221             {
00222                 name = getName();
00223 
00224                 // Check to see it plug-in is already registered
00225                 int pluginsWithName =  mRegisteredImplementations.count(name);
00226                 if ( pluginsWithName < 1 )
00227                 {
00228                     // Keep track of the plug-ins we actual use
00229                     mPlugins.push_back(libs[x]);
00230 
00231                     vprDEBUG(snxDBG, vprDBG_STATE_LVL)
00232                        << "Got plug-in '" << name << "'--registering\n"
00233                        << vprDEBUG_FLUSH;
00234 
00235                     // create the implementation
00236                     newPluginFunc newPlugin = (newPluginFunc)libs[x]->findSymbol( "newPlugin" );
00237                     ISoundImplementation* si = NULL;
00238                     if (newPlugin != NULL)
00239                     {
00240                         si = newPlugin();
00241                         if (NULL != si)
00242                         {
00243                             this->reg( name, si );
00244                         }
00245                     }
00246                 }
00247                 else
00248                 {
00249                     //Plug in was already registered so we can unload it
00250                     libs[x]->unload();
00251                 }
00252             }
00253         }
00254       }
00255       else
00256       {
00257         //Lib failed to load
00258         vprDEBUG(snxDBG, vprDBG_WARNING_LVL)
00259             << "ERROR: Plugin '" << libs[x]->getName() << "' Failed to load\n" << vprDEBUG_FLUSH;
00260       }
00261    }
00262 }

void snx::SoundFactory::unloadPlugins  
 

Definition at line 264 of file SoundFactory.cpp.

References snx::getNameFunc, mPlugins, mRegisteredImplementations, and reg.

00265 {
00266    for (unsigned int x = 0; x < mPlugins.size(); ++x)
00267    {
00268       // get the name..
00269       getNameFunc getName = (getNameFunc)mPlugins[x]->findSymbol( "getName" );
00270       std::string name;
00271       ISoundImplementation* impl = NULL;
00272       if (getName != NULL)
00273       {
00274          name = getName();
00275          impl = mRegisteredImplementations[name];
00276 
00277          // unreg it.
00278          this->reg( name, NULL );
00279       }
00280 
00281       // delete the memory using the delete func that comes with the library...
00282       if ( NULL != impl )
00283       {
00284          delete impl;
00285       }
00286 
00287       // close the library
00288       mPlugins[x]->unload();
00289    }
00290    mPlugins.clear();
00291 }

void snx::SoundFactory::createImplementation const std::string &    apiName,
snx::ISoundImplementation *&    mImplementation
 

@input name of api to create @output an implementation is returned for you to use.

@postconditions if apiName is not known, then a stub implementation is returned @semantics factory function used to create an implementation of a sound API

Definition at line 321 of file SoundFactory.cpp.

References mRegisteredImplementations.

00323 {
00324    if (mRegisteredImplementations.count( apiName ) > 0)
00325    {
00326       mRegisteredImplementations[apiName]->clone( mImplementation );
00327    }
00328 
00329    else
00330    {
00331       mImplementation = new snx::StubSoundImplementation;
00332    }
00333 
00334    //mImplementation->setName( apiName );
00335 }

void snx::SoundFactory::reg const std::string &    apiName,
snx::ISoundImplementation   impl
 

Definition at line 293 of file SoundFactory.cpp.

References mRegisteredImplementations, snx::ISoundImplementation::setName, and snxDBG.

Referenced by loadPlugins, and unloadPlugins.

00295 {
00296    if (impl != NULL)
00297    {
00298       vprDEBUG(snxDBG, vprDBG_CONFIG_LVL)
00299          << "NOTICE: Registering sound API '" << apiName << "'\n"
00300          << vprDEBUG_FLUSH;
00301 
00302       impl->setName( apiName );
00303       mRegisteredImplementations[apiName] = impl;
00304    }
00305    else
00306    {
00307       mRegisteredImplementations.erase( apiName );
00308 
00309       vprDEBUG(snxDBG, vprDBG_CONFIG_LVL)
00310          << "NOTICE: Unregistered sound API '" << apiName << "'\n"
00311          << vprDEBUG_FLUSH;
00312    }
00313 }


Member Data Documentation

std::map< std::string, snx::ISoundImplementation* > snx::SoundFactory::mRegisteredImplementations
 

Definition at line 84 of file SoundFactory.h.

Referenced by createImplementation, loadPlugins, reg, and unloadPlugins.

std::vector<vpr::LibraryPtr> snx::SoundFactory::mPlugins
 

Definition at line 85 of file SoundFactory.h.

Referenced by loadPlugins, and unloadPlugins.


The documentation for this class was generated from the following files:
Generated on Sun May 2 14:39:33 2004 for Juggler Sonix by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002