CEC_TypedEventChannel.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   CEC_TypedEventChannel.h
00006  *
00007  *  @author Jon Astle (jon@astle45.fsnet.co.uk)
00008  *
00009  *  $Id: CEC_TypedEventChannel.h 81226 2008-04-03 09:43:45Z sma $
00010  *
00011  * A new implementation of the COS Typed Event Channel, based on
00012  * the untyped version by Carlos O'Ryan (coryan@cs.wustl.edu)
00013  *
00014  */
00015 //=============================================================================
00016 
00017 #ifndef TAO_CEC_TYPEDEVENTCHANNEL_H_
00018 #define TAO_CEC_TYPEDEVENTCHANNEL_H_
00019 #include /**/ "ace/pre.h"
00020 
00021 #include "orbsvcs/CosEvent/event_serv_export.h"
00022 
00023 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00024 #pragma once
00025 #endif /* ACE_LACKS_PRAGMA_ONCE */
00026 
00027 #include "orbsvcs/CosEvent/CEC_Defaults.h"
00028 
00029 #include "orbsvcs/CosTypedEventChannelAdminS.h"
00030 
00031 #include "orbsvcs/CosEvent/CEC_Factory.h"
00032 
00033 #include "tao/IFR_Client/IFR_BasicC.h"
00034 #include "tao/AnyTypeCode/NVList.h"
00035 
00036 #include "ace/Hash_Map_Manager.h"
00037 #include "ace/Null_Mutex.h"
00038 #include "ace/SString.h"
00039 
00040 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00041 
00042 /**
00043  * @class TAO_CEC_TypedEventChannel_Attributes
00044  *
00045  * @brief Defines the construction time attributes for the Typed
00046  * Event Channel.
00047  *
00048  * The typed event channel implementation is controlled by
00049  * two mechanisms:
00050  * The CEC_Factory that provides the strategies for the EC
00051  * implementation.
00052  * The EC attributes that define constants and values required
00053  * by the EC construction.
00054  * This class encapsulates those constants and values, providing
00055  * an easy mechanism to extend the attributes without requiring
00056  * changes in the EC constructor.
00057  */
00058 class TAO_Event_Serv_Export TAO_CEC_TypedEventChannel_Attributes
00059 {
00060 public:
00061   /**
00062    * The basic constructor.
00063    * The attributes listed as arguments are *required* by the EC, and
00064    * no appropiate defaults are available for them.
00065    */
00066   TAO_CEC_TypedEventChannel_Attributes (PortableServer::POA_ptr typed_supplier_poa,
00067                                         PortableServer::POA_ptr typed_consumer_poa,
00068                                         CORBA::ORB_ptr orb,
00069                                         CORBA::Repository_ptr interface_repository);
00070 
00071   // Most fields are public, there is no need to protect them, in fact
00072   // the user should be able to set any values she wants.
00073 
00074   /// Can consumers or suppliers invoke connect_push_* multiple times?
00075   int consumer_reconnect;
00076   int supplier_reconnect;
00077 
00078   /**
00079    * It not zero the event channel will send disconnect callbacks when
00080    * a disconnect method is called on a Proxy.  In other words, if a
00081    * consumer calls disconnect_push_supplier() on its proxy the EC
00082    * will invoke disconnect_push_consumer() on the consumer.  A
00083    * similar thing is done for suppliers.
00084    * It is a matter of debate what the spec requires for the regular
00085    * event service.
00086    */
00087   int disconnect_callbacks;
00088 
00089   /**
00090    * If not zero the event channel will deactive its Impl and call
00091    * orb->shutdown(0), when destoy is invoked.
00092    */
00093   int destroy_on_shutdown;
00094 
00095 private:
00096   /// Only the EC can read the private fields.
00097   friend class TAO_CEC_TypedEventChannel;
00098 
00099   /// The POAs
00100   PortableServer::POA_ptr typed_supplier_poa;
00101   PortableServer::POA_ptr typed_consumer_poa;
00102 
00103   /// The ORB
00104   CORBA::ORB_ptr orb;
00105 
00106   /// The Interface Repository
00107   CORBA::Repository_ptr interface_repository;
00108 };
00109 
00110 class TAO_CEC_Operation_Params;
00111 
00112 //Class TAO_CEC_TypedEventChannel
00113 class TAO_Event_Serv_Export TAO_CEC_TypedEventChannel : public virtual POA_CosTypedEventChannelAdmin::TypedEventChannel
00114 {
00115 public:
00116   class ServantBaseHash
00117   {
00118   public:
00119     u_long operator() (PortableServer::ServantBase* const & ptr) const {
00120       return reinterpret_cast<u_long> (ptr);
00121     }
00122   };
00123 
00124   typedef ACE_Hash_Map_Manager_Ex<PortableServer::ServantBase*,
00125                                   unsigned int,
00126                                   ServantBaseHash,
00127                                   ACE_Equal_To<PortableServer::ServantBase*>,
00128                                   TAO_SYNCH_MUTEX> ServantRetryMap;
00129 
00130   /**
00131    * Constructor
00132    * If <own_factory> is not 0 it assumes ownership of the factory.
00133    * If the factory is <nil> it uses the Service_Configurator to load
00134    * the Factory, if not found it uses TAO_CEC_Default_Resource_Factory
00135    */
00136   TAO_CEC_TypedEventChannel (const TAO_CEC_TypedEventChannel_Attributes& attributes,
00137                              TAO_CEC_Factory* factory = 0,
00138                              int own_factory = 0);
00139 
00140   /// Destructor
00141   virtual ~TAO_CEC_TypedEventChannel (void);
00142 
00143   /// Start the internal threads (if any), etc.
00144   /// After this call the EC can be used.
00145   virtual void activate (void);
00146 
00147   /// Shutdown any internal threads, cleanup all the internal
00148   /// structures, flush all the messages, etc.
00149   virtual void shutdown (void);
00150 
00151   /// Access the dispatching module....
00152   TAO_CEC_Dispatching* dispatching (void) const;
00153 
00154   /// Access the consumer admin implementation.
00155   TAO_CEC_TypedConsumerAdmin* typed_consumer_admin (void) const;
00156 
00157   /// Access the supplier admin implementation.
00158   TAO_CEC_TypedSupplierAdmin* typed_supplier_admin (void) const;
00159 
00160   /// Access the consumer control strategy.
00161   TAO_CEC_ConsumerControl* consumer_control (void) const;
00162 
00163   /// Access the supplier control strategy.
00164   TAO_CEC_SupplierControl* supplier_control (void) const;
00165 
00166   // = The factory methods, they delegate on the CEC_Factory.
00167   /// Create and destroy a ProxyPushSupplier
00168   void create_proxy (TAO_CEC_ProxyPushSupplier*&);
00169   void destroy_proxy (TAO_CEC_ProxyPushSupplier*);
00170 
00171   /// Create and destroy a TypedProxyPushConsumer
00172   void create_proxy (TAO_CEC_TypedProxyPushConsumer*&);
00173   void destroy_proxy (TAO_CEC_TypedProxyPushConsumer*);
00174 
00175   /// Create and destroy a the collections used to store
00176   /// Proxy*Suppliers
00177   void create_proxy_collection (TAO_CEC_ProxyPushSupplier_Collection*&);
00178   void destroy_proxy_collection (TAO_CEC_ProxyPushSupplier_Collection*);
00179 
00180   /// Create and destroy a the collections used to store
00181   /// Proxy*Consumers
00182   void create_proxy_collection (TAO_CEC_TypedProxyPushConsumer_Collection*&);
00183   void destroy_proxy_collection (TAO_CEC_TypedProxyPushConsumer_Collection*);
00184 
00185   /// Access the supplier and consumer POAs from the factory.
00186   PortableServer::POA_ptr typed_supplier_poa (void);
00187   PortableServer::POA_ptr typed_consumer_poa (void);
00188 
00189   /// Locking strategies for the ProxyPushConsumer and
00190   /// ProxyPushSupplier objects
00191   ACE_Lock* create_consumer_lock (void);
00192   void destroy_consumer_lock (ACE_Lock*);
00193   ACE_Lock* create_supplier_lock (void);
00194   void destroy_supplier_lock (ACE_Lock*);
00195 
00196   /// Used to inform the EC that a Consumer has connected or
00197   /// disconnected from it.
00198   virtual void connected (TAO_CEC_TypedProxyPushConsumer*);
00199   virtual void reconnected (TAO_CEC_TypedProxyPushConsumer*);
00200   virtual void disconnected (TAO_CEC_TypedProxyPushConsumer*);
00201 
00202   /// Used to inform the EC that a Supplier has connected or
00203   /// disconnected from it.
00204   virtual void connected (TAO_CEC_ProxyPushSupplier*);
00205   virtual void reconnected (TAO_CEC_ProxyPushSupplier*);
00206   virtual void disconnected (TAO_CEC_ProxyPushSupplier*);
00207 
00208   /// Can the consumers reconnect to the EC?
00209   int consumer_reconnect (void) const;
00210 
00211   /// Can the suppliers reconnect to the EC?
00212   int supplier_reconnect (void) const;
00213 
00214   /// Should we send callback disconnect messages when a proxy is
00215   /// disconnected by the client
00216   int disconnect_callbacks (void) const;
00217 
00218   // Hash map which will operate as a IFR cache for the Supported Interface's operations and parameters
00219   typedef ACE_Hash_Map_Manager_Ex<const char *, TAO_CEC_Operation_Params *, ACE_Hash<const char *>, ACE_Equal_To<const char *>, ACE_Null_Mutex> InterfaceDescription;
00220   typedef InterfaceDescription::iterator Iterator;
00221 
00222   /// Finds a operation/parameter from the IFR cache
00223   TAO_CEC_Operation_Params * find_from_ifr_cache (const char *operation);
00224 
00225   /// Function allows consumer admin to register the uses interface
00226   int consumer_register_uses_interace (const char *uses_interface);
00227 
00228   /// Function allows supplier admin to register the supported interface
00229   int supplier_register_supported_interface (const char *supported_interface);
00230 
00231   /// Function to return the supported_interface_
00232   const char * supported_interface (void) const;
00233 
00234   /// Function to return the base_interfaces_
00235   CORBA::RepositoryId base_interfaces (CORBA::ULong index) const;
00236 
00237   /// Function to return the number of base_interfaces_
00238   CORBA::ULong number_of_base_interfaces (void) const;
00239 
00240   /// Function populates the NVList from the provide param information
00241   virtual void create_operation_list (TAO_CEC_Operation_Params *oper_params,
00242                                       CORBA::NVList_out new_list);
00243 
00244   /// Function creates an empty NVList
00245   virtual void create_list (CORBA::Long count,
00246                             CORBA::NVList_out new_list);
00247 
00248   // = The CosTypedEventChannelAdmin::TypedEventChannel methods...
00249   virtual ::CosTypedEventChannelAdmin::TypedConsumerAdmin_ptr
00250     for_consumers (void);
00251 
00252   virtual ::CosTypedEventChannelAdmin::TypedSupplierAdmin_ptr
00253     for_suppliers (void);
00254 
00255   virtual void destroy (void);
00256 
00257   ServantRetryMap& get_servant_retry_map (void);
00258 
00259   /// Forwarded to the factory
00260   CORBA::Policy_ptr
00261   create_roundtrip_timeout_policy (const ACE_Time_Value &timeout);
00262 
00263 protected:
00264   /// Function caches the full interface description from the IFR
00265   int cache_interface_description (const char *interface_);
00266 
00267   /// Insert a operation/parameter into the IFR cache
00268   int insert_into_ifr_cache (const char *operation, TAO_CEC_Operation_Params *parameters);
00269 
00270   /// Function clears the IFR cache
00271   int clear_ifr_cache (void);
00272 
00273 private:
00274   /// The POAs used to activate "supplier-side" and "consumer-side"
00275   /// objects.
00276   PortableServer::POA_var typed_supplier_poa_;
00277   PortableServer::POA_var typed_consumer_poa_;
00278 
00279   /// The ORB
00280   CORBA::ORB_var orb_;
00281 
00282   /// Storage of the IFR reference
00283   CORBA::Repository_var interface_repository_;
00284 
00285   /**
00286    * This is the abstract factory that creates all the objects that
00287    * compose an event channel, the event channel simply acts as a
00288    * Mediator among them.
00289    */
00290   TAO_CEC_Factory *factory_;
00291 
00292   /// Flag that indicates if we own the factory.
00293   int own_factory_;
00294 
00295   /// The dispatching "module"
00296   TAO_CEC_Dispatching *dispatching_;
00297 
00298   /// The ConsumerAdmin implementation
00299   TAO_CEC_TypedConsumerAdmin *typed_consumer_admin_;
00300 
00301   /// The SupplierAdmin implementation
00302   TAO_CEC_TypedSupplierAdmin *typed_supplier_admin_;
00303 
00304   /// Consumer reconnection flags
00305   int consumer_reconnect_;
00306 
00307   /// Supplier reconnection flags
00308   int supplier_reconnect_;
00309 
00310   /// If not zero we send callbacks when a proxy is disconnected
00311   int disconnect_callbacks_;
00312 
00313   /// If not zero the event channel is destroyed on shutdown
00314   int destroy_on_shutdown_;
00315 
00316   /// Set if the event channel has been destroyed
00317   int destroyed_;
00318 
00319   /// Strategies to disconnect misbehaving or destroyed consumers and
00320   /// suppliers
00321   TAO_CEC_ConsumerControl *consumer_control_;
00322   ServantRetryMap retry_map_;
00323 
00324   TAO_CEC_SupplierControl *supplier_control_;
00325 
00326   /// The uses_interface_ for the TypedConsumerAdmin.
00327   ACE_CString uses_interface_;
00328 
00329   /// The supported_interface_ for the TypedSupplierAdmin.
00330   ACE_CString supported_interface_;
00331 
00332   /// The IFR cache for the interface description
00333   InterfaceDescription interface_description_;
00334 
00335   /// The supported_interface_ base interfaces
00336   CORBA::RepositoryIdSeq base_interfaces_;
00337 };
00338 
00339 
00340 class TAO_Event_Serv_Export TAO_CEC_Param
00341 {
00342 public:
00343   /// Constructor
00344   TAO_CEC_Param (void);
00345 
00346   /// Destructor
00347   ~TAO_CEC_Param (void);
00348 
00349 private:
00350   /// Only the TypedEventChannel can read the private fields.
00351   friend class TAO_CEC_TypedEventChannel;
00352 
00353   CORBA::String_var name_;
00354   CORBA::TypeCode_var type_;
00355   CORBA::Flags direction_;
00356 };
00357 
00358 
00359 class TAO_Event_Serv_Export TAO_CEC_Operation_Params
00360 {
00361   /// constructor
00362   TAO_CEC_Operation_Params (CORBA::ULong num_params);
00363   /// destructor
00364   ~TAO_CEC_Operation_Params (void);
00365 
00366 private:
00367   /// Only the TypedEventChannel can read the private fields.
00368   friend class TAO_CEC_TypedEventChannel;
00369 
00370   CORBA::ULong num_params_;
00371   TAO_CEC_Param * parameters_;
00372 };
00373 
00374 TAO_END_VERSIONED_NAMESPACE_DECL
00375 
00376 #if defined (__ACE_INLINE__)
00377 #include "orbsvcs/CosEvent/CEC_TypedEventChannel.inl"
00378 #endif /* __ACE_INLINE__ */
00379 
00380 #include /**/ "ace/post.h"
00381 
00382 #endif /* TAO_CEC_TYPEDEVENTCHANNEL_H_ */

Generated on Tue Feb 2 17:44:51 2010 for TAO_CosEvent by  doxygen 1.4.7