Bayonne2 / Common C++ 2 Framework: pool.h Source File

Bayonne2 / Common C++ 2 Framework
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 
54  typedef TRTPSessionBase<> RTPSessionBase;
55 
56  class RTPSessionBaseHandler
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 
95  class SessionListElement {
96 private:
97   RTPSessionBase* elem;
98   bool cleared;
99 
100 public:
101  SessionListElement(RTPSessionBase* e);
102  void clear();
103  bool isCleared();
104  RTPSessionBase* get();
105 };
106 
107 
108  inline SessionListElement::SessionListElement(RTPSessionBase* e)
109  : elem(e), cleared(false) {
110 }
111 
112  inline void SessionListElement::clear() {
113  cleared = true;
114  delete elem;
115  elem = 0;
116 }
117 
118  inline bool SessionListElement::isCleared() {
119  return cleared;
120 }
121 
122  inline RTPSessionBase* SessionListElement::get() {
123  return elem;
124 }
125 
131  class PredEquals
132 {
133 protected:
134   RTPSessionBase* elem;
135 public:
136   PredEquals(RTPSessionBase* e) : elem(e) {}
137 
138   bool operator() (SessionListElement* e)
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
198   fd_set recvSocketSet;
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 
221   ~SingleRTPSessionPool()
222  { }
223 
224   void startRunning()
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 
RTPSessionPool::PoolIterator
std::list< SessionListElement * >::iterator PoolIterator
Definition: pool.h:193
RTPSessionPool::sessionList
std::list< SessionListElement * > sessionList
Definition: pool.h:192
RTPSessionBaseHandler::dispatchDataPacket
size_t dispatchDataPacket(RTPSessionBase &s)
Definition: pool.h:70
RTPSessionBaseHandler::controlTransmissionService
void controlTransmissionService(RTPSessionBase &s)
Definition: pool.h:78
RTPSessionPool::poolTimeout
timeval poolTimeout
Definition: pool.h:203
RTPSessionPool::setPoolTimeout
void setPoolTimeout(struct timeval to)
Definition: pool.h:189
microtimeout_t
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition: base.h:69
RTPSessionBase
Generic RTP protocol stack for exchange of realtime data.
RTPSessionBaseHandler::getControlRecvSocket
SOCKET getControlRecvSocket(RTPSessionBase &s) const
Definition: pool.h:84
RTPSessionBaseHandler::getDataRecvSocket
SOCKET getDataRecvSocket(RTPSessionBase &s) const
Definition: pool.h:81
Thread::start
int start(Semaphore *start=0)
When a new thread is created, it does not begin immediate execution.
SessionListElement::cleared
bool cleared
Definition: pool.h:98
SessionListElement::isCleared
bool isCleared()
Definition: pool.h:118
SingleRTPSessionPool::startRunning
void startRunning()
Definition: pool.h:224
RTPSessionBaseHandler::takeInDataPacket
size_t takeInDataPacket(RTPSessionBase &s)
Definition: pool.h:66
PredEquals
std equality for SessionListElement objects.
Definition: pool.h:131
SessionListElement::SessionListElement
SessionListElement(RTPSessionBase *e)
Definition: pool.h:108
SessionListElement::clear
void clear()
Definition: pool.h:112
SingleRTPSessionPool::SingleRTPSessionPool
SingleRTPSessionPool(int pri=0)
Definition: pool.h:216
RTPSessionPool::highestSocket
SOCKET highestSocket
Definition: pool.h:199
RTPSessionPool::recvSocketSet
fd_set recvSocketSet
Definition: pool.h:198
RTPSessionPool::~RTPSessionPool
virtual ~RTPSessionPool()
Definition: pool.h:162
RTPSessionBaseHandler::getRTCPCheckInterval
timeval getRTCPCheckInterval(RTPSessionBase &s)
Definition: pool.h:62
SessionListElement
Class for tracking session status.
Definition: pool.h:95
RTPSessionPool::poolActive
bool poolActive
Definition: pool.h:204
PredEquals::operator()
bool operator()(SessionListElement *e)
Definition: pool.h:138
ThreadLock
The ThreadLock class impliments a thread rwlock for optimal reader performance on systems which have ...
Definition: thread.h:357
RTPSessionPool::setActive
void setActive()
Definition: pool.h:180
RTPSessionPool::isActive
bool isActive()
Definition: pool.h:176
PredEquals::elem
RTPSessionBase * elem
Definition: pool.h:134
RTPSessionBaseHandler::getSchedulingTimeout
microtimeout_t getSchedulingTimeout(RTPSessionBase &s)
Definition: pool.h:59
RTPSessionBaseHandler::controlReceptionService
void controlReceptionService(RTPSessionBase &s)
Definition: pool.h:74
__EXPORT
#define __EXPORT
Definition: audio2.h:51
RTPSessionPool::poolLock
ThreadLock poolLock
Definition: pool.h:195
PredEquals::PredEquals
PredEquals(RTPSessionBase *e)
Definition: pool.h:136
SingleRTPSessionPool::~SingleRTPSessionPool
~SingleRTPSessionPool()
Definition: pool.h:221
Thread
Every thread of execution in an application is created by instantiating an object of a class derived ...
Definition: thread.h:1093
SOCKET
int SOCKET
Definition: socket.h:60
RTPSessionPool::getPoolTimeout
timeval getPoolTimeout()
Definition: pool.h:183
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:157
Thread::run
virtual void run(void)=0
All threads execute by deriving the Run method of Thread.
RTPSessionBase
TRTPSessionBase RTPSessionBase
Definition: pool.h:54
SessionListElement::get
RTPSessionBase * get()
Definition: pool.h:122
rtp.h
Generic and audio/video profile specific RTP interface of ccRTP.
SessionListElement::elem
RTPSessionBase * elem
Definition: pool.h:97
RTPSessionPool::setPoolTimeout
void setPoolTimeout(int sec, int usec)
Definition: pool.h:186

Generated on Dec 21, 2017 for commoncpp2-1.8.1, ccrtp-1.7.2, libzrtpcpp-2.3.4, ccscript3-1.1.7, ccaudio2-1.0.0 and bayonne2-2.3.2 (after installation in /usr/local/) by   doxygen 1.8.6

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