ccRTP
pool.h
Go to the documentation of this file.
1 // Copyright (C) 2001,2002,2006 Federico Montesino Pouzols <fedemp@altern.org>
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 // As a special exception, you may use this file as part of a free software
18 // library without restriction. Specifically, if other files instantiate
19 // templates or use macros or inline functions from this file, or you compile
20 // this file and link it with other files to produce an executable, this
21 // file does not by itself cause the resulting executable to be covered by
22 // the GNU General Public License. This exception does not however
23 // invalidate any other reasons why the executable file might be covered by
24 // the GNU General Public License.
25 //
26 // This exception applies only to the code released under the name GNU
27 // ccRTP. If you copy code from other releases into a copy of GNU
28 // ccRTP, as the General Public License permits, the exception does
29 // not apply to the code that you add in this way. To avoid misleading
30 // anyone as to the status of such modified files, you must delete
31 // this exception notice from them.
32 //
33 // If you write modifications of your own for GNU ccRTP, it is your choice
34 // whether to permit this exception to apply to your modifications.
35 // If you do not wish that, delete this exception notice.
36 //
37 
43 #ifndef CCXX_RTP_POOL_H
44 #define CCXX_RTP_POOL_H
45 
46 #include <list>
47 #include <ccrtp/rtp.h>
48 
49 #ifdef CCXX_NAMESPACES
50 namespace ost {
51 using std::list;
52 #endif
53 
55 
57 {
58 public:
59  inline microtimeout_t getSchedulingTimeout(RTPSessionBase& s)
60  { return s.getSchedulingTimeout(); }
61 
62  inline timeval getRTCPCheckInterval(RTPSessionBase& s)
63  { return s.getRTCPCheckInterval(); }
64 
65  size_t
66  takeInDataPacket(RTPSessionBase& s)
67  { return s.takeInDataPacket(); }
68 
69  size_t
70  dispatchDataPacket(RTPSessionBase& s)
71  { return s.dispatchDataPacket(); }
72 
73  void
74  controlReceptionService(RTPSessionBase& s)
75  { s.controlReceptionService(); }
76 
77  void
78  controlTransmissionService(RTPSessionBase& s)
79  { s.controlTransmissionService(); }
80 
81  inline SOCKET getDataRecvSocket(RTPSessionBase& s) const
82  { return s.getDataRecvSocket(); }
83 
84  inline SOCKET getControlRecvSocket(RTPSessionBase& s) const
85  { return s.getControlRecvSocket(); }
86 };
87 
96 private:
97  RTPSessionBase* elem;
98  bool cleared;
99 
100 public:
102  void clear();
103  bool isCleared();
104  RTPSessionBase* get();
105 };
106 
107 
109  : elem(e), cleared(false) {
110 }
111 
113  cleared = true;
114  delete elem;
115  elem = 0;
116 }
117 
119  return cleared;
120 }
121 
123  return elem;
124 }
125 
132 {
133 protected:
135 public:
137 
139  {
140  return e->get() == elem;
141  }
142 };
143 
157 class __EXPORT RTPSessionPool: public RTPSessionBaseHandler
158 {
159 public:
160  RTPSessionPool();
161 
162  inline virtual ~RTPSessionPool()
163  { }
164 
165  bool
166  addSession(RTPSessionBase& session);
167 
168  bool
169  removeSession(RTPSessionBase& session);
170 
171  size_t
172  getPoolLength() const;
173 
174  virtual void startRunning() = 0;
175 
176  inline bool isActive()
177  { return poolActive; }
178 
179 protected:
180  inline void setActive()
181  { poolActive = true; }
182 
183  inline timeval getPoolTimeout()
184  { return poolTimeout; }
185 
186  inline void setPoolTimeout(int sec, int usec)
187  { poolTimeout.tv_sec = sec; poolTimeout.tv_usec = usec; }
188 
189  inline void setPoolTimeout(struct timeval to)
190  { poolTimeout = to; }
191 
192  std::list<SessionListElement*> sessionList;
193  typedef std::list<SessionListElement*>::iterator PoolIterator;
194 
195  mutable ThreadLock poolLock;
196 
197 #ifndef WIN32
199  SOCKET highestSocket; // highest socket number + 1
200 #endif
201 
202 private:
203  timeval poolTimeout;
204  mutable bool poolActive;
205 };
206 
207 
208 class __EXPORT SingleRTPSessionPool :
209  public RTPSessionPool,
210  public Thread
211 {
212 public:
216  SingleRTPSessionPool(int pri = 0) :
217  RTPSessionPool(),
218  Thread(pri)
219  { }
220 
222  { }
223 
225  { setActive(); Thread::start(); }
226 
227 protected:
232  void run();
233 };
234 
235 #ifdef CCXX_NAMESPACES
236 }
237 #endif
238 
239 #endif //CCXX_RTP_POOL_H
240