groupsock/include/NetInterface.hh

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // "mTunnel" multicast access service
00017 // Copyright (c) 1996-2013 Live Networks, Inc.  All rights reserved.
00018 // Network Interfaces
00019 // C++ header
00020 
00021 #ifndef _NET_INTERFACE_HH
00022 #define _NET_INTERFACE_HH
00023 
00024 #ifndef _NET_ADDRESS_HH
00025 #include "NetAddress.hh"
00026 #endif
00027 
00028 class NetInterface {
00029 public:
00030   virtual ~NetInterface();
00031 
00032   static UsageEnvironment* DefaultUsageEnvironment;
00033       // if non-NULL, used for each new interfaces
00034 
00035 protected:
00036   NetInterface(); // virtual base class
00037 };
00038 
00039 class DirectedNetInterface: public NetInterface {
00040 public:
00041   virtual ~DirectedNetInterface();
00042 
00043   virtual Boolean write(unsigned char* data, unsigned numBytes) = 0;
00044 
00045   virtual Boolean SourceAddrOKForRelaying(UsageEnvironment& env,
00046                                           unsigned addr) = 0;
00047 
00048 protected:
00049   DirectedNetInterface(); // virtual base class
00050 };
00051 
00052 class DirectedNetInterfaceSet {
00053 public:
00054   DirectedNetInterfaceSet();
00055   virtual ~DirectedNetInterfaceSet();
00056 
00057   DirectedNetInterface* Add(DirectedNetInterface const* interf);
00058       // Returns the old value if different, otherwise 0
00059   Boolean Remove(DirectedNetInterface const* interf);
00060 
00061   Boolean IsEmpty() { return fTable->IsEmpty(); }
00062 
00063   // Used to iterate through the interfaces in the set
00064   class Iterator {
00065   public:
00066     Iterator(DirectedNetInterfaceSet& interfaces);
00067     virtual ~Iterator();
00068 
00069     DirectedNetInterface* next(); // NULL iff none
00070 
00071   private:
00072     HashTable::Iterator* fIter;
00073   };
00074 
00075 private:
00076   friend class Iterator;
00077   HashTable* fTable;
00078 };
00079 
00080 class Socket: public NetInterface {
00081 public:
00082   virtual ~Socket();
00083 
00084   virtual Boolean handleRead(unsigned char* buffer, unsigned bufferMaxSize,
00085                              unsigned& bytesRead,
00086                              struct sockaddr_in& fromAddress) = 0;
00087       // Returns False on error; resultData == NULL if data ignored
00088 
00089   int socketNum() const { return fSocketNum; }
00090 
00091   Port port() const {
00092     return fPort;
00093   }
00094 
00095   UsageEnvironment& env() const { return fEnv; }
00096 
00097   static int DebugLevel;
00098 
00099 protected:
00100   Socket(UsageEnvironment& env, Port port); // virtual base class
00101 
00102   Boolean changePort(Port newPort); // will also cause socketNum() to change
00103 
00104 private:
00105   int fSocketNum;
00106   UsageEnvironment& fEnv;
00107   Port fPort;
00108 };
00109 
00110 UsageEnvironment& operator<<(UsageEnvironment& s, const Socket& sock);
00111 
00112 // A data structure for looking up a Socket by port:
00113 
00114 class SocketLookupTable {
00115 public:
00116   virtual ~SocketLookupTable();
00117 
00118   Socket* Fetch(UsageEnvironment& env, Port port, Boolean& isNew);
00119   // Creates a new Socket if none already exists
00120   Boolean Remove(Socket const* sock);
00121 
00122 protected:
00123   SocketLookupTable(); // abstract base class
00124   virtual Socket* CreateNew(UsageEnvironment& env, Port port) = 0;
00125 
00126 private:
00127   HashTable* fTable;
00128 };
00129 
00130 // A data structure for counting traffic:
00131 
00132 class NetInterfaceTrafficStats {
00133 public:
00134   NetInterfaceTrafficStats();
00135 
00136   void countPacket(unsigned packetSize);
00137 
00138   float totNumPackets() const {return fTotNumPackets;}
00139   float totNumBytes() const {return fTotNumBytes;}
00140 
00141   Boolean haveSeenTraffic() const;
00142 
00143 private:
00144   float fTotNumPackets;
00145   float fTotNumBytes;
00146 };
00147 
00148 #endif

Generated on Tue Jun 18 13:16:50 2013 for live by  doxygen 1.5.2