pool.h
Go to the documentation of this file.
// Copyright (C) 2001,2002,2006 Federico Montesino Pouzols <fedemp@altern.org>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
//
// This exception applies only to the code released under the name GNU
// ccRTP. If you copy code from other releases into a copy of GNU
// ccRTP, as the General Public License permits, the exception does
// not apply to the code that you add in this way. To avoid misleading
// anyone as to the status of such modified files, you must delete
// this exception notice from them.
//
// If you write modifications of your own for GNU ccRTP, it is your choice
// whether to permit this exception to apply to your modifications.
// If you do not wish that, delete this exception notice.
//
#ifndef CCXX_RTP_POOL_H
#define CCXX_RTP_POOL_H
#include <list>
#include <ccrtp/rtp.h>
NAMESPACE_COMMONCPP
using std::list;
typedef TRTPSessionBase<> RTPSessionBase;
class RTPSessionBaseHandler
{
public:
inline microtimeout_t getSchedulingTimeout(RTPSessionBase& s)
{ return s.getSchedulingTimeout(); }
inline timeval getRTCPCheckInterval(RTPSessionBase& s)
{ return s.getRTCPCheckInterval(); }
size_t
takeInDataPacket(RTPSessionBase& s)
{ return s.takeInDataPacket(); }
size_t
dispatchDataPacket(RTPSessionBase& s)
{ return s.dispatchDataPacket(); }
void
controlReceptionService(RTPSessionBase& s)
{ s.controlReceptionService(); }
void
controlTransmissionService(RTPSessionBase& s)
{ s.controlTransmissionService(); }
inline SOCKET getDataRecvSocket(RTPSessionBase& s) const
{ return s.getDataRecvSocket(); }
inline SOCKET getControlRecvSocket(RTPSessionBase& s) const
{ return s.getControlRecvSocket(); }
};
class SessionListElement {
private:
RTPSessionBase* elem;
bool cleared;
public:
SessionListElement(RTPSessionBase* e);
void clear();
bool isCleared();
RTPSessionBase* get();
};
inline SessionListElement::SessionListElement(RTPSessionBase* e)
: elem(e), cleared(false) {
}
inline void SessionListElement::clear() {
cleared = true;
delete elem;
elem = 0;
}
inline bool SessionListElement::isCleared() {
return cleared;
}
inline RTPSessionBase* SessionListElement::get() {
return elem;
}
class PredEquals
{
protected:
RTPSessionBase* elem;
public:
PredEquals(RTPSessionBase* e) : elem(e) {}
bool operator() (SessionListElement* e)
{
return e->get() == elem;
}
};
class __EXPORT RTPSessionPool: public RTPSessionBaseHandler
{
public:
RTPSessionPool();
inline virtual ~RTPSessionPool()
{ }
bool
addSession(RTPSessionBase& session);
bool
removeSession(RTPSessionBase& session);
size_t
getPoolLength() const;
virtual void startRunning() = 0;
inline bool isActive()
{ return poolActive; }
protected:
inline void setActive()
{ poolActive = true; }
inline timeval getPoolTimeout()
{ return poolTimeout; }
inline void setPoolTimeout(int sec, int usec)
{ poolTimeout.tv_sec = sec; poolTimeout.tv_usec = usec; }
inline void setPoolTimeout(struct timeval to)
{ poolTimeout = to; }
std::list<SessionListElement*> sessionList;
typedef std::list<SessionListElement*>::iterator PoolIterator;
mutable ThreadLock poolLock;
#ifndef _MSWINDOWS_
fd_set recvSocketSet;
SOCKET highestSocket; // highest socket number + 1
#endif
private:
timeval poolTimeout;
mutable bool poolActive;
};
class __EXPORT SingleRTPSessionPool :
public RTPSessionPool,
public Thread
{
public:
SingleRTPSessionPool(int pri = 0) :
RTPSessionPool(),
Thread(pri)
{ }
~SingleRTPSessionPool()
{ }
void startRunning()
{ setActive(); Thread::start(); }
protected:
void run();
};
END_NAMESPACE
#endif //CCXX_RTP_POOL_H
RTPSessionPool::setPoolTimeout
void setPoolTimeout(int sec, int usec)
Definition: pool.h:184
RTPSessionBaseHandler::takeInDataPacket
size_t takeInDataPacket(RTPSessionBase &s)
Definition: pool.h:64
RTPSessionPool::highestSocket
SOCKET highestSocket
Definition: pool.h:197
SessionListElement
Class for tracking session status.
Definition: pool.h:93
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:155
PredEquals
std equality for SessionListElement objects.
Definition: pool.h:129
RTPSessionBaseHandler::getSchedulingTimeout
microtimeout_t getSchedulingTimeout(RTPSessionBase &s)
Definition: pool.h:57
microtimeout_t
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition: base.h:68
SessionListElement::get
RTPSessionBase * get()
Definition: pool.h:120
RTPSessionPool::getPoolTimeout
timeval getPoolTimeout()
Definition: pool.h:181
SessionListElement::clear
void clear()
Definition: pool.h:110
SingleRTPSessionPool::~SingleRTPSessionPool
~SingleRTPSessionPool()
Definition: pool.h:219
RTPSessionBaseHandler::controlTransmissionService
void controlTransmissionService(RTPSessionBase &s)
Definition: pool.h:76
RTPSessionBase
Generic RTP protocol stack for exchange of realtime data.
SingleRTPSessionPool::SingleRTPSessionPool
SingleRTPSessionPool(int pri=0)
Definition: pool.h:214
RTPSessionPool::recvSocketSet
fd_set recvSocketSet
Definition: pool.h:196
RTPSessionBaseHandler
Definition: pool.h:54
RTPSessionPool::poolLock
ThreadLock poolLock
Definition: pool.h:193
RTPSessionPool::PoolIterator
std::list< SessionListElement * >::iterator PoolIterator
Definition: pool.h:191
RTPSessionBaseHandler::getRTCPCheckInterval
timeval getRTCPCheckInterval(RTPSessionBase &s)
Definition: pool.h:60
SessionListElement::isCleared
bool isCleared()
Definition: pool.h:116
RTPSessionBaseHandler::controlReceptionService
void controlReceptionService(RTPSessionBase &s)
Definition: pool.h:72
RTPSessionPool::setPoolTimeout
void setPoolTimeout(struct timeval to)
Definition: pool.h:187
PredEquals::PredEquals
PredEquals(RTPSessionBase *e)
Definition: pool.h:134
RTPSessionBaseHandler::getDataRecvSocket
SOCKET getDataRecvSocket(RTPSessionBase &s) const
Definition: pool.h:79
SingleRTPSessionPool
Definition: pool.h:206
RTPSessionPool::setActive
void setActive()
Definition: pool.h:178
PredEquals::elem
RTPSessionBase * elem
Definition: pool.h:132
RTPSessionBase
TRTPSessionBase RTPSessionBase
Definition: pool.h:52
TRTPSessionBase
Definition: rtp.h:86
rtp.h
Generic and audio/video profile specific RTP interface of ccRTP.
RTPSessionBaseHandler::getControlRecvSocket
SOCKET getControlRecvSocket(RTPSessionBase &s) const
Definition: pool.h:82
RTPSessionPool::isActive
bool isActive()
Definition: pool.h:174
RTPSessionPool::sessionList
std::list< SessionListElement * > sessionList
Definition: pool.h:190
SingleRTPSessionPool::startRunning
void startRunning()
Definition: pool.h:222
RTPSessionPool::~RTPSessionPool
virtual ~RTPSessionPool()
Definition: pool.h:160
SessionListElement::SessionListElement
SessionListElement(RTPSessionBase *e)
Definition: pool.h:106
RTPSessionBaseHandler::dispatchDataPacket
size_t dispatchDataPacket(RTPSessionBase &s)
Definition: pool.h:68