3 //=============================================================================
5 * @file Message_Queue.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
9 //=============================================================================
11 #ifndef ACE_MESSAGE_QUEUE_H
12 #define ACE_MESSAGE_QUEUE_H
13 #include /**/ "ace/pre.h"
15 #include "ace/Message_Block.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 #include "ace/IO_Cntl_Msg.h"
23 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
26 class ACE_Notification_Strategy
;
27 template <ACE_SYNCH_DECL
, class TIME_POLICY
> class ACE_Message_Queue_Iterator
;
28 template <ACE_SYNCH_DECL
, class TIME_POLICY
> class ACE_Message_Queue_Reverse_Iterator
;
31 * @class ACE_Message_Queue_Base
33 * @brief Base class for ACE_Message_Queue, which is the central
34 * queuing facility for messages in the ACE framework.
36 * For all the ACE_Time_Value pointer parameters the caller will
37 * block until action is possible if @a timeout == 0. Otherwise, it
38 * will wait until the absolute time specified in *@a timeout
41 * A queue is always in one of three states:
46 class ACE_Export ACE_Message_Queue_Base
51 // Default high and low watermarks.
53 /// Default high watermark (16 K).
54 DEFAULT_HWM
= 16 * 1024,
55 /// Default low watermark (same as high water mark).
56 DEFAULT_LWM
= 16 * 1024,
58 // Queue states. Before PULSED state was added, the activate()
59 // and deactivate() methods returned WAS_INACTIVE or WAS_ACTIVE
60 // to indicate the previous condition. Now those methods
61 // return the state the queue was previously in. WAS_ACTIVE
62 // and WAS_INACTIVE are defined to match previous semantics for
63 // applications that don't use the PULSED state.
65 /// Message queue is active and processing normally
68 /// Queue is deactivated; no enqueue or dequeue operations allowed.
71 /// Message queue was pulsed; enqueue and dequeue may proceed normally.
76 ACE_Message_Queue_Base ();
78 /// Close down the message queue and release all resources.
79 virtual int close () = 0;
81 /// Close down the message queue and release all resources.
82 virtual ~ACE_Message_Queue_Base ();
84 // = Enqueue and dequeue methods.
87 * Retrieve the first ACE_Message_Block without removing it. Note
88 * that @a timeout uses <{absolute}> time rather than <{relative}>
89 * time. If the @a timeout elapses without receiving a message -1 is
90 * returned and @c errno is set to @c EWOULDBLOCK. If the queue is
91 * deactivated -1 is returned and @c errno is set to @c ESHUTDOWN.
92 * Otherwise, returns -1 on failure, else the number of items still
95 virtual int peek_dequeue_head (ACE_Message_Block
*&first_item
,
96 ACE_Time_Value
*timeout
= 0) = 0;
99 * Enqueue a <ACE_Message_Block *> into the tail of the queue.
100 * Returns number of items in queue if the call succeeds or -1
101 * otherwise. These calls return -1 when queue is closed,
102 * deactivated (in which case @c errno == @c ESHUTDOWN), when a signal
103 * occurs (in which case @c errno == @c EINTR, or if the time
104 * specified in timeout elapses (in which case @c errno ==
107 virtual int enqueue_tail (ACE_Message_Block
*new_item
,
108 ACE_Time_Value
*timeout
= 0) = 0;
109 virtual int enqueue (ACE_Message_Block
*new_item
,
110 ACE_Time_Value
*timeout
= 0) = 0;
113 * Dequeue and return the <ACE_Message_Block *> at the head of the
114 * queue. Returns number of items in queue if the call succeeds or
115 * -1 otherwise. These calls return -1 when queue is closed,
116 * deactivated (in which case @c errno == @c ESHUTDOWN), when a signal
117 * occurs (in which case @c errno == @c EINTR, or if the time
118 * specified in timeout elapses (in which case @c errno ==
121 virtual int dequeue_head (ACE_Message_Block
*&first_item
,
122 ACE_Time_Value
*timeout
= 0) = 0;
123 virtual int dequeue (ACE_Message_Block
*&first_item
,
124 ACE_Time_Value
*timeout
= 0) = 0;
126 // = Check if queue is full/empty.
127 /// True if queue is full, else false.
128 virtual bool is_full () = 0;
130 /// True if queue is empty, else false.
131 virtual bool is_empty () = 0;
133 // = Queue statistic methods.
135 /// Number of total bytes on the queue, i.e., sum of the message
137 virtual size_t message_bytes () = 0;
139 /// Number of total length on the queue, i.e., sum of the message
141 virtual size_t message_length () = 0;
143 /// Number of total messages on the queue.
144 virtual size_t message_count () = 0;
146 /// New value of the number of total bytes on the queue, i.e.,
147 /// sum of the message block sizes.
148 virtual void message_bytes (size_t new_size
) = 0;
150 /// New value of the number of total length on the queue, i.e.,
151 /// sum of the message block lengths.
152 virtual void message_length (size_t new_length
) = 0;
154 // = Activation control methods.
157 * Deactivate the queue and wake up all threads waiting on the queue
158 * so they can continue. No messages are removed from the queue,
159 * however. Any other operations called until the queue is
160 * activated again will immediately return -1 with @c errno
163 * @retval The queue's state before this call.
165 virtual int deactivate () = 0;
168 * Reactivate the queue so that threads can enqueue and dequeue
171 * @retval The queue's state before this call.
173 virtual int activate () = 0;
176 * Pulse the queue to wake up any waiting threads. Changes the
177 * queue state to PULSED; future enqueue/dequeue operations proceed
178 * as in ACTIVATED state.
180 * @retval The queue's state before this call.
182 virtual int pulse () = 0;
184 /// Returns the current state of the queue.
185 virtual int state ();
187 /// Returns 1 if the state of the queue is DEACTIVATED,
188 /// and 0 if the queue's state is ACTIVATED or PULSED.
189 virtual int deactivated () = 0;
191 /// Get the notification strategy for the Message_Queue
192 virtual ACE_Notification_Strategy
*notification_strategy () = 0;
194 /// Set the notification strategy for the Message_Queue
195 virtual void notification_strategy (ACE_Notification_Strategy
*s
) = 0;
197 // = Notification hook.
199 /// Dump the state of an object.
200 virtual void dump () const = 0;
203 // = Disallow copying and assignment.
204 ACE_Message_Queue_Base (const ACE_Message_Queue_Base
&);
205 void operator= (const ACE_Message_Queue_Base
&);
208 /// Indicates the state of the queue, which can be
209 /// <ACTIVATED>, <DEACTIVATED>, or <PULSED>.
213 ACE_END_VERSIONED_NAMESPACE_DECL
215 // Include the templates here.
216 #include "ace/Message_Queue_T.h"
218 #if defined (__ACE_INLINE__)
219 #include "ace/Message_Queue.inl"
220 #endif /* __ACE_INLINE__ */
222 #include /**/ "ace/post.h"
223 #endif /* ACE_MESSAGE_QUEUE_H */