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 
66  Base::PreSetValue(); // invalidates all nodes if this is the first call in a chain of SetValue-like calls
67 
68  Base::InternalExecute(Verify);
69 
70  if( Verify )
71  Base::InternalCheckError();
72 
73  }
74 
75  GCLOGINFOPOP( Base::m_pValueLog, "...Execute" );
76 
77  // fire callbacks inside the lock
78  std::list<CNodeCallback*>::iterator ptrCallback;
79  for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
80  {
81  (*ptrCallback)->operator ()(cbPostInsideLock);
82  }
83  }
84 
85  // fire callbacks outside the lock
86  std::list<CNodeCallback*>::iterator ptrCallback;
87  for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
88  {
89  (*ptrCallback)->operator ()(cbPostOutsideLock);
90  }
91  }
92 
94  virtual void operator()()
95  {
96  Execute();
97  }
98 
100  virtual bool IsDone(bool Verify = true)
101  {
102  typename Base::EntryMethodFinalizer E( this, meIsDone );
103 
104  bool Result = false;
105  bool FireCallbacks = false;
106 
107 
108  // a list of callbacks to fire held outside(!) the autolock on the stack(!)
109  std::list<CNodeCallback*> CallbacksToFire;
110  {
111  AutoLock l(Base::GetLock());
112 
113  GCLOGINFOPUSH( Base::m_pValueLog, "IsDone...");
114 
115  // Note that this test runs independently of the Verify flag
116  // the tests on readability/writeability are done later in the implementation
117  if( !IsImplemented( this ) )
118  throw ACCESS_EXCEPTION_NODE("Node is not implemented.");
119 
120  Result = Base::InternalIsDone(Verify, FireCallbacks);
121  // InternalCheckError is already performed by InternalIsDone
122 
123 
124  // IsDone is always called directly by the client to we do not need to deal with the bathometer here
125  if(FireCallbacks)
126  {
127  for ( NodePrivateVector_t::iterator it = Base::m_AllTerminalNodes.begin(); it != Base::m_AllTerminalNodes.end(); ++it )
128  {
129  (*it)->CollectCallbacksToFire(CallbacksToFire, true);
130  DeleteDoubleCallbacks(CallbacksToFire);
131  (*it)->SetInvalid(INodePrivate::simAll);
132  }
133  }
134 
135 #pragma BullseyeCoverage off
136  GCLOGINFOPOP( Base::m_pValueLog, "...IsDone = " + (Result ? GENICAM_NAMESPACE::gcstring("true") : GENICAM_NAMESPACE::gcstring("false") ) );
137 #pragma BullseyeCoverage on
138 
139  // fire callbacks inside the lock
140  if(FireCallbacks)
141  {
142  std::list<CNodeCallback*>::iterator ptrCallback;
143  for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
144  {
145  (*ptrCallback)->operator ()(cbPostInsideLock);
146  }
147  }
148  }
149 
150  // fire callbacks outside the lock
151  if(FireCallbacks)
152  {
153  std::list<CNodeCallback*>::iterator ptrCallback;
154  for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
155  {
156  (*ptrCallback)->operator ()(cbPostOutsideLock);
157  }
158  }
159 
160  return Result;
161  }
162 
163  };
164 
165 }
166 
167 #endif
Implementation of the ICommand interface.
Definition: CommandT.h:46
virtual bool IsDone(bool Verify=true)
Query whether the command is executed.
Definition: CommandT.h:100
#define ACCESS_EXCEPTION_NODE
Fires a access error exception, e.g. throw ACCESS_ERROR_EXCEPTION("Not everybody") ...
Definition: Exception.h:172
Invalidate the node and all of its dependents.
Definition: INodePrivate.h:94
interface GENAPI_DECL_ABSTRACT bool Verify
Definition: IBoolean.h:61
#define GCLOGINFOPUSH(cat,...)
Definition: CLog.h:163
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:164
Part of the generic device API.
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:94
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 Thu Jun 6 2019 19:10:53