ccRTP
|
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 NAMESPACE_COMMONCPP 00050 using std::list; 00051 00052 typedef TRTPSessionBase<> RTPSessionBase; 00053 00054 class RTPSessionBaseHandler 00055 { 00056 public: 00057 inline microtimeout_t getSchedulingTimeout(RTPSessionBase& s) 00058 { return s.getSchedulingTimeout(); } 00059 00060 inline timeval getRTCPCheckInterval(RTPSessionBase& s) 00061 { return s.getRTCPCheckInterval(); } 00062 00063 size_t 00064 takeInDataPacket(RTPSessionBase& s) 00065 { return s.takeInDataPacket(); } 00066 00067 size_t 00068 dispatchDataPacket(RTPSessionBase& s) 00069 { return s.dispatchDataPacket(); } 00070 00071 void 00072 controlReceptionService(RTPSessionBase& s) 00073 { s.controlReceptionService(); } 00074 00075 void 00076 controlTransmissionService(RTPSessionBase& s) 00077 { s.controlTransmissionService(); } 00078 00079 inline SOCKET getDataRecvSocket(RTPSessionBase& s) const 00080 { return s.getDataRecvSocket(); } 00081 00082 inline SOCKET getControlRecvSocket(RTPSessionBase& s) const 00083 { return s.getControlRecvSocket(); } 00084 }; 00085 00093 class SessionListElement { 00094 private: 00095 RTPSessionBase* elem; 00096 bool cleared; 00097 00098 public: 00099 SessionListElement(RTPSessionBase* e); 00100 void clear(); 00101 bool isCleared(); 00102 RTPSessionBase* get(); 00103 }; 00104 00105 00106 inline SessionListElement::SessionListElement(RTPSessionBase* e) 00107 : elem(e), cleared(false) { 00108 } 00109 00110 inline void SessionListElement::clear() { 00111 cleared = true; 00112 delete elem; 00113 elem = 0; 00114 } 00115 00116 inline bool SessionListElement::isCleared() { 00117 return cleared; 00118 } 00119 00120 inline RTPSessionBase* SessionListElement::get() { 00121 return elem; 00122 } 00123 00129 class PredEquals 00130 { 00131 protected: 00132 RTPSessionBase* elem; 00133 public: 00134 PredEquals(RTPSessionBase* e) : elem(e) {} 00135 00136 bool operator() (SessionListElement* e) 00137 { 00138 return e->get() == elem; 00139 } 00140 }; 00141 00155 class __EXPORT RTPSessionPool: public RTPSessionBaseHandler 00156 { 00157 public: 00158 RTPSessionPool(); 00159 00160 inline virtual ~RTPSessionPool() 00161 { } 00162 00163 bool 00164 addSession(RTPSessionBase& session); 00165 00166 bool 00167 removeSession(RTPSessionBase& session); 00168 00169 size_t 00170 getPoolLength() const; 00171 00172 virtual void startRunning() = 0; 00173 00174 inline bool isActive() 00175 { return poolActive; } 00176 00177 protected: 00178 inline void setActive() 00179 { poolActive = true; } 00180 00181 inline timeval getPoolTimeout() 00182 { return poolTimeout; } 00183 00184 inline void setPoolTimeout(int sec, int usec) 00185 { poolTimeout.tv_sec = sec; poolTimeout.tv_usec = usec; } 00186 00187 inline void setPoolTimeout(struct timeval to) 00188 { poolTimeout = to; } 00189 00190 std::list<SessionListElement*> sessionList; 00191 typedef std::list<SessionListElement*>::iterator PoolIterator; 00192 00193 mutable ThreadLock poolLock; 00194 00195 #ifndef _MSWINDOWS_ 00196 fd_set recvSocketSet; 00197 SOCKET highestSocket; // highest socket number + 1 00198 #endif 00199 00200 private: 00201 timeval poolTimeout; 00202 mutable bool poolActive; 00203 }; 00204 00205 00206 class __EXPORT SingleRTPSessionPool : 00207 public RTPSessionPool, 00208 public Thread 00209 { 00210 public: 00214 SingleRTPSessionPool(int pri = 0) : 00215 RTPSessionPool(), 00216 Thread(pri) 00217 { } 00218 00219 ~SingleRTPSessionPool() 00220 { } 00221 00222 void startRunning() 00223 { setActive(); Thread::start(); } 00224 00225 protected: 00230 void run(); 00231 }; 00232 00233 END_NAMESPACE 00234 00235 #endif //CCXX_RTP_POOL_H 00236