Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / LF_CH_Event.cpp
blobd3ae6c39d35e08c41dd8444fb72e3a46dfcb84da
1 #include "tao/LF_CH_Event.h"
2 #include "tao/LF_Follower.h"
3 #include "tao/debug.h"
4 #include "tao/Connection_Handler.h"
5 #include "tao/Transport.h"
7 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
9 TAO_LF_CH_Event::TAO_LF_CH_Event ()
10 : TAO_LF_Event (),
11 prev_state_ (TAO_LF_Event::LFS_IDLE)
16 TAO_LF_CH_Event::~TAO_LF_CH_Event ()
20 int
21 TAO_LF_CH_Event::bind (TAO_LF_Follower *follower)
23 return this->followers_.bind (follower, 0);
26 int
27 TAO_LF_CH_Event::unbind (TAO_LF_Follower *follower)
29 return this->followers_.unbind (follower);
32 void
33 TAO_LF_CH_Event::state_changed_i (LFS_STATE new_state)
35 if (this->state_ != new_state)
37 this->validate_state_change (new_state);
39 if (TAO_debug_level > 9)
41 size_t id = 0;
42 TAO_Connection_Handler *ch = nullptr;
43 if ((ch = dynamic_cast<TAO_Connection_Handler *> (this))
44 && ch->transport ())
46 id = ch->transport ()->id ();
49 TAOLIB_DEBUG ((LM_DEBUG, "TAO (%P|%t) - TAO_LF_CH_Event[%d]::"
50 "state_changed_i, state %C->%C\n",
51 id,
52 TAO_LF_Event::state_name(prev_state_),
53 TAO_LF_Event::state_name(state_)));
57 ACE_MT (ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->followers_.mutex ()));
59 HASH_MAP::iterator end_it = this->followers_.end ();
60 for (HASH_MAP::iterator it = this->followers_.begin (); it != end_it ; ++it)
62 it->ext_id_->signal ();
66 void
67 TAO_LF_CH_Event::validate_state_change (LFS_STATE new_state)
69 if (this->state_ == TAO_LF_Event::LFS_IDLE)
71 // From the LFS_IDLE state we can only become active.
72 if (new_state == TAO_LF_Event::LFS_CONNECTION_WAIT)
74 this->prev_state_ = this->state_;
75 this->state_ = new_state;
77 return;
79 else if (this->state_ == TAO_LF_Event::LFS_CONNECTION_WAIT)
81 // Only a few states are possible from CONNECTION_WAIT states
82 if (new_state == TAO_LF_Event::LFS_CONNECTION_CLOSED
83 || new_state == TAO_LF_Event::LFS_SUCCESS)
85 this->prev_state_ = this->state_;
86 this->state_ = new_state;
89 return;
91 else if (this->state_ == TAO_LF_Event::LFS_SUCCESS)
93 if (new_state == TAO_LF_Event::LFS_CONNECTION_CLOSED)
95 this->prev_state_ = this->state_;
96 this->state_ = new_state;
98 return;
100 else if (this->state_ == TAO_LF_Event::LFS_TIMEOUT)
102 if (new_state == TAO_LF_Event::LFS_CONNECTION_CLOSED)
104 // Dont reset the previous state
105 this->state_ = new_state;
108 return;
111 bool
112 TAO_LF_CH_Event::successful_i () const
114 if (this->prev_state_ == TAO_LF_Event::LFS_CONNECTION_WAIT)
115 return this->state_ == TAO_LF_Event::LFS_SUCCESS;
117 return this->state_ == TAO_LF_Event::LFS_CONNECTION_CLOSED;
120 bool
121 TAO_LF_CH_Event::error_detected_i () const
123 if (this->prev_state_ == TAO_LF_Event::LFS_CONNECTION_WAIT)
124 return this->state_ == TAO_LF_Event::LFS_CONNECTION_CLOSED;
126 return this->state_ == TAO_LF_Event::LFS_TIMEOUT;
129 void
130 TAO_LF_CH_Event::set_state (LFS_STATE new_state)
132 // @@ NOTE: Is this still required?
133 if (!this->is_state_final ()
134 && new_state == TAO_LF_Event::LFS_TIMEOUT)
136 this->state_ = new_state;
137 if (TAO_debug_level > 9)
139 size_t id = 0;
140 TAO_Connection_Handler *ch = nullptr;
141 if ((ch = dynamic_cast<TAO_Connection_Handler *> (this)) &&
142 ch->transport ())
144 id = ch->transport ()->id ();
146 TAOLIB_DEBUG ((LM_DEBUG, "TAO (%P|%t) - TAO_LF_CH_Event[%d]::set_state, "
147 "state_ is LFS_TIMEOUT\n", id));
152 bool
153 TAO_LF_CH_Event::is_state_final () const
155 return this->state_ == TAO_LF_Event::LFS_CONNECTION_CLOSED;
158 TAO_END_VERSIONED_NAMESPACE_DECL