NodeCallback.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:  Hartmut Nebelung
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 //-----------------------------------------------------------------------------
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     // C Functions as callbacks
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     // C++ Member functions as callbacks
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     // definition in Node.cpp
00227     GENAPI_DECL void Deregister (GENAPI_NAMESPACE::CallbackHandleType pCallbackInfo );
00228 
00229 }
00230 
00231 #endif // GENAPI_NODECALLBACK_H


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