00001
00002
00003 #include "orbsvcs/Notify/Object.h"
00004 #include "orbsvcs/Notify/POA_Helper.h"
00005 #include "orbsvcs/Notify/Worker_Task.h"
00006 #include "orbsvcs/Notify/Properties.h"
00007 #include "orbsvcs/Notify/Builder.h"
00008 #include "orbsvcs/Notify/ThreadPool_Task.h"
00009 #include "orbsvcs/Notify/Reactive_Task.h"
00010 #include "tao/debug.h"
00011 #include "orbsvcs/Notify/Event_Manager.h"
00012
00013 #if ! defined (__ACE_INLINE__)
00014 #include "orbsvcs/Notify/Object.inl"
00015 #endif
00016
00017 ACE_RCSID(Notify, TAO_Notify_Object, "Object.cpp,v 1.21 2006/03/14 06:14:34 jtc Exp")
00018
00019 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00020
00021 TAO_Notify_Object::TAO_Notify_Object (void)
00022 : poa_ (0)
00023 , proxy_poa_ (0)
00024 , own_proxy_poa_ (false)
00025 , object_poa_ (0)
00026 , own_object_poa_ (false)
00027 , id_ (0)
00028 , own_worker_task_ (false)
00029 , shutdown_ (false)
00030 {
00031 if (TAO_debug_level > 2 )
00032 ACE_DEBUG ((LM_DEBUG,"object:%x created\n", this ));
00033 }
00034
00035 TAO_Notify_Object::~TAO_Notify_Object ()
00036 {
00037 if (TAO_debug_level > 2 )
00038 ACE_DEBUG ((LM_DEBUG,"object:%x destroyed\n", this ));
00039
00040 this->destroy_proxy_poa ();
00041 this->destroy_object_poa ();
00042 this->destroy_poa ();
00043 }
00044
00045 void
00046 TAO_Notify_Object::initialize (TAO_Notify_Object* parent)
00047 {
00048 ACE_ASSERT (parent != 0 && this->event_manager_.get() == 0);
00049
00050
00051
00052
00053 this->event_manager_ = parent->event_manager_;
00054 this->admin_properties_ = parent->admin_properties_;
00055 this->inherit_poas( *parent );
00056 this->worker_task_ = parent->worker_task_;
00057
00058
00059 parent->qos_properties_.transfer (this->qos_properties_);
00060 this->qos_changed (this->qos_properties_);
00061 }
00062
00063 void
00064 TAO_Notify_Object::set_event_manager( TAO_Notify_Event_Manager* event_manager )
00065 {
00066 ACE_ASSERT( event_manager != 0 );
00067 this->event_manager_.reset( event_manager );
00068 }
00069
00070 CORBA::Object_ptr
00071 TAO_Notify_Object::activate (PortableServer::Servant servant ACE_ENV_ARG_DECL)
00072 {
00073 return this->poa_->activate (servant, this->id_ ACE_ENV_ARG_PARAMETER);
00074 }
00075
00076
00077 CORBA::Object_ptr
00078 TAO_Notify_Object::activate (
00079 PortableServer::Servant servant,
00080 CORBA::Long id
00081 ACE_ENV_ARG_DECL)
00082 {
00083 this->id_ = id;
00084 return this->poa_->activate_with_id (servant, this->id_ ACE_ENV_ARG_PARAMETER);
00085 }
00086
00087
00088 void
00089 TAO_Notify_Object::deactivate (ACE_ENV_SINGLE_ARG_DECL)
00090 {
00091 ACE_TRY
00092 {
00093 this->poa_->deactivate (this->id_ ACE_ENV_ARG_PARAMETER);
00094 ACE_TRY_CHECK;
00095 }
00096 ACE_CATCHANY
00097 {
00098
00099 if (TAO_debug_level > 2)
00100 {
00101 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "(%P|%t)\n");
00102 ACE_DEBUG ((LM_DEBUG, "Could not deactivate object %d\n", this->id_));
00103 }
00104 }
00105 ACE_ENDTRY;
00106 }
00107
00108 int
00109 TAO_Notify_Object::shutdown (ACE_ENV_SINGLE_ARG_DECL)
00110 {
00111 {
00112 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 1);
00113
00114 if (this->shutdown_ == 1)
00115 return 1;
00116
00117 this->shutdown_ = 1;
00118 }
00119
00120 this->deactivate (ACE_ENV_SINGLE_ARG_PARAMETER);
00121 ACE_CHECK_RETURN (1);
00122
00123 this->shutdown_worker_task ();
00124
00125 return 0;
00126 }
00127
00128 CORBA::Object_ptr
00129 TAO_Notify_Object::ref (ACE_ENV_SINGLE_ARG_DECL)
00130 {
00131 return this->poa_->id_to_reference (this->id_ ACE_ENV_ARG_PARAMETER);
00132 }
00133
00134 void
00135 TAO_Notify_Object::shutdown_worker_task (void)
00136 {
00137
00138 TAO_Notify_Worker_Task::Ptr task( this->worker_task_ );
00139 this->worker_task_.reset();
00140 if ( task.isSet() )
00141 {
00142 if ( this->own_worker_task_ )
00143 {
00144 task->shutdown ();
00145 }
00146 }
00147 }
00148
00149 void
00150 TAO_Notify_Object::destroy_proxy_poa (void)
00151 {
00152 if (this->proxy_poa_ != 0)
00153 {
00154 ACE_TRY_NEW_ENV
00155 {
00156 if ( this->proxy_poa_ == this->object_poa_ ) this->object_poa_ = 0;
00157 if ( this->proxy_poa_ == this->poa_ ) this->poa_ = 0;
00158
00159 if ( this->own_proxy_poa_ == true )
00160 {
00161 this->own_proxy_poa_ = false;
00162 ACE_Auto_Ptr< TAO_Notify_POA_Helper > app( object_poa_ );
00163 this->proxy_poa_->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
00164 ACE_TRY_CHECK;
00165 }
00166 this->proxy_poa_ = 0;
00167 }
00168 ACE_CATCHANY
00169 {
00170 if (TAO_debug_level > 2)
00171 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
00172 "Proxy shutdown error (%P|%t)\n");
00173 }
00174 ACE_ENDTRY;
00175 }
00176 }
00177
00178 void
00179 TAO_Notify_Object::destroy_object_poa (void)
00180 {
00181 if (this->object_poa_ != 0)
00182 {
00183 ACE_TRY_NEW_ENV
00184 {
00185 if ( this->object_poa_ == this->proxy_poa_ ) this->proxy_poa_ = 0;
00186 if ( this->object_poa_ == this->poa_ ) this->poa_ = 0;
00187
00188 if ( this->own_object_poa_ == true )
00189 {
00190 this->own_object_poa_ = false;
00191 ACE_Auto_Ptr< TAO_Notify_POA_Helper > aop( object_poa_ );
00192 this->object_poa_->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
00193 ACE_TRY_CHECK;
00194 }
00195 this->object_poa_ = 0;
00196 }
00197 ACE_CATCHANY
00198 {
00199 if (TAO_debug_level > 2)
00200 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
00201 "Proxy shutdown error (%P|%t)\n");
00202 }
00203 ACE_ENDTRY;
00204 }
00205 }
00206
00207
00208 void TAO_Notify_Object::destroy_poa (void)
00209 {
00210 this->poa_ = 0;
00211 }
00212
00213 void
00214 TAO_Notify_Object::set_worker_task (TAO_Notify_Worker_Task* worker_task)
00215 {
00216 ACE_ASSERT( worker_task != 0 );
00217
00218
00219 this->shutdown_worker_task ();
00220
00221 this->worker_task_.reset (worker_task);
00222
00223 this->own_worker_task_ = true;
00224 }
00225
00226 void
00227 TAO_Notify_Object::set_proxy_poa (TAO_Notify_POA_Helper* proxy_poa)
00228 {
00229
00230 this->destroy_proxy_poa ();
00231
00232 this->proxy_poa_ = proxy_poa;
00233
00234 this->own_proxy_poa_ = true;
00235 }
00236
00237 void
00238 TAO_Notify_Object::set_object_poa (TAO_Notify_POA_Helper* object_poa)
00239 {
00240
00241 this->destroy_object_poa ();
00242
00243 this->object_poa_ = object_poa;
00244
00245 this->own_object_poa_ = true;
00246 }
00247
00248 void
00249 TAO_Notify_Object::set_poa (TAO_Notify_POA_Helper* poa)
00250 {
00251 this->poa_ = poa;
00252 }
00253
00254 void
00255 TAO_Notify_Object::set_qos (const CosNotification::QoSProperties & qos ACE_ENV_ARG_DECL)
00256 {
00257 CosNotification::PropertyErrorSeq err_seq;
00258
00259 TAO_Notify_QoSProperties new_qos_properties;
00260
00261 if (new_qos_properties.init (qos, err_seq) == -1)
00262 ACE_THROW (CORBA::INTERNAL ());
00263
00264
00265 if (new_qos_properties.thread_pool ().is_valid ())
00266 {
00267 if (new_qos_properties.thread_pool ().value ().static_threads == 0)
00268 {
00269 TAO_Notify_PROPERTIES::instance()->builder()->apply_reactive_concurrency (*this ACE_ENV_ARG_PARAMETER);
00270 ACE_CHECK;
00271 }
00272 else
00273 {
00274 TAO_Notify_PROPERTIES::instance()->builder()->
00275 apply_thread_pool_concurrency (*this, new_qos_properties.thread_pool ().value () ACE_ENV_ARG_PARAMETER);
00276 ACE_CHECK;
00277 }
00278 }
00279 else if (new_qos_properties.thread_pool_lane ().is_valid ())
00280 TAO_Notify_PROPERTIES::instance()->builder()->
00281 apply_lane_concurrency (*this, new_qos_properties.thread_pool_lane ().value () ACE_ENV_ARG_PARAMETER);
00282 ACE_CHECK;
00283
00284
00285 this->worker_task_->update_qos_properties (new_qos_properties);
00286
00287
00288 this->qos_changed (new_qos_properties);
00289
00290
00291 if (new_qos_properties.copy (this->qos_properties_) == -1)
00292 ACE_THROW (CORBA::INTERNAL ());
00293
00294 if (err_seq.length () > 0)
00295 ACE_THROW (CosNotification::UnsupportedQoS (err_seq));
00296 }
00297
00298 CosNotification::QoSProperties*
00299 TAO_Notify_Object::get_qos (ACE_ENV_SINGLE_ARG_DECL)
00300 {
00301 CosNotification::QoSProperties_var properties;
00302
00303 ACE_NEW_THROW_EX (properties,
00304 CosNotification::QoSProperties (),
00305 CORBA::NO_MEMORY ());
00306
00307 this->qos_properties_.populate (properties);
00308
00309 return properties._retn ();
00310 }
00311
00312 bool
00313 TAO_Notify_Object::find_qos_property_value (
00314 const char * name,
00315 CosNotification::PropertyValue & value) const
00316 {
00317 return this->qos_properties_.find (name, value);
00318 }
00319
00320
00321 void
00322 TAO_Notify_Object::qos_changed (const TAO_Notify_QoSProperties& )
00323 {
00324
00325 }
00326
00327 TAO_Notify_Timer*
00328 TAO_Notify_Object::timer (void)
00329 {
00330 ACE_ASSERT (worker_task_.get() != 0);
00331 return this->worker_task_->timer ();
00332 }
00333
00334 namespace
00335 {
00336 template<class T>
00337 void add_qos_attr(TAO_Notify::NVPList& attrs, const T& prop)
00338 {
00339 if (prop.is_valid())
00340 {
00341 attrs.push_back(TAO_Notify::NVP (prop));
00342 }
00343 }
00344 }
00345
00346 void
00347 TAO_Notify_Object::save_attrs (TAO_Notify::NVPList& attrs)
00348 {
00349 add_qos_attr(attrs, this->qos_properties_.event_reliability ());
00350 add_qos_attr(attrs, this->qos_properties_.connection_reliability ());
00351 add_qos_attr(attrs, this->qos_properties_.priority ());
00352 add_qos_attr(attrs, this->qos_properties_.timeout ());
00353 add_qos_attr(attrs, this->qos_properties_.stop_time_supported ());
00354 add_qos_attr(attrs, this->qos_properties_.maximum_batch_size ());
00355 add_qos_attr(attrs, this->qos_properties_.pacing_interval ());
00356 }
00357
00358 void
00359 TAO_Notify_Object::load_attrs(const TAO_Notify::NVPList& attrs)
00360 {
00361 attrs.load (this->qos_properties_.event_reliability ());
00362 attrs.load (this->qos_properties_.connection_reliability ());
00363 attrs.load (this->qos_properties_.priority ());
00364 attrs.load (this->qos_properties_.timeout ());
00365 attrs.load (this->qos_properties_.stop_time_supported ());
00366 attrs.load (this->qos_properties_.maximum_batch_size ());
00367 attrs.load (this->qos_properties_.pacing_interval ());
00368 this->qos_properties_.init ();
00369 }
00370
00371
00372 TAO_END_VERSIONED_NAMESPACE_DECL