sipxportlib  Version 3.3
OsServerTask.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 _OsServerTask_h_
12 #define _OsServerTask_h_
13 
14 // SYSTEM INCLUDES
15 
16 // APPLICATION INCLUDES
17 #include "os/OsDefs.h"
18 #include "os/OsStatus.h"
19 #include "os/OsTask.h"
20 #include "os/OsTime.h"
21 
22 // DEFINES
23 // MACROS
24 // EXTERNAL FUNCTIONS
25 // CONSTANTS
26 // STRUCTS
27 // TYPEDEFS
28 
29 // FORWARD DECLARATIONS
30 class OsMsg;
31 
32 //:Abstract base class for tasks that process incoming msgs from an OsMsgQ
33 
34 class OsServerTask : public OsTask
35 {
36 /* //////////////////////////// PUBLIC //////////////////////////////////// */
37 public:
38 
39  static const int DEF_MAX_MSGS;
40 
41 /* ============================ CREATORS ================================== */
42 
44  OsServerTask(const UtlString& name="",
45  void* pArg=NULL,
46  const int maxRequestQMsgs=DEF_MAX_MSGS,
47  const int priority=DEF_PRIO,
48  const int options=DEF_OPTIONS,
49  const int stackSize=DEF_STACKSIZE);
61  virtual
62  ~OsServerTask();
63  //:Destructor
64  // As part of destroying the task, flush all messages from the incoming
65  // OsMsgQ.
66 
67 /* ============================ MANIPULATORS ============================== */
68 
69  virtual UtlBoolean handleMessage(OsMsg& rMsg) = 0;
70  //:Handles an incoming message
71  // If the message is not one that the object is prepared to process,
72  // the handleMessage() method in the derived class should return FALSE
73  // which will cause the OsMessageTask::handleMessage() method to be
74  // invoked on the message.
75 
76  virtual OsStatus postMessage(const OsMsg& rMsg,
77  const OsTime& rTimeout=OsTime::OS_INFINITY,
78  UtlBoolean sentFromISR=FALSE);
79  //:Posts a message to this task
80  // Return the result of the message send operation.
81 
82  virtual void requestShutdown(void);
83  //:Call OsTask::requestShutdown() and then post an OS_SHUTDOWN message
84  //:to the incoming message queue to unblock the task
85 
86 /* ============================ ACCESSORS ================================= */
87 
88  OsMsgQ* getMessageQueue();
89  //:Get the pointer to the incoming message queue
90 
91 /* ============================ INQUIRY =================================== */
92 
93 /* //////////////////////////// PROTECTED ///////////////////////////////// */
94 protected:
95 
96  OsMsgQ mIncomingQ; // Queue for incoming messages.
97 
98  virtual OsStatus receiveMessage(OsMsg*& rpMsg);
99  //:Waits for a message to arrive on the task's incoming message queue
100 
101  virtual OsStatus receiveMessage(OsMsg*& rpMsg,
102  const OsTime& rTimeout);
103  //:Waits for a message to arrive on the task's incoming message queue,
104  // with timeout.
105 
106  virtual int run(void* pArg);
107  //:The entry point for the task
108  // This method executes a message processing loop until either
109  // requestShutdown(), deleteForce(), or the destructor for this object
110  // is called.
111 
112 /* //////////////////////////// PRIVATE /////////////////////////////////// */
113 private:
114 
115  OsServerTask(const OsServerTask& rOsServerTask);
116  //:Copy constructor (not implemented for this class)
117 
118  OsServerTask& operator=(const OsServerTask& rhs);
119  //:Assignment operator (not implemented for this task)
120 
121 };
122 
123 /* ============================ INLINE METHODS ============================ */
124 
125 #endif // _OsServerTask_h_
126 
virtual int run(void *pArg)
Definition: OsServerTask.cpp:151
virtual OsStatus postMessage(const OsMsg &rMsg, const OsTime &rTimeout=OsTime::OS_INFINITY, UtlBoolean sentFromISR=FALSE)
Definition: OsServerTask.cpp:97
Definition: OsServerTask.h:34
OsMsgQ mIncomingQ
Definition: OsServerTask.h:96
OsMsgQ * getMessageQueue()
Definition: OsServerTask.cpp:125
OsStatus
Definition: OsStatus.h:27
#define NULL
Definition: UtlDefs.h:29
static const int DEF_MAX_MSGS
Definition: OsServerTask.h:39
virtual UtlBoolean handleMessage(OsMsg &rMsg)=0
Definition: OsServerTask.cpp:73
virtual ~OsServerTask()
Definition: OsServerTask.cpp:60
virtual OsStatus receiveMessage(OsMsg *&rpMsg)
Definition: OsServerTask.cpp:135
Definition: UtlString.h:48
Definition: OsTime.h:45
virtual void requestShutdown(void)
Definition: OsServerTask.cpp:111
Definition: OsTime.h:37
int UtlBoolean
Definition: UtlDefs.h:41
Definition: OsMsg.h:36
OsServerTask(const UtlString &name="", void *pArg=NULL, const int maxRequestQMsgs=DEF_MAX_MSGS, const int priority=DEF_PRIO, const int options=DEF_OPTIONS, const int stackSize=DEF_STACKSIZE)
Main constructor for OsServerTask.
Definition: OsServerTask.cpp:32
#define FALSE
Definition: UtlDefs.h:21