reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
ConsumerFifoBuffer.hxx
Go to the documentation of this file.
1#ifndef ConsumerFifoBuffer_Include_Guard
2#define ConsumerFifoBuffer_Include_Guard
3
4#include "rutil/Fifo.hxx"
5
6namespace resip
7{
8template<typename T>
10{
11 public:
13 unsigned int bufferSize=8) :
14 mFifo(fifo),
15 mBufferSize(bufferSize)
16 {}
17
20
21 T* getNext(int ms=0)
22 {
23 if(mBuffer.empty())
24 {
25 mFifo.getMultiple(ms, mBuffer, mBufferSize);
26 }
27
28 if(mBuffer.empty())
29 {
30 return 0;
31 }
32
33 T* next(mBuffer.front());
34 mBuffer.pop_front();
35 return next;
36 }
37
38 bool messageAvailable() const
39 {
40 if(mBuffer.empty())
41 {
42 return mFifo.messageAvailable();
43 }
44 return true;
45 }
46
47 unsigned int size() const
48 {
49 return mBuffer.size() + mFifo.size();
50 }
51
52 private:
53 Fifo<T>& mFifo;
54 typename Fifo<T>::Messages mBuffer;
55 unsigned int mBufferSize;
56};
57}
58
59#endif
60
61
62/* ====================================================================
63 * The Vovida Software License, Version 1.0
64 *
65 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions
67 * are met:
68 *
69 * 1. Redistributions of source code must retain the above copyright
70 * notice, this list of conditions and the following disclaimer.
71 *
72 * 2. Redistributions in binary form must reproduce the above copyright
73 * notice, this list of conditions and the following disclaimer in
74 * the documentation and/or other materials provided with the
75 * distribution.
76 *
77 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
78 * and "Vovida Open Communication Application Library (VOCAL)" must
79 * not be used to endorse or promote products derived from this
80 * software without prior written permission. For written
81 * permission, please contact vocal@vovida.org.
82 *
83 * 4. Products derived from this software may not be called "VOCAL", nor
84 * may "VOCAL" appear in their name, without prior written
85 * permission of Vovida Networks, Inc.
86 *
87 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
88 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
89 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
90 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
91 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
92 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
93 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
94 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
95 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
96 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
97 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
98 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
99 * DAMAGE.
100 *
101 * ====================================================================
102 *
103 * This software consists of voluntary contributions made by Vovida
104 * Networks, Inc. and many individuals on behalf of Vovida Networks,
105 * Inc. For more information on Vovida Networks, Inc., please see
106 * <http://www.vovida.org/>.
107 *
108 */
virtual unsigned int size() const
get the current size of the fifo.
bool messageAvailable() const
is a message available?
bool empty() const
is the queue empty?
ConsumerFifoBuffer(Fifo< T > &fifo, unsigned int bufferSize=8)
A templated, threadsafe message-queue class.
Definition Fifo.hxx:16
AbstractFifo< Msg * >::Messages Messages
Definition Fifo.hxx:30
void getMultiple(Messages &other, unsigned int max)
Definition Fifo.hxx:145
dcm! – add UnusedChecking(_enum) below;