Bayonne2 / Common C++ 2 Framework
 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,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:
60  { return s.getSchedulingTimeout(); }
61 
63  { return s.getRTCPCheckInterval(); }
64 
65  size_t
67  { return s.takeInDataPacket(); }
68 
69  size_t
71  { return s.dispatchDataPacket(); }
72 
73  void
75  { s.controlReceptionService(); }
76 
77  void
79  { s.controlTransmissionService(); }
80 
82  { return s.getDataRecvSocket(); }
83 
85  { return s.getControlRecvSocket(); }
86 };
87 
96 private:
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 
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 
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 
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 
std::list< SessionListElement * >::iterator PoolIterator
Definition: pool.h:193
std::list< SessionListElement * > sessionList
Definition: pool.h:192
size_t dispatchDataPacket(RTPSessionBase &s)
Definition: pool.h:70
void controlTransmissionService(RTPSessionBase &s)
Definition: pool.h:78
timeval poolTimeout
Definition: pool.h:203
void setPoolTimeout(struct timeval to)
Definition: pool.h:189
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition: base.h:69
Generic RTP protocol stack for exchange of realtime data.
SOCKET getControlRecvSocket(RTPSessionBase &s) const
Definition: pool.h:84
SOCKET getDataRecvSocket(RTPSessionBase &s) const
Definition: pool.h:81
int start(Semaphore *start=0)
When a new thread is created, it does not begin immediate execution.
bool cleared
Definition: pool.h:98
bool isCleared()
Definition: pool.h:118
void startRunning()
Definition: pool.h:224
size_t takeInDataPacket(RTPSessionBase &s)
Definition: pool.h:66
std equality for SessionListElement objects.
Definition: pool.h:131
SessionListElement(RTPSessionBase *e)
Definition: pool.h:108
void clear()
Definition: pool.h:112
SingleRTPSessionPool(int pri=0)
Definition: pool.h:216
SOCKET highestSocket
Definition: pool.h:199
fd_set recvSocketSet
Definition: pool.h:198
virtual ~RTPSessionPool()
Definition: pool.h:162
timeval getRTCPCheckInterval(RTPSessionBase &s)
Definition: pool.h:62
Class for tracking session status.
Definition: pool.h:95
bool poolActive
Definition: pool.h:204
bool operator()(SessionListElement *e)
Definition: pool.h:138
The ThreadLock class impliments a thread rwlock for optimal reader performance on systems which have ...
Definition: thread.h:357
void setActive()
Definition: pool.h:180
bool isActive()
Definition: pool.h:176
RTPSessionBase * elem
Definition: pool.h:134
microtimeout_t getSchedulingTimeout(RTPSessionBase &s)
Definition: pool.h:59
void controlReceptionService(RTPSessionBase &s)
Definition: pool.h:74
#define __EXPORT
Definition: audio2.h:51
ThreadLock poolLock
Definition: pool.h:195
PredEquals(RTPSessionBase *e)
Definition: pool.h:136
Every thread of execution in an application is created by instantiating an object of a class derived ...
Definition: thread.h:1093
int SOCKET
Definition: socket.h:60
timeval getPoolTimeout()
Definition: pool.h:183
This class is a base class for classes that define a group of RTP sessions that will be served by one...
Definition: pool.h:157
virtual void run(void)=0
All threads execute by deriving the Run method of Thread.
TRTPSessionBase RTPSessionBase
Definition: pool.h:54
RTPSessionBase * get()
Definition: pool.h:122
Generic and audio/video profile specific RTP interface of ccRTP.
RTPSessionBase * elem
Definition: pool.h:97
void setPoolTimeout(int sec, int usec)
Definition: pool.h:186