Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00037 #ifndef GENAPI_NODECALLBACK_H
00038 #define GENAPI_NODECALLBACK_H
00039 #include <GenApi/INode.h>
00040
00041 namespace GENAPI_NAMESPACE
00042 {
00043
00045 typedef enum _ECallbackType
00046 {
00047 cbPostInsideLock = 1,
00048 cbPostOutsideLock = 2
00049 } ECallbackType;
00050
00055 class CNodeCallback
00056 {
00057 public:
00058 CNodeCallback( INode *pNode, ECallbackType CallbackType ) :
00059 m_pNode(pNode),
00060 m_CallbackType( CallbackType )
00061 {}
00062
00064 virtual ~CNodeCallback()
00065 {};
00066
00068 virtual void operator()( ECallbackType CallbackType ) const = 0;
00069
00071 virtual void Destroy() = 0;
00072
00074 INode* GetNode()
00075 {
00076 return m_pNode;
00077 }
00078
00079 protected:
00081 INode *m_pNode;
00082
00084 ECallbackType m_CallbackType;
00085 };
00086
00087
00088
00089
00090
00095 template <class Function>
00096 class Function_NodeCallback : public CNodeCallback
00097 {
00098 public:
00100 Function_NodeCallback( INode *pNode, const Function& function, ECallbackType CallbackType ) :
00101 CNodeCallback( pNode, CallbackType ),
00102 m_pFunction( function )
00103 {}
00104
00106 virtual void operator()( ECallbackType CallbackType ) const
00107 {
00108 if (m_pFunction && m_CallbackType == CallbackType)
00109 m_pFunction( m_pNode );
00110 }
00111
00113 virtual void Destroy()
00114 {
00115 delete this;
00116 }
00117
00118 private:
00120 const Function m_pFunction;
00121
00123 Function_NodeCallback& operator=(Function_NodeCallback&);
00124 };
00125
00126
00127
00132 template <class Function>
00133 CNodeCallback *make_NodeCallback( INode *pNode, Function function, ECallbackType CallbackType )
00134 {
00135 return static_cast<CNodeCallback*>( new Function_NodeCallback<Function>(pNode, function, CallbackType) );
00136 }
00137
00138
00139
00140
00145 template<class Function>
00146 intptr_t Register( INode* pNode, Function f, ECallbackType CallbackType = cbPostInsideLock )
00147 {
00148 CNodeCallback *pCallback(make_NodeCallback(pNode, f, CallbackType));
00149 return pNode->RegisterCallback(pCallback);
00150 }
00151
00152
00153
00154
00155
00156
00161 template <class Client, class Member>
00162 class Member_NodeCallback : public CNodeCallback
00163 {
00164 public:
00166 typedef void (Client::*PMEMBERFUNC)(INode*);
00167
00169 Member_NodeCallback( INode *pNode, Client& client, Member member, ECallbackType CallbackType ) :
00170 CNodeCallback( pNode, CallbackType ),
00171 m_Client(client),
00172 m_pMemberFunc(member)
00173 {}
00174
00176 virtual void operator()( ECallbackType CallbackType ) const
00177 {
00178 if (m_pMemberFunc && m_CallbackType == CallbackType)
00179 (m_Client.*m_pMemberFunc)( m_pNode );
00180 }
00181
00183 virtual void Destroy()
00184 {
00185 delete this;
00186 }
00187
00188 private:
00190 Client& m_Client;
00191
00193 PMEMBERFUNC m_pMemberFunc;
00194
00196 Member_NodeCallback& operator=(Member_NodeCallback&);
00197 };
00198
00199
00200
00205 template <class Client, class Member>
00206 CNodeCallback *make_NodeCallback( INode *pNode, Client& client, Member member, ECallbackType CallbackType )
00207 {
00208 return static_cast<CNodeCallback*>( new Member_NodeCallback<Client,Member>(pNode, client, member, CallbackType) );
00209 }
00210
00211
00212
00217 template<class Client, class Member>
00218 intptr_t Register( INode* pNode, Client &c, Member m, ECallbackType CallbackType = cbPostInsideLock )
00219 {
00220 CNodeCallback *pCallback(make_NodeCallback(pNode, c, m, CallbackType));
00221 return pNode->RegisterCallback(pCallback);
00222 }
00223
00224
00226
00227 GENAPI_DECL void Deregister (GENAPI_NAMESPACE::CallbackHandleType pCallbackInfo );
00228
00229 }
00230
00231 #endif // GENAPI_NODECALLBACK_H