Activation_Queue.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Activation_Queue.h
00006  *
00007  *  Activation_Queue.h,v 4.34 2006/01/24 14:49:14 shuston Exp
00008  *
00009  *  @author Andres Kruse <Andres.Kruse@cern.ch>
00010  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00011  */
00012 //=============================================================================
00013 
00014 #ifndef ACE_ACTIVATION_QUEUE_H
00015 #define ACE_ACTIVATION_QUEUE_H
00016 
00017 #include /**/ "ace/pre.h"
00018 
00019 #include "ace/ACE_export.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 
00028 /// Define to be compatible with the terminology in the POSA2 book!
00029 #define ACE_Activation_List ACE_Activation_Queue
00030 
00031 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00032 
00033 class ACE_Method_Request;
00034 
00035 /**
00036  * @class ACE_Activation_Queue
00037  *
00038  * @brief Reifies a method into a request.  Subclasses typically
00039  * represent necessary state and behavior.
00040  *
00041  * Maintains a priority-ordered queue of ACE_Method_Request objects.
00042  * A scheduler class (often derived from ACE_Task) subsequently removes
00043  * each method request and invokes its @c call() method.
00044  *
00045  * This class is discussed in depth in the Active Object chapter
00046  * of POSA2. In that book, it is referred to as an Activation List.
00047  *
00048  * @sa ACE_Method_Request
00049  */
00050 class ACE_Export ACE_Activation_Queue
00051 {
00052 public:
00053   // = Initialization and termination methods.
00054   /// Constructor.
00055   /**
00056    * Initializes a new activation queue.
00057    *
00058    * @param new_queue The activation queue uses an ACE_Message_Queue to
00059    *                  queue and order the method requests. If this argument
00060    *                  is 0, a new ACE_Message_Queue is created for this
00061    *                  object's use and will be deleted when this object is
00062    *                  destroyed. If a non-zero pointer is supplied, the
00063    *                  passed object will be used and will not be deleted when
00064    *                  this object is destroyed. If an ACE_Task is being created
00065    *                  to act as the scheduler, for instance, its
00066    *                  ACE_Message_Queue pointer can be passed to this object.
00067    * @param alloc     Optional, the allocator to use when allocating
00068    *                  ACE_Message_Block instances that wrap the method requests
00069    *                  queued to this activation queue. Defaults to
00070    *                  ACE_Allocator::instance().
00071    * @param db_alloc  Optional, the allocator to use when allocating
00072    *                  data blocks for the ACE_Message_Block instances that
00073    *                  wrap the method requests queued to this activation queue.
00074    *                  Defaults to ACE_Allocator::instance().
00075    */
00076   ACE_Activation_Queue (ACE_Message_Queue<ACE_SYNCH> *new_queue = 0,
00077                         ACE_Allocator *alloc = 0,
00078                         ACE_Allocator *db_alloc = 0);
00079 
00080   /// Destructor.
00081   virtual ~ACE_Activation_Queue (void);
00082 
00083   // = Activate Queue operations.
00084 
00085   /// Dequeue the next available ACE_Method_Request.
00086   /**
00087    * @param tv  If 0, the method will block until a method request is
00088    *            available, else will wait until the absolute time specified
00089    *            in the referenced ACE_Time_Value.  This method will return,
00090    *            earlier, however, if queue is closed, deactivated, or when
00091    *            a signal occurs.
00092    *
00093    * @retval    Pointer to the dequeued ACE_Method_Request object.
00094    * @retval    0 an error occurs; errno contains further information. If
00095    *            the specified timeout elapses, errno will be @c EWOULDBLOCK.
00096    */
00097   ACE_Method_Request *dequeue (ACE_Time_Value *tv = 0);
00098 
00099   /// Enqueue the ACE_Method_Request in priority order.
00100   /**
00101    * The priority of the method request is obtained via the @c priority()
00102    * method of the queued method request. Priority ordering is determined
00103    * by the ACE_Message_Queue class; 0 is the lowest priority.
00104    *
00105    * @param new_method_request  Pointer to the ACE_Method_Request object to
00106    *            queue. This object's @c priority() method is called to obtain
00107    *            the priority.
00108    * @param tv  If 0, the method will block until the method request can
00109    *            be queued, else will wait until the absolute time specified
00110    *            in the referenced ACE_Time_Value.  This method will return,
00111    *            earlier, however, if queue is closed, deactivated, or when
00112    *            a signal occurs.
00113    *
00114    * @retval    >0 The number of method requests on the queue after adding
00115    *            the specified request.
00116    * @retval    -1 if an error occurs; errno contains further information. If
00117    *            the specified timeout elapses, errno will be @c EWOULDBLOCK.
00118    */
00119   int enqueue (ACE_Method_Request *new_method_request,
00120                ACE_Time_Value *tv = 0);
00121 
00122   /// Get the current number of method objects in the queue.
00123   size_t method_count (void) const;
00124 
00125   /// Returns 1 if the queue is empty, 0 otherwise.
00126   int is_empty (void) const;
00127 
00128   /// Returns 1 if the queue is full, 0 otherwise.
00129   int is_full (void) const;
00130 
00131   /// Dump the state of an request.
00132   void dump (void) const;
00133 
00134   /// Get a pointer to the underlying queue.
00135   ACE_Message_Queue<ACE_SYNCH> *queue (void) const;
00136 
00137   /// Set the pointer to the underlying queue.
00138   void queue (ACE_Message_Queue<ACE_SYNCH> *q);
00139 
00140   /// Declare the dynamic allocation hooks.
00141   ACE_ALLOC_HOOK_DECLARE;
00142 
00143 private:
00144 
00145   // = Prevent copying and assignment.
00146   ACE_Activation_Queue (const ACE_Activation_Queue &);
00147   void operator= (const ACE_Activation_Queue &);
00148 
00149 protected:
00150 
00151   /// Stores the Method_Requests.
00152   ACE_Message_Queue<ACE_SYNCH> *queue_;
00153 
00154   /// Keeps track of whether we need to delete the queue.
00155   int delete_queue_;
00156 
00157 private:
00158 
00159   /// Allocation strategy of the queue.
00160   ACE_Allocator *allocator_;
00161 
00162   /// Allocation strategy of the message blocks.
00163   ACE_Allocator *data_block_allocator_;
00164 
00165 };
00166 
00167 ACE_END_VERSIONED_NAMESPACE_DECL
00168 
00169 #if defined (__ACE_INLINE__)
00170 #include "ace/Activation_Queue.inl"
00171 #endif /* __ACE_INLINE__ */
00172 
00173 #include /**/ "ace/post.h"
00174 #endif /* ACE_ACTIVATION_QUEUE_H */

Generated on Thu Nov 9 09:41:45 2006 for ACE by doxygen 1.3.6