EC_Default_ProxyConsumer.cpp

Go to the documentation of this file.
00001 // $Id: EC_Default_ProxyConsumer.cpp 77001 2007-02-12 07:54:49Z johnnyw $
00002 
00003 #include "orbsvcs/Event/EC_Default_ProxyConsumer.h"
00004 #include "orbsvcs/Event/EC_Event_Channel_Base.h"
00005 #include "orbsvcs/Event/EC_Supplier_Filter_Builder.h"
00006 #include "orbsvcs/Event/EC_Supplier_Filter.h"
00007 #include "ace/Synch_T.h"
00008 
00009 ACE_RCSID(Event, EC_Default_ProxyConsumer, "$Id: EC_Default_ProxyConsumer.cpp 77001 2007-02-12 07:54:49Z johnnyw $")
00010 
00011 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00012 
00013 typedef ACE_Reverse_Lock<ACE_Lock> TAO_EC_Unlock;
00014 
00015 TAO_EC_Default_ProxyPushConsumer::
00016     TAO_EC_Default_ProxyPushConsumer (TAO_EC_Event_Channel_Base* ec)
00017   : TAO_EC_ProxyPushConsumer (ec)
00018 {
00019 }
00020 
00021 TAO_EC_Default_ProxyPushConsumer::~TAO_EC_Default_ProxyPushConsumer (void)
00022 {
00023 }
00024 
00025 void
00026 TAO_EC_Default_ProxyPushConsumer::connect_push_supplier (
00027       RtecEventComm::PushSupplier_ptr push_supplier,
00028       const RtecEventChannelAdmin::SupplierQOS& qos)
00029 {
00030   {
00031     ACE_GUARD_THROW_EX (
00032         ACE_Lock, ace_mon, *this->lock_,
00033         CORBA::INTERNAL ());
00034     // @@ RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR ());
00035 
00036     if (this->is_connected_i ())
00037       {
00038         if (this->event_channel_->supplier_reconnect () == 0)
00039           throw RtecEventChannelAdmin::AlreadyConnected ();
00040 
00041         // Re-connections are allowed, go ahead and disconnect the
00042         // consumer...
00043         this->cleanup_i ();
00044 
00045         // @@ Please read the comments in EC_ProxySuppliers about
00046         //     possible race conditions in this area...
00047         TAO_EC_Unlock reverse_lock (*this->lock_);
00048 
00049         {
00050           ACE_GUARD_THROW_EX (
00051               TAO_EC_Unlock, ace_mon, reverse_lock,
00052               CORBA::INTERNAL ());
00053           // @@ RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR ());
00054 
00055           this->event_channel_->reconnected (this);
00056         }
00057 
00058         // A separate thread could have connected siomultaneously,
00059         // this is probably an application error, handle it as
00060         // gracefully as possible
00061         if (this->is_connected_i ())
00062           return; // @@ Should we throw
00063       }
00064 
00065     this->supplier_ =
00066       RtecEventComm::PushSupplier::_duplicate (push_supplier);
00067     this->connected_ = 1;
00068     this->qos_ = qos;
00069 
00070 #if TAO_EC_ENABLE_DEBUG_MESSAGES
00071     ACE_DEBUG ((LM_DEBUG,
00072                  "Building filter for supplier <%x>.\n",
00073                 this));
00074 #endif /* TAO_EC_ENABLED_DEBUG_MESSAGES */
00075     this->filter_ =
00076       this->event_channel_->supplier_filter_builder ()->create (this->qos_);
00077     this->filter_->bind (this);
00078   }
00079 
00080   // Notify the event channel...
00081   this->event_channel_->connected (this);
00082 }
00083 
00084 void
00085 TAO_EC_Default_ProxyPushConsumer::push (const RtecEventComm::EventSet& event)
00086 {
00087   TAO_EC_ProxyPushConsumer_Guard ace_mon (this->lock_,
00088                                           this->refcount_,
00089                                           this->event_channel_,
00090                                           this);
00091   if (!ace_mon.locked ())
00092     return;
00093 
00094   ace_mon.filter->push (event, this);
00095 }
00096 
00097 void
00098 TAO_EC_Default_ProxyPushConsumer::disconnect_push_consumer ()
00099 {
00100   RtecEventComm::PushSupplier_var supplier;
00101   int connected = 0;
00102 
00103   {
00104     ACE_GUARD_THROW_EX (
00105         ACE_Lock, ace_mon, *this->lock_,
00106         CORBA::INTERNAL ());
00107     // @@ RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR ());
00108 
00109     connected = this->is_connected_i ();
00110     supplier = this->supplier_._retn ();
00111     this->connected_ = 0;
00112 
00113     if (connected)
00114       this->cleanup_i ();
00115   }
00116 
00117   // Notify the event channel...
00118   this->event_channel_->disconnected (this);
00119 
00120   if (CORBA::is_nil (supplier.in ()))
00121     {
00122       return;
00123     }
00124 
00125   if (this->event_channel_->disconnect_callbacks ())
00126     {
00127       try
00128         {
00129           supplier->disconnect_push_supplier ();
00130         }
00131       catch (const CORBA::Exception&)
00132         {
00133           // Ignore exceptions, we must isolate other clients from
00134           // failures on this one.
00135         }
00136     }
00137 }
00138 
00139 PortableServer::POA_ptr
00140 TAO_EC_Default_ProxyPushConsumer::_default_POA (void)
00141 {
00142   return PortableServer::POA::_duplicate (this->default_POA_.in ());
00143 }
00144 
00145 void
00146 TAO_EC_Default_ProxyPushConsumer::_add_ref (void)
00147 {
00148   this->_incr_refcnt ();
00149 }
00150 
00151 void
00152 TAO_EC_Default_ProxyPushConsumer::_remove_ref (void)
00153 {
00154   this->_decr_refcnt ();
00155 }
00156 
00157 void
00158 TAO_EC_Default_ProxyPushConsumer::activate (
00159    RtecEventChannelAdmin::ProxyPushConsumer_ptr &proxy)
00160 {
00161   proxy = this->_this ();
00162 }
00163 
00164 PortableServer::ObjectId
00165 TAO_EC_Default_ProxyPushConsumer::object_id (void)
00166 {
00167   PortableServer::ObjectId_var result =
00168     this->default_POA_->servant_to_id (this);
00169   return result.in ();
00170 }
00171 
00172 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:44:05 2010 for TAO_RTEvent by  doxygen 1.4.7