CommandT.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // (c) 2006 by Basler Vision Technologies
3 // Section: Vision Components
4 // Project: GenApi
5 // Author: Alexander Happe
6 // $Header$
7 //
8 // License: This file is published under the license of the EMVA GenICam Standard Group.
9 // A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
10 // If for some reason you are missing this file please contact the EMVA or visit the website
11 // (http://www.genicam.org) for a full copy.
12 //
13 // THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
14 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
17 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 // POSSIBILITY OF SUCH DAMAGE.
24 //-----------------------------------------------------------------------------
31 #ifndef GENAPI_COMMANDT_H
32 #define GENAPI_COMMANDT_H
33 
34 #include "GenApi/impl/Log.h"
36 #include "Exception.h"
37 
38 
39 namespace GENAPI_NAMESPACE
40 {
41 
45  template <class Base>
46  class CommandT : public Base
47  {
48  public:
50  virtual void Execute(bool Verify = true)
51  {
52  // a list of callbacks to fire held outside(!) the autolock on the stack(!)
53  std::list<CNodeCallback*> CallbacksToFire;
54  {
56  typename Base::EntryMethodFinalizer E( this, meExecute );
57 
58  GCLOGINFOPUSH( Base::m_pValueLog, "Execute...");
59 
60  if( Verify && !IsWritable( this ) )
61  throw ACCESS_EXCEPTION_NODE("Node is not writable.");
62 
63  {
64  typename Base::PostSetValueFinalizer PostSetValueCaller(this, CallbacksToFire); // dtor calls Base::PostSetValue
65  Base::PreSetValue(); // invalidates all nodes if this is the first call in a chain of SetValue-like calls
66  Base::InternalExecute(Verify);
67  }
68  if (Verify && Base::m_Status != Base::statusBusy)
69  Base::InternalCheckError();
70 
71  GCLOGINFOPOP( Base::m_pValueLog, "...Execute" );
72 
73  // fire callbacks inside the lock
74  std::list<CNodeCallback*>::iterator ptrCallback;
75  for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
76  {
77  (*ptrCallback)->operator ()(cbPostInsideLock);
78  }
79  }
80 
81  // fire callbacks outside the lock
82  std::list<CNodeCallback*>::iterator ptrCallback;
83  for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
84  {
85  (*ptrCallback)->operator ()(cbPostOutsideLock);
86  }
87  }
88 
90  virtual void operator()()
91  {
92  Execute();
93  }
94 
96  virtual bool IsDone(bool Verify = true)
97  {
98  typename Base::EntryMethodFinalizer E( this, meIsDone );
99 
100  bool Result = false;
101  bool FireCallbacks = false;
102 
103 
104  // a list of callbacks to fire held outside(!) the autolock on the stack(!)
105  std::list<CNodeCallback*> CallbacksToFire;
106  {
107  AutoLock l(Base::GetLock());
108 
109  GCLOGINFOPUSH( Base::m_pValueLog, "IsDone...");
110 
111  // Note that this test runs independently of the Verify flag
112  // the tests on readability/writeability are done later in the implementation
113  if( !IsImplemented( this ) )
114  throw ACCESS_EXCEPTION_NODE("Node is not implemented.");
115 
116  Result = Base::InternalIsDone(Verify, FireCallbacks);
117  // InternalCheckError is already performed by InternalIsDone
118 
119 
120  // IsDone is always called directly by the client to we do not need to deal with the bathometer here
121  if(FireCallbacks)
122  {
123  for ( NodePrivateVector_t::iterator it = Base::m_AllTerminalNodes.begin(); it != Base::m_AllTerminalNodes.end(); ++it )
124  {
125  (*it)->CollectCallbacksToFire(CallbacksToFire, true);
126  DeleteDoubleCallbacks(CallbacksToFire);
127  }
128  }
129 
130 #pragma BullseyeCoverage off
131  GCLOGINFOPOP( Base::m_pValueLog, "...IsDone = " + (Result ? GENICAM_NAMESPACE::gcstring("true") : GENICAM_NAMESPACE::gcstring("false") ) );
132 #pragma BullseyeCoverage on
133 
134  // fire callbacks inside the lock
135  if(FireCallbacks)
136  {
137  std::list<CNodeCallback*>::iterator ptrCallback;
138  for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
139  {
140  (*ptrCallback)->operator ()(cbPostInsideLock);
141  }
142  }
143  }
144 
145  // fire callbacks outside the lock
146  if(FireCallbacks)
147  {
148  std::list<CNodeCallback*>::iterator ptrCallback;
149  for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
150  {
151  (*ptrCallback)->operator ()(cbPostOutsideLock);
152  }
153  }
154 
155  return Result;
156  }
157 
158  };
159 
160 }
161 
162 #endif
Implementation of the ICommand interface.
Definition: CommandT.h:46
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT bool Verify
Definition: IBoolean.h:61
virtual bool IsDone(bool Verify=true)
Query whether the command is executed.
Definition: CommandT.h:96
#define ACCESS_EXCEPTION_NODE
Fires a access error exception, e.g. throw ACCESS_ERROR_EXCEPTION("Not everybody") ...
Definition: Exception.h:172
#define GCLOGINFOPUSH(cat,...)
Definition: CLog.h:130
bool IsImplemented(EAccessMode AccessMode)
Tests if implemented.
Definition: INode.h:214
virtual void Execute(bool Verify=true)
Execute the command.
Definition: CommandT.h:50
A string class which is a clone of std::string.
Definition: GCString.h:52
bool IsWritable(EAccessMode AccessMode)
Tests if writable.
Definition: INode.h:196
Definition of interface INodeMapPrivate.
#define GCLOGINFOPOP(cat,...)
Definition: CLog.h:134
Lexical analyzer for CIntSwissKnife.
Definition: Autovector.h:48
callback is fired on leaving the tree inside the lock-guarded area
Definition: NodeCallback.h:48
virtual void operator()()
Execute the command.
Definition: CommandT.h:90
virtual CLock & GetLock() const =0
Returns the lock which guards the node map.
void DeleteDoubleCallbacks(std::list< CNodeCallback * > &CallbackList)
deletes double callbacks from list


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Wed Mar 17 2021 02:48:40