Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages | Examples

pool.h

Go to the documentation of this file.
00001 // Copyright (C) 2001, 2002 Federico Montesino Pouzols <fedemp@altern.org>
00002 //  
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 // 
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 // 
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software 
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 // 
00017 // As a special exception, you may use this file as part of a free software
00018 // library without restriction.  Specifically, if other files instantiate
00019 // templates or use macros or inline functions from this file, or you compile
00020 // this file and link it with other files to produce an executable, this
00021 // file does not by itself cause the resulting executable to be covered by
00022 // the GNU General Public License.  This exception does not however    
00023 // invalidate any other reasons why the executable file might be covered by
00024 // the GNU General Public License.    
00025 //
00026 // This exception applies only to the code released under the name GNU
00027 // ccRTP.  If you copy code from other releases into a copy of GNU
00028 // ccRTP, as the General Public License permits, the exception does
00029 // not apply to the code that you add in this way.  To avoid misleading
00030 // anyone as to the status of such modified files, you must delete
00031 // this exception notice from them.
00032 //
00033 // If you write modifications of your own for GNU ccRTP, it is your choice
00034 // whether to permit this exception to apply to your modifications.
00035 // If you do not wish that, delete this exception notice.
00036 //
00037 
00043 #ifndef CCXX_RTP_POOL_H
00044 #define CCXX_RTP_POOL_H
00045 
00046 #include <list>
00047 #include <ccrtp/rtp.h>
00048 
00049 #ifdef  CCXX_NAMESPACES
00050 namespace ost {
00051 using std::list;
00052 #endif
00053 
00054 typedef TRTPSessionBase<> RTPSessionBase;
00055 
00056 class RTPSessionBaseHandler
00057 {
00058 public:
00059         size_t
00060         takeInDataPacket(RTPSessionBase& s)
00061         { return s.takeInDataPacket(); }
00062         
00063         size_t
00064         dispatchDataPacket(RTPSessionBase& s)
00065         { return s.dispatchDataPacket(); }
00066         
00067         void
00068         controlReceptionService(RTPSessionBase& s)
00069         { s.controlReceptionService(); }
00070         
00071         void
00072         controlTransmissionService(RTPSessionBase& s)
00073         { s.controlTransmissionService(); }
00074         
00075         inline SOCKET getDataRecvSocket(RTPSessionBase& s) const
00076         { return s.getDataRecvSocket(); }
00077         
00078         inline SOCKET getControlRecvSocket(RTPSessionBase& s) const
00079         { return s.getControlRecvSocket(); }
00080 };
00081 
00095 class __EXPORT RTPSessionPool: public RTPSessionBaseHandler
00096 {
00097 public:
00098         RTPSessionPool();
00099 
00100         inline virtual ~RTPSessionPool()
00101         { }
00102 
00103         bool
00104         addSession(RTPSessionBase& session);
00105 
00106         bool 
00107         removeSession(RTPSessionBase& session);
00108 
00109         size_t
00110         getPoolLength() const;
00111 
00112         virtual void startRunning() = 0;
00113 
00114         inline bool isActive()
00115         { return poolActive; }
00116 
00117 protected:
00118         inline void setActive()
00119         { poolActive = true; }
00120         
00121         inline timeval getPoolTimeout()
00122         { return poolTimeout; }
00123 
00124         inline void setPoolTimeout(int sec, int usec)
00125         { poolTimeout.tv_sec = sec; poolTimeout.tv_usec = usec; }
00126 
00127         inline void setPoolTimeout(struct timeval to)
00128         { poolTimeout = to; }
00129 
00130         std::list<RTPSessionBase*> sessionList;
00131         typedef std::list<RTPSessionBase*>::iterator PoolIterator;
00132 
00133 #ifndef WIN32
00134         fd_set recvSocketSet;
00135         SOCKET highestSocket;  // highest socket number + 1
00136 #endif
00137 
00138 private:
00139         mutable ThreadLock poolLock;
00140         timeval poolTimeout;
00141         mutable bool poolActive;
00142 };
00143 
00144 
00145 class __EXPORT SingleRTPSessionPool : 
00146                 public RTPSessionPool,
00147                 public Thread
00148 {
00149 public:
00153         SingleRTPSessionPool(int pri = 0) : 
00154                 RTPSessionPool(),
00155                 Thread(pri)
00156         { }
00157         
00158         ~SingleRTPSessionPool()
00159         { }
00160 
00161         void startRunning()
00162         { setActive(); Thread::start(); }
00163 
00164 protected:
00169         void run();
00170 };
00171 
00172 #ifdef  CCXX_NAMESPACES
00173 }
00174 #endif
00175 
00176 #endif //CCXX_RTP_POOL_H
00177 

Generated on Fri Dec 9 23:36:18 2005 for ccRTP by  doxygen 1.4.4