framexmit/framesend.hh

00001 #ifndef _GDS_FRAMESEND_H
00002 #define _GDS_FRAMESEND_H
00003 /*----------------------------------------------------------------------*/
00004 /*                                                                      */
00005 /* Module Name: framexmit                                               */
00006 /*                                                                      */
00007 /* Module Description: API for broadcasting frames                      */
00008 /*                     implements a reliable UDP/IP broadcast for       */
00009 /*                     large data sets over high speed links            */
00010 /*                                                                      */
00011 /* Module Arguments: none                                               */
00012 /*                                                                      */
00013 /* Revision History:                                                    */
00014 /* Rel   Date     Programmer    Comments                                */
00015 /* 1.0   10Aug99  D. Sigg       First release                           */
00016 /*                                                                      */
00017 /* Documentation References:                                            */
00018 /*      Man Pages: doc/index.html (use doc++)                           */
00019 /*      References: none                                                */
00020 /*                                                                      */
00021 /* Author Information:                                                  */
00022 /* Name          Telephone       Fax             e-mail                 */
00023 /* Daniel Sigg   (509) 372-8132  (509) 372-8137  sigg_d@ligo.mit.edu    */
00024 /*                                                                      */
00025 /* Code Compilation and Runtime Specifications:                         */
00026 /*      Code Compiled on: Ultra-Enterprise, Solaris 5.7                 */
00027 /*      Compiler Used: egcs-1.1.2                                       */
00028 /*      Runtime environment: sparc/solaris                              */
00029 /*                                                                      */
00030 /* Code Standards Conformance:                                          */
00031 /*      Code Conforms to: LIGO standards.       OK                      */
00032 /*                        Lint.                 TBD                     */
00033 /*                        ANSI                  OK                      */
00034 /*                        POSIX                 OK                      */
00035 /*                                                                      */
00036 /* Known Bugs, Limitations, Caveats:                                    */
00037 /*                                                                      */
00038 /*                                                                      */
00039 /*                                                                      */
00040 /*                      -------------------                             */
00041 /*                                                                      */
00042 /*                             LIGO                                     */
00043 /*                                                                      */
00044 /*        THE LASER INTERFEROMETER GRAVITATIONAL WAVE OBSERVATORY.      */
00045 /*                                                                      */
00046 /*                     (C) The LIGO Project, 1996.                      */
00047 /*                                                                      */
00048 /*                                                                      */
00049 /* California Institute of Technology                                   */
00050 /* LIGO Project MS 51-33                                                */
00051 /* Pasadena CA 91125                                                    */
00052 /*                                                                      */
00053 /* Massachusetts Institute of Technology                                */
00054 /* LIGO Project MS NW17-161                                             */
00055 /* Cambridge MA 01239                                                   */
00056 /*                                                                      */
00057 /* LIGO Hanford Observatory                                             */
00058 /* P.O. Box 1970 S9-02                                                  */
00059 /* Richland WA 99352                                                    */
00060 /*                                                                      */
00061 /* LIGO Livingston Observatory                                          */
00062 /* 19100 LIGO Lane Rd.                                                  */
00063 /* Livingston, LA 70754                                                 */
00064 /*                                                                      */
00065 /*----------------------------------------------------------------------*/
00066 
00067 // include files
00068 #include <netinet/in.h>
00069 #include <deque>
00070 #include "framexmit/fxmittask.h"
00071 #include "framexmit/fxmitmutex.hh"
00072 #include "framexmit/framexmittypes.hh"
00073 
00074 namespace framexmit {
00075 
00085    class frameSend {
00087       friend void xmitDaemonCallback (frameSend&);
00088    
00089    public:
00095       explicit frameSend (int maxBuffers = sndDefaultBuffers) 
00096       : sock (-1), seq (0), maxbuffers (maxBuffers) {
00097       }
00098    
00107       explicit frameSend (const char* addr, const char* interface = 0,
00108                         int port = frameXmitPort,
00109                         int maxBuffers = sndDefaultBuffers) 
00110       : sock (-1), seq (0), maxbuffers (maxBuffers) {
00111          open (addr, interface, port);
00112       }
00113    
00118       ~frameSend () {
00119          close();
00120       }
00121    
00137       bool open (const char* addr, const char* interface = 0, 
00138                 int port = frameXmitPort);
00139    
00145       bool open (int port = frameXmitPort) {
00146          return open (0, 0, port);
00147       }
00148    
00153       void close ();
00154    
00203       bool send (char* data, int len, bool* inUse = 0, bool copy = false,
00204                 unsigned int timestamp = 0, unsigned int duration = 0);
00205    
00210       int skipped () const {
00211          return skippedDataBuffers;
00212       }
00213    
00219       bool isUsed (bool& inUse) const {
00220          inUseMux.lock();
00221          bool u = inUse;
00222          inUseMux.unlock();
00223          return u;
00224       }
00225    
00226    private:
00228       int                       sock;
00230       bool                      multicast;
00232       struct sockaddr_in        name;
00234       unsigned int              seq;
00236       int                       maxbuffers;
00238       int                       skippedDataBuffers;
00240       mutable mutex             inUseMux;
00241    
00245       class buffer {
00246       public:
00248          buffer ();
00250          buffer (const buffer& buf);
00252          buffer (char* Data, int Len, unsigned int Seq, bool Own = false,
00253                 bool* Used = 0, mutex* InUseMux = 0, 
00254                 unsigned int Timestamp = 0, unsigned int Duration = 0);
00256          ~buffer();
00258          buffer& operator= (const buffer& buf);
00259       
00261          unsigned int   seq;
00263          mutable bool   own;
00265          char*          data;
00267          int            len;
00269          mutable bool*  used;
00271          mutex*         inUseMux;
00273          unsigned int   timestamp;
00275          unsigned int   duration;
00277          int            sofar;
00278       };
00280       static bool compSeqeuence (const buffer&, const retransmitpacket&);   
00281    
00283       std::deque<buffer>        buffers;
00285       int                       curbuf;
00287       framexmit::mutex          mux;
00289       bool send (buffer& data);
00291       friend  bool compSeqeuence (const buffer& b,      
00292                         const retransmitpacket& p);
00294       taskID_t                  daemon;
00295    
00297       bool putPackets (packet pkts[], int n);
00299       bool getRetransmitPacket (retransmitpacket& pkt);
00301       void xmitDaemon ();
00302    
00304       frameSend (const frameSend&);
00306       frameSend& operator= (const frameSend&);
00307    };
00308 
00309 }
00310 
00311 #endif // _GDS_FRAMESEND_H

Generated on Sun Mar 8 19:20:47 2009 for dmt by  doxygen 1.5.4