ECG_UDP_EH.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /**
00004  *  @file   ECG_UDP_EH.h
00005  *
00006  *  ECG_UDP_EH.h,v 1.7 2006/03/15 07:52:21 jtc Exp
00007  *
00008  *  @author Carlos O'Ryan (coryan@cs.wustl.edu)
00009  *  @author Marina Spivak (marina@atdesk.com)
00010  *
00011  * http://doc.ece.uci.edu/~coryan/EC/index.html
00012  */
00013 
00014 #ifndef TAO_ECG_UDP_EH_H
00015 #define TAO_ECG_UDP_EH_H
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "ace/Event_Handler.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 #include /**/ "orbsvcs/Event/event_serv_export.h"
00025 #include "orbsvcs/Event/ECG_Adapters.h"
00026 #include "ace/SOCK_Dgram.h"
00027 
00028 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00029 
00030 class TAO_ECG_UDP_Receiver;
00031 
00032 /**
00033  * @class TAO_ECG_UDP_EH
00034  *
00035  * @brief Event Handler for UDP messages.
00036  *
00037  * Listens for messages on a UDP socket.  When there is a message,
00038  * calls handle_input () on a specified TAO_ECG_Dgram_Handler to
00039  * inform it about message arrival.
00040  *
00041  * NOT THREAD-SAFE.
00042  */
00043 class TAO_RTEvent_Serv_Export TAO_ECG_UDP_EH :
00044   public ACE_Event_Handler
00045 , public TAO_ECG_Handler_Shutdown
00046 {
00047 public:
00048 
00049   /// Initialization and termination methods.
00050   //@{
00051   /// Constructor.
00052   /// Messages received by this EH will be forwarded to the <recv>.
00053   /*
00054    * See comments for <receiver_> data member on why raw pointer is
00055    * used for the <recv> argument.
00056    */
00057   TAO_ECG_UDP_EH (TAO_ECG_Dgram_Handler *recv);
00058 
00059   /// Destructor.
00060   virtual ~TAO_ECG_UDP_EH (void);
00061 
00062   /// Open the datagram and register itself with this->reactor().
00063   /// To insure proper resource clean up, if open () is successful,
00064   /// the user MUST call shutdown () when handler is no longer needed
00065   /// (and its reactor still exists).
00066   int open (const ACE_INET_Addr& ipaddr,
00067             int reuse_addr = 0);
00068 
00069   /// TAO_ECG_Handler_Shutdown method.
00070   /// Unsubscribe from the reactor and close the datagram.
00071   virtual int shutdown (void);
00072   //@}
00073 
00074   /// Main method - reactor callback.  Notify <receiver_> that
00075   /// <dgram_> is ready for reading.
00076   virtual int handle_input (ACE_HANDLE fd);
00077 
00078   /**
00079    * Obtain the dgram, this is one of those "controlled violations of
00080    * type safety", allowing the user to setup options and gain access
00081    * to low-level features.
00082    */
00083   ACE_SOCK_Dgram &dgram (void);
00084 
00085 private:
00086 
00087   /// The datagram used to receive the data.
00088   ACE_SOCK_Dgram dgram_;
00089 
00090   /// We callback to this object when a message arrives.
00091   /*
00092    * We can keep a raw pointer to the receiver (even though it may
00093    * be a refcounted object) because receiver guarantees
00094    * to notify us (by calling shutdown ()) before going away.
00095    *
00096    * We have to use raw pointer instead of a refcounting mechanism
00097    * here to avoid a circular refcounting dependency between
00098    * receiver and handler.
00099    */
00100   TAO_ECG_Dgram_Handler* receiver_;
00101 };
00102 
00103 TAO_END_VERSIONED_NAMESPACE_DECL
00104 
00105 #if defined(__ACE_INLINE__)
00106 #include "orbsvcs/Event/ECG_UDP_EH.i"
00107 #endif /* __ACE_INLINE__ */
00108 
00109 #include /**/ "ace/post.h"
00110 #endif /* TAO_ECG_UDP_EH_H */

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