- Main Page
- Modules
- Classes
- Files
- Examples

- File List
- File Members

# pool.h

Go to the documentation of this file.

    00001 // Copyright (C) 2001,2002,2006 Federico Montesino Pouzols <fedemp@altern.org>
    00002 //
    00003 // This program is free software; you can redistribute it and/or modify
    00004 // it under the terms of the GNU General Public License as published by
    00005 // the Free Software Foundation; either version 2 of the License, or
    00006 // (at your option) any later version.
    00007 //
    00008 // This program is distributed in the hope that it will be useful,
    00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00011 // GNU General Public License for more details.
    00012 //
    00013 // You should have received a copy of the GNU General Public License
    00014 // along with this program; if not, write to the Free Software
    00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    00016 //
    00017 // As a special exception, you may use this file as part of a free software
    00018 // library without restriction.  Specifically, if other files instantiate
    00019 // templates or use macros or inline functions from this file, or you compile
    00020 // this file and link it with other files to produce an executable, this
    00021 // file does not by itself cause the resulting executable to be covered by
    00022 // the GNU General Public License.  This exception does not however
    00023 // invalidate any other reasons why the executable file might be covered by
    00024 // the GNU General Public License.
    00025 //
    00026 // This exception applies only to the code released under the name GNU
    00027 // ccRTP.  If you copy code from other releases into a copy of GNU
    00028 // ccRTP, as the General Public License permits, the exception does
    00029 // not apply to the code that you add in this way.  To avoid misleading
    00030 // anyone as to the status of such modified files, you must delete
    00031 // this exception notice from them.
    00032 //
    00033 // If you write modifications of your own for GNU ccRTP, it is your choice
    00034 // whether to permit this exception to apply to your modifications.
    00035 // If you do not wish that, delete this exception notice.
    00036 //
    00037
    00043 #ifndef CCXX_RTP_POOL_H
    00044 #define CCXX_RTP_POOL_H
    00045
    00046 #include <list>
    00047 #include <ccrtp/rtp.h>
    00048
    00049 #ifdef  CCXX_NAMESPACES
    00050 namespace ost {
    00051 using std::list;
    00052 #endif
    00053
    00054 typedef TRTPSessionBase<> RTPSessionBase;
    00055
    00056 class RTPSessionBaseHandler
    00057 {
    00058 public:
    00059         inline microtimeout_t getSchedulingTimeout(RTPSessionBase& s)
    00060         { return s.getSchedulingTimeout(); }
    00061
    00062         inline timeval getRTCPCheckInterval(RTPSessionBase& s)
    00063         { return s.getRTCPCheckInterval(); }
    00064
    00065         size_t
    00066         takeInDataPacket(RTPSessionBase& s)
    00067         { return s.takeInDataPacket(); }
    00068
    00069         size_t
    00070         dispatchDataPacket(RTPSessionBase& s)
    00071         { return s.dispatchDataPacket(); }
    00072
    00073         void
    00074         controlReceptionService(RTPSessionBase& s)
    00075         { s.controlReceptionService(); }
    00076
    00077         void
    00078         controlTransmissionService(RTPSessionBase& s)
    00079         { s.controlTransmissionService(); }
    00080
    00081         inline SOCKET getDataRecvSocket(RTPSessionBase& s) const
    00082         { return s.getDataRecvSocket(); }
    00083
    00084         inline SOCKET getControlRecvSocket(RTPSessionBase& s) const
    00085         { return s.getControlRecvSocket(); }
    00086 };
    00087
    00095 class SessionListElement {
    00096 private:
    00097         RTPSessionBase* elem;
    00098         bool cleared;
    00099
    00100 public:
    00101         SessionListElement(RTPSessionBase* e);
    00102         void clear();
    00103         bool isCleared();
    00104         RTPSessionBase* get();
    00105 };
    00106
    00107
    00108 inline SessionListElement::SessionListElement(RTPSessionBase* e)
    00109         : elem(e), cleared(false) {
    00110 }
    00111
    00112 inline void SessionListElement::clear() {
    00113         cleared = true;
    00114         delete elem;
    00115         elem = 0;
    00116 }
    00117
    00118 inline bool SessionListElement::isCleared() {
    00119         return cleared;
    00120 }
    00121
    00122 inline RTPSessionBase* SessionListElement::get() {
    00123         return elem;
    00124 }
    00125
    00131 class PredEquals
    00132 {
    00133 protected:
    00134     RTPSessionBase* elem;
    00135 public:
    00136     PredEquals(RTPSessionBase* e) : elem(e) {}
    00137
    00138     bool operator() (SessionListElement* e)
    00139     {
    00140             return e->get() == elem;
    00141     }
    00142 };
    00143
    00157 class __EXPORT RTPSessionPool: public RTPSessionBaseHandler
    00158 {
    00159 public:
    00160         RTPSessionPool();
    00161
    00162         inline virtual ~RTPSessionPool()
    00163         { }
    00164
    00165         bool
    00166         addSession(RTPSessionBase& session);
    00167
    00168         bool
    00169         removeSession(RTPSessionBase& session);
    00170
    00171         size_t
    00172         getPoolLength() const;
    00173
    00174         virtual void startRunning() = 0;
    00175
    00176         inline bool isActive()
    00177         { return poolActive; }
    00178
    00179 protected:
    00180         inline void setActive()
    00181         { poolActive = true; }
    00182
    00183         inline timeval getPoolTimeout()
    00184         { return poolTimeout; }
    00185
    00186         inline void setPoolTimeout(int sec, int usec)
    00187         { poolTimeout.tv_sec = sec; poolTimeout.tv_usec = usec; }
    00188
    00189         inline void setPoolTimeout(struct timeval to)
    00190         { poolTimeout = to; }
    00191
    00192         std::list<SessionListElement*> sessionList;
    00193         typedef std::list<SessionListElement*>::iterator PoolIterator;
    00194
    00195         mutable ThreadLock poolLock;
    00196
    00197 #ifndef WIN32
    00198         fd_set recvSocketSet;
    00199         SOCKET highestSocket;  // highest socket number + 1
    00200 #endif
    00201
    00202 private:
    00203         timeval poolTimeout;
    00204         mutable bool poolActive;
    00205 };
    00206
    00207
    00208 class __EXPORT SingleRTPSessionPool :
    00209                 public RTPSessionPool,
    00210                 public Thread
    00211 {
    00212 public:
    00216         SingleRTPSessionPool(int pri = 0) :
    00217                 RTPSessionPool(),
    00218                 Thread(pri)
    00219         { }
    00220
    00221         ~SingleRTPSessionPool()
    00222         { }
    00223
    00224         void startRunning()
    00225         { setActive(); Thread::start(); }
    00226
    00227 protected:
    00232         void run();
    00233 };
    00234
    00235 #ifdef  CCXX_NAMESPACES
    00236 }
    00237 #endif
    00238
    00239 #endif //CCXX_RTP_POOL_H
    00240