00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Message_Queue_Vx.h 00006 * 00007 * $Id: Message_Queue_Vx.h 78675 2007-06-30 06:00:47Z johnnyw $ 00008 * 00009 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef ACE_MESSAGE_QUEUE_VX_H 00014 #define ACE_MESSAGE_QUEUE_VX_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 #if defined (ACE_VXWORKS) 00024 00025 // Include the templates here. 00026 #include "ace/Message_Queue_T.h" 00027 00028 # include /**/ <msgQLib.h> 00029 # include "ace/Null_Mutex.h" 00030 # include "ace/Null_Condition.h" 00031 00032 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00033 00034 /** 00035 * @class ACE_Message_Queue_Vx 00036 * 00037 * @brief Wrapper for VxWorks message queues. 00038 * 00039 * Specialization of ACE_Message_Queue to simply wrap VxWorks 00040 * MsgQ. It does not use any synchronization, because it relies 00041 * on the native MsgQ implementation to take care of that. The 00042 * only system calls that it uses are VxWorks msgQLib calls, so 00043 * it is suitable for use in interrupt service routines. 00044 * @note *Many* ACE_Message_Queue features are not supported with 00045 * this specialization, including: 00046 * * The two size arguments to the constructor and <open> are 00047 * interpreted differently. The first is interpreted as the 00048 * maximum number of bytes in a message. The second is 00049 * interpreted as the maximum number of messages that can be 00050 * queued. 00051 * * <dequeue_head> *requires* that the ACE_Message_Block 00052 * pointer argument point to an ACE_Message_Block that was 00053 * allocated by the caller. It must be big enough to support 00054 * the received message, without using continuation. The 00055 * pointer argument is not modified. 00056 * * Message priority. MSG_Q_FIFO is hard-coded. 00057 * * enqueue method timeouts. 00058 * * <peek_dequeue_head>. 00059 * * <ACE_Message_Queue_Iterators>. 00060 * * The ability to change low and high water marks after creation. 00061 * * <Message_Block> chains. The continuation field of ACE_Message_Block 00062 * * is ignored; only the first block of a fragment chain is 00063 * * recognized. 00064 */ 00065 class ACE_Message_Queue_Vx : public ACE_Message_Queue<ACE_NULL_SYNCH> 00066 { 00067 public: 00068 // = Initialization and termination methods. 00069 ACE_Message_Queue_Vx (size_t max_messages, 00070 size_t max_message_length, 00071 ACE_Notification_Strategy * = 0); 00072 00073 // Create a message queue with all the defaults. 00074 /// Create a message queue with all the defaults. 00075 virtual int open (size_t max_messages, 00076 size_t max_message_length, 00077 ACE_Notification_Strategy * = 0); 00078 00079 /// Close down the message queue and release all resources. 00080 virtual int close (void); 00081 00082 /// Close down the message queue and release all resources. 00083 virtual ~ACE_Message_Queue_Vx (void); 00084 00085 // = Queue statistic methods. 00086 /** 00087 * Number of total bytes on the queue, i.e., sum of the message 00088 * block sizes. 00089 */ 00090 virtual size_t message_bytes (void); 00091 00092 /** 00093 * Number of total length on the queue, i.e., sum of the message 00094 * block lengths. 00095 */ 00096 virtual size_t message_length (void); 00097 00098 /** 00099 * Number of total messages on the queue. 00100 */ 00101 virtual size_t message_count (void); 00102 00103 // = Manual changes to these stats (used when queued message blocks 00104 // change size or lengths). 00105 /** 00106 * New value of the number of total bytes on the queue, i.e., sum of 00107 * the message block sizes. 00108 */ 00109 virtual void message_bytes (size_t new_size); 00110 /** 00111 * New value of the number of total length on the queue, i.e., sum 00112 * of the message block lengths. 00113 */ 00114 virtual void message_length (size_t new_length); 00115 00116 // = Flow control routines 00117 00118 /// Get high watermark. 00119 virtual size_t high_water_mark (void); 00120 00121 /// Set high watermark. 00122 virtual void high_water_mark (size_t hwm); 00123 00124 /// Get low watermark. 00125 virtual size_t low_water_mark (void); 00126 00127 /// Set low watermark. 00128 virtual void low_water_mark (size_t lwm); 00129 00130 // = Activation control methods. 00131 00132 /// Dump the state of an object. 00133 void dump (void) const; 00134 00135 /// Declare the dynamic allocation hooks. 00136 ACE_ALLOC_HOOK_DECLARE; 00137 00138 protected: 00139 /// Enqueue an <ACE_Message_Block *> in accordance with its priority. 00140 virtual int enqueue_i (ACE_Message_Block *new_item); 00141 00142 /// Enqueue an <ACE_Message_Block *> in accordance with its deadline time. 00143 virtual int enqueue_deadline_i (ACE_Message_Block *new_item); 00144 00145 /// Enqueue an <ACE_Message_Block *> at the end of the queue. 00146 virtual int enqueue_tail_i (ACE_Message_Block *new_item); 00147 00148 /// Enqueue an <ACE_Message_Block *> at the head of the queue. 00149 virtual int enqueue_head_i (ACE_Message_Block *new_item); 00150 00151 /// Dequeue and return the <ACE_Message_Block *> at the head of the 00152 /// queue. 00153 virtual int dequeue_head_i (ACE_Message_Block *&first_item); 00154 00155 /// Dequeue and return the <ACE_Message_Block *> with the lowest 00156 /// priority. 00157 virtual int dequeue_prio_i (ACE_Message_Block *&dequeued); 00158 00159 /// Dequeue and return the <ACE_Message_Block *> at the tail of the 00160 /// queue. 00161 virtual int dequeue_tail_i (ACE_Message_Block *&dequeued); 00162 00163 /// Dequeue and return the <ACE_Message_Block *> that has the lowest 00164 /// deadline time. 00165 virtual int dequeue_deadline_i (ACE_Message_Block *&dequeued); 00166 00167 // = Check the boundary conditions (assumes locks are held). 00168 /// True if queue is full, else false. 00169 virtual int is_full_i (void); 00170 00171 /// True if queue is empty, else false. 00172 virtual int is_empty_i (void); 00173 00174 // = Implementation of public <activate>/<deactivate> methods above. 00175 00176 // These methods assume locks are held. 00177 00178 // = Helper methods to factor out common #ifdef code. 00179 /// Wait for the queue to become non-full. 00180 virtual int wait_not_full_cond (ACE_Guard<ACE_Null_Mutex> &mon, 00181 ACE_Time_Value *tv); 00182 00183 /// Wait for the queue to become non-empty. 00184 virtual int wait_not_empty_cond (ACE_Guard<ACE_Null_Mutex> &mon, 00185 ACE_Time_Value *tv); 00186 00187 /// Inform any threads waiting to enqueue that they can procede. 00188 virtual int signal_enqueue_waiters (void); 00189 00190 /// Inform any threads waiting to dequeue that they can procede. 00191 virtual int signal_dequeue_waiters (void); 00192 00193 /// Access the underlying msgQ. 00194 MSG_Q_ID msgq (void); 00195 00196 private: 00197 00198 // Disallow copying and assignment. 00199 ACE_Message_Queue_Vx (const ACE_Message_Queue_Vx &); 00200 void operator= (const ACE_Message_Queue_Vx &); 00201 00202 ACE_UNIMPLEMENTED_FUNC (virtual int peek_dequeue_head 00203 (ACE_Message_Block *&first_item, 00204 ACE_Time_Value *tv = 0)) 00205 00206 private: 00207 /// Maximum number of messages that can be queued. 00208 int max_messages_; 00209 00210 /// Maximum message size, in bytes. 00211 int max_message_length_; 00212 00213 /// Native message queue options. 00214 int options_; 00215 00216 }; 00217 00218 ACE_END_VERSIONED_NAMESPACE_DECL 00219 00220 #endif /* ACE_VXWORKS */ 00221 00222 #if defined (__ACE_INLINE__) 00223 #include "ace/Message_Queue_Vx.inl" 00224 #endif /* __ACE_INLINE__ */ 00225 00226 #include /**/ "ace/post.h" 00227 #endif /* ACE_MESSAGE_QUEUE_VX_H */