TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/host/ofx/OfxhPropertySuite.cpp
Go to the documentation of this file.
00001 #include "OfxhPropertySuite.hpp"
00002 #include "property/OfxhSet.hpp"
00003 
00004 //#define DEBUG_PROPERTIES true
00005 
00006 namespace tuttle {
00007 namespace host {
00008 namespace ofx {
00009 namespace property {
00010 
00011 namespace {
00012 
00013 /// static functions for the suite
00014 template<class T>
00015 OfxStatus propSet( OfxPropertySetHandle properties,
00016                    const char*          property,
00017                    int                  index,
00018                    typename T::APIType  value )
00019 {
00020         #ifdef DEBUG_PROPERTIES
00021         std::cout << "propSet - " << properties << " " << property << "[" << index << "] = " << value << " \n";
00022         #endif
00023         try
00024         {
00025                 OfxhSet* thisSet = reinterpret_cast<OfxhSet*>( properties );
00026                 if( !thisSet->verifyMagic() )
00027                         return kOfxStatErrBadHandle;
00028 
00029                 OfxhPropertyTemplate<T>& prop = thisSet->fetchLocalTypedProperty<OfxhPropertyTemplate<T> >( property );
00030 
00031                 if( prop.getPluginReadOnly() )
00032                 {
00033                         TUTTLE_LOG_ERROR( "Plugin is trying to set a property (" << property << " at index " << index << ") which is read-only." );
00034                         return kOfxStatErrValue;
00035                 }
00036 
00037                 prop.setValue( value, index, eModifiedByPlugin );
00038 
00039                 //              #ifdef DEBUG_PROPERTIES
00040                 //              std::cout << "propSet error !!! returning status kOfxStatErrUnknown" << std::endl;
00041                 //              #endif
00042                 //              return kOfxStatErrUnknown;
00043         }
00044         catch( OfxhException& e )
00045         {
00046                 #ifdef DEBUG_PROPERTIES
00047                 std::cout << " returning status " << e.getStatus() << "\n";
00048                 #endif
00049                 return e.getStatus();
00050         }
00051         catch(... )
00052         {
00053                 return kOfxStatErrUnknown;
00054         }
00055         return kOfxStatOK;
00056 }
00057 
00058 /// static functions for the suite
00059 
00060 template<class T>
00061 OfxStatus propSetN( OfxPropertySetHandle properties,
00062                     const char*          property,
00063                     int                  count,
00064                     typename T::APIType* values )
00065 {
00066         #ifdef DEBUG_PROPERTIES
00067         std::cout << "propSetN - " << properties << " " << property << " \n";
00068         #endif
00069 
00070         try
00071         {
00072                 OfxhSet* thisSet = reinterpret_cast<OfxhSet*>( properties );
00073                 if( !thisSet->verifyMagic() )
00074                         return kOfxStatErrBadHandle;
00075 
00076                 OfxhPropertyTemplate<T>& prop = thisSet->fetchLocalTypedProperty<OfxhPropertyTemplate<T> >( property );
00077 
00078                 if( prop.getPluginReadOnly() )
00079                 {
00080                         TUTTLE_LOG_ERROR( "Plugin is trying to set property " << property << " of size " << count << ") which is read-only." );
00081                         return kOfxStatErrValue;
00082                 }
00083 
00084                 prop.setValueN( values, count, eModifiedByPlugin );
00085         }
00086         catch( OfxhException& e )
00087         {
00088                 return e.getStatus();
00089         }
00090         catch(... )
00091         {
00092                 return kOfxStatErrUnknown;
00093         }
00094         return kOfxStatOK;
00095 }
00096 
00097 /// static functions for the suite
00098 
00099 template<class T>
00100 OfxStatus propGet( OfxPropertySetHandle          properties,
00101                    const char*                   property,
00102                    int                           index,
00103                    typename T::APITypeConstless* value )
00104 {
00105         #ifdef DEBUG_PROPERTIES
00106         std::cout << "propGet - " << properties << " " << property << " = ...";
00107         #endif
00108 
00109         try
00110         {
00111                 OfxhSet* thisSet = reinterpret_cast<OfxhSet*>( properties );
00112                 if( !thisSet->verifyMagic() )
00113                         return kOfxStatErrBadHandle;
00114                 *value = thisSet->fetchTypedProperty<OfxhPropertyTemplate<T> >( property ).getAPIConstlessValue( index );
00115                 //*value = castAwayConst( castToAPIType( prop->getValue( index ) ) );
00116 
00117                 #ifdef DEBUG_PROPERTIES
00118                 std::cout << *value << "\n";
00119                 #endif
00120         }
00121         catch( OfxhException& e )
00122         {
00123 
00124                 #ifdef DEBUG_PROPERTIES
00125                 std::cout <<  "dpxreader /datas/tmp/master32secsh01.####.dpx  // jpegwriter /datas/tmp/test.####.jpg" << std::endl;
00126 
00127                 #endif
00128                 return e.getStatus();
00129         }
00130         catch(... )
00131         {
00132                 return kOfxStatErrUnknown;
00133         }
00134         return kOfxStatOK;
00135 }
00136 
00137 ///@todo tuttle: remove this !
00138 inline int* castToConst( int* s )
00139 {
00140         return s;
00141 }
00142 
00143 inline double* castToConst( double* s )
00144 {
00145         return s;
00146 }
00147 
00148 inline void* * castToConst( void** s )
00149 {
00150         return s;
00151 }
00152 
00153 ///@todo tuttle: remove this !
00154 inline const char* * castToConst( char** s )
00155 {
00156         return const_cast<const char**>( s );
00157 }
00158 
00159 /// static functions for the suite
00160 
00161 template<class T>
00162 OfxStatus propGetN( OfxPropertySetHandle          properties,
00163                     const char*                   property,
00164                     int                           count,
00165                     typename T::APITypeConstless* values )
00166 {
00167         try
00168         {
00169                 OfxhSet* thisSet = reinterpret_cast<OfxhSet*>( properties );
00170                 if( !thisSet->verifyMagic() )
00171                         return kOfxStatErrBadHandle;
00172                 thisSet->fetchTypedProperty<OfxhPropertyTemplate<T> >( property ).getValueN( castToConst( values ), count );
00173         }
00174         catch( OfxhException& e )
00175         {
00176                 return e.getStatus();
00177         }
00178         catch(... )
00179         {
00180                 return kOfxStatErrUnknown;
00181         }
00182         return kOfxStatOK;
00183 }
00184 
00185 /**
00186  * static functions for the suite
00187  */
00188 OfxStatus propReset( OfxPropertySetHandle properties, const char* property )
00189 {
00190         try
00191         {
00192                 OfxhSet* thisSet = reinterpret_cast<OfxhSet*>( properties );
00193                 if( !thisSet->verifyMagic() )
00194                         return kOfxStatErrBadHandle;
00195 
00196                 OfxhProperty& prop = thisSet->fetchLocalProperty( property );
00197 
00198                 //              if( prop.getPluginReadOnly() )
00199                 //              {
00200                 //                      TUTTLE_LOG_ERROR("Plugin is trying to reset a read-only property " << property );
00201                 //                      return kOfxStatErrValue;
00202                 //              }
00203 
00204                 prop.reset();
00205 
00206         }
00207         catch( OfxhException& e )
00208         {
00209                 return e.getStatus();
00210         }
00211         catch(... )
00212         {
00213                 return kOfxStatErrUnknown;
00214         }
00215         return kOfxStatOK;
00216 }
00217 
00218 /**
00219  * static functions for the suite
00220  */
00221 OfxStatus propGetDimension( OfxPropertySetHandle properties, const char* property, int* count )
00222 {
00223         try
00224         {
00225                 OfxhSet* thisSet = reinterpret_cast<OfxhSet*>( properties );
00226                 *count = thisSet->fetchProperty( property ).getDimension();
00227         }
00228         catch( OfxhException& e )
00229         {
00230                 return e.getStatus();
00231         }
00232         catch(... )
00233         {
00234                 return kOfxStatErrUnknown;
00235         }
00236         return kOfxStatOK;
00237 }
00238 
00239 /**
00240  * the actual suite that is passed across the API to manage properties
00241  */
00242 struct OfxPropertySuiteV1 gSuite =
00243 {
00244         propSet<OfxhPointerValue>,
00245         propSet<OfxhStringValue>,
00246         propSet<OfxhDoubleValue>,
00247         propSet<OfxhIntValue>,
00248         propSetN<OfxhPointerValue>,
00249         propSetN<OfxhStringValue>,
00250         propSetN<OfxhDoubleValue>,
00251         propSetN<OfxhIntValue>,
00252         propGet<OfxhPointerValue>,
00253         propGet<OfxhStringValue>,
00254         propGet<OfxhDoubleValue>,
00255         propGet<OfxhIntValue>,
00256         propGetN<OfxhPointerValue>,
00257         propGetN<OfxhStringValue>,
00258         propGetN<OfxhDoubleValue>,
00259         propGetN<OfxhIntValue>,
00260         propReset,
00261         propGetDimension
00262 };
00263 
00264 }
00265 
00266 /// return the OFX function suite that manages properties
00267 void* getPropertySuite( const int version )
00268 {
00269         if( version == 1 )
00270                 return static_cast<void*>( &gSuite );
00271         return NULL;
00272 }
00273 
00274 }
00275 }
00276 }
00277 }
00278