ECG_Mcast_Gateway.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /**
00004  *  @file   ECG_Mcast_Gateway.h
00005  *
00006  *  ECG_Mcast_Gateway.h,v 1.11 2006/03/15 07:52:21 jtc Exp
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             ACE_ENV_ARG_DECL);
00225 
00226 private:
00227 
00228   /// Helpers.
00229   //@{
00230   /// Check that arguments to run() are not nil.
00231   void verify_args (CORBA::ORB_ptr orb,
00232                     RtecEventChannelAdmin::EventChannel_ptr ec
00233                     ACE_ENV_ARG_DECL);
00234 
00235   /// Verifies configuration values specified through init() make sense.
00236   int validate_configuration (void);
00237   //@}
00238 
00239   /// Allocate and initialize appropriate objects.
00240   //@{
00241   PortableServer::ServantBase *
00242         init_address_server (void);
00243 
00244   TAO_EC_Servant_Var<TAO_ECG_UDP_Sender>
00245         init_sender (RtecEventChannelAdmin::EventChannel_ptr ec,
00246                      RtecUDPAdmin::AddrServer_ptr address_server,
00247                      TAO_ECG_Refcounted_Endpoint endpoint_rptr
00248                      ACE_ENV_ARG_DECL);
00249 
00250   TAO_EC_Servant_Var<TAO_ECG_UDP_Receiver>
00251         init_receiver (RtecEventChannelAdmin::EventChannel_ptr ec,
00252                        RtecUDPAdmin::AddrServer_ptr address_server,
00253                        TAO_ECG_Refcounted_Endpoint endpoint_rptr
00254                        ACE_ENV_ARG_DECL);
00255 
00256   TAO_ECG_Refcounted_Endpoint init_endpoint (void);
00257 
00258   TAO_ECG_Refcounted_Handler
00259         init_handler (TAO_ECG_Dgram_Handler *recv,
00260                       RtecEventChannelAdmin::EventChannel_ptr ec,
00261                       ACE_Reactor * reactor
00262                       ACE_ENV_ARG_DECL);
00263   //@}
00264 
00265   /// Flags controlling configuration.
00266   //@{
00267   Service_Type service_type_;
00268   Handler_Type handler_type_;
00269   Address_Server_Type address_server_type_;
00270   ACE_CString address_server_arg_;
00271   u_char ttl_value_;
00272   ACE_CString nic_;
00273   int ip_multicast_loop_;
00274   int non_blocking_;
00275 
00276   RtecEventChannelAdmin::ConsumerQOS consumer_qos_;
00277   //@}
00278 };
00279 
00280 TAO_END_VERSIONED_NAMESPACE_DECL
00281 
00282 #if defined (__ACE_INLINE__)
00283 #include "orbsvcs/Event/ECG_Mcast_Gateway.i"
00284 #endif /* __ACE_INLINE__ */
00285 
00286 ACE_STATIC_SVC_DECLARE (TAO_ECG_Mcast_Gateway)
00287 ACE_FACTORY_DECLARE (TAO_RTEvent_Serv, TAO_ECG_Mcast_Gateway)
00288 
00289 #include /**/ "ace/post.h"
00290 #endif /* TAO_ECG_MCAST_GATEWAY_H */

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