reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
Dispatcher.cxx
Go to the documentation of this file.
5
6
7namespace resip
8{
9
10Dispatcher::Dispatcher(std::unique_ptr<Worker> prototype,
11 resip::SipStack* stack,
12 int workers,
13 bool startImmediately):
14 mStack(stack),
15 mFifo(0,0),
16 mAcceptingWork(false),
17 mShutdown(false),
18 mStarted(false),
19 mWorkerPrototype(prototype.release())
20{
21 for(int i=0; i<workers;i++)
22 {
24 }
25
26 if(startImmediately)
27 {
28 startAll();
29 }
30}
31
33{
35
36 std::vector<WorkerThread*>::iterator i;
37 for(i=mWorkerThreads.begin(); i!=mWorkerThreads.end(); ++i)
38 {
39 delete *i;
40 }
41
42 mWorkerThreads.clear();
43
44 while(!mFifo.empty())
45 {
46 delete mFifo.getNext();
47 }
48
49 delete mWorkerPrototype;
50
51}
52
53bool
54Dispatcher::post(std::unique_ptr<resip::ApplicationMessage>& work)
55{
58 {
59 mFifo.add(work.release(),
61 return true;
62 }
63
64 return false;
65
66 //If we aren't accepting work, the auto ptr is not released. (We don't
67 // take ownership, and the caller gets to handle the contents of the
68 // unique_ptr)
69}
70
71size_t
73{
74 return mFifo.getCountDepth();
75}
76
77time_t
79{
80 return mFifo.getTimeDepth();
81}
82
83int
85{
86 return (int)mWorkerThreads.size();
87}
88
89void
95
96void
102
103void
105{
107 if(!mShutdown)
108 {
109 mAcceptingWork=false;
110 mShutdown=true;
111
112 std::vector<WorkerThread*>::iterator i;
113 for(i=mWorkerThreads.begin(); i!=mWorkerThreads.end(); ++i)
114 {
115 (*i)->shutdown();
116 (*i)->join();
117 }
118 }
119}
120
121void
123{
125 if(!mShutdown && !mStarted)
126 {
127 std::vector<WorkerThread*>::iterator i;
128 for(i=mWorkerThreads.begin(); i!=mWorkerThreads.end(); ++i)
129 {
130 (*i)->run();
131 }
132 mStarted=true;
133 mAcceptingWork=true;
134 }
135}
136
137} //namespace resip
138
139/* ====================================================================
140 * The Vovida Software License, Version 1.0
141 *
142 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
143 *
144 * Redistribution and use in source and binary forms, with or without
145 * modification, are permitted provided that the following conditions
146 * are met:
147 *
148 * 1. Redistributions of source code must retain the above copyright
149 * notice, this list of conditions and the following disclaimer.
150 *
151 * 2. Redistributions in binary form must reproduce the above copyright
152 * notice, this list of conditions and the following disclaimer in
153 * the documentation and/or other materials provided with the
154 * distribution.
155 *
156 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
157 * and "Vovida Open Communication Application Library (VOCAL)" must
158 * not be used to endorse or promote products derived from this
159 * software without prior written permission. For written
160 * permission, please contact vocal@vovida.org.
161 *
162 * 4. Products derived from this software may not be called "VOCAL", nor
163 * may "VOCAL" appear in their name, without prior written
164 * permission of Vovida Networks, Inc.
165 *
166 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
167 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
168 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
169 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
170 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
171 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
172 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
173 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
174 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
175 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
176 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
177 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
178 * DAMAGE.
179 *
180 * ====================================================================
181 *
182 * This software consists of voluntary contributions made by Vovida
183 * Networks, Inc. and many individuals on behalf of Vovida Networks,
184 * Inc. For more information on Vovida Networks, Inc., please see
185 * <http://www.vovida.org/>.
186 *
187 */
bool empty() const
is the queue empty?
resip::TimeLimitFifo< resip::ApplicationMessage > mFifo
virtual bool post(std::unique_ptr< resip::ApplicationMessage > &work)
Posts a message to this thread bank.
std::vector< WorkerThread * > mWorkerThreads
void startAll()
Starts the thread bank.
int workPoolSize() const
void shutdownAll()
Shuts down the thread-bank.
void resume()
Resumes accepting work.
Dispatcher(std::unique_ptr< Worker > prototype, resip::SipStack *stack, int workers=2, bool startImmediately=true)
virtual ~Dispatcher()
Worker * mWorkerPrototype
time_t fifoTimeDepth() const
resip::RWMutex mMutex
void stop()
This Dispatcher will stop accepting new work, but processing will continue normally on the messages a...
resip::SipStack * mStack
size_t fifoCountDepth() const
This is the primary point of interaction between the app-layer and the stack.
Definition SipStack.hxx:160
virtual size_t getCountDepth() const
gets the depth of the FIFO
Msg * getNext()
Returns the first message available.
virtual time_t getTimeDepth() const
Return the time depth of the queue.
bool add(Msg *msg, DepthUsage usage)
Add a message to the fifo.
virtual Worker * clone() const =0
dcm! – add UnusedChecking(_enum) below;