TAO_ECG_UDP_Receiver Class Reference

Receive events from UDP or Multicast and push them to a "local" EC. NOT THREAD-SAFE. More...

#include <ECG_UDP_Receiver.h>

Inheritance diagram for TAO_ECG_UDP_Receiver:

Inheritance graph
[legend]
Collaboration diagram for TAO_ECG_UDP_Receiver:

Collaboration graph
[legend]
List of all members.

[NOHEADER]

 ~TAO_ECG_UDP_Receiver (void)
void init (RtecEventChannelAdmin::EventChannel_ptr lcl_ec, TAO_ECG_Refcounted_Endpoint ignore_from, RtecUDPAdmin::AddrServer_ptr addr_server)
void connect (const RtecEventChannelAdmin::SupplierQOS &pub)
 Connect or reconnect to the EC with the given publications.

void set_handler_shutdown (TAO_ECG_Refcounted_Handler handler_shutdown_rptr)
void shutdown ()
TAO_EC_Servant_Var< TAO_ECG_UDP_Receivercreate (CORBA::Boolean perform_crc=0)

Public Member Functions

void get_addr (const RtecEventComm::EventHeader &header, RtecUDPAdmin::UDP_Addr_out addr)
virtual void disconnect_push_supplier () throw (CORBA::SystemException)
virtual int handle_input (ACE_SOCK_Dgram &dgram)
 TAO_ECG_Dgram_Handler method.


Protected Member Functions

 TAO_ECG_UDP_Receiver (CORBA::Boolean perform_crc=0)

Private Types

typedef TAO_EC_Auto_Command<
TAO_ECG_UDP_Receiver_Disconnect_Command
ECG_Receiver_Auto_Proxy_Disconnect

Private Member Functions

void new_connect (const RtecEventChannelAdmin::SupplierQOS &pub)
void reconnect (const RtecEventChannelAdmin::SupplierQOS &pub)

Private Attributes

RtecEventChannelAdmin::EventChannel_var lcl_ec_
 Event Channel to which we act as a supplier.

RtecUDPAdmin::AddrServer_var addr_server_
 The server used to map event types to multicast groups.

RtecEventChannelAdmin::ProxyPushConsumer_var consumer_proxy_
 Proxy used to supply events to the Event Channel.

TAO_ECG_CDR_Message_Receiver cdr_receiver_
TAO_ECG_Refcounted_Handler handler_rptr_
ECG_Receiver_Auto_Proxy_Disconnect auto_proxy_disconnect_
 Manages our connection to Consumer Proxy.


Detailed Description

Receive events from UDP or Multicast and push them to a "local" EC. NOT THREAD-SAFE.

This class connects as a supplier to an EventChannel, and supplies to it all events it receives via UDP or Multicast.

Definition at line 103 of file ECG_UDP_Receiver.h.


Member Typedef Documentation

typedef TAO_EC_Auto_Command<TAO_ECG_UDP_Receiver_Disconnect_Command> TAO_ECG_UDP_Receiver::ECG_Receiver_Auto_Proxy_Disconnect [private]
 

Definition at line 227 of file ECG_UDP_Receiver.h.

Referenced by new_connect().


Constructor & Destructor Documentation

TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO_ECG_UDP_Receiver::~TAO_ECG_UDP_Receiver void   ) 
 

Definition at line 20 of file ECG_UDP_Receiver.cpp.

References consumer_proxy_, ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::get(), and handler_rptr_.

00021 {
00022   this->consumer_proxy_ =
00023     RtecEventChannelAdmin::ProxyPushConsumer::_nil ();
00024 
00025   if (this->handler_rptr_.get ())
00026     this->handler_rptr_->shutdown ();
00027 }

ACE_INLINE TAO_ECG_UDP_Receiver::TAO_ECG_UDP_Receiver CORBA::Boolean  perform_crc = 0  )  [protected]
 

Constructor (protected). Clients can create new TAO_ECG_UDP_Receiver objects using the static create() method.

Definition at line 60 of file ECG_UDP_Receiver.i.

00061   : lcl_ec_ ()
00062   , addr_server_ ()
00063   , consumer_proxy_ ()
00064   , cdr_receiver_ (perform_crc)
00065   , handler_rptr_ ()
00066   , auto_proxy_disconnect_ ()
00067 {
00068 }


Member Function Documentation

void TAO_ECG_UDP_Receiver::connect const RtecEventChannelAdmin::SupplierQOS pub  ) 
 

Connect or reconnect to the EC with the given publications.

Note:
If we are already connected to EC and a reconnection is necessary, the EC must have reconnects enabled in order for this method to succeed.

Definition at line 56 of file ECG_UDP_Receiver.cpp.

References ACE_CHECK, ACE_ENV_ARG_PARAMETER, ACE_ERROR, ACE_THROW, CORBA::is_nil(), LM_ERROR, new_connect(), and reconnect().

00058 {
00059   if (CORBA::is_nil (this->lcl_ec_.in ()))
00060     {
00061       ACE_ERROR ((LM_ERROR,
00062                   "Error initializing TAO_ECG_UDP_Receiver: "
00063                   "init() hasn't been called before connect().\n"));
00064       ACE_THROW (CORBA::INTERNAL ());
00065     }
00066 
00067   if (pub.publications.length () == 0)
00068     {
00069       ACE_ERROR ((LM_ERROR,
00070                   "TAO_ECG_UDP_Receiver::connect(): "
00071                   "0-length publications argument.\n"));
00072       ACE_THROW (CORBA::INTERNAL ());
00073     }
00074 
00075   if (CORBA::is_nil (this->consumer_proxy_.in ()))
00076     {
00077       this->new_connect (pub ACE_ENV_ARG_PARAMETER);
00078       ACE_CHECK;
00079     }
00080   else
00081     {
00082       this->reconnect (pub ACE_ENV_ARG_PARAMETER);
00083       ACE_CHECK;
00084     }
00085 }

ACE_INLINE TAO_EC_Servant_Var< TAO_ECG_UDP_Receiver > TAO_ECG_UDP_Receiver::create CORBA::Boolean  perform_crc = 0  )  [static]
 

Create a new TAO_ECG_UDP_Receiver object. (Constructor access is restricted to insure that all TAO_ECG_UDP_Receiver objects are heap-allocated.)

Definition at line 71 of file ECG_UDP_Receiver.i.

References ACE_NEW_RETURN.

00072 {
00073   TAO_EC_Servant_Var<TAO_ECG_UDP_Receiver> r;
00074   ACE_NEW_RETURN (r,
00075                   TAO_ECG_UDP_Receiver (perform_crc),
00076                   r);
00077   return r;
00078 }

void TAO_ECG_UDP_Receiver::disconnect_push_supplier  )  throw (CORBA::SystemException) [virtual]
 

The PushSupplier idl method. Invokes shutdown (), which may result in the object being deleted, if refcounting is used to manage its lifetime.

Definition at line 151 of file ECG_UDP_Receiver.cpp.

References ACE_ENV_SINGLE_ARG_PARAMETER.

00153 {
00154   // Prevent attempts to disconnect.
00155   this->auto_proxy_disconnect_.disallow_command ();
00156 
00157   this->shutdown (ACE_ENV_SINGLE_ARG_PARAMETER);
00158 }

ACE_INLINE void TAO_ECG_UDP_Receiver::get_addr const RtecEventComm::EventHeader header,
RtecUDPAdmin::UDP_Addr_out  addr
[virtual]
 

Accessor. Call the RtecUDPAdmin::AddrServer::get_addr. Throws exception if nill Address Server was specified in init ().

Implements TAO_ECG_Dgram_Handler.

Definition at line 88 of file ECG_UDP_Receiver.i.

References ACE_ENV_ARG_PARAMETER, ACE_ERROR, ACE_THROW, addr_server_, CORBA::is_nil(), and LM_ERROR.

00091 {
00092   if (CORBA::is_nil (this->addr_server_.in ()))
00093     {
00094       ACE_ERROR ((LM_ERROR,
00095                   "TAO_ECG_UDP_Receiver::get_addr() called but "
00096                   "nil Address Server was supplied during "
00097                   "initialization through init().\n"));
00098 
00099       ACE_THROW (CORBA::INTERNAL ());
00100     }
00101 
00102   this->addr_server_->get_addr (header, addr
00103                                 ACE_ENV_ARG_PARAMETER);
00104 }

int TAO_ECG_UDP_Receiver::handle_input ACE_SOCK_Dgram dgram  )  [virtual]
 

TAO_ECG_Dgram_Handler method.

UDP/Multicast Event_Handlers call this method when data is available at the socket - the is ready for reading. Data is read from the socket, and, if complete message is received, the event is pushed to the local Event Channel.

Implements TAO_ECG_Dgram_Handler.

Definition at line 200 of file ECG_UDP_Receiver.cpp.

References ACE_ANY_EXCEPTION, ACE_CATCHANY, ACE_DEBUG, ACE_DECLARE_NEW_CORBA_ENV, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_ERROR, ACE_ERROR_RETURN, ACE_TRY, ACE_TRY_CHECK, cdr_receiver_, consumer_proxy_, TAO_ECG_Event_CDR_Decoder::events, TAO_ECG_CDR_Message_Receiver::handle_input(), CORBA::is_nil(), LM_ERROR, and shutdown().

00201 {
00202   ACE_DECLARE_NEW_CORBA_ENV;
00203   ACE_TRY
00204     {
00205       // Make sure we are connected to the Event Channel before proceeding
00206       // any further.
00207       if (CORBA::is_nil (this->consumer_proxy_.in ()))
00208         {
00209           ACE_ERROR ((LM_ERROR,
00210                       "TAO_ECG_UDP_Receiver::handle_input() "
00211                       "called but the Receiver is not connected "
00212                       "to an event channel. Shutting down the Receiver.\n"));
00213           this->shutdown (ACE_ENV_SINGLE_ARG_PARAMETER);
00214           ACE_TRY_CHECK;
00215 
00216           return 0;
00217         }
00218 
00219       // Receive data.
00220       TAO_ECG_Event_CDR_Decoder cdr_decoder;
00221       int result = this->cdr_receiver_.handle_input (dgram, &cdr_decoder);
00222 
00223       if (result == 0)
00224         // No data to act on.
00225         {
00226           return 0;
00227         }
00228       if (result == -1)
00229         {
00230           ACE_ERROR_RETURN ((LM_ERROR,
00231                             "Error receiving multicasted events.\n"),
00232                             0);
00233         }
00234 
00235       this->consumer_proxy_->push (cdr_decoder.events ACE_ENV_ARG_PARAMETER);
00236       ACE_TRY_CHECK;
00237     }
00238 
00239   ACE_CATCHANY
00240     {
00241       ACE_DEBUG ((LM_ERROR,
00242                   "Caught and swallowed EXCEPTION in "
00243                   "ECG_UDP_Receiver::handle_input: %s\n",
00244                   ACE_ANY_EXCEPTION._info ().c_str ()));
00245     }
00246   ACE_ENDTRY;
00247   return 0;
00248 }

void TAO_ECG_UDP_Receiver::init RtecEventChannelAdmin::EventChannel_ptr  lcl_ec,
TAO_ECG_Refcounted_Endpoint  ignore_from,
RtecUDPAdmin::AddrServer_ptr  addr_server
 

Parameters:
lcl_ec Event Channel to which we will act as a supplier of events.
ignore_from Endpoint used to remove events generated by the same process.
addr_server Address server used to obtain mapping of event type to multicast group. To insure proper resource clean up, if init () is successful, shutdown () must be called when the receiver is no longer needed. This is done by disconnect_push_supplier() method. If disconnect_push_supplier() will not be called, it is the responsibility of the user. Furthermore, if shutdown() is not explicitly called by either disconnect_push_supplier () or the user, the receiver will clean up the resources in its destructor, however, certain entities involved in cleanup must still exist at that point, e.g., POA.

Definition at line 30 of file ECG_UDP_Receiver.cpp.

References ACE_ERROR, ACE_THROW, addr_server_, cdr_receiver_, TAO_ECG_CDR_Message_Receiver::init(), CORBA::is_nil(), lcl_ec_, LM_ERROR, and TAO_ECG_Refcounted_Endpoint.

00034 {
00035   // Verify arguments.
00036   // <addr_server> is allowed to be nil.  But then, if get_addr () method
00037   // is invoked, it throws an exception.
00038   if (CORBA::is_nil (lcl_ec))
00039     {
00040       ACE_ERROR ((LM_ERROR,
00041                   "TAO_ECG_UDP_Receiver::init(): "
00042                   "<lcl_ec> argument is nil.\n"));
00043       ACE_THROW (CORBA::INTERNAL ());
00044     }
00045 
00046   this->cdr_receiver_.init (ignore_from);
00047 
00048   this->lcl_ec_ =
00049     RtecEventChannelAdmin::EventChannel::_duplicate (lcl_ec);
00050 
00051   this->addr_server_ =
00052     RtecUDPAdmin::AddrServer::_duplicate (addr_server);
00053 }

void TAO_ECG_UDP_Receiver::new_connect const RtecEventChannelAdmin::SupplierQOS pub  )  [private]
 

Definition at line 88 of file ECG_UDP_Receiver.cpp.

References ACE_CHECK, ACE_ENV_ARG_PARAMETER, ACE_ENV_SINGLE_ARG_PARAMETER, activate(), auto_proxy_disconnect_, consumer_proxy_, ECG_Receiver_Auto_Proxy_Disconnect, lcl_ec_, TAO_EC_Auto_Command< T >::set_command(), and TAO_EC_Deactivated_Object::set_deactivator().

Referenced by connect().

00090 {
00091   // Activate with poa.
00092   RtecEventComm::PushSupplier_var supplier_ref;
00093   PortableServer::POA_var poa = this->_default_POA ();
00094 
00095   TAO_EC_Object_Deactivator deactivator;
00096   activate (supplier_ref,
00097             poa.in (),
00098             this,
00099             deactivator
00100             ACE_ENV_ARG_PARAMETER);
00101   ACE_CHECK;
00102 
00103   // Connect as a supplier to the local EC.
00104   RtecEventChannelAdmin::SupplierAdmin_var supplier_admin =
00105     this->lcl_ec_->for_suppliers (ACE_ENV_SINGLE_ARG_PARAMETER);
00106   ACE_CHECK;
00107 
00108   RtecEventChannelAdmin::ProxyPushConsumer_var proxy =
00109     supplier_admin->obtain_push_consumer (ACE_ENV_SINGLE_ARG_PARAMETER);
00110   ACE_CHECK;
00111   ECG_Receiver_Auto_Proxy_Disconnect new_proxy_disconnect (proxy.in ());
00112 
00113   proxy->connect_push_supplier (supplier_ref.in (),
00114                                 pub
00115                                 ACE_ENV_ARG_PARAMETER);
00116   ACE_CHECK;
00117 
00118   // Update resource managers.
00119   this->consumer_proxy_ = proxy._retn ();
00120   this->auto_proxy_disconnect_.set_command (new_proxy_disconnect);
00121   this->set_deactivator (deactivator);
00122 }

void TAO_ECG_UDP_Receiver::reconnect const RtecEventChannelAdmin::SupplierQOS pub  )  [private]
 

Definition at line 125 of file ECG_UDP_Receiver.cpp.

References ACE_CHECK, ACE_ENV_ARG_PARAMETER, ACE_THROW, consumer_proxy_, and CORBA::is_nil().

Referenced by connect().

00127 {
00128   // Obtain our object reference from the POA.
00129   RtecEventComm::PushSupplier_var supplier_ref;
00130   PortableServer::POA_var poa = this->_default_POA ();
00131 
00132   CORBA::Object_var obj = poa->servant_to_reference (this ACE_ENV_ARG_PARAMETER);
00133   ACE_CHECK;
00134   supplier_ref =
00135     RtecEventComm::PushSupplier::_narrow (obj.in () ACE_ENV_ARG_PARAMETER);
00136   ACE_CHECK;
00137 
00138   if (CORBA::is_nil (supplier_ref.in ()))
00139     {
00140       ACE_THROW (CORBA::INTERNAL ());
00141     }
00142 
00143   // Reconnect.
00144   this->consumer_proxy_->connect_push_supplier (supplier_ref.in (),
00145                                                 pub
00146                                                 ACE_ENV_ARG_PARAMETER);
00147   ACE_CHECK;
00148 }

ACE_INLINE void TAO_ECG_UDP_Receiver::set_handler_shutdown TAO_ECG_Refcounted_Handler  handler_shutdown_rptr  ) 
 

Set the handler we must notify when shutdown occurs. (This is the handler that alerts us when data is available on udp/mcast socket.) Shutdown notification gives the handler an opportunity to properly clean up resources.

Definition at line 81 of file ECG_UDP_Receiver.i.

References handler_rptr_, and TAO_ECG_Refcounted_Handler.

00083 {
00084   this->handler_rptr_ = handler_shutdown_rptr;
00085 }

void TAO_ECG_UDP_Receiver::shutdown  ) 
 

If this class is used with refcounting, calling this method may result in decrementing of the reference count (due to deactivation) and deletion of the object.

Definition at line 161 of file ECG_UDP_Receiver.cpp.

References auto_proxy_disconnect_, cdr_receiver_, consumer_proxy_, TAO_EC_Object_Deactivator::deactivate(), TAO_EC_Auto_Command< T >::execute(), ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::get(), handler_rptr_, TAO_ECG_CDR_Message_Receiver::shutdown(), and TAO_ECG_Refcounted_Handler.

Referenced by handle_input().

00162 {
00163   if (this->handler_rptr_.get ())
00164     this->handler_rptr_->shutdown ();
00165   TAO_ECG_Refcounted_Handler empty_handler_rptr;
00166   this->handler_rptr_ = empty_handler_rptr;
00167 
00168   this->consumer_proxy_ =
00169     RtecEventChannelAdmin::ProxyPushConsumer::_nil ();
00170 
00171   this->auto_proxy_disconnect_.execute ();
00172 
00173   this->deactivator_.deactivate ();
00174 
00175   this->cdr_receiver_.shutdown ();
00176 }


Member Data Documentation

RtecUDPAdmin::AddrServer_var TAO_ECG_UDP_Receiver::addr_server_ [private]
 

The server used to map event types to multicast groups.

Definition at line 212 of file ECG_UDP_Receiver.h.

Referenced by get_addr(), and init().

ECG_Receiver_Auto_Proxy_Disconnect TAO_ECG_UDP_Receiver::auto_proxy_disconnect_ [private]
 

Manages our connection to Consumer Proxy.

Definition at line 229 of file ECG_UDP_Receiver.h.

Referenced by new_connect(), and shutdown().

TAO_ECG_CDR_Message_Receiver TAO_ECG_UDP_Receiver::cdr_receiver_ [private]
 

Helper for reading incoming UDP/Multicast messages. It assembles message fragments and provides access to a cdr stream once the complete message has been received.

Definition at line 220 of file ECG_UDP_Receiver.h.

Referenced by handle_input(), init(), and shutdown().

RtecEventChannelAdmin::ProxyPushConsumer_var TAO_ECG_UDP_Receiver::consumer_proxy_ [private]
 

Proxy used to supply events to the Event Channel.

Definition at line 215 of file ECG_UDP_Receiver.h.

Referenced by handle_input(), new_connect(), reconnect(), shutdown(), and ~TAO_ECG_UDP_Receiver().

TAO_ECG_Refcounted_Handler TAO_ECG_UDP_Receiver::handler_rptr_ [private]
 

Handler we must notify when shutdown occurs, so it has an opportunity to clean up resources.

Definition at line 224 of file ECG_UDP_Receiver.h.

Referenced by set_handler_shutdown(), shutdown(), and ~TAO_ECG_UDP_Receiver().

RtecEventChannelAdmin::EventChannel_var TAO_ECG_UDP_Receiver::lcl_ec_ [private]
 

Event Channel to which we act as a supplier.

Definition at line 209 of file ECG_UDP_Receiver.h.

Referenced by init(), and new_connect().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 13:16:26 2006 for TAO_RTEvent by doxygen 1.3.6