Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

IDEA::MessageObserver Class Reference
[Agent handle classes]

This class is a base abstract class that allows the user to implement an observer on instances of MessageHandle. More...

#include <MessageObserver.hh>

Inheritance diagram for IDEA::MessageObserver:

IDEA::ComRelay IDEA::Reactor IDEA::BoomerangRelay IDEA::IPCRelay IDEA::DefaultReactor IDEA::ShutdownReactor IDEA::SimulatorResponseScheduler IDEA::ReactivePlannerImpl IDEA::PlasmaReactivePlannerImpl List of all members.

Public Methods

virtual ~MessageObserver ()
 Destructor.

const std::string & getName () const
 Returns the name of the invoking observer.

bool hasPendingMessages ()
 Returns true if the invoking observer has pending messages in the queue.

int getNrOfPendingMessages ()
 Returns the number of pending messages in the queue.

UpdatePolicysetUpdatePolicy (UpdatePolicy *policy, bool deleteInst=false)
 Sets the update-policy to policy and will delete the old one if it was constructed by the constructor of the invoking observer or if it was set with deleteInst true.

UpdatePolicygetUpdatePolicy () const
 Returns the current UpdatePolicy of the invoking observer.

AcceptorPolicysetAcceptorPolicy (AcceptorPolicy *policy, bool deleteInst=false)
 Sets the acceptor-policy to policy and will delete the old one if it was constructed by the constructor of the invoking observer or if it was set with deleteInst true.

AcceptorPolicygetAcceptorPolicy () const
 Returns the current AcceptorPolicy of the invoking observer.

virtual void startUpdating ()
 Forces the invoking observer to start updating any of the messages in the queue using the UpdatePolicy of the invoking observer.

bool isUpdating () const
 Returns true if the invoking observer is in the process of updating messages in the queue, otherwise returns false.

bool isActive () const
 Returns true if the invoking observer is active otherwise false.

bool updatesInSeperateThread () const
 Returns true if the invoking observer will update messages in a seperate thread. Otherwise returns false.


Protected Types

typedef ACE_Thread_Condition<
ThreadMutex
ConditionVariable

Protected Methods

 MessageObserver (const std::string &name="MessageObserver", bool threaded=false, long subscribeToMessages=Message::START|Message::STOP|Message::VALUE|Message::STATUS|Message::TELEMETRY|Message::OBJECT|Message::USERDEFINED)
 Constructor.

int notify (MessageHandle message)
 Notifies the invoking observer that a message has been observed.

virtual int activate ()
 Activates the invoking message-observer.

virtual void deActivate ()
 De-activates the invoking message-observer.

virtual int initialize ()
 Hook for additional setup, should return -1 in case of failed initialization.

void updateInternal (const MessageHandle &message)
 Updates the message by checking type and extracting data and invoking the correct update method depending on the type.

virtual void updateStartMessage (const Time &time, const StartMessageData *data)
 Invoked when a start-message is being updated.

virtual void updateStopMessage (const Time &time, const StopMessageData *data)
 Invoked when a stop-message is being updated.

virtual void updateValueMessage (const Time &time, const ValueMessageData *data)
 Invoked when a value-message is being updated.

virtual void updateStatusMessage (const Time &time, const StatusMessageData *data)
 Invoked when a status-message is being updated.

virtual void updateObjectMessage (const Time &time, const ObjectMessageData *data)
 Invoked when a object-message is being updated.

virtual void updateTelemetryMessage (const Time &time, const TelemetryMessageData *data)
virtual void updateUserDefinedMessage (const Time &time, const MessageData *data)
 Invoked when a user-defined-message is being updated.

virtual void onQueueEmpty ()
 This method is invoked when the queue becomes empty. No signal is signalled at initialization (empty).

virtual void onQueueNonEmpty ()
 This method is invoked when the queue becomes non-empty.

int update ()
 Pops MessageHandle instance from the top of the queue and asks the UpdatePolicy if the message should be updated and if so will update based upon type of the message and release the handle when done.

int svc (void)
 Main thred function used when invoking class has been constructed with threaded option true.


Protected Attributes

MessageHandleQueue m_ObservedMessages
 A queue containing MessageHandle instance to be updated. The queue sorts the message conform the binary function latestTime (that is the top of the queue is the MessageHandle whose getTime is latest).

std::string m_Name
 Name of the invoking observer.

UpdatePolicym_UpdatePolicy
 Policy used for when to start updating and till what message in the queue.

bool m_DeleteUpdatePolicy
 Indicating if the destructor of the invoking observer should delete the update-policy.

bool m_Updating
 Indiates if the observer is updating messages.

bool m_Active
 Indicates if the invoking observer is active.

bool m_Threaded
 Boolean indicating if the messages will be udpated in a seperate thread.

ThreadMutex m_Mutex
ConditionVariablem_StartCondition
 If the invoking class runs it's own thread to update the messages this variable is used to notify the thread to start updating.

AcceptorPolicym_AcceptorPolicy
 Policy used for what message to accept to push in the queue.

bool m_DeleteAcceptorPolicy
 Indicating if the destructor of the invoking observer should delete the acceptor-policy.


Friends

class AgentRelay
class ReactivePlanner

Detailed Description

This class is a base abstract class that allows the user to implement an observer on instances of MessageHandle.

Author:
David Rijsman rijsman@email.arc.nasa.gov
The observer, MessageObserver, is invoked by a subject using API MessageObserver::notify( message ).

When the MessageObserver is notified it will invoke the UpdatePolicy associated with the invoked instance which will determine when the message(s) observed will be updated. When updated the message(s) will be filtered by type and the following (virtual) methods will be invoked:

The MessageObserver has 'empty' implementation of these methods.

Warning:
After MessageObserver invoked any of the update messages mentioned above it will release the MessageHandle passed as parameter of these functions. This means you have to invoke MessageHandle::copy if you want the message to be around after invocation.
One can limit what messages will actually be stored on the queue when the MessageObserver is being notified in the constructor (see subscribeToMessages). This way the update will not be invoked for messages you have not subscribed to.


Member Typedef Documentation

typedef ACE_Thread_Condition< ThreadMutex > IDEA::MessageObserver::ConditionVariable [protected]
 


Constructor & Destructor Documentation

IDEA::MessageObserver::~MessageObserver   [virtual]
 

Destructor.

IDEA::MessageObserver::MessageObserver const std::string &    name = "MessageObserver",
bool    threaded = false,
long    subscribeToMessages = Message::START|Message::STOP|Message::VALUE|Message::STATUS|Message::TELEMETRY|Message::OBJECT|Message::USERDEFINED
[protected]
 

Constructor.

Generates a MessageObserver with name name and will listen to messages subscribed to by using the flag subscribeToMessages.

One can add or remove messages to the subscribtion by using the bitwise OR ( | ) operator on the following flags(enumeration):


Member Function Documentation

int IDEA::MessageObserver::activate   [protected, virtual]
 

Activates the invoking message-observer.

release all the messages we did not update

void IDEA::MessageObserver::deActivate   [protected, virtual]
 

De-activates the invoking message-observer.

AcceptorPolicy* IDEA::MessageObserver::getAcceptorPolicy   const [inline]
 

Returns the current AcceptorPolicy of the invoking observer.

const std::string& IDEA::MessageObserver::getName   const [inline]
 

Returns the name of the invoking observer.

int IDEA::MessageObserver::getNrOfPendingMessages   [inline]
 

Returns the number of pending messages in the queue.

UpdatePolicy* IDEA::MessageObserver::getUpdatePolicy   const [inline]
 

Returns the current UpdatePolicy of the invoking observer.

bool IDEA::MessageObserver::hasPendingMessages  
 

Returns true if the invoking observer has pending messages in the queue.

Will take into account the logic of the UpdatePolicy, that is it will take the message at the top of the queue and check with the updatePolicy ( updateNextMessage( msg ) ) if it would be updated if we would invoke update. So there can be messages in the queue ( getNrOfPendingMessages() != 0 ) and this method returns false.

virtual int IDEA::MessageObserver::initialize   [inline, protected, virtual]
 

Hook for additional setup, should return -1 in case of failed initialization.

Reimplemented in IDEA::ReactivePlannerImpl, and IDEA::IPCRelay.

bool IDEA::MessageObserver::isActive   const [inline]
 

Returns true if the invoking observer is active otherwise false.

bool IDEA::MessageObserver::isUpdating  
 

Returns true if the invoking observer is in the process of updating messages in the queue, otherwise returns false.

int IDEA::MessageObserver::notify MessageHandle    message [protected]
 

Notifies the invoking observer that a message has been observed.

virtual void IDEA::MessageObserver::onQueueEmpty   [inline, protected, virtual]
 

This method is invoked when the queue becomes empty. No signal is signalled at initialization (empty).

virtual void IDEA::MessageObserver::onQueueNonEmpty   [inline, protected, virtual]
 

This method is invoked when the queue becomes non-empty.

AcceptorPolicy * IDEA::MessageObserver::setAcceptorPolicy AcceptorPolicy   policy,
bool    deleteInst = false
 

Sets the acceptor-policy to policy and will delete the old one if it was constructed by the constructor of the invoking observer or if it was set with deleteInst true.

Returns the old acceptor-policy if it was not deleted otherwise 0.

The acceptor-policy is used to decide to accept messages when the invoking class is notified. Be aware the new policy will override the message-types to accept passed in the constructor of the invoking class.

UpdatePolicy * IDEA::MessageObserver::setUpdatePolicy UpdatePolicy   policy,
bool    deleteInst = false
 

Sets the update-policy to policy and will delete the old one if it was constructed by the constructor of the invoking observer or if it was set with deleteInst true.

Returns the old update-policy if it was not deleted otherwise 0.

The update-policy is used to trigger the updating of the messages.

void IDEA::MessageObserver::startUpdating   [virtual]
 

Forces the invoking observer to start updating any of the messages in the queue using the UpdatePolicy of the invoking observer.

int IDEA::MessageObserver::svc void    [protected]
 

Main thred function used when invoking class has been constructed with threaded option true.

int IDEA::MessageObserver::update   [protected]
 

Pops MessageHandle instance from the top of the queue and asks the UpdatePolicy if the message should be updated and if so will update based upon type of the message and release the handle when done.

Returns -1 in case of an error.

void IDEA::MessageObserver::updateInternal const MessageHandle   message [protected]
 

Updates the message by checking type and extracting data and invoking the correct update method depending on the type.

void IDEA::MessageObserver::updateObjectMessage const Time   time,
const ObjectMessageData   data
[protected, virtual]
 

Invoked when a object-message is being updated.

To be implemented in the specialization.

Reimplemented in IDEA::BoomerangRelay, IDEA::DefaultReactor, IDEA::SimulatorResponseScheduler, and IDEA::IPCRelay.

bool IDEA::MessageObserver::updatesInSeperateThread   const [inline]
 

Returns true if the invoking observer will update messages in a seperate thread. Otherwise returns false.

void IDEA::MessageObserver::updateStartMessage const Time   time,
const StartMessageData   data
[protected, virtual]
 

Invoked when a start-message is being updated.

To be implemented in the specialization.

Reimplemented in IDEA::BoomerangRelay, IDEA::DefaultReactor, IDEA::ShutdownReactor, IDEA::SimulatorResponseScheduler, and IDEA::IPCRelay.

void IDEA::MessageObserver::updateStatusMessage const Time   time,
const StatusMessageData   data
[protected, virtual]
 

Invoked when a status-message is being updated.

To be implemented in the specialization.

Reimplemented in IDEA::BoomerangRelay, IDEA::DefaultReactor, IDEA::SimulatorResponseScheduler, and IDEA::IPCRelay.

void IDEA::MessageObserver::updateStopMessage const Time   time,
const StopMessageData   data
[protected, virtual]
 

Invoked when a stop-message is being updated.

To be implemented in the specialization.

Reimplemented in IDEA::BoomerangRelay, IDEA::DefaultReactor, IDEA::SimulatorResponseScheduler, and IDEA::IPCRelay.

void IDEA::MessageObserver::updateTelemetryMessage const Time   time,
const TelemetryMessageData   data
[protected, virtual]
 

Invoked when a telemetry-message is being updated.

To be implemented in the specialization.

Reimplemented in IDEA::BoomerangRelay, IDEA::DefaultReactor, and IDEA::IPCRelay.

void IDEA::MessageObserver::updateUserDefinedMessage const Time   time,
const MessageData   data
[protected, virtual]
 

Invoked when a user-defined-message is being updated.

To be implemented in the specialization.

Reimplemented in IDEA::BoomerangRelay, and IDEA::SimulatorResponseScheduler.

void IDEA::MessageObserver::updateValueMessage const Time   time,
const ValueMessageData   data
[protected, virtual]
 

Invoked when a value-message is being updated.

To be implemented in the specialization.

Reimplemented in IDEA::BoomerangRelay, IDEA::DefaultReactor, IDEA::SimulatorResponseScheduler, and IDEA::IPCRelay.


Friends And Related Function Documentation

friend class AgentRelay [friend]
 

Reimplemented in IDEA::ComRelay, and IDEA::ShutdownReactor.

friend class ReactivePlanner [friend]
 

Reimplemented in IDEA::ReactivePlannerImpl.


Member Data Documentation

AcceptorPolicy* IDEA::MessageObserver::m_AcceptorPolicy [protected]
 

Policy used for what message to accept to push in the queue.

bool IDEA::MessageObserver::m_Active [protected]
 

Indicates if the invoking observer is active.

bool IDEA::MessageObserver::m_DeleteAcceptorPolicy [protected]
 

Indicating if the destructor of the invoking observer should delete the acceptor-policy.

bool IDEA::MessageObserver::m_DeleteUpdatePolicy [protected]
 

Indicating if the destructor of the invoking observer should delete the update-policy.

ThreadMutex IDEA::MessageObserver::m_Mutex [protected]
 

std::string IDEA::MessageObserver::m_Name [protected]
 

Name of the invoking observer.

MessageHandleQueue IDEA::MessageObserver::m_ObservedMessages [protected]
 

A queue containing MessageHandle instance to be updated. The queue sorts the message conform the binary function latestTime (that is the top of the queue is the MessageHandle whose getTime is latest).

ConditionVariable* IDEA::MessageObserver::m_StartCondition [protected]
 

If the invoking class runs it's own thread to update the messages this variable is used to notify the thread to start updating.

bool IDEA::MessageObserver::m_Threaded [protected]
 

Boolean indicating if the messages will be udpated in a seperate thread.

UpdatePolicy* IDEA::MessageObserver::m_UpdatePolicy [protected]
 

Policy used for when to start updating and till what message in the queue.

bool IDEA::MessageObserver::m_Updating [protected]
 

Indiates if the observer is updating messages.


Contact information
© IDEA
Generated on Fri Feb 3 17:09:46 2006 for IDEA.