CEC_ProxyPushConsumer.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   CEC_ProxyPushConsumer.h
00006  *
00007  *  $Id: CEC_ProxyPushConsumer.h 77001 2007-02-12 07:54:49Z johnnyw $
00008  *
00009  *  @author Carlos O'Ryan (coryan@cs.wustl.edu)
00010  */
00011 //=============================================================================
00012 
00013 
00014 #ifndef TAO_CEC_PROXYPUSHCONSUMER_H
00015 #define TAO_CEC_PROXYPUSHCONSUMER_H
00016 
00017 #include /**/ "ace/pre.h"
00018 
00019 #include "orbsvcs/CosEventChannelAdminS.h"
00020 #include "orbsvcs/CosEvent/event_serv_export.h"
00021 
00022 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00023 # pragma once
00024 #endif /* ACE_LACKS_PRAGMA_ONCE */
00025 
00026 #include "orbsvcs/ESF/ESF_Worker.h"
00027 
00028 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00029 
00030 class TAO_CEC_EventChannel;
00031 class TAO_CEC_Dispatching;
00032 class TAO_CEC_ProxyPushSupplier;
00033 
00034 /**
00035  * @class TAO_CEC_ProxyPushConsumer
00036  *
00037  * @brief ProxyPushConsumer
00038  *
00039  * Implement the CosEventChannelAdmin::ProxyPushConsumer interface,
00040  * remember that this class is used to communicate with a
00041  * PushSupplier, so, in effect, this is the ambassador for a
00042  * supplier inside the event channel.
00043  * = MEMORY MANAGMENT
00044  * The object commits suicide when disconnect_push_consumer() is
00045  * called.
00046  */
00047 class TAO_Event_Serv_Export TAO_CEC_ProxyPushConsumer
00048   : public POA_CosEventChannelAdmin::ProxyPushConsumer
00049 {
00050 public:
00051   typedef CosEventChannelAdmin::ProxyPushConsumer_ptr _ptr_type;
00052   typedef CosEventChannelAdmin::ProxyPushConsumer_var _var_type;
00053 
00054   /// constructor...
00055   TAO_CEC_ProxyPushConsumer (TAO_CEC_EventChannel* event_channel,
00056                              const ACE_Time_Value &timeout);
00057 
00058   /// destructor...
00059   virtual ~TAO_CEC_ProxyPushConsumer (void);
00060 
00061   /// Activate in the POA
00062   virtual void activate (
00063       CosEventChannelAdmin::ProxyPushConsumer_ptr &activated_proxy);
00064 
00065   /// Deactivate from the POA
00066   virtual void deactivate (void);
00067 
00068   /// Return false if no supplier is connected...
00069   CORBA::Boolean is_connected (void) const;
00070 
00071   /// Return the consumer object reference. It returns nil() if it has
00072   /// not connected yet.
00073   CosEventComm::PushSupplier_ptr supplier (void) const;
00074 
00075   /**
00076    * Invoke the _non_existent() pseudo-operation on the supplier. If
00077    * it is disconnected then it returns true and sets the
00078    * <disconnected> flag.
00079    */
00080   CORBA::Boolean supplier_non_existent (CORBA::Boolean_out disconnected);
00081 
00082   /// The event channel is shutting down
00083   virtual void shutdown (void);
00084 
00085   /// Increment and decrement the reference count.
00086   CORBA::ULong _incr_refcnt (void);
00087   CORBA::ULong _decr_refcnt (void);
00088 
00089   // = The CosEventChannelAdmin::ProxyPushConsumer methods...
00090   virtual void connect_push_supplier (
00091                 CosEventComm::PushSupplier_ptr push_supplier);
00092   virtual void push (const CORBA::Any& event);
00093   virtual void disconnect_push_consumer (void);
00094 
00095   // = The Servant methods
00096   virtual PortableServer::POA_ptr _default_POA (void);
00097   virtual void _add_ref (void);
00098   virtual void _remove_ref (void);
00099 
00100 protected:
00101   /// Set the supplier, used by some implementations to change the
00102   /// policies used when invoking operations on the supplier.
00103   void supplier (CosEventComm::PushSupplier_ptr supplier);
00104   void supplier_i (CosEventComm::PushSupplier_ptr supplier);
00105 
00106   friend class TAO_CEC_ProxyPushConsumer_Guard;
00107   // The guard needs access to the following protected methods.
00108 
00109   /// The private version (without locking) of is_connected().
00110   CORBA::Boolean is_connected_i (void) const;
00111 
00112   /// Release the supplier
00113   void cleanup_i (void);
00114 
00115   /// Assigns the parameter to both supplier_ and nopolicy_supplier_, and
00116   /// applies policies (when appropriate) to supplier_.
00117   CosEventComm::PushSupplier_ptr apply_policy
00118   (CosEventComm::PushSupplier_ptr s);
00119 
00120 private:
00121   /// The supplier admin, used for activation and memory managment.
00122   TAO_CEC_EventChannel* event_channel_;
00123 
00124   ACE_Time_Value timeout_;
00125 
00126   /// The locking strategy.
00127   ACE_Lock* lock_;
00128 
00129   /// The reference count.
00130   CORBA::ULong refcount_;
00131 
00132   /// The supplier -- use apply_policy() instead of assigning directly to
00133   /// supplier_.  This will keep supplier_ and nopolicy_supplier_ in sync.
00134   CosEventComm::PushSupplier_var supplier_;
00135 
00136   /// The supplier without any policies applied
00137   CosEventComm::PushSupplier_var nopolicy_supplier_;
00138 
00139   /// If the flag is true then we are connected, notice that the
00140   /// supplier can be nil.
00141   bool connected_;
00142 
00143   /// Store the default POA.
00144   PortableServer::POA_var default_POA_;
00145 };
00146 
00147 // ****************************************************************
00148 
00149 /**
00150  * @class TAO_CEC_ProxyPushConsumer_Guard
00151  *
00152  * @brief A Guard for the ProxyPushConsumer reference count
00153  *
00154  * This is a helper class used in the implementation of
00155  * ProxyPushConumer.  It provides a Guard mechanism to increment
00156  * the reference count on the proxy, eliminating the need to hold
00157  * mutexes during long operations.
00158  */
00159 class TAO_Event_Serv_Export TAO_CEC_ProxyPushConsumer_Guard
00160 {
00161 public:
00162   /// Constructor
00163   TAO_CEC_ProxyPushConsumer_Guard (ACE_Lock *lock,
00164                                    CORBA::ULong &refcount,
00165                                    TAO_CEC_EventChannel *ec,
00166                                    TAO_CEC_ProxyPushConsumer *proxy);
00167 
00168   /// Destructor
00169   ~TAO_CEC_ProxyPushConsumer_Guard (void);
00170 
00171   /// Returns true if the reference count successfully acquired
00172   bool locked (void) const;
00173 
00174 private:
00175   /// The lock used to protect the reference count
00176   ACE_Lock *lock_;
00177 
00178   /// The reference count
00179   CORBA::ULong &refcount_;
00180 
00181   /// The event channel used to destroy the proxy
00182   TAO_CEC_EventChannel *event_channel_;
00183 
00184   /// The proxy whose lifetime is controlled by the reference count
00185   TAO_CEC_ProxyPushConsumer *proxy_;
00186 
00187   /// This flag is set to true if the reference count was successfully
00188   /// acquired.
00189   bool locked_;
00190 };
00191 
00192 TAO_END_VERSIONED_NAMESPACE_DECL
00193 
00194 #if defined (__ACE_INLINE__)
00195 #include "orbsvcs/CosEvent/CEC_ProxyPushConsumer.inl"
00196 #endif /* __ACE_INLINE__ */
00197 
00198 #include /**/ "ace/post.h"
00199 
00200 #endif /* TAO_CEC_PROXYPUSHCONSUMER_H */

Generated on Sun Jan 27 15:37:17 2008 for TAO_CosEvent by doxygen 1.3.6