"Fossies" - the Fresh Open Source Software Archive

Member "muscle/dataio/ProxyDataIO.h" (8 Jun 2019, 4449 Bytes) of package /linux/privat/muscle7.30.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ProxyDataIO.h" see the Fossies "Dox" file reference documentation.

    1 /* This file is Copyright 2000-2013 Meyer Sound Laboratories Inc.  See the included LICENSE.txt file for details. */
    2 
    3 #ifndef MuscleProxyDataIO_h
    4 #define MuscleProxyDataIO_h
    5 
    6 #include "dataio/PacketDataIO.h"
    7 #include "dataio/SeekableDataIO.h"
    8 
    9 namespace muscle {
   10  
   11 /** This DataIO is a "wrapper" DataIO that passes all calls through verbatim
   12   * to a held "child" DataIO.  It's not terribly useful by itself, but can
   13   * be useful as a base class for a subclass that wants to modify certain
   14   * DataIO calls' behaviors while leaving the rest as-is.
   15   */
   16 class ProxyDataIO : public PacketDataIO, public SeekableDataIO
   17 {
   18 public:
   19    /** Default Constructor.  Be sure to set a child dataIO with SetChildDataIO()
   20      * before using this DataIO, so that this object will do something useful!
   21      */
   22    ProxyDataIO() : _seekableChildIO(NULL), _packetChildIO(NULL) {/* empty */}
   23 
   24    /** Constructor. 
   25      * @param childIO Reference to the DataIO to pass calls on through to
   26      *                after the data has been XOR'd.
   27      */
   28    ProxyDataIO(const DataIORef & childIO) {SetChildDataIO(childIO);}
   29 
   30    /** Destructor. */
   31    virtual ~ProxyDataIO() {/* empty */}
   32 
   33    virtual int32 Read(void * buffer, uint32 size) {return _childIO() ? _childIO()->Read(buffer, size) : -1;}
   34    virtual int32 Write(const void * buffer, uint32 size) {return _childIO() ? _childIO()->Write(buffer, size) : -1;}
   35    virtual uint64 GetOutputStallLimit() const {return _childIO() ? _childIO()->GetOutputStallLimit() : MUSCLE_TIME_NEVER;}
   36 
   37    virtual void FlushOutput() {if (_childIO()) _childIO()->FlushOutput();}
   38    virtual void Shutdown() {if (_childIO()) _childIO()->Shutdown(); _childIO.Reset();}
   39 
   40    virtual const ConstSocketRef & GetReadSelectSocket()  const {return _childIO() ? _childIO()->GetReadSelectSocket()  : GetNullSocket();}
   41    virtual const ConstSocketRef & GetWriteSelectSocket() const {return _childIO() ? _childIO()->GetWriteSelectSocket() : GetNullSocket();}
   42    virtual status_t GetReadByteTimeStamp(int32 whichByte, uint64 & retStamp) const {return _childIO() ? _childIO()->GetReadByteTimeStamp(whichByte, retStamp) : B_ERROR;}
   43 
   44    virtual bool HasBufferedOutput() const {return _childIO() ? _childIO()->HasBufferedOutput() : false;}
   45    virtual void WriteBufferedOutput() {if (_childIO()) _childIO()->WriteBufferedOutput();}
   46 
   47    virtual status_t Seek(int64 offset, int whence) {return _seekableChildIO ? _seekableChildIO->Seek(offset, whence) : B_ERROR;}
   48    virtual int64 GetPosition() const {return _seekableChildIO ? _seekableChildIO->GetPosition() : -1;}
   49    virtual int64 GetLength() {return _seekableChildIO ? _seekableChildIO->GetLength() : -1;}
   50 
   51    virtual const IPAddressAndPort & GetSourceOfLastReadPacket() const {return _packetChildIO ? _packetChildIO->GetSourceOfLastReadPacket() : GetDefaultObjectForType<IPAddressAndPort>();}
   52    virtual const IPAddressAndPort & GetPacketSendDestination() const  {return _packetChildIO ? _packetChildIO->GetPacketSendDestination()  : GetDefaultObjectForType<IPAddressAndPort>();}
   53    virtual status_t SetPacketSendDestination(const IPAddressAndPort & iap) {return _packetChildIO ? _packetChildIO->SetPacketSendDestination(iap) : B_ERROR;}
   54    virtual uint32 GetMaximumPacketSize() const {return _packetChildIO ? _packetChildIO->GetMaximumPacketSize() : 0;}
   55    virtual int32 ReadFrom(void * buffer, uint32 size, IPAddressAndPort & retPacketSource) {return _packetChildIO ? _packetChildIO->ReadFrom(buffer, size, retPacketSource) : -1;}
   56    virtual int32 WriteTo(const void * buffer, uint32 size, const IPAddressAndPort & packetDest) {return _packetChildIO ? _packetChildIO->WriteTo(buffer, size, packetDest) : -1;}
   57 
   58    /** Returns a reference to our held child DataIO (if any) */
   59    const DataIORef & GetChildDataIO() const {return _childIO;}
   60 
   61    /** Sets our current held child DataIO.
   62      * @param childDataIO The new child DataIO to forward method calls along to.
   63      */
   64    virtual void SetChildDataIO(const DataIORef & childDataIO) 
   65    {
   66       _childIO         = childDataIO;
   67       _seekableChildIO = dynamic_cast<SeekableDataIO *>(_childIO());
   68       _packetChildIO   = dynamic_cast<PacketDataIO *>(_childIO());
   69    }
   70 
   71 private:
   72    DataIORef _childIO;
   73    SeekableDataIO * _seekableChildIO;  // points to the same object as (_childIO()), or NULL
   74    PacketDataIO   * _packetChildIO;    // points to the same object as (_childIO()), or NULL
   75 };
   76 DECLARE_REFTYPES(ProxyDataIO);
   77 
   78 } // end namespace muscle
   79 
   80 #endif