CEC_ProxyPullSupplier.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   CEC_ProxyPullSupplier.h
00006  *
00007  *  $Id: CEC_ProxyPullSupplier.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_PROXYPULLSUPPLIER_H
00015 #define TAO_CEC_PROXYPULLSUPPLIER_H
00016 
00017 #include /**/ "ace/pre.h"
00018 
00019 #include "orbsvcs/CosEventChannelAdminS.h"
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 # pragma once
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 
00025 #include "ace/Message_Queue.h"
00026 #include "ace/Condition_Thread_Mutex.h"
00027 #include "ace/Unbounded_Queue.h"
00028 
00029 #include "orbsvcs/CosEvent/event_serv_export.h"
00030 
00031 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00032 
00033 class TAO_CEC_EventChannel;
00034 class TAO_CEC_ProxyPullConsumer;
00035 
00036 /**
00037  * @class TAO_CEC_ProxyPullSupplier
00038  *
00039  * @brief ProxyPullSupplier
00040  *
00041  * Implement the CosEventChannelAdmin::ProxyPullSupplier interface,
00042  * remember that this class is used to communicate with a
00043  * PullConsumer, so, in effect, this is the ambassador for a
00044  * consumer inside the event channel.
00045  * = MEMORY MANAGMENT
00046  * It does not assume ownership of the TAO_CEC_Dispatching object.
00047  * It makes a copy of the ConsumerQOS and the consumer object
00048  * reference.
00049  * = LOCKING
00050  * Locking is strategized, the event channel acts as a factory for
00051  * the locking strategies.
00052  */
00053 class TAO_Event_Serv_Export TAO_CEC_ProxyPullSupplier : public POA_CosEventChannelAdmin::ProxyPullSupplier
00054 {
00055 public:
00056   typedef CosEventChannelAdmin::ProxyPullSupplier_ptr _ptr_type;
00057   typedef CosEventChannelAdmin::ProxyPullSupplier_var _var_type;
00058 
00059   /// constructor...
00060   TAO_CEC_ProxyPullSupplier (TAO_CEC_EventChannel* event_channel,
00061                              const ACE_Time_Value &timeout);
00062 
00063   /// destructor...
00064   virtual ~TAO_CEC_ProxyPullSupplier (void);
00065 
00066   /// Activate in the POA
00067   virtual void activate (
00068       CosEventChannelAdmin::ProxyPullSupplier_ptr &activated_proxy);
00069 
00070   /// Deactivate from the POA
00071   virtual void deactivate (void);
00072 
00073   /// Return 0 if no consumer is connected...
00074   CORBA::Boolean is_connected (void) const;
00075 
00076   /**
00077    * Return the consumer object reference. It returns nil() if it has
00078    * not connected yet.
00079    * NOTE: This method does not return a new reference!!! Doing so
00080    * will increase the locking overhead on the critical path.
00081    */
00082   CosEventComm::PullConsumer_ptr consumer (void) const;
00083 
00084   /// The event channel is shutting down
00085   virtual void shutdown (void);
00086 
00087   /**
00088    * Invoke the _non_existent() pseudo-operation on the consumer. If
00089    * it is disconnected then it returns true and sets the
00090    * <disconnected> flag.
00091    */
00092   CORBA::Boolean consumer_non_existent (CORBA::Boolean_out disconnected);
00093 
00094   /// Push an event into the queue.
00095   void push (const CORBA::Any &event);
00096 
00097   // = The CosEventChannelAdmin::ProxyPullSupplier methods...
00098   virtual void connect_pull_consumer (
00099                 CosEventComm::PullConsumer_ptr pull_consumer);
00100   virtual CORBA::Any * pull (void);
00101   virtual CORBA::Any * try_pull (CORBA::Boolean_out has_event);
00102   virtual void disconnect_pull_supplier (void);
00103 
00104   /// Increment and decrement the reference count.
00105   CORBA::ULong _incr_refcnt (void);
00106   CORBA::ULong _decr_refcnt (void);
00107 
00108   // = The Servant methods
00109   virtual PortableServer::POA_ptr _default_POA (void);
00110   virtual void _add_ref (void);
00111   virtual void _remove_ref (void);
00112 
00113 protected:
00114   /// Set the consumer, used by some implementations to change the
00115   /// policies used when invoking operations on the consumer.
00116   void consumer (CosEventComm::PullConsumer_ptr consumer);
00117   void consumer_i (CosEventComm::PullConsumer_ptr consumer);
00118 
00119   /// The private version (without locking) of is_connected().
00120   CORBA::Boolean is_connected_i (void) const;
00121 
00122   /// Release the child and the consumer
00123   void cleanup_i (void);
00124 
00125   /// Assigns the parameter to both consumer_ and nopolicy_consumer_, and
00126   /// applies policies (when appropriate) to consumer_.
00127   CosEventComm::PullConsumer_ptr apply_policy
00128   (CosEventComm::PullConsumer_ptr c);
00129 
00130 private:
00131   /// The Event Channel that owns this object.
00132   TAO_CEC_EventChannel* event_channel_;
00133 
00134   ACE_Time_Value timeout_;
00135 
00136   /// The locking strategy.
00137   ACE_Lock* lock_;
00138 
00139   /// The reference count.
00140   CORBA::ULong refcount_;
00141 
00142   /// The consumer -- use apply_policy() instead of assigning directly to
00143   /// consumer_.  This will keep consumer_ and nopolicy_consumer_ in sync.
00144   CosEventComm::PullConsumer_var consumer_;
00145 
00146   /// The consumer without any policies applied
00147   CosEventComm::PullConsumer_var nopolicy_consumer_;
00148 
00149   /// If the flag is not zero then we are connected, notice that the
00150   /// consumer can be nil.
00151   int connected_;
00152 
00153   /// Store the default POA.
00154   PortableServer::POA_var default_POA_;
00155 
00156   /// Use a message queue to pass the
00157   TAO_SYNCH_MUTEX queue_lock_;
00158   TAO_SYNCH_CONDITION wait_not_empty_;
00159   ACE_Unbounded_Queue<CORBA::Any> queue_;
00160 };
00161 
00162 TAO_END_VERSIONED_NAMESPACE_DECL
00163 
00164 #if defined (__ACE_INLINE__)
00165 #include "orbsvcs/CosEvent/CEC_ProxyPullSupplier.inl"
00166 #endif /* __ACE_INLINE__ */
00167 
00168 #include /**/ "ace/post.h"
00169 
00170 #endif  /* TAO_CEC_PROXYPULLSUPPLIER_H */

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