00001
00002
00003 #include "orbsvcs/Event/EC_Event_Channel_Base.h"
00004 #include "orbsvcs/Event/EC_Dispatching.h"
00005 #include "orbsvcs/Event/EC_ConsumerAdmin.h"
00006 #include "orbsvcs/Event/EC_SupplierAdmin.h"
00007 #include "orbsvcs/Event/EC_Timeout_Generator.h"
00008 #include "orbsvcs/Event/EC_ObserverStrategy.h"
00009 #include "orbsvcs/Event/EC_ConsumerControl.h"
00010 #include "orbsvcs/Event/EC_SupplierControl.h"
00011 #include "ace/Dynamic_Service.h"
00012
00013 #if ! defined (__ACE_INLINE__)
00014 #include "orbsvcs/Event/EC_Event_Channel_Base.inl"
00015 #endif
00016
00017 ACE_RCSID(Event, EC_Event_Channel_Base, "$Id: EC_Event_Channel_Base.cpp 77001 2007-02-12 07:54:49Z johnnyw $")
00018
00019 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00020
00021 TAO_EC_Event_Channel_Base::
00022 TAO_EC_Event_Channel_Base (const TAO_EC_Event_Channel_Attributes& attr,
00023 TAO_EC_Factory* factory,
00024 int own_factory)
00025 : supplier_poa_ (PortableServer::POA::_duplicate (attr.supplier_poa)),
00026 consumer_poa_ (PortableServer::POA::_duplicate (attr.consumer_poa)),
00027 factory_ (factory),
00028 own_factory_ (own_factory),
00029 dispatching_ (0),
00030 filter_builder_ (0),
00031 supplier_filter_builder_ (0),
00032 consumer_admin_ (0),
00033 supplier_admin_ (0),
00034 timeout_generator_ (0),
00035 observer_strategy_ (0),
00036 scheduling_strategy_(0),
00037 consumer_reconnect_ (attr.consumer_reconnect),
00038 supplier_reconnect_ (attr.supplier_reconnect),
00039 disconnect_callbacks_ (attr.disconnect_callbacks),
00040 consumer_control_ (0),
00041 supplier_control_ (0),
00042 status_ (EC_S_IDLE)
00043 {
00044 this->scheduler_ =
00045 CORBA::Object::_duplicate (attr.scheduler);
00046 }
00047
00048 TAO_EC_Event_Channel_Base::~TAO_EC_Event_Channel_Base (void)
00049 {
00050
00051
00052
00053 this->factory_->destroy_supplier_control (this->supplier_control_);
00054 this->supplier_control_ = 0;
00055 this->factory_->destroy_consumer_control (this->consumer_control_);
00056 this->consumer_control_ = 0;
00057
00058 this->factory_->destroy_scheduling_strategy (this->scheduling_strategy_);
00059 this->scheduling_strategy_ = 0;
00060
00061 this->factory_->destroy_observer_strategy (this->observer_strategy_);
00062 this->observer_strategy_ = 0;
00063
00064 this->factory_->destroy_timeout_generator (this->timeout_generator_);
00065 this->timeout_generator_ = 0;
00066
00067 this->factory_->destroy_supplier_admin (this->supplier_admin_);
00068 this->supplier_admin_ = 0;
00069 this->factory_->destroy_consumer_admin (this->consumer_admin_);
00070 this->consumer_admin_ = 0;
00071
00072 this->factory_->destroy_supplier_filter_builder (this->supplier_filter_builder_);
00073 this->supplier_filter_builder_ = 0;
00074
00075 this->factory_->destroy_filter_builder (this->filter_builder_);
00076 this->filter_builder_ = 0;
00077
00078 this->factory_->destroy_dispatching (this->dispatching_);
00079 this->dispatching_ = 0;
00080
00081 this->factory (0, 0);
00082 }
00083
00084 void
00085 TAO_EC_Event_Channel_Base::create_strategies (void)
00086 {
00087 this->dispatching_ =
00088 this->factory_->create_dispatching (this);
00089 this->filter_builder_ =
00090 this->factory_->create_filter_builder (this);
00091 this->supplier_filter_builder_ =
00092 this->factory_->create_supplier_filter_builder (this);
00093 this->consumer_admin_ =
00094 this->factory_->create_consumer_admin (this);
00095 this->supplier_admin_ =
00096 this->factory_->create_supplier_admin (this);
00097 this->timeout_generator_ =
00098 this->factory_->create_timeout_generator (this);
00099 this->observer_strategy_ =
00100 this->factory_->create_observer_strategy (this);
00101
00102 this->scheduling_strategy_ =
00103 this->factory_->create_scheduling_strategy (this);
00104
00105 this->consumer_control_ =
00106 this->factory_->create_consumer_control (this);
00107 this->supplier_control_ =
00108 this->factory_->create_supplier_control (this);
00109 }
00110
00111 void
00112 TAO_EC_Event_Channel_Base::activate (void)
00113 {
00114 {
00115
00116
00117 ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->mutex_);
00118 if (this->status_ != EC_S_IDLE)
00119 return;
00120 this->status_ = EC_S_ACTIVATING;
00121 }
00122 this->dispatching_->activate ();
00123 this->timeout_generator_->activate ();
00124 this->consumer_control_->activate ();
00125 this->supplier_control_->activate ();
00126 {
00127
00128
00129 ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->mutex_);
00130 ACE_ASSERT (this->status_ == EC_S_ACTIVATING);
00131 this->status_ = EC_S_ACTIVE;
00132 }
00133 }
00134
00135 void
00136 TAO_EC_Event_Channel_Base::shutdown (void)
00137 {
00138 {
00139
00140
00141 ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->mutex_);
00142 if (this->status_ != EC_S_ACTIVE)
00143 return;
00144 this->status_ = EC_S_DESTROYING;
00145 }
00146 this->dispatching_->shutdown ();
00147 this->timeout_generator_->shutdown ();
00148 this->supplier_control_->shutdown ();
00149 this->consumer_control_->shutdown ();
00150
00151 this->deactivate_supplier_admin ();
00152 this->deactivate_consumer_admin ();
00153
00154 this->supplier_admin_->shutdown ();
00155
00156 this->consumer_admin_->shutdown ();
00157
00158 {
00159
00160
00161 ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->mutex_);
00162 ACE_ASSERT (this->status_ == EC_S_DESTROYING);
00163 this->status_ = EC_S_DESTROYED;
00164 }
00165 }
00166
00167 void
00168 TAO_EC_Event_Channel_Base::deactivate_supplier_admin (void)
00169 {
00170 try
00171 {
00172 PortableServer::POA_var supplier_poa =
00173 this->supplier_admin_->_default_POA ();
00174 PortableServer::ObjectId_var supplier_id =
00175 supplier_poa->servant_to_id (this->supplier_admin_);
00176 supplier_poa->deactivate_object (supplier_id.in ());
00177 }
00178 catch (const CORBA::Exception&)
00179 {
00180
00181 }
00182 }
00183
00184 void
00185 TAO_EC_Event_Channel_Base::deactivate_consumer_admin (void)
00186 {
00187 try
00188 {
00189 PortableServer::POA_var consumer_poa =
00190 this->consumer_admin_->_default_POA ();
00191 PortableServer::ObjectId_var consumer_id =
00192 consumer_poa->servant_to_id (this->consumer_admin_);
00193 consumer_poa->deactivate_object (consumer_id.in ());
00194 }
00195 catch (const CORBA::Exception&)
00196 {
00197
00198 }
00199 }
00200
00201 void
00202 TAO_EC_Event_Channel_Base::connected (TAO_EC_ProxyPushConsumer* consumer)
00203 {
00204 this->consumer_admin_->peer_connected (consumer);
00205 this->supplier_admin_->connected (consumer);
00206 this->observer_strategy_->connected (consumer);
00207 }
00208
00209 void
00210 TAO_EC_Event_Channel_Base::reconnected (TAO_EC_ProxyPushConsumer* consumer)
00211 {
00212 this->consumer_admin_->peer_reconnected (consumer);
00213 this->supplier_admin_->reconnected (consumer);
00214 this->observer_strategy_->connected (consumer);
00215 }
00216
00217 void
00218 TAO_EC_Event_Channel_Base::disconnected (TAO_EC_ProxyPushConsumer* consumer)
00219 {
00220 this->consumer_admin_->peer_disconnected (consumer);
00221 this->supplier_admin_->disconnected (consumer);
00222 this->observer_strategy_->disconnected (consumer);
00223 }
00224
00225 void
00226 TAO_EC_Event_Channel_Base::connected (TAO_EC_ProxyPushSupplier* supplier)
00227 {
00228 this->supplier_admin_->peer_connected (supplier);
00229 this->consumer_admin_->connected (supplier);
00230 this->observer_strategy_->connected (supplier);
00231 }
00232
00233 void
00234 TAO_EC_Event_Channel_Base::reconnected (TAO_EC_ProxyPushSupplier* supplier)
00235 {
00236 this->supplier_admin_->peer_reconnected (supplier);
00237 this->consumer_admin_->reconnected (supplier);
00238 this->observer_strategy_->connected (supplier);
00239 }
00240
00241 void
00242 TAO_EC_Event_Channel_Base::disconnected (TAO_EC_ProxyPushSupplier* supplier)
00243 {
00244 this->supplier_admin_->peer_disconnected (supplier);
00245 this->consumer_admin_->disconnected (supplier);
00246 this->observer_strategy_->disconnected (supplier);
00247 }
00248
00249 RtecEventChannelAdmin::ConsumerAdmin_ptr
00250 TAO_EC_Event_Channel_Base::for_consumers (void)
00251 {
00252 return this->consumer_admin_->_this ();
00253 }
00254
00255 RtecEventChannelAdmin::SupplierAdmin_ptr
00256 TAO_EC_Event_Channel_Base::for_suppliers (void)
00257 {
00258 return this->supplier_admin_->_this ();
00259 }
00260
00261 void
00262 TAO_EC_Event_Channel_Base::destroy (void)
00263 {
00264 this->shutdown ();
00265 }
00266
00267 RtecEventChannelAdmin::Observer_Handle
00268 TAO_EC_Event_Channel_Base::append_observer (
00269 RtecEventChannelAdmin::Observer_ptr observer)
00270 {
00271 return this->observer_strategy_->append_observer (observer);
00272 }
00273
00274 void
00275 TAO_EC_Event_Channel_Base::remove_observer (
00276 RtecEventChannelAdmin::Observer_Handle handle)
00277 {
00278 this->observer_strategy_->remove_observer (handle);
00279 }
00280
00281 void
00282 TAO_EC_Event_Channel_Base::for_each_consumer (
00283 TAO_ESF_Worker<TAO_EC_ProxyPushSupplier> *worker)
00284 {
00285 this->consumer_admin_->for_each (worker);
00286 }
00287
00288 void
00289 TAO_EC_Event_Channel_Base::for_each_supplier (
00290 TAO_ESF_Worker<TAO_EC_ProxyPushConsumer> *worker)
00291 {
00292 this->supplier_admin_->for_each (worker);
00293 }
00294
00295 TAO_END_VERSIONED_NAMESPACE_DECL