00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Message_Queue.h 00006 * 00007 * $Id: Message_Queue.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_MESSAGE_QUEUE_H 00014 #define ACE_MESSAGE_QUEUE_H 00015 #include /**/ "ace/pre.h" 00016 00017 #include "ace/Message_Block.h" 00018 00019 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00020 # pragma once 00021 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00022 00023 #include "ace/IO_Cntl_Msg.h" 00024 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO) 00025 # include "ace/Synch_Traits.h" /* Needed in ACE_Message_Queue_NT */ 00026 # include "ace/Thread_Mutex.h" /* Needed in ACE_Message_Queue_NT */ 00027 #endif 00028 00029 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00030 00031 // Forward decls. 00032 class ACE_Notification_Strategy; 00033 template <ACE_SYNCH_DECL> class ACE_Message_Queue_Iterator; 00034 template <ACE_SYNCH_DECL> class ACE_Message_Queue_Reverse_Iterator; 00035 00036 /** 00037 * @class ACE_Message_Queue_Base 00038 * 00039 * @brief Base class for ACE_Message_Queue, which is the central 00040 * queueing facility for messages in the ACE framework. 00041 * 00042 * For all the ACE_Time_Value pointer parameters the caller will 00043 * block until action is possible if @a timeout == 0. Otherwise, it 00044 * will wait until the absolute time specified in *@a timeout 00045 * elapses. 00046 * 00047 * A queue is always in one of three states: 00048 * . ACTIVATED 00049 * . DEACTIVATED 00050 * . PULSED 00051 */ 00052 class ACE_Export ACE_Message_Queue_Base 00053 { 00054 public: 00055 enum 00056 { 00057 // Default high and low watermarks. 00058 00059 /// Default high watermark (16 K). 00060 DEFAULT_HWM = 16 * 1024, 00061 /// Default low watermark (same as high water mark). 00062 DEFAULT_LWM = 16 * 1024, 00063 00064 // Queue states. Before PULSED state was added, the activate() 00065 // and deactivate() methods returned WAS_INACTIVE or WAS_ACTIVE 00066 // to indicate the previous condition. Now those methods 00067 // return the state the queue was previously in. WAS_ACTIVE 00068 // and WAS_INACTIVE are defined to match previous semantics for 00069 // applications that don't use the PULSED state. 00070 00071 /// @deprecated Use ACTIVATED instead. 00072 WAS_ACTIVE = 1, 00073 /// Message queue is active and processing normally 00074 ACTIVATED = 1, 00075 00076 /// @deprecated Use DEACTIVATED instead. 00077 WAS_INACTIVE = 2, 00078 /// Queue is deactivated; no enqueue or dequeue operations allowed. 00079 DEACTIVATED = 2, 00080 00081 /// Message queue was pulsed; enqueue and dequeue may proceed normally. 00082 PULSED = 3 00083 00084 }; 00085 00086 ACE_Message_Queue_Base (void); 00087 00088 /// Close down the message queue and release all resources. 00089 virtual int close (void) = 0; 00090 00091 /// Close down the message queue and release all resources. 00092 virtual ~ACE_Message_Queue_Base (void); 00093 00094 // = Enqueue and dequeue methods. 00095 00096 /** 00097 * Retrieve the first ACE_Message_Block without removing it. Note 00098 * that @a timeout uses <{absolute}> time rather than <{relative}> 00099 * time. If the @a timeout elapses without receiving a message -1 is 00100 * returned and @c errno is set to @c EWOULDBLOCK. If the queue is 00101 * deactivated -1 is returned and @c errno is set to <ESHUTDOWN>. 00102 * Otherwise, returns -1 on failure, else the number of items still 00103 * on the queue. 00104 */ 00105 virtual int peek_dequeue_head (ACE_Message_Block *&first_item, 00106 ACE_Time_Value *timeout = 0) = 0; 00107 00108 /** 00109 * Enqueue a <ACE_Message_Block *> into the tail of the queue. 00110 * Returns number of items in queue if the call succeeds or -1 00111 * otherwise. These calls return -1 when queue is closed, 00112 * deactivated (in which case @c errno == <ESHUTDOWN>), when a signal 00113 * occurs (in which case @c errno == <EINTR>, or if the time 00114 * specified in timeout elapses (in which case @c errno == 00115 * @c EWOULDBLOCK). 00116 */ 00117 virtual int enqueue_tail (ACE_Message_Block *new_item, 00118 ACE_Time_Value *timeout = 0) = 0; 00119 virtual int enqueue (ACE_Message_Block *new_item, 00120 ACE_Time_Value *timeout = 0) = 0; 00121 00122 /** 00123 * Dequeue and return the <ACE_Message_Block *> at the head of the 00124 * queue. Returns number of items in queue if the call succeeds or 00125 * -1 otherwise. These calls return -1 when queue is closed, 00126 * deactivated (in which case @c errno == <ESHUTDOWN>), when a signal 00127 * occurs (in which case @c errno == <EINTR>, or if the time 00128 * specified in timeout elapses (in which case @c errno == 00129 * @c EWOULDBLOCK). 00130 */ 00131 virtual int dequeue_head (ACE_Message_Block *&first_item, 00132 ACE_Time_Value *timeout = 0) = 0; 00133 virtual int dequeue (ACE_Message_Block *&first_item, 00134 ACE_Time_Value *timeout = 0) = 0; 00135 00136 // = Check if queue is full/empty. 00137 /// True if queue is full, else false. 00138 virtual bool is_full (void) = 0; 00139 00140 /// True if queue is empty, else false. 00141 virtual bool is_empty (void) = 0; 00142 00143 // = Queue statistic methods. 00144 00145 /// Number of total bytes on the queue, i.e., sum of the message 00146 /// block sizes. 00147 virtual size_t message_bytes (void) = 0; 00148 00149 /// Number of total length on the queue, i.e., sum of the message 00150 /// block lengths. 00151 virtual size_t message_length (void) = 0; 00152 00153 /// Number of total messages on the queue. 00154 virtual size_t message_count (void) = 0; 00155 00156 /// New value of the number of total bytes on the queue, i.e., 00157 /// sum of the message block sizes. 00158 virtual void message_bytes (size_t new_size) = 0; 00159 00160 /// New value of the number of total length on the queue, i.e., 00161 /// sum of the message block lengths. 00162 virtual void message_length (size_t new_length) = 0; 00163 00164 // = Activation control methods. 00165 00166 /** 00167 * Deactivate the queue and wake up all threads waiting on the queue 00168 * so they can continue. No messages are removed from the queue, 00169 * however. Any other operations called until the queue is 00170 * activated again will immediately return -1 with @c errno 00171 * ESHUTDOWN. 00172 * 00173 * @retval The queue's state before this call. 00174 */ 00175 virtual int deactivate (void) = 0; 00176 00177 /** 00178 * Reactivate the queue so that threads can enqueue and dequeue 00179 * messages again. 00180 * 00181 * @retval The queue's state before this call. 00182 */ 00183 virtual int activate (void) = 0; 00184 00185 /** 00186 * Pulse the queue to wake up any waiting threads. Changes the 00187 * queue state to PULSED; future enqueue/dequeue operations proceed 00188 * as in ACTIVATED state. 00189 * 00190 * @retval The queue's state before this call. 00191 */ 00192 virtual int pulse (void) = 0; 00193 00194 /// Returns the current state of the queue. 00195 virtual int state (void); 00196 00197 /// Returns 1 if the state of the queue is DEACTIVATED, 00198 /// and 0 if the queue's state is ACTIVATED or PULSED. 00199 virtual int deactivated (void) = 0; 00200 00201 /// Get the notification strategy for the <Message_Queue> 00202 virtual ACE_Notification_Strategy *notification_strategy (void) = 0; 00203 00204 /// Set the notification strategy for the <Message_Queue> 00205 virtual void notification_strategy (ACE_Notification_Strategy *s) = 0; 00206 00207 // = Notification hook. 00208 00209 /// Dump the state of an object. 00210 virtual void dump (void) const = 0; 00211 00212 /// Declare the dynamic allocation hooks. 00213 ACE_ALLOC_HOOK_DECLARE; 00214 00215 private: 00216 // = Disallow copying and assignment. 00217 ACE_Message_Queue_Base (const ACE_Message_Queue_Base &); 00218 void operator= (const ACE_Message_Queue_Base &); 00219 00220 protected: 00221 /// Indicates the state of the queue, which can be 00222 /// <ACTIVATED>, <DEACTIVATED>, or <PULSED>. 00223 int state_; 00224 00225 }; 00226 00227 ACE_END_VERSIONED_NAMESPACE_DECL 00228 00229 // Include the templates here. 00230 #include "ace/Message_Queue_T.h" 00231 00232 #if defined (__ACE_INLINE__) 00233 #include "ace/Message_Queue.inl" 00234 #endif /* __ACE_INLINE__ */ 00235 00236 #include /**/ "ace/post.h" 00237 #endif /* ACE_MESSAGE_QUEUE_H */