LCOV - code coverage report
Current view: directory - netwerk/base/src - nsBufferedStreams.h (source / functions) Found Hit Coverage
Test: app.info Lines: 10 10 100.0 %
Date: 2012-06-02 Functions: 10 10 100.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      26                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : #ifndef nsBufferedStreams_h__
      39                 : #define nsBufferedStreams_h__
      40                 : 
      41                 : #include "nsIBufferedStreams.h"
      42                 : #include "nsIInputStream.h"
      43                 : #include "nsIOutputStream.h"
      44                 : #include "nsISafeOutputStream.h"
      45                 : #include "nsISeekableStream.h"
      46                 : #include "nsIStreamBufferAccess.h"
      47                 : #include "nsCOMPtr.h"
      48                 : #include "nsIIPCSerializable.h"
      49                 : 
      50                 : ////////////////////////////////////////////////////////////////////////////////
      51                 : 
      52                 : class nsBufferedStream : public nsISeekableStream
      53                 : {
      54                 : public:
      55                 :     NS_DECL_ISUPPORTS
      56                 :     NS_DECL_NSISEEKABLESTREAM
      57                 : 
      58                 :     nsBufferedStream();
      59                 :     virtual ~nsBufferedStream();
      60                 : 
      61                 :     nsresult Close();
      62                 : 
      63                 : protected:
      64                 :     nsresult Init(nsISupports* stream, PRUint32 bufferSize);
      65                 :     NS_IMETHOD Fill() = 0;
      66                 :     NS_IMETHOD Flush() = 0;
      67                 : 
      68                 :     PRUint32                    mBufferSize;
      69                 :     char*                       mBuffer;
      70                 : 
      71                 :     // mBufferStartOffset is the offset relative to the start of mStream.
      72                 :     PRInt64                     mBufferStartOffset;
      73                 : 
      74                 :     // mCursor is the read cursor for input streams, or write cursor for
      75                 :     // output streams, and is relative to mBufferStartOffset.
      76                 :     PRUint32                    mCursor;
      77                 : 
      78                 :     // mFillPoint is the amount available in the buffer for input streams,
      79                 :     // or the high watermark of bytes written into the buffer, and therefore
      80                 :     // is relative to mBufferStartOffset.
      81                 :     PRUint32                    mFillPoint;
      82                 : 
      83                 :     nsISupports*                mStream;        // cast to appropriate subclass
      84                 : 
      85                 :     bool                        mBufferDisabled;
      86                 :     bool                        mEOF;  // True if mStream is at EOF
      87                 :     PRUint8                     mGetBufferCount;
      88                 : };
      89                 : 
      90                 : ////////////////////////////////////////////////////////////////////////////////
      91                 : 
      92                 : class nsBufferedInputStream : public nsBufferedStream,
      93                 :                               public nsIBufferedInputStream,
      94                 :                               public nsIStreamBufferAccess,
      95                 :                               public nsIIPCSerializable
      96                 : {
      97                 : public:
      98                 :     NS_DECL_ISUPPORTS_INHERITED
      99                 :     NS_DECL_NSIINPUTSTREAM
     100                 :     NS_DECL_NSIBUFFEREDINPUTSTREAM
     101                 :     NS_DECL_NSISTREAMBUFFERACCESS
     102                 :     NS_DECL_NSIIPCSERIALIZABLE
     103                 : 
     104            2775 :     nsBufferedInputStream() : nsBufferedStream() {}
     105           11100 :     virtual ~nsBufferedInputStream() {}
     106                 : 
     107                 :     static nsresult
     108                 :     Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
     109                 : 
     110           10025 :     nsIInputStream* Source() { 
     111           10025 :         return (nsIInputStream*)mStream;
     112                 :     }
     113                 : 
     114                 : protected:
     115                 :     NS_IMETHOD Fill();
     116               2 :     NS_IMETHOD Flush() { return NS_OK; } // no-op for input streams
     117                 : };
     118                 : 
     119                 : ////////////////////////////////////////////////////////////////////////////////
     120                 : 
     121                 : class nsBufferedOutputStream : public nsBufferedStream, 
     122                 :                                public nsISafeOutputStream,
     123                 :                                public nsIBufferedOutputStream,
     124                 :                                public nsIStreamBufferAccess
     125                 : {
     126                 : public:
     127                 :     NS_DECL_ISUPPORTS_INHERITED
     128                 :     NS_DECL_NSIOUTPUTSTREAM
     129                 :     NS_DECL_NSISAFEOUTPUTSTREAM
     130                 :     NS_DECL_NSIBUFFEREDOUTPUTSTREAM
     131                 :     NS_DECL_NSISTREAMBUFFERACCESS
     132                 : 
     133            1144 :     nsBufferedOutputStream() : nsBufferedStream() {}
     134            4576 :     virtual ~nsBufferedOutputStream() { nsBufferedOutputStream::Close(); }
     135                 : 
     136                 :     static nsresult
     137                 :     Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
     138                 : 
     139            9966 :     nsIOutputStream* Sink() { 
     140            9966 :         return (nsIOutputStream*)mStream;
     141                 :     }
     142                 : 
     143                 : protected:
     144            5487 :     NS_IMETHOD Fill() { return NS_OK; } // no-op for input streams
     145                 : 
     146                 :     nsCOMPtr<nsISafeOutputStream> mSafeStream; // QI'd from mStream
     147                 : };
     148                 : 
     149                 : ////////////////////////////////////////////////////////////////////////////////
     150                 : 
     151                 : #endif // nsBufferedStreams_h__

Generated by: LCOV version 1.7