ECG_Mcast_Gateway.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /**
00004  *  @file   ECG_Mcast_Gateway.h
00005  *
00006  *  $Id: ECG_Mcast_Gateway.h 76589 2007-01-25 18:04:11Z elliott_c $
00007  *
00008  *  @author Marina Spivak (marina@atdesk.com)
00009  */
00010 
00011 #ifndef TAO_ECG_MCAST_GATEWAY_H
00012 #define TAO_ECG_MCAST_GATEWAY_H
00013 #include /**/ "ace/pre.h"
00014 
00015 #include "orbsvcs/Event/ECG_UDP_Sender.h"
00016 
00017 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00018 # pragma once
00019 #endif /* ACE_LACKS_PRAGMA_ONCE */
00020 
00021 #include "orbsvcs/Event/ECG_Defaults.h"
00022 #include /**/ "orbsvcs/Event/event_serv_export.h"
00023 #include "orbsvcs/Event/ECG_UDP_Receiver.h"
00024 #include "orbsvcs/Event/ECG_UDP_Out_Endpoint.h"
00025 #include "ace/Service_Object.h"
00026 #include "ace/Service_Config.h"
00027 #include "ace/SString.h"
00028 #include "ace/os_include/os_stdint.h"
00029 
00030 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00031 class ACE_Event_Handler;
00032 ACE_END_VERSIONED_NAMESPACE_DECL
00033 
00034 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00035 
00036 /**
00037  * @class TAO_ECG_Mcast_Gateway
00038  *
00039  * @brief Implement the builder for setting up Event Channel multicast
00040  *        gateway.
00041  *        NOT THREAD-SAFE.
00042  *
00043  * This class simplifies creation of federated Event Channels by
00044  * presenting a simple unified interface for creating and configuring
00045  * all components needed to federate an Event Channel.
00046  * Configuration options are described below.
00047  *
00048  * NOTE: This class does not own any of the components it creates and
00049  * its lifetime is independent of theirs.  This class acts purely as a
00050  * wrapper facade for creating and wiring appropriate components
00051  * together.
00052  *
00053  * @todo This class is an ACE_Service_Object, but the only reason for
00054  * it is the need for easy configuration using files.  Since
00055  * ACE_Service_Object provides much more than that, we should look
00056  * into replacing it with a more lightweight utility that would serve
00057  * our needs.
00058  *
00059  * CONFIGURATION OPTIONS
00060  * There are two ways to use this class:
00061  * 1) Use service config file to specify configuration options (which
00062  *    are described below), and use service configurator to obtain a
00063  *    an instance of configured TAO_ECG_Mcast_Gateway in your program.  (See
00064  *    TAO/orbsvcs/tests/Event/Mcast/Common and
00065  *    TAO/orbsvcs/tests/Event/Mcast/Simple for an example.)
00066  *
00067  * Service config file options:
00068  *
00069  * -ECGService <service>
00070  *  Valid values: sender, receiver, two_way
00071  *  Specifies whether this gateway should act as a multicast sender of
00072  *  the events or multicast receiver, or both.
00073  *
00074  * -ECGAddressServer <server_type>
00075  *  Valid values: basic, source, type
00076  *  Specifies what implementation of the address server should be used
00077  *  by the gateway.  basic - the same multicast address is returned for
00078  *  all event headers.  source - multicast addresses are returned based
00079  *  on the event source, according to the mapping provided at
00080  *  initialization.  type - multicast addresses are returned based
00081  *  on the event type, according to the mapping provided at
00082  *  initialization.
00083  *
00084  * -ECGAddressServerArg <arg>
00085  *  Valid value: arg is a string, whose format requirements are
00086  *  specific to the implementation of address server used.
00087  *  Arg is not interpreted by the gateway, but simply passed to the
00088  *  address server specified by -ECGAddressServer during initialization.
00089  *  THIS OPTION MUST ALWAYS BE SPECIFIED BY THE USER (there is no
00090  *  default value for it)
00091  *
00092  * -ECGHandler <handler_type>
00093  *  Valid values: basic, complex, udp
00094  *  Specifies what implementation of event handler should be used if
00095  *  gateway is acting as events receiver. basic - a simple event
00096  *  handler listening on a single mcast address.  complex -
00097  *  event handler listening on multiple mcast addresses based on
00098  *  events of interest to consumers.  udp - similar to basic handler,
00099  *  except listens on udp address as opposed to a multicast group.
00100  *
00101  * -ECGTTL <ttl>
00102  *  Valid values: a number > 0
00103  *  IP_Multicast time to live value that should be set on a sending socket.
00104  *  This option matters only if the gateway is acting as a sender of
00105  *  mcast messages.
00106  *
00107  * -ECGNIC <nic>
00108  *  Valid values: name of the network interface
00109  *  This interface is used for sending and/or receiving multicast messages.
00110  *
00111  * -ECGNonBlocking
00112  *  Boolean flag to configure if the socket is in blocking or
00113  *  non-blocking code.  The default is non-blocking.
00114  *  NOTE: Certain device drivers block the process if the physical
00115  *        link fails.
00116  *
00117  *
00118  * 2) Create an instance of TAO_ECG_Mcast_Gateway in your code, on the stack or
00119  *    dynamically, and use init () method to configure it.  No
00120  *    configuration files involved.  See service config options above for the
00121  *    description of configurable options, and init() method below for how
00122  *    to specify them.
00123  *
00124  *
00125  * Default configuration values (for either use case) can be found in
00126  * ECG_Defaults.h
00127  */
00128 class TAO_RTEvent_Serv_Export TAO_ECG_Mcast_Gateway
00129   : public ACE_Service_Object
00130 {
00131 public:
00132 
00133   /// The Service_Object entry points.
00134   //@{
00135   virtual int init (int argc, ACE_TCHAR* argv[]);
00136   virtual int fini (void);
00137   //@}
00138 
00139   /// Helper function to register the Gateway into the service
00140   /// configurator.
00141   static int init_svcs (void);
00142 
00143   /// Constructor.
00144   TAO_ECG_Mcast_Gateway (void);
00145 
00146   /// Values for some configuration parameters to init ().
00147   //@{
00148   enum Service_Type {ECG_MCAST_SENDER,
00149                      ECG_MCAST_RECEIVER,
00150                      ECG_MCAST_TWO_WAY};
00151 
00152   enum Address_Server_Type {ECG_ADDRESS_SERVER_BASIC,
00153                             ECG_ADDRESS_SERVER_SOURCE,
00154                             ECG_ADDRESS_SERVER_TYPE};
00155 
00156   enum Handler_Type {ECG_HANDLER_BASIC,
00157                      ECG_HANDLER_COMPLEX,
00158                      ECG_HANDLER_UDP};
00159   //@}
00160 
00161   /**
00162    * @struct Attributes
00163    *
00164    * @brief Helper class to initialize a TAO_ECG_Mcast_Gateway.
00165    *
00166    * The TAO_ECG_Mcast_Gateway class has several properties that can
00167    * be configured at initialization time, with default values.  The
00168    * canonical trick of using a constructor or init() method with
00169    * multiple arguments does not work because to change the last
00170    * argument the application developer needs to know all the other
00171    * defaults.
00172    *
00173    * Instead we define a helper class that initializes all the fields
00174    * to reasonable defaults.  The application only sets the fields
00175    * that it is interested into, if new fields are added applications
00176    * do not need to change.
00177    *
00178    * With a little trickery we can even eliminate named temporaries:
00179    *
00180    * TAO_ECG_Mcast_Gateway gw;<BR>
00181    * gw.init(TAO_ECG_Mcast_Gateway::Attributes().set_foo(x).set_bar(y));
00182    *
00183    * but we are not implementing that one (detecting errors is too
00184    * hard without exceptions and ACE+TAO are somewhat shy of
00185    * exceptions at this point.)
00186    */
00187   struct TAO_RTEvent_Serv_Export Attributes
00188   {
00189     Attributes (void);
00190 
00191     Address_Server_Type address_server_type;
00192     Handler_Type handler_type;
00193     Service_Type service_type;
00194     u_char ttl_value;
00195     ACE_CString nic;
00196     int ip_multicast_loop;
00197     int non_blocking;
00198   };
00199 
00200   /// Configure TAO_ECG_Mcast_Gateway programatically.  This method should
00201   /// be used when NOT using service configurator to obtain/configure
00202   /// TAO_ECG_Mcast_Gateway.  See class documentation above for more
00203   /// info.
00204   int init (const char * address_server_arg,
00205             const Attributes & attributes = Attributes());
00206 
00207   /// Same as the method above, but also gives the client an opportunity to
00208   /// specify consumer qos, i.e., which EC traffic should get multicasted.
00209   /*
00210    * By default, multicast sender subscribes to all events in the
00211    * Event Channel, i.e., all events pushed to the EC get multicasted
00212    * (as long as their ttl is > 0).  This method allows clients to
00213    * specify a more restrictive qos, hence limiting which EC traffic
00214    * gets multicasted.
00215    */
00216   int init (const RtecEventChannelAdmin::ConsumerQOS & consumer_qos,
00217             const char * address_server_arg,
00218             const Attributes & attributes = Attributes());
00219 
00220   /// The main method - create, configure and run federation
00221   /// components according to the specified configuration.
00222   void run (CORBA::ORB_ptr orb,
00223             RtecEventChannelAdmin::EventChannel_ptr ec);
00224 
00225 private:
00226 
00227   /// Helpers.
00228   //@{
00229   /// Check that arguments to run() are not nil.
00230   void verify_args (CORBA::ORB_ptr orb,
00231                     RtecEventChannelAdmin::EventChannel_ptr ec);
00232 
00233   /// Verifies configuration values specified through init() make sense.
00234   int validate_configuration (void);
00235   //@}
00236 
00237   /// Allocate and initialize appropriate objects.
00238   //@{
00239   PortableServer::ServantBase *
00240         init_address_server (void);
00241 
00242   TAO_EC_Servant_Var<TAO_ECG_UDP_Sender>
00243         init_sender (RtecEventChannelAdmin::EventChannel_ptr ec,
00244                      RtecUDPAdmin::AddrServer_ptr address_server,
00245                      TAO_ECG_Refcounted_Endpoint endpoint_rptr);
00246 
00247   TAO_EC_Servant_Var<TAO_ECG_UDP_Receiver>
00248         init_receiver (RtecEventChannelAdmin::EventChannel_ptr ec,
00249                        RtecUDPAdmin::AddrServer_ptr address_server,
00250                        TAO_ECG_Refcounted_Endpoint endpoint_rptr);
00251 
00252   TAO_ECG_Refcounted_Endpoint init_endpoint (void);
00253 
00254   TAO_ECG_Refcounted_Handler
00255         init_handler (TAO_ECG_Dgram_Handler *recv,
00256                       RtecEventChannelAdmin::EventChannel_ptr ec,
00257                       ACE_Reactor * reactor);
00258   //@}
00259 
00260   /// Flags controlling configuration.
00261   //@{
00262   Service_Type service_type_;
00263   Handler_Type handler_type_;
00264   Address_Server_Type address_server_type_;
00265   ACE_CString address_server_arg_;
00266   u_char ttl_value_;
00267   ACE_CString nic_;
00268   int ip_multicast_loop_;
00269   int non_blocking_;
00270 
00271   RtecEventChannelAdmin::ConsumerQOS consumer_qos_;
00272   //@}
00273 };
00274 
00275 TAO_END_VERSIONED_NAMESPACE_DECL
00276 
00277 #if defined (__ACE_INLINE__)
00278 #include "orbsvcs/Event/ECG_Mcast_Gateway.inl"
00279 #endif /* __ACE_INLINE__ */
00280 
00281 ACE_STATIC_SVC_DECLARE (TAO_ECG_Mcast_Gateway)
00282 ACE_FACTORY_DECLARE (TAO_RTEvent_Serv, TAO_ECG_Mcast_Gateway)
00283 
00284 #include /**/ "ace/post.h"
00285 #endif /* TAO_ECG_MCAST_GATEWAY_H */

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