sipxportlib  Version 3.3
OsMsgQ.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 #ifndef _OsMsgQ_h_
12 #define _OsMsgQ_h_
13 
14 // SYSTEM INCLUDES
15 
16 // APPLICATION INCLUDES
17 #include "os/OsDefs.h"
18 #include "os/OsStatus.h"
19 #include "os/OsTime.h"
20 #include "utl/UtlString.h"
21 
22 // DEFINES
23 // MACROS
24 // EXTERNAL FUNCTIONS
25 // EXTERNAL VARIABLES
26 // CONSTANTS
27 // STRUCTS
28 
29 // FORWARD DECLARATIONS
30 class OsMsg;
31 
32 // TYPEDEFS
33 typedef UtlBoolean (*OsMsgQSendHookPtr) (const OsMsg& rMsg);
34 typedef void (*OsMsgQFlushHookPtr) (const OsMsg& rMsg);
35 
36 //:Message queue for inter-task communication
37 
39 {
40 /* //////////////////////////// PUBLIC //////////////////////////////////// */
41 public:
42 
43  static const int DEF_MAX_MSGS;
44  static const int DEF_MAX_MSG_LEN;
45  static const UtlString MSGQ_PREFIX;
46 
48  enum Options
49  {
50  Q_FIFO = 0x0,
51  Q_PRIORITY = 0x1
52  };
53 
54 
55 /* ============================ CREATORS ================================== */
56 
58  OsMsgQBase(const UtlString& name);
63  virtual ~OsMsgQBase();
65 
67  static OsMsgQBase* getMsgQByName(const UtlString& name);
68 
69 /* ============================ MANIPULATORS ============================== */
70 
71 
73  virtual OsStatus send(const OsMsg& rMsg,
74  const OsTime& rTimeout=OsTime::OS_INFINITY) = 0;
82  virtual OsStatus sendNoCopy(OsMsg *pMsg,
84  const OsTime& rTimeout=OsTime::OS_INFINITY) = 0;
92  virtual OsStatus sendUrgent(const OsMsg& rMsg,
94  const OsTime& rTimeout=OsTime::OS_INFINITY) = 0;
99  virtual OsStatus sendFromISR(OsMsg& rMsg) = 0;
110  virtual OsStatus receive(OsMsg*& rpMsg,
112  const OsTime& rTimeout=OsTime::OS_INFINITY) = 0;
119  virtual void flush();
121 
123  virtual void setSendHook(OsMsgQSendHookPtr func);
132  virtual void setFlushHook(OsMsgQFlushHookPtr func);
141 /* ============================ ACCESSORS ================================= */
142 
144  virtual int numMsgs() = 0;
145 
147  int maxMsgs() const;
148 
150  virtual OsMsgQSendHookPtr getSendHook() const;
151 
152 /* ============================ INQUIRY =================================== */
153 
155  virtual UtlBoolean isEmpty();
156 
158  const UtlString& getName() const { return mName; }
159 
160 /* //////////////////////////// PROTECTED ///////////////////////////////// */
161 protected:
162 
165 
168 
169 /* ---------------------------- DEBUG SCAFFOLDING ------------------------- */
170 protected:
171 
172  int mMaxMsgs;
173 
174 #if MSGQ_IS_VALID_CHECK
175  virtual void testMessageQ() = 0;
176 
177  unsigned int mNumInsertEntry;
178  unsigned int mNumInsertExitOk;
179  unsigned int mNumInsertExitFail;
180 
181  unsigned int mNumRemoveEntry;
182  unsigned int mNumRemoveExitOk;
183  unsigned int mNumRemoveExitFail;
184 
185  unsigned int mLastSuccessTest;
186 #endif
187 
188 /* //////////////////////////// PRIVATE /////////////////////////////////// */
189 private:
190 
191  UtlString mName;
192 
194  OsMsgQBase(const OsMsgQBase& rOsMsgQBase);
195 
197  OsMsgQBase& operator=(const OsMsgQBase& rhs);
198 };
199 
200 /* ============================ INLINE METHODS ============================ */
201 
202 // Depending on the native OS that we are running on, we include the class
203 // declaration for the appropriate lower level implementation and use a
204 // "typedef" statement to associate the OS-independent class name (OsMsgQ)
205 // with the OS-dependent realization of that type (e.g., OsMsgQWnt).
206 #if defined(_WIN32)
207 # include "os/shared/OsMsgQShared.h"
208  typedef class OsMsgQShared OsMsgQ;
209 #elif defined(_VXWORKS)
210 # include "os/Vxw/OsMsgQVxw.h"
211  typedef class OsMsgQVxw OsMsgQ;
212 #elif defined(__pingtel_on_posix__)
213 # include "os/shared/OsMsgQShared.h"
214  typedef class OsMsgQShared OsMsgQ;
215 #else
216 # error Unsupported target platform.
217 #endif
218 
219 #endif // _OsMsgQ_h_
virtual OsStatus sendNoCopy(OsMsg *pMsg, const OsTime &rTimeout=OsTime::OS_INFINITY)=0
Insert an original of the message at the tail of the queue.
virtual OsStatus sendFromISR(OsMsg &rMsg)=0
Insert a copy of the message at the tail of the queue with ISR flag.
Definition: OsMsgQShared.h:80
queue blocked tasks based on their priority
Definition: OsMsgQ.h:51
virtual OsStatus sendUrgent(const OsMsg &rMsg, const OsTime &rTimeout=OsTime::OS_INFINITY)=0
Insert a copy of the message at the head of the queue.
Options
Definition: OsMsgQ.h:48
static const int DEF_MAX_MSGS
Default maximum number of messages.
Definition: OsMsgQ.h:43
static const int DEF_MAX_MSG_LEN
Default maximum msg length (in bytes)
Definition: OsMsgQ.h:44
virtual ~OsMsgQBase()
Destructor.
Definition: OsMsgQ.cpp:50
virtual OsStatus send(const OsMsg &rMsg, const OsTime &rTimeout=OsTime::OS_INFINITY)=0
Insert a copy of the message at the tail of the queue.
static OsMsgQBase * getMsgQByName(const UtlString &name)
Return a pointer to the named queue, or NULL if not found.
Definition: OsMsgQ.cpp:62
OsStatus
Definition: OsStatus.h:27
virtual void setSendHook(OsMsgQSendHookPtr func)
Set the function that is invoked whenever a msg is sent to the queue.
Definition: OsMsgQ.cpp:100
virtual int numMsgs()=0
Return the number of messages in the queue.
virtual UtlBoolean isEmpty()
Return TRUE if the message queue is empty, FALSE otherwise.
Definition: OsMsgQ.cpp:131
UtlBoolean(* OsMsgQSendHookPtr)(const OsMsg &rMsg)
Definition: OsMsgQ.h:33
Definition: UtlString.h:48
int maxMsgs() const
Returns the maximum number of messages that can be queued.
Definition: OsMsgQ.cpp:123
Definition: OsTime.h:45
static const UtlString MSGQ_PREFIX
Prefix for OsMsgQ names stored in < the name database.
Definition: OsMsgQ.h:45
queue blocked tasks on a first-in, first-out basis
Definition: OsMsgQ.h:50
OsMsgQBase(const UtlString &name)
Constructor.
Definition: OsMsgQ.cpp:40
virtual void flush()
Delete all messages currently in the queue.
Definition: OsMsgQ.cpp:82
int mMaxMsgs
maximum number of messages the queue can hold
Definition: OsMsgQ.h:172
OsMsgQFlushHookPtr mFlushHookFunc
Method that is invoked whenever a message is flushed from the queue.
Definition: OsMsgQ.h:167
Definition: OsTime.h:37
virtual OsMsgQSendHookPtr getSendHook() const
Return a pointer to the current send hook function.
Definition: OsMsgQ.cpp:117
int UtlBoolean
Definition: UtlDefs.h:41
virtual void setFlushHook(OsMsgQFlushHookPtr func)
Set the function that is invoked whenever a msg is flushed from the queue.
Definition: OsMsgQ.cpp:109
OsMsgQSendHookPtr mSendHookFunc
Method that is invoked whenever a message is sent to the queue.
Definition: OsMsgQ.h:164
void(* OsMsgQFlushHookPtr)(const OsMsg &rMsg)
Definition: OsMsgQ.h:34
Definition: OsMsg.h:36
Definition: OsMsgQ.h:38
const UtlString & getName() const
Get the name associated with the queue.
Definition: OsMsgQ.h:158
virtual OsStatus receive(OsMsg *&rpMsg, const OsTime &rTimeout=OsTime::OS_INFINITY)=0
Remove a message from the head of the queue.