NodeCallback.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: Hartmut Nebelung
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 //-----------------------------------------------------------------------------
37 #ifndef GENAPI_NODECALLBACK_H
38 #define GENAPI_NODECALLBACK_H
39 #include <GenApi/INode.h>
40 
41 namespace GENAPI_NAMESPACE
42 {
43 
45  typedef enum _ECallbackType
46  {
49  } ECallbackType;
50 
56  {
57  public:
58  CNodeCallback( INode *pNode, ECallbackType CallbackType ) :
59  m_pNode(pNode),
60  m_CallbackType( CallbackType )
61  {}
62 
64  virtual ~CNodeCallback()
65  {};
66 
68  virtual void operator()( ECallbackType CallbackType ) const = 0;
69 
71  virtual void Destroy() = 0;
72 
75  {
76  return m_pNode;
77  }
78 
79  protected:
82 
85  };
86 
87  /***************************************************************************/
88  // C Functions as callbacks
89  /***************************************************************************/
90 
95  template <class Function>
97  {
98  public:
100  Function_NodeCallback( INode *pNode, const Function& function, ECallbackType CallbackType ) :
101  CNodeCallback( pNode, CallbackType ),
102  m_pFunction( function )
103  {}
104 
106  virtual void operator()( ECallbackType CallbackType ) const
107  {
108  if (m_pFunction && m_CallbackType == CallbackType)
109  m_pFunction( m_pNode );
110  }
111 
113  virtual void Destroy()
114  {
115  delete this;
116  }
117 
118  private:
120  const Function m_pFunction;
121 
124  };
125 
126  /*-----------------------------------------------------------------------------*/
127 
132  template <class Function>
133  CNodeCallback *make_NodeCallback( INode *pNode, Function function, ECallbackType CallbackType )
134  {
135  return static_cast<CNodeCallback*>( new Function_NodeCallback<Function>(pNode, function, CallbackType) );
136  }
137 
138  /*-----------------------------------------------------------------------------*/
139 
140 
145  template<class Function>
146  intptr_t Register( INode* pNode, Function f, ECallbackType CallbackType = cbPostInsideLock )
147  {
148  CNodeCallback *pCallback(make_NodeCallback(pNode, f, CallbackType));
149  return pNode->RegisterCallback(pCallback);
150  }
151 
152 
153  /***************************************************************************/
154  // C++ Member functions as callbacks
155  /***************************************************************************/
156 
161  template <class Client, class Member>
163  {
164  public:
166  typedef void (Client::*PMEMBERFUNC)(INode*);
167 
169  Member_NodeCallback( INode *pNode, Client& client, Member member, ECallbackType CallbackType ) :
170  CNodeCallback( pNode, CallbackType ),
171  m_Client(client),
172  m_pMemberFunc(member)
173  {}
174 
176  virtual void operator()( ECallbackType CallbackType ) const
177  {
178  if (m_pMemberFunc && m_CallbackType == CallbackType)
179  (m_Client.*m_pMemberFunc)( m_pNode );
180  }
181 
183  virtual void Destroy()
184  {
185  delete this;
186  }
187 
188  private:
190  Client& m_Client;
191 
193  PMEMBERFUNC m_pMemberFunc;
194 
197  };
198 
199  /*-----------------------------------------------------------------------------*/
200 
205  template <class Client, class Member>
206  CNodeCallback *make_NodeCallback( INode *pNode, Client& client, Member member, ECallbackType CallbackType )
207  {
208  return static_cast<CNodeCallback*>( new Member_NodeCallback<Client,Member>(pNode, client, member, CallbackType) );
209  }
210 
211  /*-----------------------------------------------------------------------------*/
212 
217  template<class Client, class Member>
218  intptr_t Register( INode* pNode, Client &c, Member m, ECallbackType CallbackType = cbPostInsideLock )
219  {
220  CNodeCallback *pCallback(make_NodeCallback(pNode, c, m, CallbackType));
221  return pNode->RegisterCallback(pCallback);
222  }
223 
224 
226  // definition in Node.cpp
228 
229 }
230 
231 #endif // GENAPI_NODECALLBACK_H
_ECallbackType
the type of callback
Definition: NodeCallback.h:45
virtual void Destroy()
destroys the object
Definition: NodeCallback.h:183
Definition of interface INode and types NodeList_t and CallbackHandleType:
virtual void operator=(bool Value)
Set node value.
Definition: IBoolean.h:64
ECallbackType m_CallbackType
the type of the callback
Definition: NodeCallback.h:84
virtual void Destroy()
destroys the object
Definition: NodeCallback.h:113
virtual void operator()(ECallbackType CallbackType) const
execute operation: call the function
Definition: NodeCallback.h:106
PMEMBERFUNC m_pMemberFunc
The method to call.
Definition: NodeCallback.h:193
callback body instance for INode pointers
Definition: NodeCallback.h:55
#define GENAPI_DECL
Definition: GenApiDll.h:55
INode * GetNode()
returns the node the callback is registered to
Definition: NodeCallback.h:74
Client & m_Client
The object the method function belongs to.
Definition: NodeCallback.h:190
Member_NodeCallback(INode *pNode, Client &client, Member member, ECallbackType CallbackType)
Constructor.
Definition: NodeCallback.h:169
enum GENAPI_NAMESPACE::_ECallbackType ECallbackType
the type of callback
INode * m_pNode
the node were the callback is installed
Definition: NodeCallback.h:81
CNodeCallback(INode *pNode, ECallbackType CallbackType)
Definition: NodeCallback.h:58
const Function m_pFunction
the callback function
Definition: NodeCallback.h:120
Container for a member function pointer.
Definition: NodeCallback.h:162
virtual void operator()(ECallbackType CallbackType) const =0
fires the callback if the type is right
intptr_t CallbackHandleType
the callback handle for nodes
Definition: INode.h:58
virtual void Destroy()=0
destroys the object
intptr_t Register(INode *pNode, Function f, ECallbackType CallbackType=cbPostInsideLock)
Register a C-function as a callback.
Definition: NodeCallback.h:146
GENAPI_DECL void Deregister(GENAPI_NAMESPACE::CallbackHandleType pCallbackInfo)
Unregistering callback by handle.
Function_NodeCallback(INode *pNode, const Function &function, ECallbackType CallbackType)
Constructor.
Definition: NodeCallback.h:100
virtual void operator()(ECallbackType CallbackType) const
execute operation
Definition: NodeCallback.h:176
CNodeCallback * make_NodeCallback(INode *pNode, Function function, ECallbackType CallbackType)
make a new callback object for C functions
Definition: NodeCallback.h:133
interface GENAPI_DECL_ABSTRACT INode
Interface common to all nodes.
Definition: INode.h:60
Container for a function pointer.
Definition: NodeCallback.h:96
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 ~CNodeCallback()
virtual destructor
Definition: NodeCallback.h:64


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 19:10:54