Dynamic_Message_Strategy.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //==========================================================================
00004 /**
00005  *  @file    Dynamic_Message_Strategy.h
00006  *
00007  *  $Id: Dynamic_Message_Strategy.h 80826 2008-03-04 14:51:23Z wotte $
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00010  */
00011 //==========================================================================
00012 
00013 #ifndef ACE_DYNAMIC_MESSAGE_STRATEGY_H
00014 #define ACE_DYNAMIC_MESSAGE_STRATEGY_H
00015 
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "ace/config-lite.h"
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_Block.h"
00026 
00027 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00028 
00029 /**
00030  * @class ACE_Dynamic_Message_Strategy
00031  *
00032  * @brief An abstract base class which provides dynamic priority
00033  * evaluation methods for use by the ACE_Dynamic_Message_Queue
00034  * class or any other class which needs to manage the priorities
00035  * of a collection of ACE_Message_Blocks dynamically.
00036  *
00037  * Methods for deadline and laxity based priority evaluation are
00038  * provided.  These methods assume a specific partitioning of
00039  * the message priority number into a higher order dynamic bit
00040  * field and a lower order static priority bit field.  The
00041  * default partitioning assumes an unsigned dynamic message
00042  * priority field of 22 bits and an unsigned static message
00043  * priority field of 10 bits.  This corresponds to the initial
00044  * values of the static class members.  To provide a different
00045  * partitioning, assign a different set of values to the static
00046  * class memebers before using the static member functions.
00047  */
00048 class ACE_Export ACE_Dynamic_Message_Strategy
00049 {
00050 public:
00051 
00052   // = Message priority status
00053 
00054   // Values are defined as bit flags so that status combinations may
00055   // be specified easily.
00056 
00057   enum Priority_Status
00058   {
00059     /// Message can still make its deadline
00060     PENDING     = 0x01,
00061     /// Message cannot make its deadline
00062     LATE        = 0x02,
00063     /// Message is so late its priority is undefined
00064     BEYOND_LATE = 0x04,
00065     /// Mask to match any priority status
00066     ANY_STATUS  = 0x07
00067   };
00068 
00069   /// Constructor.
00070   ACE_Dynamic_Message_Strategy (unsigned long static_bit_field_mask,
00071                                 unsigned long static_bit_field_shift,
00072                                 unsigned long dynamic_priority_max,
00073                                 unsigned long dynamic_priority_offset);
00074 
00075   /// Virtual destructor.
00076   virtual ~ACE_Dynamic_Message_Strategy (void);
00077 
00078   /// Updates the message's priority and returns its priority status.
00079   Priority_Status priority_status (ACE_Message_Block &mb,
00080                                    const ACE_Time_Value &tv);
00081 
00082   /// Get static bit field mask.
00083   unsigned long static_bit_field_mask (void) const;
00084 
00085   /// Set static bit field mask.
00086   void static_bit_field_mask (unsigned long);
00087 
00088   /// Get left shift value to make room for static bit field.
00089   unsigned long static_bit_field_shift (void) const;
00090 
00091   /// Set left shift value to make room for static bit field.
00092   void static_bit_field_shift (unsigned long);
00093 
00094   /// Get maximum supported priority value.
00095   unsigned long dynamic_priority_max (void) const;
00096 
00097   /// Set maximum supported priority value.
00098   void dynamic_priority_max (unsigned long);
00099 
00100   /// Get offset to boundary between signed range and unsigned range.
00101   unsigned long dynamic_priority_offset (void) const;
00102 
00103   /// Set offset to boundary between signed range and unsigned range.
00104   void dynamic_priority_offset (unsigned long);
00105 
00106   /// Dump the state of the strategy.
00107   virtual void dump (void) const;
00108 
00109 protected:
00110   /// Hook method for dynamic priority conversion.
00111   virtual void convert_priority (ACE_Time_Value &priority,
00112                                  const ACE_Message_Block &mb) = 0;
00113 
00114   /// This is a bit mask with all ones in the static bit field.
00115   unsigned long static_bit_field_mask_;
00116 
00117   /**
00118    * This is a left shift value to make room for static bit field:
00119    * this value should be the logarithm base 2 of
00120    * (static_bit_field_mask_ + 1).
00121    */
00122   unsigned long static_bit_field_shift_;
00123 
00124   /// Maximum supported priority value.
00125   unsigned long dynamic_priority_max_;
00126 
00127   /// Offset to boundary between signed range and unsigned range.
00128   unsigned long dynamic_priority_offset_;
00129 
00130   /// Maximum late time value that can be represented.
00131   ACE_Time_Value max_late_;
00132 
00133   /// Minimum pending time value that can be represented.
00134   ACE_Time_Value min_pending_;
00135 
00136   /// Time value by which to shift pending priority.
00137   ACE_Time_Value pending_shift_;
00138 };
00139 
00140 /**
00141  * @class ACE_Deadline_Message_Strategy
00142  *
00143  * @brief Deadline based message priority strategy.
00144  *
00145  * Assigns dynamic message priority according to time to deadline.  The
00146  * message priority is divided into high and low order bit fields.  The
00147  * high order bit field is used for dynamic message priority, which is
00148  * updated whenever the convert_priority() method is called.  The
00149  * low order bit field is used for static message priority and is left
00150  * unchanged.  The partitioning of the priority value into high and low
00151  * order bit fields is done according to the arguments passed to the
00152  * strategy object's constructor.
00153  */
00154 class ACE_Export ACE_Deadline_Message_Strategy : public ACE_Dynamic_Message_Strategy
00155 {
00156 public:
00157   /// Ctor, with all arguments defaulted.
00158   ACE_Deadline_Message_Strategy (unsigned long static_bit_field_mask = 0x3FFUL,       // 2^(10) - 1
00159                                  unsigned long static_bit_field_shift = 10,           // 10 low order bits
00160                                  unsigned long dynamic_priority_max = 0x3FFFFFUL,     // 2^(22)-1
00161                                  unsigned long dynamic_priority_offset = 0x200000UL); // 2^(22-1)
00162 
00163   /// Virtual dtor.
00164   virtual ~ACE_Deadline_Message_Strategy (void);
00165 
00166   /// Dynamic priority conversion function based on time to deadline.
00167   virtual void convert_priority (ACE_Time_Value &priority,
00168                                  const ACE_Message_Block &mb);
00169 
00170   /// Dump the state of the strategy.
00171   virtual void dump (void) const;
00172 };
00173 
00174 /**
00175  * @class ACE_Laxity_Message_Strategy
00176  *
00177  * @brief Laxity based message priority strategy.
00178  *
00179  * Assigns dynamic message priority according to laxity (time to
00180  * deadline minus worst case execution time).  The message priority is
00181  * divided into high and low order bit fields.  The high order
00182  * bit field is used for dynamic message priority, which is
00183  * updated whenever the convert_priority() method is called.  The
00184  * low order bit field is used for static message priority and is left
00185  * unchanged.  The partitioning of the priority value into high and low
00186  * order bit fields is done according to the arguments passed to the
00187  * strategy object's constructor.
00188  */
00189 class ACE_Export ACE_Laxity_Message_Strategy : public ACE_Dynamic_Message_Strategy
00190 {
00191 public:
00192   /// Ctor, with all arguments defaulted.
00193   ACE_Laxity_Message_Strategy (unsigned long static_bit_field_mask = 0x3FFUL,       // 2^(10) - 1
00194                                unsigned long static_bit_field_shift = 10,           // 10 low order bits
00195                                unsigned long dynamic_priority_max = 0x3FFFFFUL,     // 2^(22)-1
00196                                unsigned long dynamic_priority_offset = 0x200000UL); // 2^(22-1)
00197 
00198   /// virtual dtor.
00199   virtual ~ACE_Laxity_Message_Strategy (void);
00200 
00201   /// Dynamic priority conversion function based on laxity.
00202   virtual void convert_priority (ACE_Time_Value &priority,
00203                                  const ACE_Message_Block &mb);
00204 
00205   /// Dump the state of the strategy.
00206   virtual void dump (void) const;
00207 };
00208 
00209 ACE_END_VERSIONED_NAMESPACE_DECL
00210 
00211 #if defined (__ACE_INLINE__)
00212 #include "ace/Dynamic_Message_Strategy.inl"
00213 #endif /* __ACE_INLINE__ */
00214 
00215 #include /**/ "ace/post.h"
00216 
00217 #endif /* ACE_DYNAMIC_MESSAGE_STRATEGY_H */

Generated on Tue Feb 2 17:18:39 2010 for ACE by  doxygen 1.4.7