reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
EventStackThread.cxx
Go to the documentation of this file.
1#include <climits>
2
5//#include "resip/stack/SipMessage.hxx"
6//#include "rutil/SelectInterruptor.hxx"
7//#include "resip/stack/FdPoll.hxx"
8
9#include "rutil/Logger.hxx"
10#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
11
12using namespace resip;
13
14/****************************************************************
15 *
16 * EventThreadInterruptor
17 *
18 ****************************************************************/
19
25
30
31/****************************************************************
32 *
33 * EventStackThread
34 *
35 ****************************************************************/
36
38 FdPollGrp& pollGrp)
39 : mIntr(si), mPollGrp(pollGrp)
40{
41}
42
44 FdPollGrp& pollGrp)
45 : mIntr(si), mPollGrp(pollGrp)
46{
47 addStack(stack);
48}
49
50
52{
53 //InfoLog (<< "EventStackThread::~EventStackThread()");
54}
55
56void
58{
59 mStacks.push_back(&stack);
60}
61
62void
64{
65 while (!isShutdown())
66 {
67 unsigned waitMs = getTimeTillNextProcessMS();
68 if ( waitMs > INT_MAX )
69 waitMs = INT_MAX;
70 StackList::iterator it;
71 for ( it=mStacks.begin(); it!=mStacks.end(); ++it)
72 {
73 SipStack *ss = *it;
74 unsigned wms = ss->getTimeTillNextProcessMS();
75 if ( wms < waitMs )
76 waitMs = wms;
77 // NOTE: In theory, we could early-out when waitMs gets to zero
78 // but I fear the stack may depend upon doing real-work in the query.
79 }
80 mPollGrp.waitAndProcess((int)waitMs);
81 for ( it=mStacks.begin(); it!=mStacks.end(); ++it)
82 {
83 SipStack *ss = *it;
84 ss->processTimers();
85 }
87 }
88 InfoLog (<< "Shutting down stack thread");
89}
90
91void
97
98unsigned int
100{
101 return 10000;
102}
103
104void
108
109
110/****************************************************************
111 *
112 * EventStackSimpleMgr
113 *
114 * This is a helper class that constructs the thread-related
115 * classes in the appropriate order, and destructs them when done.
116 * It is to help save typing in simple applications.
117 *
118 ****************************************************************/
119
121 : mPollGrp(0), mIntr(0), mThread(0), mStack(0)
122{
123 mPollGrp = FdPollGrp::create(implName);
126}
127
132
133void
139
140
143{
144 setOptions(options);
145 mStack = new SipStack(options);
147 return *mStack;
148}
149
150void
152{
153 if ( mThread )
154 {
155 delete mThread; mThread = NULL;
156 }
157 if ( mStack )
158 {
159 // we only delete the stack if we created, not if externally created
160 delete mStack; mStack = NULL;
161 }
162 if ( mIntr )
163 {
164 delete mIntr; mIntr = NULL;
165 }
166 if ( mPollGrp )
167 {
168 delete mPollGrp; mPollGrp = NULL;
169 }
170}
171
172/* ====================================================================
173 * The Vovida Software License, Version 1.0
174 *
175 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
176 *
177 * Redistribution and use in source and binary forms, with or without
178 * modification, are permitted provided that the following conditions
179 * are met:
180 *
181 * 1. Redistributions of source code must retain the above copyright
182 * notice, this list of conditions and the following disclaimer.
183 *
184 * 2. Redistributions in binary form must reproduce the above copyright
185 * notice, this list of conditions and the following disclaimer in
186 * the documentation and/or other materials provided with the
187 * distribution.
188 *
189 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
190 * and "Vovida Open Communication Application Library (VOCAL)" must
191 * not be used to endorse or promote products derived from this
192 * software without prior written permission. For written
193 * permission, please contact vocal@vovida.org.
194 *
195 * 4. Products derived from this software may not be called "VOCAL", nor
196 * may "VOCAL" appear in their name, without prior written
197 * permission of Vovida Networks, Inc.
198 *
199 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
200 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
201 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
202 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
203 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
204 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
205 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
206 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
207 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
208 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
209 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
210 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
211 * DAMAGE.
212 *
213 * ====================================================================
214 *
215 * This software consists of voluntary contributions made by Vovida
216 * Networks, Inc. and many individuals on behalf of Vovida Networks,
217 * Inc. For more information on Vovida Networks, Inc., please see
218 * <http://www.vovida.org/>.
219 *
220 * vi: set shiftwidth=3 expandtab:
221 */
#define FPEM_Read
Definition FdPoll.hxx:29
#define InfoLog(args_)
Definition Logger.hxx:131
EventThreadInterruptor * mIntr
SipStack & createStack(SipStackOptions &options)
EventStackSimpleMgr(const char *implName)
void setOptions(SipStackOptions &options)
This class creates a thread in which to run one or more SipStacks.
virtual unsigned int getTimeTillNextProcessMS() const
void addStack(SipStack &stack)
EventStackThread(EventThreadInterruptor &si, FdPollGrp &pollGrp)
EventThreadInterruptor(FdPollGrp &pollGrp)
static FdPollGrp * create(const char *implName=NULL)
factory
Definition FdPoll.cxx:972
virtual FdPollItemHandle addPollItem(Socket sock, FdPollEventMask newMask, FdPollItemIf *item)=0
virtual void delPollItem(FdPollItemHandle handle)=0
virtual bool waitAndProcess(int ms=0)=0
Wait at most {ms} milliseconds.
void interrupt()
cause the 'artificial' fd to signal
This class holds constructor-time initialization arguments for SipStack.
Definition SipStack.hxx:112
AsyncProcessHandler * mAsyncProcessHandler
Definition SipStack.hxx:124
This is the primary point of interaction between the app-layer and the stack.
Definition SipStack.hxx:160
virtual unsigned int getTimeTillNextProcessMS()
Returns time in milliseconds when process next needs to be called.
virtual void processTimers()
Check all timers.
virtual void shutdown()
Definition ThreadIf.cxx:190
bool isShutdown() const
Definition ThreadIf.cxx:212
dcm! – add UnusedChecking(_enum) below;