NITE 1.5.1 - API Reference

XnVMessageListener.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 *                                                                              *
00003 *   PrimeSense NITE 1.3                                                        *
00004 *   Copyright (C) 2010 PrimeSense Ltd.                                         *
00005 *                                                                              *
00006 *******************************************************************************/
00007 
00008 
00009 #ifndef _XNV_MESSAGE_LISTENER_H_
00010 #define _XNV_MESSAGE_LISTENER_H_
00011 
00012 #include <XnThreadSafeQueue.h>
00013 #include "XnVMessage.h"
00014 
00015 class XnVMessageQueue;
00016 class XnVMessageSpecificEvent;
00017 class XnVEvent;
00018 
00024 class XNV_NITE_API XnVMessageListener
00025 {
00026 public:
00030     typedef void (XN_CALLBACK_TYPE* MessageUpdateCB)(XnVMessage* pMessage, void* cxt);
00034     typedef void (XN_CALLBACK_TYPE* ActivateCB)(void* cxt);
00038     typedef void (XN_CALLBACK_TYPE* DeactivateCB)(void* cxt);
00039 
00045     XnVMessageListener(const XnChar* strName = "XnVMessageListener");
00046     virtual ~XnVMessageListener();
00047 
00054     void BaseUpdate(XnVMessage* pMessage);
00060     virtual void Update(XnVMessage* pMessage) = 0;
00061     
00069     virtual void HandleCCMessages(XnVMessage* pMessage);
00070 
00076     virtual void Activate(XnBool bActive) {}
00077 
00083     const XnChar* GetListenerName() const;
00084 
00090     void Run(XnUInt32 nSessionMaxLength = ms_nSessionDefaultLength);
00096     XnStatus RunAsThread();
00102     void SetThreadId(XN_THREAD_ID hThread);
00106     void SetCurrentThread();
00107 
00116     XnCallbackHandle RegisterUpdate(void* cxt, MessageUpdateCB CB);
00125     XnCallbackHandle RegisterActivate(void* cxt, ActivateCB CB);
00134     XnCallbackHandle RegisterDeactivate(void* cxt, DeactivateCB CB);
00135 
00141     void UnregisterUpdate(XnCallbackHandle hCB);
00147     void UnregisterActivate(XnCallbackHandle hCB);
00153     void UnregisterDeactivate(XnCallbackHandle hCB);
00154 
00160     void SetThreadProtectionQueueMode(XnBool bMode);
00166     XnBool GetThreadProtectecionQueueMode() const;
00170     virtual void ClearQueue();
00171 protected:
00172 
00173     XnBool IsInActivityThread() const;
00174 
00175     static XN_THREAD_PROC MessageListenerThread(XN_THREAD_PARAM param);
00176     void MainLoop();
00177 
00178     XN_THREAD_ID m_hActivityThreadId;
00179 
00180     XN_THREAD_HANDLE m_hActivityThread; // When thread is internal
00181     XnBool m_bInternalThreadAlive;
00182     XnBool m_bInternalThreadKill;
00183 
00184     XnBool m_bThreadProtectionQueueMode;
00185 
00186     static const XnUInt32 ms_nSessionDefaultLength;
00187 
00188     XnVMessageQueue* m_pMessageQueue;
00189 
00190     XnVMessageSpecificEvent* m_pUpdateCBs;
00191     XnVEvent* m_pActivateCBs;
00192     XnVEvent* m_pDeactivateCBs;
00193 
00194     XnChar* m_strListenerName;
00195 
00196     XN_CRITICAL_SECTION_HANDLE m_hListenerCS;
00197 };
00198 
00199 #endif