1 #include "tao/LF_CH_Event.h"
2 #include "tao/LF_Follower.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 ()
11 prev_state_ (TAO_LF_Event::LFS_IDLE
)
16 TAO_LF_CH_Event::~TAO_LF_CH_Event ()
21 TAO_LF_CH_Event::bind (TAO_LF_Follower
*follower
)
23 return this->followers_
.bind (follower
, 0);
27 TAO_LF_CH_Event::unbind (TAO_LF_Follower
*follower
)
29 return this->followers_
.unbind (follower
);
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)
42 TAO_Connection_Handler
*ch
= nullptr;
43 if ((ch
= dynamic_cast<TAO_Connection_Handler
*> (this))
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",
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 ();
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
;
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
;
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
;
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
;
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
;
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
;
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)
140 TAO_Connection_Handler
*ch
= nullptr;
141 if ((ch
= dynamic_cast<TAO_Connection_Handler
*> (this)) &&
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
));
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