|
reSIProcate/rutil
9694
|
00001 #if !defined(RESIP_FiniteFifo_hxx) 00002 #define RESIP_FiniteFifo_hxx 00003 00004 #include "rutil/AbstractFifo.hxx" 00005 00006 // efficiency note: use a circular buffer do avoid list node allocation 00007 00008 // what happens to timers that can't be queued? 00009 00010 namespace resip 00011 { 00012 00019 template < class Msg > 00020 class FiniteFifo : public AbstractFifo<Msg*> 00021 { 00022 public: 00023 FiniteFifo(unsigned int maxSize); 00024 virtual ~FiniteFifo(); 00025 00026 using AbstractFifo<Msg*>::mFifo; 00027 using AbstractFifo<Msg*>::mMutex; 00028 using AbstractFifo<Msg*>::mCondition; 00029 using AbstractFifo<Msg*>::empty; 00030 using AbstractFifo<Msg*>::size; 00031 00032 // Add a message to the fifo. 00033 // return true if succeed, false if full 00034 bool add(Msg* msg); 00035 00042 Msg* getNext(); 00043 00051 Msg* getNext(int ms); 00052 private: 00053 unsigned int mMaxSize; 00054 }; 00055 00056 template <class Msg> 00057 FiniteFifo<Msg>::FiniteFifo(unsigned int maxSize) 00058 : AbstractFifo<Msg*>(), 00059 mMaxSize(maxSize) 00060 { 00061 } 00062 00063 template <class Msg> 00064 FiniteFifo<Msg>::~FiniteFifo() 00065 { 00066 Lock lock(mMutex); (void)lock; 00067 while ( ! mFifo.empty() ) 00068 { 00069 delete mFifo.front(); 00070 mFifo.pop_front(); 00071 } 00072 } 00073 00074 template <class Msg> 00075 bool 00076 FiniteFifo<Msg>::add(Msg* msg) 00077 { 00078 Lock lock(mMutex); (void)lock; 00079 if (mFifo.size() >= mMaxSize) 00080 { 00081 return false; 00082 } 00083 else 00084 { 00085 mFifo.push_back(msg); 00086 mCondition.signal(); 00087 return true; 00088 } 00089 } 00090 00091 template <class Msg> 00092 Msg* 00093 FiniteFifo<Msg> ::getNext() 00094 { 00095 return AbstractFifo<Msg*>::getNext(); 00096 } 00097 00098 template <class Msg> 00099 Msg* 00100 FiniteFifo<Msg> ::getNext(int ms) 00101 { 00102 Msg* result(0); 00103 AbstractFifo<Msg*>::getNext(ms, result); 00104 return result; 00105 } 00106 00107 } // namespace resip 00108 00109 #endif 00110 00111 /* ==================================================================== 00112 * The Vovida Software License, Version 1.0 00113 * 00114 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00115 * 00116 * Redistribution and use in source and binary forms, with or without 00117 * modification, are permitted provided that the following conditions 00118 * are met: 00119 * 00120 * 1. Redistributions of source code must retain the above copyright 00121 * notice, this list of conditions and the following disclaimer. 00122 * 00123 * 2. Redistributions in binary form must reproduce the above copyright 00124 * notice, this list of conditions and the following disclaimer in 00125 * the documentation and/or other materials provided with the 00126 * distribution. 00127 * 00128 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00129 * and "Vovida Open Communication Application Library (VOCAL)" must 00130 * not be used to endorse or promote products derived from this 00131 * software without prior written permission. For written 00132 * permission, please contact vocal@vovida.org. 00133 * 00134 * 4. Products derived from this software may not be called "VOCAL", nor 00135 * may "VOCAL" appear in their name, without prior written 00136 * permission of Vovida Networks, Inc. 00137 * 00138 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00139 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00140 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00141 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00142 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00143 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00144 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00145 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00146 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00147 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00148 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00149 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00150 * DAMAGE. 00151 * 00152 * ==================================================================== 00153 * 00154 * This software consists of voluntary contributions made by Vovida 00155 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00156 * Inc. For more information on Vovida Networks, Inc., please see 00157 * <http://www.vovida.org/>. 00158 * 00159 */
1.7.5.1