reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
Fifo.hxx
Go to the documentation of this file.
1#if !defined(RESIP_FIFO_HXX)
2#define RESIP_FIFO_HXX
3
4#include "rutil/ResipAssert.h"
7
8namespace resip
9{
10
14template < class Msg >
15class Fifo : public AbstractFifo<Msg*>
16{
17 public:
18 Fifo(AsyncProcessHandler* interruptor=0);
19 virtual ~Fifo();
20
21 using AbstractFifo<Msg*>::mFifo;
22 using AbstractFifo<Msg*>::mMutex;
23 using AbstractFifo<Msg*>::mCondition;
24 using AbstractFifo<Msg*>::empty;
25 using AbstractFifo<Msg*>::size;
26
28 size_t add(Msg* msg);
29
31 size_t addMultiple(Messages& msgs);
32
39 Msg* getNext();
40
41
49 Msg* getNext(int ms);
50
51 void getMultiple(Messages& other, unsigned int max);
52 bool getMultiple(int ms, Messages& other, unsigned int max);
53
55 virtual void clear();
57
58 private:
59 AsyncProcessHandler* mInterruptor;
60 Fifo(const Fifo& rhs);
61 Fifo& operator=(const Fifo& rhs);
62};
63
64
65template <class Msg>
67 AbstractFifo<Msg*>(),
68 mInterruptor(interruptor)
69{
70}
71
72template <class Msg>
74{
75 clear();
76}
77
78template <class Msg>
79void
81{
82 Lock lock(mMutex); (void)lock;
83 mInterruptor=interruptor;
84}
85
86
87template <class Msg>
88void
90{
91 Lock lock(mMutex); (void)lock;
92 while ( ! mFifo.empty() )
93 {
94 delete mFifo.front();
95 mFifo.pop_front();
96 }
97 resip_assert(mFifo.empty());
98}
99
100template <class Msg>
101size_t
103{
104 size_t size = AbstractFifo<Msg*>::add(msg);
105 if(size==1 && mInterruptor)
106 {
107 // Only do this when the queue goes from empty to not empty.
108 mInterruptor->handleProcessNotification();
109 }
110 return size;
111}
112
113template <class Msg>
114size_t
116{
117 size_t inSize = msgs.size();
118 size_t size = AbstractFifo<Msg*>::addMultiple(msgs);
119 if(size==inSize && inSize != 0 && mInterruptor)
120 {
121 // Only do this when the queue goes from empty to not empty.
122 mInterruptor->handleProcessNotification();
123 }
124 return size;
125}
126
127template <class Msg>
128Msg*
133
134template <class Msg>
135Msg*
137{
138 Msg* result(0);
139 AbstractFifo<Msg*>::getNext(ms, result);
140 return result;
141}
142
143template <class Msg>
144void
146{
148}
149
150template <class Msg>
151bool
152Fifo<Msg>::getMultiple(int ms, Messages& other, unsigned int max)
153{
154 return AbstractFifo<Msg*>::getMultiple(ms, other, max);
155}
156} // namespace resip
157
158#endif
159
160/* ====================================================================
161 * The Vovida Software License, Version 1.0
162 *
163 * Redistribution and use in source and binary forms, with or without
164 * modification, are permitted provided that the following conditions
165 * are met:
166 *
167 * 1. Redistributions of source code must retain the above copyright
168 * notice, this list of conditions and the following disclaimer.
169 *
170 * 2. Redistributions in binary form must reproduce the above copyright
171 * notice, this list of conditions and the following disclaimer in
172 * the documentation and/or other materials provided with the
173 * distribution.
174 *
175 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
176 * and "Vovida Open Communication Application Library (VOCAL)" must
177 * not be used to endorse or promote products derived from this
178 * software without prior written permission. For written
179 * permission, please contact vocal@vovida.org.
180 *
181 * 4. Products derived from this software may not be called "VOCAL", nor
182 * may "VOCAL" appear in their name, without prior written
183 * permission of Vovida Networks, Inc.
184 *
185 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
186 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
187 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
188 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
189 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
190 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
191 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
192 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
193 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
194 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
195 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
196 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
197 * DAMAGE.
198 *
199 * ====================================================================
200 *
201 * This software consists of voluntary contributions made by Vovida
202 * Networks, Inc. and many individuals on behalf of Vovida Networks,
203 * Inc. For more information on Vovida Networks, Inc., please see
204 * <http://www.vovida.org/>.
205 *
206 */
#define max(x, y)
#define resip_assert(x)
This file needs to work for both C and C++ code.
The base class from which various templated Fifo classes are derived.
virtual unsigned int size() const
get the current size of the fifo.
Condition mCondition
condition for waiting on new queue items
T getNext()
Returns the first message available.
std::deque< T > Messages
bool empty() const
is the queue empty?
size_t add(const T &item)
size_t addMultiple(Messages &items)
Messages mFifo
container for FIFO items
void getMultiple(Messages &other, unsigned int max)
Mutex mMutex
access serialization lock
A templated, threadsafe message-queue class.
Definition Fifo.hxx:16
bool getMultiple(int ms, Messages &other, unsigned int max)
Definition Fifo.hxx:152
virtual ~Fifo()
Definition Fifo.hxx:73
virtual void clear()
delete all elements in the queue
Definition Fifo.hxx:89
AbstractFifo< Msg * >::Messages Messages
Definition Fifo.hxx:30
void setInterruptor(AsyncProcessHandler *interruptor)
Definition Fifo.hxx:80
Fifo(AsyncProcessHandler *interruptor=0)
Definition Fifo.hxx:66
Msg * getNext()
Returns the first message available.
Definition Fifo.hxx:129
size_t addMultiple(Messages &msgs)
Definition Fifo.hxx:115
void getMultiple(Messages &other, unsigned int max)
Definition Fifo.hxx:145
Msg * getNext(int ms)
Returns the next message available.
Definition Fifo.hxx:136
size_t add(Msg *msg)
Add a message to the fifo.
Definition Fifo.hxx:102
dcm! – add UnusedChecking(_enum) below;
std::unique_lock< Mutex > Lock
A convenience class to lock a Lockable (such as a Mutex) on object creation, and unlock on destructio...
Definition Lock.hxx:28