EC_ProxyConsumer.cpp

Go to the documentation of this file.
00001 // EC_ProxyConsumer.cpp,v 1.40 2006/03/14 06:14:25 jtc Exp
00002 
00003 #include "orbsvcs/Event/EC_ProxyConsumer.h"
00004 #include "orbsvcs/Event/EC_Event_Channel_Base.h"
00005 #include "orbsvcs/Event/EC_Supplier_Filter.h"
00006 #include "orbsvcs/Event/EC_Supplier_Filter_Builder.h"
00007 
00008 #include "ace/Reverse_Lock_T.h"
00009 
00010 #if ! defined (__ACE_INLINE__)
00011 #include "orbsvcs/Event/EC_ProxyConsumer.i"
00012 #endif /* __ACE_INLINE__ */
00013 
00014 ACE_RCSID (Event,
00015            EC_ProxyConsumer,
00016            "EC_ProxyConsumer.cpp,v 1.40 2006/03/14 06:14:25 jtc Exp")
00017 
00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00019 
00020 typedef ACE_Reverse_Lock<ACE_Lock> TAO_EC_Unlock;
00021 
00022 TAO_EC_ProxyPushConsumer::
00023     TAO_EC_ProxyPushConsumer (TAO_EC_Event_Channel_Base* ec)
00024   : event_channel_ (ec),
00025     refcount_ (1),
00026     connected_ (0),
00027     filter_ (0)
00028 {
00029   this->lock_ =
00030     this->event_channel_->create_consumer_lock ();
00031 
00032   this->default_POA_ =
00033     this->event_channel_->consumer_poa ();
00034 
00035   this->qos_.is_gateway = 0;
00036 }
00037 
00038 TAO_EC_ProxyPushConsumer::~TAO_EC_ProxyPushConsumer (void)
00039 {
00040   this->event_channel_->destroy_consumer_lock (this->lock_);
00041   this->cleanup_i ();
00042 }
00043 
00044 
00045 CORBA::Boolean
00046 TAO_EC_ProxyPushConsumer::supplier_non_existent (
00047       CORBA::Boolean_out disconnected
00048       ACE_ENV_ARG_DECL)
00049 {
00050   CORBA::Object_var supplier;
00051   {
00052     ACE_GUARD_THROW_EX (
00053         ACE_Lock, ace_mon, *this->lock_,
00054         CORBA::INTERNAL ());
00055     ACE_CHECK_RETURN (0);
00056 
00057     disconnected = 0;
00058     if (this->is_connected_i () == 0)
00059       {
00060         disconnected = 1;
00061         return 0;
00062       }
00063     if (CORBA::is_nil (this->supplier_.in ()))
00064       {
00065         return 0;
00066       }
00067     supplier = CORBA::Object::_duplicate (this->supplier_.in ());
00068   }
00069 
00070 #if (TAO_HAS_MINIMUM_CORBA == 0)
00071   return supplier->_non_existent (ACE_ENV_SINGLE_ARG_PARAMETER);
00072 #else
00073   return 0;
00074 #endif /* TAO_HAS_MINIMUM_CORBA */
00075 }
00076 
00077 void
00078 TAO_EC_ProxyPushConsumer::connected (TAO_EC_ProxyPushSupplier* supplier
00079                                      ACE_ENV_ARG_DECL)
00080 {
00081   TAO_EC_ProxyPushConsumer_Guard ace_mon (this->lock_,
00082                                           this->refcount_,
00083                                           this->event_channel_,
00084                                           this);
00085   if (!ace_mon.locked ())
00086     return;
00087 
00088   ace_mon.filter->connected (supplier ACE_ENV_ARG_PARAMETER);
00089 }
00090 
00091 void
00092 TAO_EC_ProxyPushConsumer::reconnected (TAO_EC_ProxyPushSupplier* supplier
00093                                        ACE_ENV_ARG_DECL)
00094 {
00095   TAO_EC_ProxyPushConsumer_Guard ace_mon (this->lock_,
00096                                           this->refcount_,
00097                                           this->event_channel_,
00098                                           this);
00099   if (!ace_mon.locked ())
00100     return;
00101 
00102   ace_mon.filter->reconnected (supplier ACE_ENV_ARG_PARAMETER);
00103 }
00104 
00105 void
00106 TAO_EC_ProxyPushConsumer::disconnected (TAO_EC_ProxyPushSupplier* supplier
00107                                         ACE_ENV_ARG_DECL)
00108 {
00109   TAO_EC_ProxyPushConsumer_Guard ace_mon (this->lock_,
00110                                           this->refcount_,
00111                                           this->event_channel_,
00112                                           this);
00113   if (!ace_mon.locked ())
00114     return;
00115 
00116   ace_mon.filter->disconnected (supplier ACE_ENV_ARG_PARAMETER);
00117 }
00118 
00119 void
00120 TAO_EC_ProxyPushConsumer::connected (TAO_EC_ProxyPushConsumer*
00121                                      ACE_ENV_ARG_DECL_NOT_USED)
00122 {
00123 }
00124 
00125 void
00126 TAO_EC_ProxyPushConsumer::reconnected (TAO_EC_ProxyPushConsumer*
00127                                        ACE_ENV_ARG_DECL_NOT_USED)
00128 {
00129 }
00130 
00131 void
00132 TAO_EC_ProxyPushConsumer::disconnected (TAO_EC_ProxyPushConsumer*
00133                                         ACE_ENV_ARG_DECL_NOT_USED)
00134 {
00135 }
00136 
00137 void
00138 TAO_EC_ProxyPushConsumer::shutdown_hook (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
00139 {
00140 }
00141 
00142 void
00143 TAO_EC_ProxyPushConsumer::shutdown (ACE_ENV_SINGLE_ARG_DECL)
00144 {
00145   RtecEventComm::PushSupplier_var supplier;
00146 
00147   {
00148     ACE_GUARD_THROW_EX (
00149         ACE_Lock, ace_mon, *this->lock_,
00150         RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR ());
00151     ACE_CHECK;
00152 
00153     supplier = this->supplier_._retn ();
00154     this->connected_ = 0;
00155 
00156     this->shutdown_hook (ACE_ENV_SINGLE_ARG_PARAMETER);
00157     ACE_CHECK;
00158 
00159     if (this->filter_ != 0)
00160       {
00161         this->filter_->shutdown (ACE_ENV_SINGLE_ARG_PARAMETER);
00162         ACE_CHECK;
00163 
00164         this->cleanup_i ();
00165       }
00166   }
00167 
00168   this->deactivate (ACE_ENV_SINGLE_ARG_PARAMETER);
00169   ACE_CHECK;
00170 
00171   if (CORBA::is_nil (supplier.in ()))
00172     return;
00173 
00174   ACE_TRY
00175     {
00176       supplier->disconnect_push_supplier (ACE_ENV_SINGLE_ARG_PARAMETER);
00177       ACE_TRY_CHECK;
00178     }
00179   ACE_CATCHANY
00180     {
00181       // Ignore exceptions, we must isolate other clients from
00182       // failures on this one.
00183     }
00184   ACE_ENDTRY;
00185 }
00186 
00187 void
00188 TAO_EC_ProxyPushConsumer::cleanup_i (void)
00189 {
00190   this->supplier_ =
00191     RtecEventComm::PushSupplier::_nil ();
00192   this->connected_ = 0;
00193 
00194   if (this->filter_ != 0)
00195     {
00196       this->filter_->unbind (this);
00197       this->filter_->_decr_refcnt ();
00198       this->filter_ = 0;
00199     }
00200 }
00201 
00202 void
00203 TAO_EC_ProxyPushConsumer::deactivate (ACE_ENV_SINGLE_ARG_DECL)
00204 {
00205   ACE_TRY
00206     {
00207       PortableServer::ObjectId id =
00208           this->object_id (ACE_ENV_SINGLE_ARG_PARAMETER);
00209       ACE_TRY_CHECK;
00210       this->default_POA_->deactivate_object (id ACE_ENV_ARG_PARAMETER);
00211       ACE_TRY_CHECK;
00212     }
00213   ACE_CATCHANY
00214     {
00215       // Exceptions here should not be propagated.  They usually
00216       // indicate that an object is beign disconnected twice, or some
00217       // race condition, but not a fault that the user needs to know
00218       // about.
00219     }
00220   ACE_ENDTRY;
00221 }
00222 
00223 CORBA::ULong
00224 TAO_EC_ProxyPushConsumer::_incr_refcnt (void)
00225 {
00226   ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->lock_, 0);
00227   return this->refcount_++;
00228 }
00229 
00230 void
00231 TAO_EC_ProxyPushConsumer::refcount_zero_hook (void)
00232 {
00233   // Use the event channel
00234   this->event_channel_->destroy_proxy (this);
00235 }
00236 
00237 CORBA::ULong
00238 TAO_EC_ProxyPushConsumer::_decr_refcnt (void)
00239 {
00240   {
00241     ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->lock_, 0);
00242     this->refcount_--;
00243     if (this->refcount_ != 0)
00244       return this->refcount_;
00245   }
00246 
00247   this->refcount_zero_hook ();
00248   return 0;
00249 }
00250 
00251 
00252 // ****************************************************************
00253 
00254 TAO_EC_ProxyPushConsumer_Guard::
00255     TAO_EC_ProxyPushConsumer_Guard (ACE_Lock *lock,
00256                                     CORBA::ULong &refcount,
00257                                     TAO_EC_Event_Channel_Base *ec,
00258                                     TAO_EC_ProxyPushConsumer *proxy)
00259  :   lock_ (lock),
00260      refcount_ (refcount),
00261      event_channel_ (ec),
00262      proxy_ (proxy),
00263      locked_ (0)
00264 {
00265   ACE_Guard<ACE_Lock> ace_mon (*this->lock_);
00266   // If the guard fails there is not much we can do, raising an
00267   // exception is wrong, the client has *no* way to handle that kind
00268   // of error.  Even worse, there is no exception to raise in that
00269   // case.
00270   // @@ Returning something won't work either, the error should be
00271   // logged though!
00272 
00273   if (proxy->is_connected_i () == 0)
00274     return;
00275 
00276   this->filter = this->proxy_->filter_i ();
00277   this->filter->_incr_refcnt ();
00278 
00279   this->locked_ = 1;
00280   this->refcount_++;
00281 }
00282 
00283 TAO_EC_ProxyPushConsumer_Guard::
00284     ~TAO_EC_ProxyPushConsumer_Guard (void)
00285 {
00286   // This access is safe because guard objects are created on the
00287   // stack, only one thread has access to them
00288   if (!this->locked_)
00289     return;
00290 
00291   {
00292     ACE_Guard<ACE_Lock> ace_mon (*this->lock_);
00293     // If the guard fails there is not much we can do, raising an
00294     // exception is wrong, the client has *no* way to handle that kind
00295     // of error.  Even worse, there is no exception to raise in that
00296     // case.
00297     // @@ Returning something won't work either, the error should be
00298     // logged though!
00299 
00300     this->filter->_decr_refcnt ();
00301 
00302     this->refcount_--;
00303     if (this->refcount_ != 0)
00304       return;
00305   }
00306 
00307   this->proxy_->refcount_zero_hook ();
00308 }
00309 
00310 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 13:11:08 2006 for TAO_RTEvent by doxygen 1.3.6