Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Activation_Queue.h

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

Generated on Mon Jun 16 11:19:02 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002