TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/host/ofx/OfxhPluginLoadGuard.cpp
Go to the documentation of this file.
00001 #include "OfxhPluginLoadGuard.hpp"
00002 #include "OfxhPlugin.hpp"
00003 #include "OfxhPluginBinary.hpp"
00004 
00005 #include <boost/lexical_cast.hpp>
00006 
00007 namespace tuttle {
00008 namespace host {
00009 namespace ofx {
00010 
00011 typedef OfxPlugin*( *OfxGetPluginType )( int );
00012 
00013 OfxhPluginLoadGuard::OfxhPluginLoadGuard( OfxhPlugin& plugin, OfxhHost& host )
00014         : _plugin( &plugin )
00015         , _pluginBinary( &plugin.getBinary() )
00016         , _rawOfxPlugin( 0 )
00017 {
00018         _pluginBinary->_binary.ref();
00019         OfxGetPluginType getPlugin_func = (OfxGetPluginType)_pluginBinary->_binary.findSymbol( "OfxGetPlugin" );
00020         _rawOfxPlugin = getPlugin_func( _plugin->getIndex() );
00021 
00022         if( !_rawOfxPlugin )
00023         {
00024                 // We throw inside the constructor, so the destructor will not be called.
00025                 _pluginBinary->_binary.unref();
00026                 
00027                 BOOST_THROW_EXCEPTION( exception::Data()
00028                     << exception::user( "Loading plugin failed." )
00029                     << exception::dev() + "OfxGetPlugin call failed at index " + _plugin->getIndex() + "."
00030                     << exception::filename( _pluginBinary->getBundlePath() ) );
00031         }
00032         _rawOfxPlugin->setHost( host.getHandle() );
00033 }
00034 
00035 OfxhPluginLoadGuard::~OfxhPluginLoadGuard()
00036 {
00037         _pluginBinary->_binary.unref();
00038 }
00039 
00040 }
00041 }
00042 }
00043