sources.h

Go to the documentation of this file.
00001 // Copyright (C) 2001,2002,2003,2004 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 
00044 #ifndef CCXX_RTP_SOURCES_H_
00045 #define CCXX_RTP_SOURCES_H_
00046 
00047 #include <string>
00048 #include <ccrtp/rtcppkt.h>
00049 
00050 #ifdef  CCXX_NAMESPACES
00051 namespace ost {
00052 #endif
00053 
00067 class __EXPORT SDESItemsHolder
00068 {
00069 public:
00070         const std::string&
00071         getItem(SDESItemType type) const;
00072 
00073         inline const std::string& 
00074         getPRIVPrefix() const
00075         { return sdesItems[SDESItemTypeEND]; }
00076 
00077         void
00078         setItem(SDESItemType item, const std::string& val);
00079         
00080         inline void
00081         setPRIVPrefix(const std::string& val)
00082         { sdesItems[SDESItemTypeEND] = val; }
00083 
00084 protected:
00085         SDESItemsHolder()
00086         { }
00087         
00088         inline virtual ~SDESItemsHolder()
00089         { }
00090         
00091 private:
00092         // SDES items for a participant.
00093         // sdesItems[0] (== sdesItems[SDESItemTypeEND]) holds the prefix
00094         // value for the PRIV item. The rest of entries hold the
00095         // correponding SDES item value.
00096         std::string sdesItems[SDESItemTypeLast + 1];
00097 };
00098 
00127 class __EXPORT Participant : private SDESItemsHolder
00128 {
00129 public:
00142         const std::string&
00143         getSDESItem(SDESItemType type) const
00144         { return SDESItemsHolder::getItem(type); }
00145 
00153         inline const std::string& 
00154         getPRIVPrefix() const
00155         { return SDESItemsHolder::getPRIVPrefix(); }
00156 
00162         Participant(const std::string& cname);
00163 
00164         ~Participant();
00165 
00166 private:
00167         friend class ParticipantHandler;
00168 
00172         inline void
00173         setSDESItem(SDESItemType item, const std::string& val)
00174         { SDESItemsHolder::setItem(item,val); }
00175 
00179         inline void
00180         setPRIVPrefix(const std::string val)
00181         { SDESItemsHolder::setPRIVPrefix(val); }
00182 };
00183 
00195 class __EXPORT SyncSource
00196 {
00197 public:
00228         typedef enum {
00229                 stateUnknown,     
00230                 statePrevalid,    
00231 
00232 
00233                 stateActive,      
00234 
00235                 stateInactive,    
00236 
00237 
00238                 stateLeaving      
00239 
00240         }       State;
00241 
00246         SyncSource(uint32 ssrc); 
00247 
00248         ~SyncSource();
00249 
00250         State
00251         getState() const
00252         { return state; }
00253 
00257         bool isSender() const
00258         { return activeSender; }
00259 
00260         uint32 getID() const
00261         { return SSRC; }
00262 
00270         inline Participant*
00271         getParticipant() const
00272         { return participant; }
00273 
00274         tpport_t getDataTransportPort() const
00275         { return dataTransportPort; }
00276 
00277         tpport_t getControlTransportPort() const
00278         { return controlTransportPort; }
00279         
00280         const InetAddress& getNetworkAddress() const
00281         { return networkAddress; }
00282 
00283 protected:
00287         SyncSource(const SyncSource& source);
00288 
00289         SyncSource&
00290         operator=(const SyncSource& source);
00291 
00292 private:
00293         friend class SyncSourceHandler;
00294 
00295         inline void
00296         setState(State st)
00297         { state = st; }
00298 
00302         inline void
00303         setSender(bool active)
00304         { activeSender = active; }
00305 
00306         inline void
00307         setParticipant(Participant& p)
00308         { participant = &p; }
00309         
00310         void setDataTransportPort(tpport_t p)
00311         { dataTransportPort = p; }
00312 
00313         void setControlTransportPort(tpport_t p)
00314         { controlTransportPort = p; }
00315 
00316         void setNetworkAddress(InetAddress addr)
00317         { networkAddress = addr; }
00318 
00319         inline void
00320         setLink(void *l)
00321         { link = l; }
00322 
00323         void *getLink() const
00324         { return link; }
00325 
00326         // validity state of this source
00327         State state;
00328         // 32-bit SSRC identifier.
00329         uint32 SSRC;
00330         // A valid source not always is active
00331         bool activeSender;
00332         // The corresponding participant.
00333         Participant* participant;
00334 
00335         // Network protocol address for data and control connection
00336         // (both are assumed to be the same).
00337         InetAddress networkAddress;
00338         tpport_t dataTransportPort;
00339         tpport_t controlTransportPort;
00340 
00341         // Pointer to the SyncSourceLink or similar object in the
00342         // service queue. Saves a lot of searches in the membership
00343         // table.
00344         void* link;
00345 };
00346 
00367 class __EXPORT RTPApplication : private SDESItemsHolder
00368 {
00369 private:
00370         struct ParticipantLink;
00371 
00372 public:
00380         RTPApplication(const std::string& cname);
00381 
00382         ~RTPApplication();
00383 
00384         inline void
00385         setSDESItem(SDESItemType item, const std::string& val)
00386         { SDESItemsHolder::setItem(item,val); }
00387 
00388         inline void
00389         setPRIVPrefix(const std::string& val)
00390         { SDESItemsHolder::setPRIVPrefix(val); }
00391 
00392         const std::string&
00393         getSDESItem(SDESItemType item) const
00394         { return SDESItemsHolder::getItem(item); }
00395 
00396         inline const std::string&
00397         getPRIVPrefix() const
00398         { return SDESItemsHolder::getPRIVPrefix(); }
00399 
00404         class ParticipantsIterator
00405         {
00406         public:
00407                 typedef std::forward_iterator_tag iterator_category;
00408                 typedef Participant value_type;
00409                 typedef ptrdiff_t difference_type;
00410                 typedef const Participant* pointer;
00411                 typedef const Participant& reference;
00412 
00413                 ParticipantsIterator(ParticipantLink* p = NULL) : 
00414                         link(p) 
00415                 { }
00416 
00417                 ParticipantsIterator(const ParticipantsIterator& pi) : 
00418                         link(pi.link)
00419                 { }
00420 
00421                 reference operator*() const
00422                 { return *(link->getParticipant()); }
00423 
00424                 pointer operator->() const
00425                 { return link->getParticipant(); }
00426 
00427                 ParticipantsIterator& operator++() {
00428                         link = link->getNext();
00429                         return *this;
00430                 }
00431 
00432                 ParticipantsIterator operator++(int) {
00433                         ParticipantsIterator result(*this);
00434                         ++(*this);
00435                         return result;
00436                 }
00437                 friend bool operator==(const ParticipantsIterator& l,
00438                                        const ParticipantsIterator& r)
00439                 { return l.link == r.link; }
00440 
00441                 friend bool operator!=(const ParticipantsIterator& l,
00442                                        const ParticipantsIterator& r)
00443                 { return l.link != r.link; }
00444         private:
00445                 ParticipantLink *link;
00446         };
00447 
00448         ParticipantsIterator begin()
00449         { return ParticipantsIterator(firstPart); }
00450         
00451         ParticipantsIterator end()
00452         { return ParticipantsIterator(NULL); }
00453 
00454         const Participant*
00455         getParticipant(const std::string& cname) const;
00456         
00457 private:
00458         friend class ApplicationHandler;
00459 
00460         struct ParticipantLink {
00461                 ParticipantLink(Participant& p, 
00462                                 ParticipantLink* l) :
00463                         participant(&p), next(l) 
00464                 { }
00465                 inline ~ParticipantLink() { delete participant; }
00466                 inline Participant* getParticipant() { return participant; }
00467                 inline ParticipantLink* getPrev() { return prev; }
00468                 inline ParticipantLink* getNext() { return next; }
00469                 inline void setPrev(ParticipantLink* l) { prev = l; }
00470                 inline void setNext(ParticipantLink* l) { next = l; }
00471                 Participant* participant;
00472                 ParticipantLink* next, *prev;
00473         };
00474 
00475         void
00476         addParticipant(Participant& part);
00477 
00478         void
00479         removeParticipant(ParticipantLink* part);
00480 
00485         void
00486         findCNAME();
00487 
00489         static const size_t defaultParticipantsNum;
00490         Participant** participants;
00492         ParticipantLink* firstPart, * lastPart;
00493 };
00494 
00504 __EXPORT RTPApplication& defaultApplication();
00505  // sources
00507 
00508 #ifdef CCXX_NAMESPACES
00509 }
00510 #endif
00511 
00512 #endif //CCXX_RTP_SOURCES_H_
00513 

Generated on Wed Mar 7 07:29:37 2007 for ccRTP by  doxygen 1.5.1