EC_Dispatching_Task.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /**
00004  *  @file   EC_Dispatching_Task.h
00005  *
00006  *  $Id: EC_Dispatching_Task.h 79745 2007-10-02 20:04:36Z johnnyw $
00007  *
00008  *  @author Carlos O'Ryan (coryan@cs.wustl.edu)
00009  *
00010  * Based on previous work by Tim Harrison (harrison@cs.wustl.edu) and
00011  * other members of the DOC group. More details can be found in:
00012  *
00013  * http://doc.ece.uci.edu/~coryan/EC/index.html
00014  */
00015 
00016 #ifndef TAO_EC_DISPATCHING_TASK_H
00017 #define TAO_EC_DISPATCHING_TASK_H
00018 
00019 #include /**/ "ace/pre.h"
00020 
00021 #include "orbsvcs/Event/EC_ProxySupplier.h"
00022 
00023 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00024 # pragma once
00025 #endif /* ACE_LACKS_PRAGMA_ONCE */
00026 
00027 #include "orbsvcs/RtecEventCommC.h"
00028 #include /**/ "orbsvcs/Event/event_serv_export.h"
00029 #include "ace/Task.h"
00030 #include "ace/Message_Block.h"
00031 #include "ace/Lock_Adapter_T.h"
00032 #include "ace/Service_Config.h"
00033 #include "ace/Global_Macros.h"
00034 
00035 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00036 
00037 // Forward decl
00038 class TAO_EC_Dispatching_Task;
00039 
00040 class TAO_RTEvent_Serv_Export TAO_EC_Queue_Full_Service_Object : public ACE_Service_Object
00041 {
00042 public:
00043   enum QueueFullActionReturnValue
00044   {
00045     WAIT_TO_EMPTY = 0,
00046     SILENTLY_DISCARD = -1
00047   };
00048 
00049   // Called when
00050   virtual int queue_full_action (TAO_EC_Dispatching_Task *task,
00051                                  TAO_EC_ProxyPushSupplier *proxy,
00052                                  RtecEventComm::PushConsumer_ptr consumer,
00053                                  RtecEventComm::EventSet& event) = 0;
00054 };
00055 
00056 class TAO_RTEvent_Serv_Export TAO_EC_Simple_Queue_Full_Action :
00057   public TAO_EC_Queue_Full_Service_Object
00058 {
00059 public:
00060   TAO_EC_Simple_Queue_Full_Action ();
00061 
00062   /// Helper function to register the default action into the service
00063   /// configurator.
00064   static int init_svcs (void);
00065 
00066   // = The Service_Object entry points
00067   virtual int init (int argc, char* argv[]);
00068   virtual int fini (void);
00069 
00070   virtual int queue_full_action (TAO_EC_Dispatching_Task *task,
00071                                  TAO_EC_ProxyPushSupplier *proxy,
00072                                  RtecEventComm::PushConsumer_ptr consumer,
00073                                  RtecEventComm::EventSet& event);
00074 
00075 protected:
00076   int queue_full_action_return_value_;
00077 };
00078 
00079 class TAO_RTEvent_Serv_Export TAO_EC_Queue : public ACE_Message_Queue<ACE_SYNCH>
00080 {
00081 public:
00082   TAO_EC_Queue (size_t high_water_mark = ACE_Message_Queue_Base::DEFAULT_HWM,
00083                 size_t low_water_mark = ACE_Message_Queue_Base::DEFAULT_LWM,
00084                 ACE_Notification_Strategy * = 0);
00085 
00086 protected:
00087   // = Override the default definition in the Message_Queue, to count
00088   // the number of messages (and not their size).
00089   virtual bool is_full_i (void);
00090 };
00091 
00092 /**
00093  * @class TAO_EC_Dispatching_Task
00094  *
00095  * @brief Implement the dispatching queues for FIFO and Priority
00096  * dispatching.
00097  *
00098  */
00099 class TAO_RTEvent_Serv_Export TAO_EC_Dispatching_Task : public ACE_Task<ACE_SYNCH>
00100 {
00101 public:
00102   /// Constructor
00103   TAO_EC_Dispatching_Task (ACE_Thread_Manager* thr_manager = 0, TAO_EC_Queue_Full_Service_Object* queue_full_service_object = 0);
00104 
00105   /// Process the events in the queue.
00106   virtual int svc (void);
00107 
00108   virtual void push (TAO_EC_ProxyPushSupplier *proxy,
00109                      RtecEventComm::PushConsumer_ptr consumer,
00110                      RtecEventComm::EventSet& event);
00111 
00112 private:
00113   /// An per-task allocator
00114   ACE_Allocator *allocator_;
00115 
00116   /// Helper data structure to minimize memory allocations...
00117   ACE_Locked_Data_Block<ACE_Lock_Adapter<TAO_SYNCH_MUTEX> > data_block_;
00118 
00119   /// The queue
00120   TAO_EC_Queue the_queue_;
00121 
00122   TAO_EC_Queue_Full_Service_Object* queue_full_service_object_;
00123 };
00124 
00125 // ****************************************************************
00126 
00127 class TAO_RTEvent_Serv_Export TAO_EC_Dispatch_Command : public ACE_Message_Block
00128 {
00129 public:
00130   /// Constructor, it will allocate its own data block
00131   TAO_EC_Dispatch_Command (ACE_Allocator *mb_allocator = 0);
00132 
00133   /// Constructor, it assumes ownership of the data block
00134   TAO_EC_Dispatch_Command (ACE_Data_Block*,
00135                            ACE_Allocator *mb_allocator = 0);
00136 
00137   /// Destructor
00138   virtual ~TAO_EC_Dispatch_Command (void);
00139 
00140   /// Command callback
00141   virtual int execute (void) = 0;
00142 };
00143 
00144 // ****************************************************************
00145 
00146 class TAO_RTEvent_Serv_Export TAO_EC_Shutdown_Task_Command : public TAO_EC_Dispatch_Command
00147 {
00148 public:
00149   /// Constructor
00150   TAO_EC_Shutdown_Task_Command (ACE_Allocator *mb_allocator = 0);
00151 
00152   /// Command callback
00153   virtual int execute (void);
00154 };
00155 
00156 // ****************************************************************
00157 
00158 class TAO_RTEvent_Serv_Export TAO_EC_Push_Command : public TAO_EC_Dispatch_Command
00159 {
00160 public:
00161   /// Constructor
00162   TAO_EC_Push_Command (TAO_EC_ProxyPushSupplier* proxy,
00163                        RtecEventComm::PushConsumer_ptr consumer,
00164                        RtecEventComm::EventSet& event,
00165                        ACE_Data_Block* data_block,
00166                        ACE_Allocator *mb_allocator);
00167 
00168   /// Destructor
00169   virtual ~TAO_EC_Push_Command (void);
00170 
00171   /// Command callback
00172   virtual int execute (void);
00173 
00174 private:
00175   /// The proxy
00176   TAO_EC_ProxyPushSupplier* proxy_;
00177 
00178   /// The consumer connected to the proxy when the event was pushed.
00179   RtecEventComm::PushConsumer_var consumer_;
00180 
00181   /// The event
00182   RtecEventComm::EventSet event_;
00183 };
00184 
00185 TAO_END_VERSIONED_NAMESPACE_DECL
00186 
00187 #if defined (__ACE_INLINE__)
00188 #include "orbsvcs/Event/EC_Dispatching_Task.inl"
00189 #endif /* __ACE_INLINE__ */
00190 
00191 ACE_STATIC_SVC_DECLARE (TAO_EC_Simple_Queue_Full_Action)
00192 ACE_FACTORY_DECLARE (TAO_RTEvent_Serv, TAO_EC_Simple_Queue_Full_Action)
00193 
00194 #include /**/ "ace/post.h"
00195 
00196 #endif  /* TAO_EC_DISPATCHING_TASK_H */

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