ccRTP 2.1.2: pool.h Source File

ccRTP 2.1.2
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 
51  typedef TRTPSessionBase<> RTPSessionBase;
52 
53  class RTPSessionBaseHandler
54 {
55 public:
56   inline microtimeout_t getSchedulingTimeout(RTPSessionBase& s)
57  { return s.getSchedulingTimeout(); }
58 
59   inline timeval getRTCPCheckInterval(RTPSessionBase& s)
60  { return s.getRTCPCheckInterval(); }
61 
62  size_t
63   takeInDataPacket(RTPSessionBase& s)
64  { return s.takeInDataPacket(); }
65 
66  size_t
67   dispatchDataPacket(RTPSessionBase& s)
68  { return s.dispatchDataPacket(); }
69 
70  void
71   controlReceptionService(RTPSessionBase& s)
72  { s.controlReceptionService(); }
73 
74  void
75   controlTransmissionService(RTPSessionBase& s)
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 
92  class SessionListElement {
93 private:
94   RTPSessionBase* elem;
95   bool cleared;
96 
97 public:
98  SessionListElement(RTPSessionBase* e);
99  void clear();
100  bool isCleared();
101  RTPSessionBase* get();
102 };
103 
104 
105  inline SessionListElement::SessionListElement(RTPSessionBase* e)
106  : elem(e), cleared(false) {
107 }
108 
109  inline void SessionListElement::clear() {
110  cleared = true;
111  delete elem;
112  elem = 0;
113 }
114 
115  inline bool SessionListElement::isCleared() {
116  return cleared;
117 }
118 
119  inline RTPSessionBase* SessionListElement::get() {
120  return elem;
121 }
122 
128  class PredEquals
129 {
130 protected:
131   RTPSessionBase* elem;
132 public:
133   PredEquals(RTPSessionBase* e) : elem(e) {}
134 
135   bool operator() (SessionListElement* e)
136  {
137  return e->get() == elem;
138  }
139 };
140 
154  class __EXPORT RTPSessionPool: public RTPSessionBaseHandler
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_
195   fd_set recvSocketSet;
196   SOCKET highestSocket; // highest socket number + 1
197 #endif
198 
199 private:
200   timeval poolTimeout;
201   mutable bool poolActive;
202 };
203 
204 
205  class __EXPORT SingleRTPSessionPool :
206  public RTPSessionPool,
207  public Thread
208 {
209 public:
213   SingleRTPSessionPool(int pri = 0) :
214  RTPSessionPool(),
215  Thread(pri)
216  { }
217 
218   ~SingleRTPSessionPool()
219  { }
220 
221   void startRunning()
222  { setActive(); Thread::start(); }
223 
224 protected:
229  void run();
230 };
231 
232 END_NAMESPACE
233 
234 #endif //CCXX_RTP_POOL_H
235 
RTPSessionPool::PoolIterator
std::list< SessionListElement * >::iterator PoolIterator
Definition: pool.h:190
RTPSessionPool::sessionList
std::list< SessionListElement * > sessionList
Definition: pool.h:189
RTPSessionBaseHandler::dispatchDataPacket
size_t dispatchDataPacket(RTPSessionBase &s)
Definition: pool.h:67
RTPSessionBaseHandler::controlTransmissionService
void controlTransmissionService(RTPSessionBase &s)
Definition: pool.h:75
RTPSessionPool::poolTimeout
timeval poolTimeout
Definition: pool.h:200
RTPSessionPool::setPoolTimeout
void setPoolTimeout(struct timeval to)
Definition: pool.h:186
microtimeout_t
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition: base.h:67
RTPSessionBase
Generic RTP protocol stack for exchange of realtime data.
RTPSessionBaseHandler::getControlRecvSocket
SOCKET getControlRecvSocket(RTPSessionBase &s) const
Definition: pool.h:81
RTPSessionBaseHandler::getDataRecvSocket
SOCKET getDataRecvSocket(RTPSessionBase &s) const
Definition: pool.h:78
SessionListElement::cleared
bool cleared
Definition: pool.h:95
SessionListElement::isCleared
bool isCleared()
Definition: pool.h:115
SingleRTPSessionPool::startRunning
void startRunning()
Definition: pool.h:221
RTPSessionBaseHandler::takeInDataPacket
size_t takeInDataPacket(RTPSessionBase &s)
Definition: pool.h:63
PredEquals
std equality for SessionListElement objects.
Definition: pool.h:128
SessionListElement::SessionListElement
SessionListElement(RTPSessionBase *e)
Definition: pool.h:105
SessionListElement::clear
void clear()
Definition: pool.h:109
SingleRTPSessionPool::SingleRTPSessionPool
SingleRTPSessionPool(int pri=0)
Definition: pool.h:213
RTPSessionPool::highestSocket
SOCKET highestSocket
Definition: pool.h:196
RTPSessionPool::recvSocketSet
fd_set recvSocketSet
Definition: pool.h:195
RTPSessionPool::~RTPSessionPool
virtual ~RTPSessionPool()
Definition: pool.h:159
RTPSessionBaseHandler::getRTCPCheckInterval
timeval getRTCPCheckInterval(RTPSessionBase &s)
Definition: pool.h:59
SessionListElement
Class for tracking session status.
Definition: pool.h:92
RTPSessionPool::poolActive
bool poolActive
Definition: pool.h:201
__EXPORT
#define __EXPORT
Definition: ZrtpCallback.h:40
PredEquals::operator()
bool operator()(SessionListElement *e)
Definition: pool.h:135
RTPSessionPool::setActive
void setActive()
Definition: pool.h:177
RTPSessionPool::isActive
bool isActive()
Definition: pool.h:173
PredEquals::elem
RTPSessionBase * elem
Definition: pool.h:131
RTPSessionBaseHandler::getSchedulingTimeout
microtimeout_t getSchedulingTimeout(RTPSessionBase &s)
Definition: pool.h:56
RTPSessionBaseHandler::controlReceptionService
void controlReceptionService(RTPSessionBase &s)
Definition: pool.h:71
RTPSessionPool::poolLock
ThreadLock poolLock
Definition: pool.h:192
PredEquals::PredEquals
PredEquals(RTPSessionBase *e)
Definition: pool.h:133
SingleRTPSessionPool::~SingleRTPSessionPool
~SingleRTPSessionPool()
Definition: pool.h:218
RTPSessionPool::getPoolTimeout
timeval getPoolTimeout()
Definition: pool.h:180
RTPSessionPool
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
RTPSessionBase
TRTPSessionBase RTPSessionBase
Definition: pool.h:51
SessionListElement::get
RTPSessionBase * get()
Definition: pool.h:119
rtp.h
Generic and audio/video profile specific RTP interface of ccRTP.
SessionListElement::elem
RTPSessionBase * elem
Definition: pool.h:94
RTPSessionPool::setPoolTimeout
void setPoolTimeout(int sec, int usec)
Definition: pool.h:183

Generated on Dec 15, 2017 for ccrtp-2.1.2 (*.h and *.cpp) and libzrtpcpp-2.3.4 (*.h), by   doxygen 1.8.6

AltStyle によって変換されたページ (->オリジナル) /