Object.cpp

Go to the documentation of this file.
00001 // $Id: Object.cpp 79324 2007-08-13 11:20:01Z elliott_c $
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 /* __ACE_INLINE__ */
00016 
00017 ACE_RCSID(Notify, TAO_Notify_Object, "$Id: Object.cpp 79324 2007-08-13 11:20:01Z elliott_c $")
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   // Do not use sets to avoid asserts.
00051   // Object must be able to inherit NULL references
00052   // due to current design.
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   // Pass  QoS
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)
00072 {
00073   return this->poa_->activate (servant, this->id_);
00074 }
00075 
00076 /// Activate with existing id
00077 CORBA::Object_ptr
00078 TAO_Notify_Object::activate (
00079     PortableServer::Servant servant,
00080     CORBA::Long id)
00081 {
00082   this->id_ = id;
00083   return this->poa_->activate_with_id (servant, this->id_);
00084 }
00085 
00086 
00087 void
00088 TAO_Notify_Object::deactivate (void)
00089 {
00090   try
00091   {
00092     this->poa_->deactivate (this->id_);
00093   }
00094   catch (const CORBA::Exception& ex)
00095   {
00096     // Do not propagate any exceptions
00097     if (TAO_debug_level > 2)
00098     {
00099       ex._tao_print_exception ("(%P|%t)\n");
00100       ACE_DEBUG ((LM_DEBUG, "Could not deactivate object %d\n", this->id_));
00101     }
00102   }
00103 }
00104 
00105 int
00106 TAO_Notify_Object::shutdown (void)
00107 {
00108   {
00109     ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 1);
00110 
00111     if (this->shutdown_ == 1)
00112       return 1; // Another thread has already run shutdown.
00113 
00114     this->shutdown_ = 1;
00115   }
00116 
00117   this->deactivate ();
00118 
00119   this->shutdown_worker_task ();
00120 
00121   return 0;
00122 }
00123 
00124 CORBA::Object_ptr
00125 TAO_Notify_Object::ref (void)
00126 {
00127   return this->poa_->id_to_reference (this->id_);
00128 }
00129 
00130 void
00131 TAO_Notify_Object::shutdown_worker_task (void)
00132 {
00133   // Only do this if we are the owner.
00134   TAO_Notify_Worker_Task::Ptr task( this->worker_task_ );
00135   this->worker_task_.reset();
00136   if ( task.isSet() )
00137   {
00138     if ( this->own_worker_task_ )
00139     {
00140       task->shutdown ();
00141     }
00142   }
00143 }
00144 
00145 void
00146 TAO_Notify_Object::destroy_proxy_poa (void)
00147 {
00148   if (this->proxy_poa_ != 0)
00149   {
00150     try
00151     {
00152       if ( this->proxy_poa_ == this->object_poa_ ) this->object_poa_ = 0;
00153       if ( this->proxy_poa_ == this->poa_ ) this->poa_ = 0;
00154 
00155       if ( this->own_proxy_poa_ == true )
00156       {
00157         this->own_proxy_poa_ = false;
00158         ACE_Auto_Ptr< TAO_Notify_POA_Helper > app( proxy_poa_ );
00159         this->proxy_poa_->destroy ();
00160       }
00161       this->proxy_poa_ = 0;
00162     }
00163     catch (const CORBA::Exception& ex)
00164     {
00165       if (TAO_debug_level > 2)
00166         ex._tao_print_exception ("Proxy shutdown error (%P|%t)\n");
00167     }
00168   }
00169 }
00170 
00171 void
00172 TAO_Notify_Object::destroy_object_poa (void)
00173 {
00174   if (this->object_poa_ != 0)
00175   {
00176     try
00177     {
00178       if ( this->object_poa_ == this->proxy_poa_ ) this->proxy_poa_ = 0;
00179       if ( this->object_poa_ == this->poa_ ) this->poa_ = 0;
00180 
00181       if ( this->own_object_poa_ == true )
00182       {
00183         this->own_object_poa_ = false;
00184         ACE_Auto_Ptr< TAO_Notify_POA_Helper > aop( object_poa_ );
00185         this->object_poa_->destroy ();
00186       }
00187       this->object_poa_ = 0;
00188     }
00189     catch (const CORBA::Exception& ex)
00190     {
00191       if (TAO_debug_level > 2)
00192         ex._tao_print_exception ("Proxy shutdown error (%P|%t)\n");
00193     }
00194   }
00195 }
00196 
00197 /// Shutdown the current poa.
00198 void TAO_Notify_Object::destroy_poa (void)
00199 {
00200   this->poa_ = 0;
00201 }
00202 
00203 void
00204 TAO_Notify_Object::set_worker_task (TAO_Notify_Worker_Task* worker_task)
00205 {
00206   ACE_ASSERT( worker_task != 0 );
00207 
00208   // shutdown the current worker.
00209   this->shutdown_worker_task ();
00210 
00211   this->worker_task_.reset (worker_task);
00212 
00213   this->own_worker_task_ = true;
00214 }
00215 
00216 void
00217 TAO_Notify_Object::set_proxy_poa (TAO_Notify_POA_Helper* proxy_poa)
00218 {
00219   // shutdown current proxy poa.
00220   this->destroy_proxy_poa ();
00221 
00222   this->proxy_poa_ = proxy_poa;
00223 
00224   this->own_proxy_poa_ = true;
00225 }
00226 
00227 void
00228 TAO_Notify_Object::set_object_poa (TAO_Notify_POA_Helper* object_poa)
00229 {
00230   // shutdown current object poa.
00231   this->destroy_object_poa ();
00232 
00233   this->object_poa_ = object_poa;
00234 
00235   this->own_object_poa_ = true;
00236 }
00237 
00238 void
00239 TAO_Notify_Object::set_poa (TAO_Notify_POA_Helper* poa)
00240 {
00241   this->poa_ = poa;
00242 }
00243 
00244 void
00245 TAO_Notify_Object::set_qos (const CosNotification::QoSProperties & qos)
00246 {
00247   CosNotification::PropertyErrorSeq err_seq;
00248 
00249   TAO_Notify_QoSProperties new_qos_properties;
00250 
00251   if (new_qos_properties.init (qos, err_seq) == -1)
00252     throw CORBA::INTERNAL ();
00253 
00254   // Apply the appropriate concurrency QoS
00255   if (new_qos_properties.thread_pool ().is_valid ())
00256   {
00257     if (new_qos_properties.thread_pool ().value ().static_threads == 0)
00258       {
00259         TAO_Notify_PROPERTIES::instance()->builder()->apply_reactive_concurrency (*this);
00260       }
00261     else
00262       {
00263         TAO_Notify_PROPERTIES::instance()->builder()->
00264         apply_thread_pool_concurrency (*this, new_qos_properties.thread_pool ().value ());
00265       }
00266   }
00267   else if (new_qos_properties.thread_pool_lane ().is_valid ())
00268     TAO_Notify_PROPERTIES::instance()->builder()->
00269     apply_lane_concurrency (*this, new_qos_properties.thread_pool_lane ().value ());
00270 
00271   // Update the Thread Task's QoS properties..
00272   this->worker_task_->update_qos_properties (new_qos_properties);
00273 
00274   // Inform subclasses of QoS changed.
00275   this->qos_changed (new_qos_properties);
00276 
00277   // Init the the overall QoS on this object.
00278   if (new_qos_properties.copy (this->qos_properties_) == -1)
00279     throw CORBA::INTERNAL ();
00280 
00281   if (err_seq.length () > 0) // Unsupported Property
00282     throw CosNotification::UnsupportedQoS (err_seq);
00283 }
00284 
00285 CosNotification::QoSProperties*
00286 TAO_Notify_Object::get_qos (void)
00287 {
00288   CosNotification::QoSProperties_var properties;
00289 
00290   ACE_NEW_THROW_EX (properties,
00291     CosNotification::QoSProperties (),
00292     CORBA::NO_MEMORY ());
00293 
00294   this->qos_properties_.populate (properties);
00295 
00296   return properties._retn ();
00297 }
00298 
00299 bool
00300 TAO_Notify_Object::find_qos_property_value (
00301   const char * name,
00302   CosNotification::PropertyValue & value) const
00303 {
00304   // qos_properties_ is essentially a map and the find() method returns
00305   // zero on success.  We must convert this to a boolean value.
00306   return (this->qos_properties_.find (name, value) == 0);
00307 }
00308 
00309 
00310 void
00311 TAO_Notify_Object::qos_changed (const TAO_Notify_QoSProperties& /*qos_properties*/)
00312 {
00313   // NOP.
00314 }
00315 
00316 TAO_Notify_Timer*
00317 TAO_Notify_Object::timer (void)
00318 {
00319   ACE_ASSERT (worker_task_.get() != 0);
00320   return this->worker_task_->timer ();
00321 }
00322 
00323 namespace
00324 {
00325   template<class T>
00326   void add_qos_attr(TAO_Notify::NVPList& attrs, const T& prop)
00327   {
00328     if (prop.is_valid())
00329     {
00330       attrs.push_back(TAO_Notify::NVP (prop));
00331     }
00332   }
00333 } // namespace
00334 
00335 void
00336 TAO_Notify_Object::save_attrs (TAO_Notify::NVPList& attrs)
00337 {
00338   add_qos_attr(attrs, this->qos_properties_.event_reliability ());
00339   add_qos_attr(attrs, this->qos_properties_.connection_reliability ());
00340   add_qos_attr(attrs, this->qos_properties_.priority ());
00341   add_qos_attr(attrs, this->qos_properties_.timeout ());
00342   add_qos_attr(attrs, this->qos_properties_.stop_time_supported ());
00343   add_qos_attr(attrs, this->qos_properties_.maximum_batch_size ());
00344   add_qos_attr(attrs, this->qos_properties_.pacing_interval ());
00345 }
00346 
00347 void
00348 TAO_Notify_Object::load_attrs(const TAO_Notify::NVPList& attrs)
00349 {
00350   attrs.load (this->qos_properties_.event_reliability ());
00351   attrs.load (this->qos_properties_.connection_reliability ());
00352   attrs.load (this->qos_properties_.priority ());
00353   attrs.load (this->qos_properties_.timeout ());
00354   attrs.load (this->qos_properties_.stop_time_supported ());
00355   attrs.load (this->qos_properties_.maximum_batch_size ());
00356   attrs.load (this->qos_properties_.pacing_interval ());
00357   this->qos_properties_.init ();
00358 }
00359 
00360 TAO_Notify_Worker_Task*
00361 TAO_Notify_Object::get_worker_task (void)
00362 {
00363   return this->worker_task_.get ();
00364 }
00365 
00366 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:45:29 2010 for TAO_CosNotification by  doxygen 1.4.7