TuttleOFX
1
|
00001 #ifndef OFXH_PLUGIN_HPP 00002 #define OFXH_PLUGIN_HPP 00003 00004 #include "OfxhPluginDesc.hpp" 00005 #include "OfxhPluginAPICache.hpp" 00006 00007 namespace tuttle { 00008 namespace host { 00009 namespace ofx { 00010 00011 class OfxhPluginBinary; 00012 00013 /** 00014 * class that we use to manipulate a plugin. 00015 * 00016 * Owned by the PluginBinary it lives inside. 00017 * Plugins can only be pass about either by pointer or reference. 00018 */ 00019 class OfxhPlugin : public OfxhPluginDesc 00020 { 00021 public: 00022 typedef OfxhPlugin This; 00023 00024 private: 00025 OfxhPlugin( const This& ); ///< hidden 00026 OfxhPlugin& operator=( const This& ); ///< hidden 00027 00028 protected: 00029 OfxhPluginBinary* _binary; ///< the file I live inside 00030 int _index; ///< where I live inside that file 00031 bool _isSupported; ///< Indicates if the plugin can be loaded (actions: Load and Describe) 00032 00033 public: 00034 OfxhPlugin() 00035 : _binary( NULL ) 00036 , _index( -1 ) 00037 , _isSupported(false) 00038 {} 00039 00040 /** 00041 * construct this based on the struct returned by the getNthPlugin() in the binary 00042 */ 00043 OfxhPlugin( OfxhPluginBinary& bin, int idx, OfxPlugin& o ) : OfxhPluginDesc( o ) 00044 , _binary( &bin ) 00045 , _index( idx ) 00046 , _isSupported(false) 00047 {} 00048 00049 /** 00050 * construct me from the cache 00051 */ 00052 OfxhPlugin( OfxhPluginBinary& bin, int idx, const std::string& api, 00053 int apiVersion, const std::string& identifier, 00054 const std::string& rawIdentifier, 00055 int majorVersion, int minorVersion ) 00056 : OfxhPluginDesc( api, apiVersion, identifier, rawIdentifier, majorVersion, minorVersion ) 00057 , _binary( &bin ) 00058 , _index( idx ) 00059 , _isSupported(false) 00060 {} 00061 00062 virtual ~OfxhPlugin() = 0; 00063 00064 bool operator==( const This& other ) const; 00065 bool operator!=( const This& other ) const { return !This::operator==( other ); } 00066 00067 void setBinary( OfxhPluginBinary& binary ) { _binary = &binary; } 00068 OfxhPluginBinary& getBinary() { return *_binary; } 00069 const OfxhPluginBinary& getBinary() const { return *_binary; } 00070 00071 void setIsSupported( bool isSupported ) 00072 { 00073 _isSupported = isSupported; 00074 } 00075 bool isSupported() const 00076 { 00077 return _isSupported; 00078 } 00079 00080 int getIndex() const 00081 { 00082 return _index; 00083 } 00084 00085 bool trumps( OfxhPlugin& other ) 00086 { 00087 int myMajor = getVersionMajor(); 00088 int theirMajor = other.getVersionMajor(); 00089 00090 int myMinor = getVersionMinor(); 00091 int theirMinor = other.getVersionMinor(); 00092 00093 if( myMajor > theirMajor ) 00094 { 00095 return true; 00096 } 00097 00098 if( myMajor == theirMajor && myMinor > theirMinor ) 00099 { 00100 return true; 00101 } 00102 00103 return false; 00104 } 00105 00106 #ifndef SWIG 00107 virtual void setApiHandler( APICache::OfxhPluginAPICacheI& ) = 0; 00108 virtual APICache::OfxhPluginAPICacheI& getApiHandler() = 0; 00109 virtual const APICache::OfxhPluginAPICacheI& getApiHandler() const = 0; 00110 00111 private: 00112 friend class boost::serialization::access; 00113 template<class Archive> 00114 void serialize( Archive& ar, const unsigned int version ) 00115 { 00116 ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP( OfxhPluginDesc ); 00117 // ar & BOOST_SERIALIZATION_NVP(_binary); // just a link, don't save 00118 ar& BOOST_SERIALIZATION_NVP( _index ); 00119 ar& BOOST_SERIALIZATION_NVP( _isSupported ); 00120 } 00121 00122 #endif 00123 }; 00124 00125 } 00126 } 00127 } 00128 00129 // BOOST_SERIALIZATION_ASSUME_ABSTRACT(tuttle::host::ofx::OfxhPlugin) 00130 00131 #endif 00132