Nebula
Loading...
Searching...
No Matches
Messaging::AsyncPort Class Reference

#include <asyncport.h>

Detailed Description

The AsyncPort class runs its handlers in a separate thread, so that message processing happens in a separate thread and doesn't block the main thread.

Inherits Core::RefCounted.

Inherited by Interface::InterfaceBase.

Public Member Functions

 AsyncPort ()
 constructor
 
virtual ~AsyncPort ()
 destructor
 
void SetHandlerThread (const Ptr< HandlerThreadBase > &handlerThread)
 set pointer to handler thread object (must be derived from HandlerThreadBase)
 
const Ptr< HandlerThreadBase > & GetHandlerThread () const
 get pointer to handler thread object
 
virtual void AttachHandler (const Ptr< Handler > &h)
 attach a handler to the port, may be called before or after Open()
 
virtual void RemoveHandler (const Ptr< Handler > &h)
 dynamically remove a handler from the port
 
virtual void Open ()
 open the async port
 
virtual void Close ()
 close the async port
 
bool IsOpen () const
 return true if port is open
 
template<class MESSAGETYPE >
void Send (const Ptr< MESSAGETYPE > &msg)
 send an asynchronous message to the port
 
template<class MESSAGETYPE >
void SendWait (const Ptr< MESSAGETYPE > &msg)
 send a message and wait for completion
 
template<class MESSAGETYPE >
void Wait (const Ptr< MESSAGETYPE > &msg)
 wait for a message to be handled
 
template<class MESSAGETYPE >
bool Peek (const Ptr< MESSAGETYPE > &msg)
 peek a message whether it has been handled
 
template<class MESSAGETYPE >
void Cancel (const Ptr< MESSAGETYPE > &msg)
 cancel a pending message
 
- Public Member Functions inherited from Core::RefCounted
 RefCounted ()
 constructor
 
int GetRefCount () const
 get the current refcount
 
void AddRef ()
 increment refcount by one
 
void Release ()
 decrement refcount and destroy object if refcount is zero
 
bool IsInstanceOf (const Rtti &rtti) const
 return true if this object is instance of given class
 
bool IsInstanceOf (const Util::String &className) const
 return true if this object is instance of given class by string
 
bool IsInstanceOf (const Util::FourCC &classFourCC) const
 return true if this object is instance of given class by fourcc
 
bool IsA (const Rtti &rtti) const
 return true if this object is instance of given class, or a derived class
 
bool IsA (const Util::String &rttiName) const
 return true if this object is instance of given class, or a derived class, by string
 
bool IsA (const Util::FourCC &rttiFourCC) const
 return true if this object is instance of given class, or a derived class, by fourcc
 
const Util::StringGetClassName () const
 get the class name
 
Util::FourCC GetClassFourCC () const
 get the class FourCC code
 

Private Member Functions

 __DeclareClass (AsyncPort)
 
void SendInternal (const Ptr< Message > &msg)
 send an asynchronous message to the port
 
void SendWaitInternal (const Ptr< Message > &msg)
 send a message and wait for completion
 
void WaitInternal (const Ptr< Message > &msg)
 wait for a message to be handled
 
bool PeekInternal (const Ptr< Message > &msg)
 peek a message whether it has been handled
 
void CancelInternal (const Ptr< Message > &msg)
 cancel a pending message
 
void ClearHandlers ()
 clear all attached message handlers
 

Private Attributes

Ptr< HandlerThreadBasethread
 
bool isOpen
 

Additional Inherited Members

- Static Public Member Functions inherited from Core::RefCounted
static void DumpRefCountingLeaks ()
 dump refcounting leaks, call at end of application (NEBULA_DEBUG builds only!)
 
- Protected Member Functions inherited from Core::RefCounted
virtual ~RefCounted ()
 destructor (called when refcount reaches zero)
 

Constructor & Destructor Documentation

◆ AsyncPort()

Messaging::AsyncPort::AsyncPort ( )

constructor

◆ ~AsyncPort()

Messaging::AsyncPort::~AsyncPort ( )
virtual

destructor

Member Function Documentation

◆ __DeclareClass()

Messaging::AsyncPort::__DeclareClass ( AsyncPort )
private

◆ AttachHandler()

void Messaging::AsyncPort::AttachHandler ( const Ptr< Handler > & h)
virtual

attach a handler to the port, may be called before or after Open()

Add a message handler, this can either be called before the handler thread is started, or any time afterwards.

Reimplemented in Interface::InterfaceBase.

◆ Cancel()

template<class MESSAGETYPE >
void Messaging::AsyncPort::Cancel ( const Ptr< MESSAGETYPE > & msg)
inline

cancel a pending message

◆ CancelInternal()

void Messaging::AsyncPort::CancelInternal ( const Ptr< Message > & msg)
private

cancel a pending message

This method will cancel a pending message.

◆ ClearHandlers()

void Messaging::AsyncPort::ClearHandlers ( )
private

clear all attached message handlers

◆ Close()

void Messaging::AsyncPort::Close ( )
virtual

close the async port

Closes the async port.

Reimplemented in Interface::InterfaceBase, and IO::IoInterface.

◆ GetHandlerThread()

const Ptr< HandlerThreadBase > & Messaging::AsyncPort::GetHandlerThread ( ) const
inline

get pointer to handler thread object

◆ IsOpen()

bool Messaging::AsyncPort::IsOpen ( ) const
inline

return true if port is open

◆ Open()

void Messaging::AsyncPort::Open ( )
virtual

open the async port

Open the async port.

The async port needs a valid name before it is opened. Messages can only be sent to an open port.

Reimplemented in Debug::DebugInterface, Http::HttpInterface, Interface::InterfaceBase, and IO::IoInterface.

◆ Peek()

template<class MESSAGETYPE >
bool Messaging::AsyncPort::Peek ( const Ptr< MESSAGETYPE > & msg)
inline

peek a message whether it has been handled

◆ PeekInternal()

bool Messaging::AsyncPort::PeekInternal ( const Ptr< Message > & msg)
private

peek a message whether it has been handled

This method peeks whether a message has already been handled.

If the caller expects any return arguments from the message handling it can use this message to check whether the results are ready using this non-blocking method. The caller can also wait for the results to become ready using the Wait() method.

◆ RemoveHandler()

void Messaging::AsyncPort::RemoveHandler ( const Ptr< Handler > & h)
virtual

dynamically remove a handler from the port

Dynamically remove a message handler.

◆ Send()

template<class MESSAGETYPE >
void Messaging::AsyncPort::Send ( const Ptr< MESSAGETYPE > & msg)
inline

send an asynchronous message to the port

◆ SendInternal()

void Messaging::AsyncPort::SendInternal ( const Ptr< Message > & msg)
private

send an asynchronous message to the port

Handle an asynchronous message and return immediately.

If the caller expects any results from the message he can poll with the AsyncPort::Peek() method, or he may wait for the message to be handled with the AsyncPort::Wait() method.

◆ SendWait()

template<class MESSAGETYPE >
void Messaging::AsyncPort::SendWait ( const Ptr< MESSAGETYPE > & msg)
inline

send a message and wait for completion

◆ SendWaitInternal()

void Messaging::AsyncPort::SendWaitInternal ( const Ptr< Message > & msg)
private

send a message and wait for completion

Send an asynchronous message and wait until the message has been handled.

◆ SetHandlerThread()

void Messaging::AsyncPort::SetHandlerThread ( const Ptr< HandlerThreadBase > & handlerThread)
inline

set pointer to handler thread object (must be derived from HandlerThreadBase)

◆ Wait()

template<class MESSAGETYPE >
void Messaging::AsyncPort::Wait ( const Ptr< MESSAGETYPE > & msg)
inline

wait for a message to be handled

◆ WaitInternal()

void Messaging::AsyncPort::WaitInternal ( const Ptr< Message > & msg)
private

wait for a message to be handled

This method will wait until a message has been handled.

If the caller expects any return arguments from the message handling it can use this method to wait for the results.

Member Data Documentation

◆ isOpen

bool Messaging::AsyncPort::isOpen
private

◆ thread

Ptr<HandlerThreadBase> Messaging::AsyncPort::thread
private

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