TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/host/ofx/OfxhPluginBinary.cpp
Go to the documentation of this file.
00001 #include "OfxhPluginBinary.hpp"
00002 #include "OfxhPluginCache.hpp"
00003 
00004 #include <tuttle/host/exceptions.hpp>
00005 
00006 namespace tuttle {
00007 namespace host {
00008 namespace ofx {
00009 
00010 typedef int( *OfxGetNumberOfPluginsType )( void );
00011 typedef OfxPlugin*( *OfxGetPluginType )( int );
00012 
00013 /**
00014  * @brief try to open the plugin bundle object and query it for plugins
00015  */
00016 void OfxhPluginBinary::loadPluginInfo( OfxhPluginCache* cache )
00017 {
00018         _fileModificationTime = _binary.getTime();
00019         _fileSize = _binary.getSize();
00020         _binaryChanged = false;
00021 
00022         _binary.load();
00023 
00024         OfxGetNumberOfPluginsType getNumberOfPlugins_func = (OfxGetNumberOfPluginsType)_binary.findSymbol( "OfxGetNumberOfPlugins" );
00025         OfxGetPluginType getPlugin_func = (OfxGetPluginType)_binary.findSymbol( "OfxGetPlugin" );
00026 
00027         if( getNumberOfPlugins_func == 0 || getPlugin_func == 0 )
00028         {
00029                 _binary.setInvalid( true );
00030         }
00031         else
00032         {
00033                 int pluginCount = ( *getNumberOfPlugins_func )( );
00034 
00035                 _plugins.clear();
00036                 _plugins.reserve( pluginCount );
00037 
00038                 for( int i = 0; i < pluginCount; ++i )
00039                 {
00040                         OfxPlugin& plug = *( *getPlugin_func )( i );
00041 
00042                         APICache::OfxhPluginAPICacheI* api = cache->findApiHandler( plug.pluginApi, plug.apiVersion );
00043                         assert( api );
00044 
00045                         OfxhPlugin* newPlug = api->newPlugin( *this, i, plug );
00046                         if( newPlug == NULL )
00047                         {
00048                                 BOOST_THROW_EXCEPTION( exception::Unknown()
00049                                     << exception::dev( "Error creating a new OfxhPlugin." )
00050                                     << exception::pluginIdentifier( plug.pluginIdentifier )
00051                                     << exception::ofxApi( plug.pluginApi )
00052                                     << exception::filename( _binary.getBinaryPath() ) );
00053                         }
00054                         _plugins.push_back( newPlug );
00055                 }
00056         }
00057         _binary.unload();
00058 }
00059 
00060 OfxhPluginBinary::~OfxhPluginBinary()
00061 {}
00062 
00063 }
00064 }
00065 }
00066