Use the Leader/Follower loop to wait for one specific event. More...
#include <LF_Event.h>
Public Member Functions | |
TAO_LF_Event (void) | |
Constructor. | |
virtual | ~TAO_LF_Event (void) |
Destructor. | |
virtual int | bind (TAO_LF_Follower *follower) |
Bind a follower. | |
virtual int | unbind (TAO_LF_Follower *follower) |
Unbind the follower. | |
void | reset_state (int new_state) |
Reset the state, irrespective of the previous states. | |
Static Public Member Functions | |
static const char * | state_name (int st) |
Protected Member Functions | |
virtual void | state_changed_i (int new_state)=0 |
Validate the state change. | |
virtual int | is_state_final (void)=0 |
Check whether we have reached the final state.. | |
Protected Attributes | |
int | state_ |
The current state. | |
TAO_LF_Follower * | follower_ |
The bounded follower. | |
Private Member Functions | |
virtual void | set_state (int new_state) |
Set the state irrespective of anything. | |
Friends | |
class | TAO_Leader_Follower |
State management | |
A Leader/Followers event goes through several states during its lifetime. We use an enum to represent those states and state changes are validated according to the rules defined in the concrete classes. We treat the states as finite states in a FSM. The possible sequence of states through which the FSM migrates is defined in the concrete classes. | |
enum | { LFS_IDLE = 0, LFS_ACTIVE, LFS_CONNECTION_WAIT, LFS_SUCCESS, LFS_FAILURE, LFS_TIMEOUT, LFS_CONNECTION_CLOSED } |
void | state_changed (int new_state, TAO_Leader_Follower &lf) |
virtual int | successful (void) const =0 |
virtual int | error_detected (void) const =0 |
int | keep_waiting (void) |
Check if we should keep waiting. |
Use the Leader/Follower loop to wait for one specific event.
The Leader/Follower event loop is used to wait for incoming responses, as well as to wait for all the data to be flushed. This class encapsulates this event loop. It uses Template Method to parametrize the 'waited for' predicate (i.e. reply received or message sent or connection establishment etc.)
Definition at line 50 of file LF_Event.h.
anonymous enum |
Virtual methods for this class hierarchy.. Accessor to change the state. The state isnt changed unless certain conditions are satisfied.
Sort of double-checked optimization..
Definition at line 88 of file LF_Event.h.
{ /// The event is created, and is in initial state LFS_IDLE = 0, /// The event is active LFS_ACTIVE, /// The event is waiting for connection completion. LFS_CONNECTION_WAIT, /// The event has completed successfully LFS_SUCCESS, /// A failure has been detected while the event was active LFS_FAILURE, /// The event has timed out LFS_TIMEOUT, /// The connection was closed. LFS_CONNECTION_CLOSED };
TAO_LF_Event::TAO_LF_Event | ( | void | ) |
Constructor.
Definition at line 18 of file LF_Event.cpp.
: state_ (TAO_LF_Event::LFS_IDLE) , follower_ (0) { }
TAO_LF_Event::~TAO_LF_Event | ( | void | ) | [virtual] |
int TAO_LF_Event::bind | ( | TAO_LF_Follower * | follower | ) | [virtual] |
Bind a follower.
An event can be waited on by at most one follower thread, this method is used to bind the waiting thread to the event, in order to let the event signal any important state changes.
This is virtual to allow the LF_Multi_Event derived type share the follower with all the subordinate LF_CH_Events.
Reimplemented in TAO_LF_CH_Event, and TAO_LF_Multi_Event.
Definition at line 8 of file LF_Event.inl.
virtual int TAO_LF_Event::error_detected | ( | void | ) | const [pure virtual] |
Return 1 if an error was detected while waiting for the event
Implemented in TAO_LF_CH_Event, TAO_LF_Invocation_Event, and TAO_LF_Multi_Event.
virtual int TAO_LF_Event::is_state_final | ( | void | ) | [protected, pure virtual] |
Check whether we have reached the final state..
Implemented in TAO_LF_CH_Event, TAO_LF_Invocation_Event, and TAO_LF_Multi_Event.
int TAO_LF_Event::keep_waiting | ( | void | ) |
Check if we should keep waiting.
Definition at line 32 of file LF_Event.inl.
{ return (this->successful () == 0) && (this->error_detected () == 0); }
void TAO_LF_Event::reset_state | ( | int | new_state | ) |
Reset the state, irrespective of the previous states.
Definition at line 26 of file LF_Event.inl.
{ this->state_ = new_state; }
void TAO_LF_Event::set_state | ( | int | new_state | ) | [private, virtual] |
Set the state irrespective of anything.
Reimplemented in TAO_LF_CH_Event.
Definition at line 44 of file LF_Event.cpp.
{ this->state_ = new_state; }
void TAO_LF_Event::state_changed | ( | int | new_state, | |
TAO_Leader_Follower & | lf | |||
) |
Virtual methods for this class hierarchy.. Accessor to change the state. The state isnt changed unless certain conditions are satisfied.
Sort of double-checked optimization..
Definition at line 29 of file LF_Event.cpp.
{ ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, lf.lock ()); if (this->is_state_final () == 0) { this->state_changed_i (new_state); /// Sort of double-checked optimization.. if (this->follower_ != 0) this->follower_->signal (); } }
virtual void TAO_LF_Event::state_changed_i | ( | int | new_state | ) | [protected, pure virtual] |
Validate the state change.
Implemented in TAO_LF_CH_Event, TAO_LF_Invocation_Event, and TAO_LF_Multi_Event.
const char * TAO_LF_Event::state_name | ( | int | st | ) | [static] |
Definition at line 38 of file LF_Event.inl.
{ #define TAO_LF_EVENT_ENTRY(X) case X: return #X switch (st) { TAO_LF_EVENT_ENTRY (LFS_IDLE); TAO_LF_EVENT_ENTRY (LFS_ACTIVE); TAO_LF_EVENT_ENTRY (LFS_CONNECTION_WAIT); TAO_LF_EVENT_ENTRY (LFS_SUCCESS); TAO_LF_EVENT_ENTRY (LFS_FAILURE); TAO_LF_EVENT_ENTRY (LFS_TIMEOUT); TAO_LF_EVENT_ENTRY (LFS_CONNECTION_CLOSED); } return "***Unknown enum value, update TAO_LF_Event::state_name()"; #undef TAO_LF_EVENT_ENTRY }
virtual int TAO_LF_Event::successful | ( | void | ) | const [pure virtual] |
Return 1 if the condition was satisfied successfully, 0 if it has not
Implemented in TAO_LF_CH_Event, TAO_LF_Invocation_Event, and TAO_LF_Multi_Event.
int TAO_LF_Event::unbind | ( | TAO_LF_Follower * | follower | ) | [virtual] |
Unbind the follower.
Reimplemented in TAO_LF_CH_Event, and TAO_LF_Multi_Event.
Definition at line 17 of file LF_Event.inl.
friend class TAO_Leader_Follower [friend] |
Definition at line 54 of file LF_Event.h.
TAO_LF_Follower* TAO_LF_Event::follower_ [protected] |
The bounded follower.
Definition at line 147 of file LF_Event.h.
int TAO_LF_Event::state_ [protected] |
The current state.
Definition at line 144 of file LF_Event.h.