TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/host/ofx/OfxhImageEffectPlugin.hpp
Go to the documentation of this file.
00001 /*
00002  * Software License :
00003  *
00004  * Copyright (c) 2007-2009, The Open Effects Association Ltd.  All Rights Reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *
00009  * Redistributions of source code must retain the above copyright notice,
00010  *    this list of conditions and the following disclaimer.
00011  * Redistributions in binary form must reproduce the above copyright notice,
00012  *    this list of conditions and the following disclaimer in the documentation
00013  *    and/or other materials provided with the distribution.
00014  * Neither the name The Open Effects Association Ltd, nor the names of its
00015  *    contributors may be used to endorse or promote products derived from this
00016  *    software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00019  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00020  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00021  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
00022  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00023  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00024  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00025  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00026  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00027  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #ifndef _TUTTLE_HOST_OFX_IMAGEEFFECT_API_HPP_
00031 #define _TUTTLE_HOST_OFX_IMAGEEFFECT_API_HPP_
00032 
00033 #include "OfxhImageEffectHost.hpp"
00034 #include "OfxhImageEffectNode.hpp"
00035 #include "OfxhPluginLoadGuard.hpp"
00036 #include "OfxhPluginCache.hpp"
00037 #include "OfxhHost.hpp"
00038 
00039 #include <ofxCore.h>
00040 #include <ofxImageEffect.h>
00041 
00042 #include <boost/scoped_ptr.hpp>
00043 #include <boost/ptr_container/serialize_ptr_map.hpp>
00044 
00045 #include <boost/serialization/extended_type_info.hpp>
00046 #include <boost/serialization/serialization.hpp>
00047 #include <boost/serialization/nvp.hpp>
00048 #include <boost/serialization/export.hpp>
00049 #include <boost/serialization/scoped_ptr.hpp>
00050 
00051 #include <string>
00052 #include <set>
00053 #include <memory>
00054 
00055 namespace tuttle {
00056 namespace host {
00057 namespace ofx {
00058 namespace imageEffect {
00059 
00060 class OfxhImageEffectPluginCache;
00061 
00062 /**
00063  * subclass of Plugin representing an ImageEffect plugin.
00064  * used to store API-specific data
00065  */
00066 class OfxhImageEffectPlugin : public OfxhPlugin
00067 {
00068 public:
00069         typedef OfxhImageEffectPlugin This;
00070         typedef boost::ptr_map<std::string, OfxhImageEffectNodeDescriptor> ContextMap;
00071         typedef std::set<std::string> ContextSet;
00072 
00073 private:
00074         OfxhImageEffectPluginCache* _imageEffectPluginCache;
00075 
00076         /// map to store contexts in
00077         ContextMap _contexts;
00078         ContextSet _knownContexts;
00079         boost::scoped_ptr<OfxhPluginLoadGuard> _pluginLoadGuard;
00080 
00081         // this comes off Descriptor's property set after a describe
00082         // context independent
00083         /// @todo tuttle: ???
00084         boost::scoped_ptr<OfxhImageEffectNodeDescriptor> _baseDescriptor;     ///< NEEDS TO BE MADE WITH A FACTORY FUNCTION ON THE HOST!!!!!!
00085 
00086 private:
00087         OfxhImageEffectPlugin();
00088 
00089 public:
00090         OfxhImageEffectPlugin( OfxhImageEffectPluginCache& imageEffectPluginCache, OfxhPluginBinary& pluginBinary, int pluginIndex, OfxPlugin& plugin );
00091 
00092         OfxhImageEffectPlugin( OfxhImageEffectPluginCache& imageEffectPluginCache,
00093                                OfxhPluginBinary&           pluginBinary,
00094                                int                         pluginIndex,
00095                                const std::string&          api,
00096                                int                         apiVersion,
00097                                const std::string&          pluginId,
00098                                const std::string&          rawId,
00099                                int                         pluginMajorVersion,
00100                                int                         pluginMinorVersion );
00101 
00102         ~OfxhImageEffectPlugin();
00103 
00104         bool operator==( const OfxhImageEffectPlugin& other ) const;
00105         bool operator!=( const OfxhImageEffectPlugin& other ) const { return !This::operator==( other ); }
00106 
00107         void setApiHandler( OfxhImageEffectPluginCache& api ) { _imageEffectPluginCache = &api; }
00108         void setApiHandler( APICache::OfxhPluginAPICacheI& api );
00109 
00110         /// @return the API handler this plugin was constructed by
00111         APICache::OfxhPluginAPICacheI&       getApiHandler();
00112         const APICache::OfxhPluginAPICacheI& getApiHandler() const;
00113 
00114         /// @brief get the base image effect descriptor
00115         OfxhImageEffectNodeDescriptor& getDescriptor();
00116 
00117         /// @brief get the base image effect descriptor, const version
00118         const OfxhImageEffectNodeDescriptor& getDescriptor() const;
00119 
00120         /// @brief get the image effect descriptor for the context
00121         OfxhImageEffectNodeDescriptor& getDescriptorInContext( const std::string& context );
00122 
00123         #ifndef SWIG
00124         void addContext( const std::string& context );
00125         void addContext( const std::string& context, OfxhImageEffectNodeDescriptor* ied );
00126         #endif
00127 
00128         void              initContexts();
00129         const ContextSet& getContexts() const;
00130         bool              supportsContext( const std::string& context ) const;
00131 
00132         OfxhPluginLoadGuard*       getPluginLoadGuardPtr()       { return _pluginLoadGuard.get(); }
00133         const OfxhPluginLoadGuard* getPluginLoadGuardPtr() const { return _pluginLoadGuard.get(); }
00134 
00135         void loadAndDescribeActions();
00136 
00137         void unloadAction();
00138 
00139         /**
00140          * @brief this is called to make an instance of the effect
00141          *  the client data ptr is what is passed back to the client creation function
00142          */
00143         imageEffect::OfxhImageEffectNode* createInstance( const std::string& context );
00144 
00145 private:
00146         OfxhImageEffectNodeDescriptor& describeInContextAction( const std::string& context );
00147 
00148 private:
00149         friend class boost::serialization::access;
00150         template<class Archive>
00151         void serialize( Archive& ar, const unsigned int version )
00152         {
00153                 ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP( OfxhPlugin );
00154                 ar& BOOST_SERIALIZATION_NVP( _baseDescriptor );
00155                 //ar & BOOST_SERIALIZATION_NVP(_pluginLoadGuard); // don't save this
00156                 ar& BOOST_SERIALIZATION_NVP( _contexts );
00157         }
00158 };
00159 
00160 }
00161 }
00162 }
00163 }
00164 
00165 #ifndef SWIG
00166 BOOST_CLASS_EXPORT_KEY( tuttle::host::ofx::imageEffect::OfxhImageEffectPlugin )
00167 #endif
00168 
00169 #endif
00170