ccRTP 2.1.2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pool.h
Go to the documentation of this file.
1 // Copyright (C) 2001-2015 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 Lesser General Public License
14 // along with GNU ccRTP. If not, see <http://www.gnu.org/licenses/>.
15 //
16 // As a special exception, you may use this file as part of a free software
17 // library without restriction. Specifically, if other files instantiate
18 // templates or use macros or inline functions from this file, or you compile
19 // this file and link it with other files to produce an executable, this
20 // file does not by itself cause the resulting executable to be covered by
21 // the GNU General Public License. This exception does not however
22 // invalidate any other reasons why the executable file might be covered by
23 // the GNU General Public License.
24 //
25 // This exception applies only to the code released under the name GNU
26 // ccRTP. If you copy code from other releases into a copy of GNU
27 // ccRTP, as the General Public License permits, the exception does
28 // not apply to the code that you add in this way. To avoid misleading
29 // anyone as to the status of such modified files, you must delete
30 // this exception notice from them.
31 //
32 // If you write modifications of your own for GNU ccRTP, it is your choice
33 // whether to permit this exception to apply to your modifications.
34 // If you do not wish that, delete this exception notice.
35 //
36 
42 #ifndef CCXX_RTP_POOL_H
43 #define CCXX_RTP_POOL_H
44 
45 #include <list>
46 #include <ccrtp/rtp.h>
47 
48 NAMESPACE_COMMONCPP
49 using std::list;
50 
52 
54 {
55 public:
57  { return s.getSchedulingTimeout(); }
58 
60  { return s.getRTCPCheckInterval(); }
61 
62  size_t
64  { return s.takeInDataPacket(); }
65 
66  size_t
68  { return s.dispatchDataPacket(); }
69 
70  void
72  { s.controlReceptionService(); }
73 
74  void
76  { s.controlTransmissionService(); }
77 
78  inline SOCKET getDataRecvSocket(RTPSessionBase& s) const
79  { return s.getDataRecvSocket(); }
80 
81  inline SOCKET getControlRecvSocket(RTPSessionBase& s) const
82  { return s.getControlRecvSocket(); }
83 };
84 
93 private:
95  bool cleared;
96 
97 public:
99  void clear();
100  bool isCleared();
101  RTPSessionBase* get();
102 };
103 
104 
106  : elem(e), cleared(false) {
107 }
108 
110  cleared = true;
111  delete elem;
112  elem = 0;
113 }
114 
116  return cleared;
117 }
118 
120  return elem;
121 }
122 
129 {
130 protected:
132 public:
134 
136  {
137  return e->get() == elem;
138  }
139 };
140 
155 {
156 public:
157  RTPSessionPool();
158 
159  inline virtual ~RTPSessionPool()
160  { }
161 
162  bool
163  addSession(RTPSessionBase& session);
164 
165  bool
166  removeSession(RTPSessionBase& session);
167 
168  size_t
169  getPoolLength() const;
170 
171  virtual void startRunning() = 0;
172 
173  inline bool isActive()
174  { return poolActive; }
175 
176 protected:
177  inline void setActive()
178  { poolActive = true; }
179 
180  inline timeval getPoolTimeout()
181  { return poolTimeout; }
182 
183  inline void setPoolTimeout(int sec, int usec)
184  { poolTimeout.tv_sec = sec; poolTimeout.tv_usec = usec; }
185 
186  inline void setPoolTimeout(struct timeval to)
187  { poolTimeout = to; }
188 
189  std::list<SessionListElement*> sessionList;
190  typedef std::list<SessionListElement*>::iterator PoolIterator;
191 
192  mutable ThreadLock poolLock;
193 
194 #ifndef _MSWINDOWS_
196  SOCKET highestSocket; // highest socket number + 1
197 #endif
198 
199 private:
200  timeval poolTimeout;
201  mutable bool poolActive;
202 };
203 
204 
206  public RTPSessionPool,
207  public Thread
208 {
209 public:
213  SingleRTPSessionPool(int pri = 0) :
214  RTPSessionPool(),
215  Thread(pri)
216  { }
217 
219  { }
220 
222  { setActive(); Thread::start(); }
223 
224 protected:
229  void run();
230 };
231 
232 END_NAMESPACE
233 
234 #endif //CCXX_RTP_POOL_H
235 
std::list< SessionListElement * >::iterator PoolIterator
Definition: pool.h:190
std::list< SessionListElement * > sessionList
Definition: pool.h:189
size_t dispatchDataPacket(RTPSessionBase &s)
Definition: pool.h:67
void controlTransmissionService(RTPSessionBase &s)
Definition: pool.h:75
timeval poolTimeout
Definition: pool.h:200
void setPoolTimeout(struct timeval to)
Definition: pool.h:186
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition: base.h:67
Generic RTP protocol stack for exchange of realtime data.
SOCKET getControlRecvSocket(RTPSessionBase &s) const
Definition: pool.h:81
SOCKET getDataRecvSocket(RTPSessionBase &s) const
Definition: pool.h:78
bool cleared
Definition: pool.h:95
bool isCleared()
Definition: pool.h:115
void startRunning()
Definition: pool.h:221
size_t takeInDataPacket(RTPSessionBase &s)
Definition: pool.h:63
std equality for SessionListElement objects.
Definition: pool.h:128
SessionListElement(RTPSessionBase *e)
Definition: pool.h:105
void clear()
Definition: pool.h:109
SingleRTPSessionPool(int pri=0)
Definition: pool.h:213
SOCKET highestSocket
Definition: pool.h:196
fd_set recvSocketSet
Definition: pool.h:195
virtual ~RTPSessionPool()
Definition: pool.h:159
timeval getRTCPCheckInterval(RTPSessionBase &s)
Definition: pool.h:59
Class for tracking session status.
Definition: pool.h:92
bool poolActive
Definition: pool.h:201
#define __EXPORT
Definition: ZrtpCallback.h:40
bool operator()(SessionListElement *e)
Definition: pool.h:135
void setActive()
Definition: pool.h:177
bool isActive()
Definition: pool.h:173
RTPSessionBase * elem
Definition: pool.h:131
microtimeout_t getSchedulingTimeout(RTPSessionBase &s)
Definition: pool.h:56
void controlReceptionService(RTPSessionBase &s)
Definition: pool.h:71
ThreadLock poolLock
Definition: pool.h:192
PredEquals(RTPSessionBase *e)
Definition: pool.h:133
timeval getPoolTimeout()
Definition: pool.h:180
This class is a base class for classes that define a group of RTP sessions that will be served by one...
Definition: pool.h:154
TRTPSessionBase RTPSessionBase
Definition: pool.h:51
RTPSessionBase * get()
Definition: pool.h:119
Generic and audio/video profile specific RTP interface of ccRTP.
RTPSessionBase * elem
Definition: pool.h:94
void setPoolTimeout(int sec, int usec)
Definition: pool.h:183