Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes

XnVMessageListener Class Reference

#include <XnVMessageListener.h>

Inheritance diagram for XnVMessageListener:
Inheritance graph
[legend]

List of all members.

Public Types

typedef void(XN_CALLBACK_TYPE * MessageUpdateCB )(XnVMessage *pMessage, void *cxt)
typedef void(XN_CALLBACK_TYPE * ActivateCB )(void *cxt)
typedef void(XN_CALLBACK_TYPE * DeactivateCB )(void *cxt)

Public Member Functions

 XnVMessageListener (const XnChar *strName="XnVMessageListener")
virtual ~XnVMessageListener ()
void BaseUpdate (XnVMessage *pMessage)
virtual void Update (XnVMessage *pMessage)=0
virtual void HandleCCMessages (XnVMessage *pMessage)
virtual void Activate (XnBool bActive)
const XnChar * GetListenerName () const
void Run (XnUInt32 nSessionMaxLength=ms_nSessionDefaultLength)
XnStatus RunAsThread ()
void SetThreadId (XN_THREAD_ID hThread)
void SetCurrentThread ()
XnCallbackHandle RegisterUpdate (void *cxt, MessageUpdateCB CB)
XnCallbackHandle RegisterActivate (void *cxt, ActivateCB CB)
XnCallbackHandle RegisterDeactivate (void *cxt, DeactivateCB CB)
void UnregisterUpdate (XnCallbackHandle hCB)
void UnregisterActivate (XnCallbackHandle hCB)
void UnregisterDeactivate (XnCallbackHandle hCB)
void SetThreadProtectionQueueMode (XnBool bMode)
XnBool GetThreadProtectecionQueueMode () const
virtual void ClearQueue ()

Protected Member Functions

 XN_DECLARE_THREAD_SAFE_QUEUE_DECL (XNV_NITE_API, XnVMessage *, XnVMessageQueue)
 XN_DECLARE_EVENT_1ARG (XnVMessageSpecificEvent, XnVMessageEvent, XnVMessage *, pMessage)
XnBool IsInActivityThread () const
void MainLoop ()

Static Protected Member Functions

static XN_THREAD_PROC MessageListenerThread (XN_THREAD_PARAM param)

Protected Attributes

XN_THREAD_ID m_hActivityThreadId
XN_THREAD_HANDLE m_hActivityThread
XnBool m_bInternalThreadAlive
XnBool m_bInternalThreadKill
XnBool m_bThreadProtectionQueueMode
XnVMessageQueue m_MessageQueue
XnVMessageSpecificEvent m_UpdateCBs
XnVEvent m_ActivateCBs
XnVEvent m_DeactivateCBs
XnChar * m_strListenerName
XN_CRITICAL_SECTION_HANDLE m_hListenerCS

Static Protected Attributes

static const XnUInt32 ms_nSessionDefaultLength

Detailed Description

A XnVMessageListener is a general listener, that received Messages and handles them. It supports Multi-Threaded work, by knowing the thread it works in, and putting Messages in a Queue when accessed from other threads.

Definition at line 21 of file XnVMessageListener.h.


Member Typedef Documentation

typedef void(XN_CALLBACK_TYPE* XnVMessageListener::ActivateCB)(void *cxt)

Type for callbacks on activation

Definition at line 31 of file XnVMessageListener.h.

typedef void(XN_CALLBACK_TYPE* XnVMessageListener::DeactivateCB)(void *cxt)

Type for callbacks on deactivation

Definition at line 35 of file XnVMessageListener.h.

typedef void(XN_CALLBACK_TYPE* XnVMessageListener::MessageUpdateCB)(XnVMessage *pMessage, void *cxt)

Type for callbacks after a Message is handled

Definition at line 27 of file XnVMessageListener.h.


Constructor & Destructor Documentation

XnVMessageListener::XnVMessageListener ( const XnChar *  strName = "XnVMessageListener"  ) 

Constructor. Create a new Message Listener

Parameters:
[in] strName Name of the control, for log purposes.
virtual XnVMessageListener::~XnVMessageListener (  )  [virtual]

Member Function Documentation

virtual void XnVMessageListener::Activate ( XnBool  bActive  )  [inline, virtual]

This method is called (by the default HandleCCMessages) when an Activation Message is received.

Parameters:
[in] bActive TRUE if this listener is now active, FALSE if it is now inactive

Definition at line 73 of file XnVMessageListener.h.

void XnVMessageListener::BaseUpdate ( XnVMessage pMessage  ) 

This method handles multi-thread support, calling Update only when run from the proper thread and copying the Message to a Queue when not.

Parameters:
[in] pMessage The Message that should be handled
virtual void XnVMessageListener::ClearQueue (  )  [virtual]

Clear the Multi-thread queue

Reimplemented in XnVContextFilter, XnVFlowRouter, and XnVPointFilter.

const XnChar* XnVMessageListener::GetListenerName (  )  const

Get the listener's name. Mostly for Log use.

Returns:
The current Listener's name
XnBool XnVMessageListener::GetThreadProtectecionQueueMode (  )  const

Get the current multi-thread mode

Returns:
TRUE if queues are used, FALSE if Update will be called from anywhere
virtual void XnVMessageListener::HandleCCMessages ( XnVMessage pMessage  )  [virtual]

Handle Control Messages. By default, it calls Activate for Activation Messages. Can be reimplemented to handle additional Message types. Is called from BaseUpdate, before Update.

Parameters:
[in] pMessage The message to handle
XnBool XnVMessageListener::IsInActivityThread (  )  const [protected]
void XnVMessageListener::MainLoop (  )  [protected]
static XN_THREAD_PROC XnVMessageListener::MessageListenerThread ( XN_THREAD_PARAM  param  )  [static, protected]
XnCallbackHandle XnVMessageListener::RegisterActivate ( void *  cxt,
ActivateCB  CB 
)

Register for the activation event

Parameters:
[in] cxt User's context
[in] CB The Callback to call when the event is invoked.
Returns:
A handle, to allow unregistration.
XnCallbackHandle XnVMessageListener::RegisterDeactivate ( void *  cxt,
DeactivateCB  CB 
)

Register for the deactivation event

Parameters:
[in] cxt User's context
[in] CB The Callback to call when the event is invoked.
Returns:
A handle, to allow unregistration.
XnCallbackHandle XnVMessageListener::RegisterUpdate ( void *  cxt,
MessageUpdateCB  CB 
)

Register a callback to be called after the Message is handled

Parameters:
[in] cxt User's context
[in] CB The Callback to call when the event is invoked.
Returns:
A handle, to allow unregistration.
void XnVMessageListener::Run ( XnUInt32  nSessionMaxLength = ms_nSessionDefaultLength  ) 

Supply the Message Listener with run-time from its thread. Read from the Queue, and BaseUpdate.

Parameters:
[in] nSessionMaxLength Maximum number of Messages to be handled in a single Run
XnStatus XnVMessageListener::RunAsThread (  ) 

Open a thread, and run the Listener in it.

Returns:
XN_STATUS_OK if OK, other on error
void XnVMessageListener::SetCurrentThread (  ) 

Change the working thread to the one from which it is called

void XnVMessageListener::SetThreadId ( XN_THREAD_ID  hThread  ) 

Change the working thread, in which actual work is done

Parameters:
[in] hThread The ID of the relevant thread
void XnVMessageListener::SetThreadProtectionQueueMode ( XnBool  bMode  ) 

Change the multi-thread mode.

Parameters:
[in] bMode The new mode
void XnVMessageListener::UnregisterActivate ( XnCallbackHandle  hCB  ) 

Unregister from the activation event

Parameters:
[in] hCB The handle provided on registration.
void XnVMessageListener::UnregisterDeactivate ( XnCallbackHandle  hCB  ) 

Unregister from the deactivation event

Parameters:
[in] hCB The handle provided on registration.
void XnVMessageListener::UnregisterUpdate ( XnCallbackHandle  hCB  ) 

Unregister from the Message Update

Parameters:
[in] hCB The handle provided on registration.
virtual void XnVMessageListener::Update ( XnVMessage pMessage  )  [pure virtual]

This method will be implemented by descendants, handling the Message

Parameters:
[in] pMessage The Message that was received

Implemented in XnVDepthControl, XnVContextControl, XnVFlowRouter, XnVPointArea, XnVPointControl, XnVPointDenoiser, XnVPointFilter, and XnVVirtualCoordinates.

XnVMessageListener::XN_DECLARE_EVENT_1ARG ( XnVMessageSpecificEvent  ,
XnVMessageEvent  ,
XnVMessage ,
pMessage   
) [protected]
XnVMessageListener::XN_DECLARE_THREAD_SAFE_QUEUE_DECL ( XNV_NITE_API  ,
XnVMessage ,
XnVMessageQueue   
) [protected]

Member Data Documentation

XnVEvent XnVMessageListener::m_ActivateCBs [protected]

Definition at line 190 of file XnVMessageListener.h.

Definition at line 180 of file XnVMessageListener.h.

Definition at line 181 of file XnVMessageListener.h.

Definition at line 183 of file XnVMessageListener.h.

Definition at line 191 of file XnVMessageListener.h.

XN_THREAD_HANDLE XnVMessageListener::m_hActivityThread [protected]

Definition at line 179 of file XnVMessageListener.h.

XN_THREAD_ID XnVMessageListener::m_hActivityThreadId [protected]

Definition at line 177 of file XnVMessageListener.h.

XN_CRITICAL_SECTION_HANDLE XnVMessageListener::m_hListenerCS [protected]

Definition at line 195 of file XnVMessageListener.h.

XnVMessageQueue XnVMessageListener::m_MessageQueue [protected]

Definition at line 187 of file XnVMessageListener.h.

Definition at line 193 of file XnVMessageListener.h.

XnVMessageSpecificEvent XnVMessageListener::m_UpdateCBs [protected]

Definition at line 189 of file XnVMessageListener.h.

const XnUInt32 XnVMessageListener::ms_nSessionDefaultLength [static, protected]

Definition at line 185 of file XnVMessageListener.h.


The documentation for this class was generated from the following file: