TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/host/ofx/OfxhProgressSuite.cpp
Go to the documentation of this file.
00001 #include "OfxhProgressSuite.hpp"
00002 #include "OfxhIObject.hpp"
00003 #include "OfxhProgress.hpp"
00004 #include "OfxhException.hpp"
00005 
00006 namespace tuttle {
00007 namespace host {
00008 namespace ofx {
00009 
00010 namespace {
00011 
00012 OfxStatus ProgressStart( void*       effectInstance,
00013                          const char* label )
00014 {
00015         try
00016         {
00017                 OfxhIProgress* me = dynamic_cast<OfxhIProgress*>( reinterpret_cast<OfxhIObject*>( effectInstance ) );
00018                 if( !me )
00019                         return kOfxStatErrBadHandle;
00020 
00021                 me->progressStart( label );
00022 
00023                 return kOfxStatOK;
00024         }
00025         catch( OfxhException& e )
00026         {
00027                 return e.getStatus();
00028         }
00029         catch(... )
00030         {
00031                 return kOfxStatErrUnknown;
00032         }
00033 }
00034 
00035 /**
00036  * finish progressing
00037  */
00038 OfxStatus ProgressEnd( void* effectInstance )
00039 {
00040         try
00041         {
00042                 OfxhIProgress* me = dynamic_cast<OfxhIProgress*>( reinterpret_cast<OfxhIObject*>( effectInstance ) );
00043                 if( !me )
00044                         return kOfxStatErrBadHandle;
00045 
00046                 me->progressEnd();
00047 
00048                 return kOfxStatOK;
00049         }
00050         catch( OfxhException& e )
00051         {
00052                 return e.getStatus();
00053         }
00054         catch(... )
00055         {
00056                 return kOfxStatErrUnknown;
00057         }
00058 }
00059 
00060 /**
00061  * update progressing
00062  */
00063 OfxStatus ProgressUpdate( void* effectInstance, double progress )
00064 {
00065         try
00066         {
00067                 OfxhIProgress* me = dynamic_cast<OfxhIProgress*>( reinterpret_cast<OfxhIObject*>( effectInstance ) );
00068                 if( !me )
00069                         return kOfxStatErrBadHandle;
00070 
00071                 const bool v = me->progressUpdate( progress );
00072 
00073                 // if v abort the process
00074                 return v ? kOfxStatReplyNo : kOfxStatOK;
00075         }
00076         catch( OfxhException& e )
00077         {
00078                 return e.getStatus();
00079         }
00080         catch(... )
00081         {
00082                 return kOfxStatErrUnknown;
00083         }
00084 }
00085 
00086 /**
00087  * our progress suite
00088  */
00089 struct OfxProgressSuiteV1 gProgressSuite =
00090 {
00091         ProgressStart,
00092         ProgressUpdate,
00093         ProgressEnd
00094 };
00095 
00096 }
00097 
00098 void* getProgressSuite( const int version )
00099 {
00100         if( version == 1 )
00101                 return &gProgressSuite;
00102         return NULL;
00103 }
00104 
00105 }
00106 }
00107 }
00108