CommandT.h
Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 //  (c) 2006 by Basler Vision Technologies
00003 //  Section: Vision Components
00004 //  Project: GenApi
00005 //  Author:  Alexander Happe
00006 //  $Header$
00007 //
00008 //  License: This file is published under the license of the EMVA GenICam  Standard Group.
00009 //  A text file describing the legal terms is included in  your installation as 'GenICam_license.pdf'.
00010 //  If for some reason you are missing  this file please contact the EMVA or visit the website
00011 //  (http://www.genicam.org) for a full copy.
00012 //
00013 //  THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
00014 //  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00015 //  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00016 //  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD  GROUP
00017 //  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,  SPECIAL,
00018 //  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT  LIMITED TO,
00019 //  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  DATA, OR PROFITS;
00020 //  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  THEORY OF LIABILITY,
00021 //  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)
00022 //  ARISING IN ANY WAY OUT OF THE USE  OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00023 //  POSSIBILITY OF SUCH DAMAGE.
00024 //-----------------------------------------------------------------------------
00031 #ifndef GENAPI_COMMANDT_H
00032 #define GENAPI_COMMANDT_H
00033 
00034 #include "GenApi/impl/Log.h"
00035 #include "GenApi/impl/INodeMapPrivate.h"
00036 #include "Exception.h"
00037 
00038 
00039 namespace GENAPI_NAMESPACE
00040 {
00041 
00045     template <class Base>
00046     class CommandT : public Base
00047     {
00048     public:
00050         virtual void Execute(bool Verify = true)
00051         {
00052             // a list of callbacks to fire held outside(!) the autolock on the stack(!)
00053             std::list<CNodeCallback*> CallbacksToFire;
00054             {
00055                 AutoLock l(Base::GetLock());
00056                 typename Base::EntryMethodFinalizer E( this, meExecute );
00057 
00058                 GCLOGINFOPUSH( Base::m_pValueLog, "Execute...");
00059 
00060                 if( Verify && !IsWritable( this ) )
00061                     throw ACCESS_EXCEPTION_NODE("Node is not writable.");
00062 
00063                 {
00064                     typename Base::PostSetValueFinalizer PostSetValueCaller(this, CallbacksToFire);  // dtor calls Base::PostSetValue
00065 
00066                     Base::PreSetValue(); // invalidates all nodes if this is the first call in a chain of SetValue-like calls
00067 
00068                     Base::InternalExecute(Verify);
00069 
00070                     if( Verify )
00071                         Base::InternalCheckError();
00072 
00073                 }
00074 
00075                 GCLOGINFOPOP( Base::m_pValueLog, "...Execute" );
00076 
00077                 // fire callbacks inside the lock
00078                 std::list<CNodeCallback*>::iterator ptrCallback;
00079                 for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
00080                 {
00081                     (*ptrCallback)->operator ()(cbPostInsideLock);
00082                 }
00083             }
00084 
00085             // fire callbacks outside the lock
00086             std::list<CNodeCallback*>::iterator ptrCallback;
00087             for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
00088             {
00089                 (*ptrCallback)->operator ()(cbPostOutsideLock);
00090             }
00091         }
00092 
00094         virtual void operator()()
00095         {
00096             Execute();
00097         }
00098 
00100         virtual bool IsDone(bool Verify = true)
00101         {
00102             typename Base::EntryMethodFinalizer E( this, meIsDone );
00103 
00104             bool Result = false;
00105             bool FireCallbacks = false;
00106 
00107 
00108             // a list of callbacks to fire held outside(!) the autolock on the stack(!)
00109             std::list<CNodeCallback*> CallbacksToFire;
00110             {
00111                 AutoLock l(Base::GetLock());
00112 
00113                 GCLOGINFOPUSH( Base::m_pValueLog, "IsDone...");
00114 
00115                 // Note that this test runs independently of the Verify flag
00116                 // the tests on readability/writeability are done later in the implementation
00117                 if( !IsImplemented( this ) )
00118                     throw ACCESS_EXCEPTION_NODE("Node is not implemented.");
00119 
00120                 Result = Base::InternalIsDone(Verify, FireCallbacks); 
00121                 // InternalCheckError is already performed by InternalIsDone
00122 
00123 
00124                 // IsDone is always called directly by the client to we do not need to deal with the bathometer here
00125                 if(FireCallbacks)
00126                 {
00127                     for ( NodePrivateVector_t::iterator it = Base::m_AllTerminalNodes.begin(); it != Base::m_AllTerminalNodes.end(); ++it )
00128                     {
00129                         (*it)->CollectCallbacksToFire(CallbacksToFire, true);
00130                         DeleteDoubleCallbacks(CallbacksToFire);
00131                         (*it)->SetInvalid(INodePrivate::simAll);
00132                     }
00133                 }
00134 
00135 #pragma BullseyeCoverage off
00136                 GCLOGINFOPOP( Base::m_pValueLog, "...IsDone = " + (Result ? GENICAM_NAMESPACE::gcstring("true") : GENICAM_NAMESPACE::gcstring("false") ) );
00137 #pragma BullseyeCoverage on
00138 
00139                 // fire callbacks inside the lock
00140                 if(FireCallbacks)
00141                 {
00142                     std::list<CNodeCallback*>::iterator ptrCallback;
00143                     for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
00144                     {
00145                         (*ptrCallback)->operator ()(cbPostInsideLock);
00146                     }
00147                 }
00148             }
00149 
00150             // fire callbacks outside the lock
00151             if(FireCallbacks)
00152             {
00153                 std::list<CNodeCallback*>::iterator ptrCallback;
00154                 for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
00155                 {
00156                     (*ptrCallback)->operator ()(cbPostOutsideLock);
00157                 }
00158             }
00159 
00160             return Result;
00161         }
00162 
00163     };
00164 
00165 }
00166 
00167 #endif


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 18:42:46