ECG_Simple_Mcast_EH.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /**
00004  * @file ECG_Simple_Mcast_EH.h
00005  *
00006  * ECG_Simple_Mcast_EH.h,v 1.8 2006/03/15 07:52:21 jtc Exp
00007  *
00008  * @author Marina Spivak <marina@atdesk.com>
00009  *
00010  */
00011 #ifndef TAO_ECG_SIMPLE_MCAST_EH_H
00012 #define TAO_ECG_SIMPLE_MCAST_EH_H
00013 #include /**/ "ace/pre.h"
00014 
00015 #include "ace/Event_Handler.h"
00016 
00017 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00018 # pragma once
00019 #endif /* ACE_LACKS_PRAGMA_ONCE */
00020 
00021 #include /**/ "orbsvcs/Event/event_serv_export.h"
00022 #include "orbsvcs/Event/ECG_Adapters.h"
00023 #include "ace/SOCK_Dgram_Mcast.h"
00024 
00025 
00026 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00027 
00028 /**
00029  * @class TAO_ECG_Simple_Mcast_EH
00030  *
00031  * @brief Simple Event Handler for mcast messages.  Listens for
00032  *        messages on a single mcast group.  Useful in environments
00033  *        where event traffic is not separated into different groups.
00034  *        Calls handle_input (ACE_SOCK_Dgram_Mcast dgram) on a specified
00035  *        TAO_ECG_Dgram_Handler to inform it about message arrival.
00036  *
00037  *        NOT THREAD-SAFE.
00038  */
00039 class TAO_RTEvent_Serv_Export TAO_ECG_Simple_Mcast_EH
00040   : public ACE_Event_Handler
00041   , public TAO_ECG_Handler_Shutdown
00042 {
00043 public:
00044 
00045   /// Initialization and termination methods.
00046   //@{
00047   /// Constructor.
00048   /// Messages received by this EH will be forwarded to the <recv>.
00049   /*
00050    * See comments for <receiver_> data member on why raw pointer is
00051    * used for the <recv> argument.
00052    */
00053   TAO_ECG_Simple_Mcast_EH (TAO_ECG_Dgram_Handler *recv);
00054 
00055   /// Destructor.
00056   virtual ~TAO_ECG_Simple_Mcast_EH (void);
00057 
00058   /// Join the specified multicast group and register itself with the
00059   /// reactor.
00060   /// To insure proper resource clean up, if open () is successful,
00061   /// the user MUST call shutdown () when handler is no longer needed
00062   /// (and its reactor still exists).
00063   int open (const char * mcast_addr,
00064             const ACE_TCHAR *net_if = 0);
00065 
00066   /// TAO_ECG_Handler_Shutdown method.
00067   /// Unsubscribe from the reactor and close the datagram.
00068   virtual int shutdown (void);
00069   //@}
00070 
00071   /// Main method - reactor callback.  Notify <receiver_> that
00072   /// <dgram_> is ready for reading.
00073   virtual int handle_input (ACE_HANDLE fd);
00074 
00075 private:
00076 
00077   // Socket on which we listen for messages.
00078   ACE_SOCK_Dgram_Mcast dgram_;
00079 
00080   /// We callback to this object when a message arrives.
00081   /*
00082    * We can keep a raw pointer to the receiver (even though it may
00083    * be a refcounted object) because receiver guarantees
00084    * to notify us (by calling shutdown ()) before going away.
00085    *
00086    * We have to use raw pointer instead of a refcounting mechanism
00087    * here to avoid a circular refcounting dependency between
00088    * receiver and handler.
00089    */
00090   TAO_ECG_Dgram_Handler* receiver_;
00091 };
00092 
00093 TAO_END_VERSIONED_NAMESPACE_DECL
00094 
00095 #include /**/ "ace/post.h"
00096 #endif /* TAO_ECG_SIMPLE_Mcast_EH_H */

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