Go to the documentation of this file.00001 #include "tao/LF_CH_Event.h"
00002 #include "tao/LF_Follower.h"
00003 #include "tao/debug.h"
00004 #include "tao/Connection_Handler.h"
00005 #include "tao/Transport.h"
00006
00007 ACE_RCSID(tao,
00008 LF_Invocation_Event,
00009 "$Id: LF_CH_Event.cpp 84489 2009-02-17 14:04:16Z johnnyw $")
00010
00011 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00012
00013 TAO_LF_CH_Event::TAO_LF_CH_Event (void)
00014 : TAO_LF_Event (),
00015 prev_state_ (TAO_LF_Event::LFS_IDLE)
00016
00017 {
00018 }
00019
00020 TAO_LF_CH_Event::~TAO_LF_CH_Event (void)
00021 {
00022 }
00023
00024 int
00025 TAO_LF_CH_Event::bind (TAO_LF_Follower *follower)
00026 {
00027 return this->followers_.bind (follower, 0);
00028 }
00029
00030 int
00031 TAO_LF_CH_Event::unbind (TAO_LF_Follower *follower)
00032 {
00033 return this->followers_.unbind (follower);
00034 }
00035
00036 void
00037 TAO_LF_CH_Event::state_changed_i (int new_state)
00038 {
00039 if (this->state_ != new_state)
00040 {
00041 this->validate_state_change (new_state);
00042
00043 if (TAO_debug_level > 9)
00044 {
00045 size_t id = 0;
00046 TAO_Connection_Handler *ch = 0;
00047 if ((ch = dynamic_cast<TAO_Connection_Handler *> (this))
00048 && ch->transport ())
00049 {
00050 id = ch->transport ()->id ();
00051 }
00052
00053 ACE_DEBUG ((LM_DEBUG, "TAO (%P|%t) - TAO_LF_CH_Event[%d]::"
00054 "state_changed_i, state %C->%C\n",
00055 id,
00056 TAO_LF_Event::state_name(prev_state_),
00057 TAO_LF_Event::state_name(state_)));
00058 }
00059 }
00060
00061 ACE_MT (ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->followers_.mutex ()));
00062
00063 HASH_MAP::iterator end_it = this->followers_.end ();
00064 for (HASH_MAP::iterator it = this->followers_.begin (); it != end_it ; ++it)
00065 {
00066 it->ext_id_->signal ();
00067 }
00068 }
00069
00070 void
00071 TAO_LF_CH_Event::validate_state_change (int new_state)
00072 {
00073 if (this->state_ == TAO_LF_Event::LFS_IDLE)
00074 {
00075
00076 if (new_state == TAO_LF_Event::LFS_CONNECTION_WAIT)
00077 {
00078 this->prev_state_ = this->state_;
00079 this->state_ = new_state;
00080 }
00081 return;
00082 }
00083 else if (this->state_ == TAO_LF_Event::LFS_CONNECTION_WAIT)
00084 {
00085
00086 if (new_state == TAO_LF_Event::LFS_CONNECTION_CLOSED
00087 || new_state == TAO_LF_Event::LFS_SUCCESS)
00088 {
00089 this->prev_state_ = this->state_;
00090 this->state_ = new_state;
00091 }
00092
00093 return;
00094 }
00095 else if (this->state_ == TAO_LF_Event::LFS_SUCCESS)
00096 {
00097 if (new_state == TAO_LF_Event::LFS_CONNECTION_CLOSED)
00098 {
00099 this->prev_state_ = this->state_;
00100 this->state_ = new_state;
00101 }
00102 return;
00103 }
00104 else if (this->state_ == TAO_LF_Event::LFS_TIMEOUT)
00105 {
00106 if (new_state == TAO_LF_Event::LFS_CONNECTION_CLOSED)
00107 {
00108
00109 this->state_ = new_state;
00110 }
00111 }
00112 return;
00113 }
00114
00115
00116 int
00117 TAO_LF_CH_Event::successful (void) const
00118 {
00119 if (this->prev_state_ == TAO_LF_Event::LFS_CONNECTION_WAIT)
00120 return this->state_ == TAO_LF_Event::LFS_SUCCESS;
00121
00122 return this->state_ == TAO_LF_Event::LFS_CONNECTION_CLOSED;
00123 }
00124
00125 int
00126 TAO_LF_CH_Event::error_detected (void) const
00127 {
00128 if (this->prev_state_ == TAO_LF_Event::LFS_CONNECTION_WAIT)
00129 return this->state_ == TAO_LF_Event::LFS_CONNECTION_CLOSED;
00130
00131 return this->state_ == TAO_LF_Event::LFS_TIMEOUT;
00132 }
00133
00134 void
00135 TAO_LF_CH_Event::set_state (int new_state)
00136 {
00137
00138 if (this->is_state_final () == 0
00139 && new_state == TAO_LF_Event::LFS_TIMEOUT)
00140 {
00141 this->state_ = new_state;
00142 if (TAO_debug_level > 9)
00143 {
00144 size_t id = 0;
00145 TAO_Connection_Handler *ch = 0;
00146 if ((ch = dynamic_cast<TAO_Connection_Handler *> (this)) &&
00147 ch->transport ())
00148 {
00149 id = ch->transport ()->id ();
00150 }
00151 ACE_DEBUG ((LM_DEBUG, "TAO (%P|%t) - TAO_LF_CH_Event[%d]::set_state, "
00152 "state_ is LFS_TIMEOUT\n", id));
00153 }
00154 }
00155 }
00156
00157 int
00158 TAO_LF_CH_Event::is_state_final (void)
00159 {
00160 return this->state_ == TAO_LF_Event::LFS_CONNECTION_CLOSED;
00161 }
00162
00163 TAO_END_VERSIONED_NAMESPACE_DECL