00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file LF_CH_Event.h 00006 * 00007 * $Id: LF_CH_Event.h 82657 2008-08-25 23:32:27Z mitza $ 00008 * 00009 * @author Balachandran Natarajan <bala@cs.wustl.edu> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef TAO_LF_CH_EVENT_H 00014 #define TAO_LF_CH_EVENT_H 00015 00016 #include /**/ "ace/pre.h" 00017 00018 #include "tao/LF_Event.h" 00019 #include "tao/orbconf.h" 00020 #include "ace/Hash_Map_Manager_T.h" 00021 #include "ace/Null_Mutex.h" 00022 #include "ace/Thread_Mutex.h" 00023 00024 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00025 # pragma once 00026 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00027 00028 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00029 00030 class TAO_LF_Multi_Event; 00031 00032 /** 00033 * @class TAO_LF_CH_Event 00034 * 00035 * @brief Use the Leader/Follower loop to wait for one specific event 00036 * in the invocation path. 00037 * 00038 * Concrete event types and manipulation class which is used for 00039 * connection handling purposes. 00040 */ 00041 class TAO_Export TAO_LF_CH_Event: public TAO_LF_Event 00042 { 00043 public: 00044 /** 00045 * The TAO_LF_Multi_Event class is another specialization of 00046 * TAO_LF_Event, used for aggregating many connection handlers into 00047 * a single event object.. It requires friendship so that it can 00048 * check the is_state_final() flag on each of its contained 00049 * connection handlers. 00050 */ 00051 friend class TAO_LF_Multi_Event; 00052 00053 /// Constructor 00054 TAO_LF_CH_Event (void); 00055 00056 /// Destructor 00057 virtual ~TAO_LF_CH_Event (void); 00058 00059 //@{ 00060 /// Return 1 if the condition was satisfied successfully, 0 if it 00061 /// has not 00062 int successful (void) const; 00063 00064 /// Return 1 if an error was detected while waiting for the 00065 /// event 00066 int error_detected (void) const; 00067 00068 protected: 00069 00070 /// Check whether we have reached the final state.. 00071 virtual int is_state_final (void); 00072 00073 //@} 00074 private: 00075 /// Validate and change the state 00076 /* 00077 * This concrete class uses the following states declared in the 00078 * class TAO_LF_Event to transition states 00079 * 00080 * LFS_IDLE - The event is created, and is in 00081 * initial state. 00082 * 00083 * LFS_CONNECTION_WAIT - The event is waiting for connection 00084 * completion and it can transition to 00085 * any of the following states, all the 00086 * states are final. 00087 * 00088 * LFS_SUCCESS - The event, connection establishment, has 00089 * completed successfully. 00090 * 00091 * LFS_TIMEOUT - The event has timed out. 00092 * 00093 * LFS_CONNECTION_CLOSED - The connection was closed since 00094 * an error occured while trying to 00095 * establish connection 00096 * 00097 * Event State Diagram 00098 * ------------------- 00099 * |----> CLOSED 00100 * | ^ 00101 * | | 00102 * IDLE ---> CONNECTION_WAIT--| | 00103 * | | 00104 * | | 00105 * |----> SUCESS 00106 * 00107 * Timeouts can occur while waiting for connections. 00108 * 00109 */ 00110 virtual void state_changed_i (int new_state); 00111 00112 /// Set the state irrespective of anything. 00113 virtual void set_state (int new_state); 00114 00115 virtual int bind (TAO_LF_Follower *follower); 00116 virtual int unbind (TAO_LF_Follower *follower); 00117 00118 private: 00119 00120 /// The previous state that the LF_CH_Event was in 00121 int prev_state_; 00122 00123 void validate_state_change (int new_state); 00124 00125 typedef ACE_Hash_Map_Manager_Ex <TAO_LF_Follower *, int, 00126 ACE_Hash<void *>, 00127 ACE_Equal_To<TAO_LF_Follower *>, 00128 TAO_SYNCH_MUTEX> HASH_MAP; 00129 HASH_MAP followers_; 00130 }; 00131 00132 TAO_END_VERSIONED_NAMESPACE_DECL 00133 00134 #include /**/ "ace/post.h" 00135 00136 #endif /* TAO_LF_CH_EVENT_H */