michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: #ifndef _nsDiskCacheStreams_h_ michael@0: #define _nsDiskCacheStreams_h_ michael@0: michael@0: #include "mozilla/MemoryReporting.h" michael@0: #include "nsDiskCacheBinding.h" michael@0: michael@0: #include "nsCache.h" michael@0: michael@0: #include "nsIInputStream.h" michael@0: #include "nsIOutputStream.h" michael@0: michael@0: #include "mozilla/Atomics.h" michael@0: michael@0: class nsDiskCacheInputStream; michael@0: class nsDiskCacheDevice; michael@0: michael@0: class nsDiskCacheStreamIO : public nsIOutputStream { michael@0: public: michael@0: nsDiskCacheStreamIO(nsDiskCacheBinding * binding); michael@0: virtual ~nsDiskCacheStreamIO(); michael@0: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIOUTPUTSTREAM michael@0: michael@0: nsresult GetInputStream(uint32_t offset, nsIInputStream ** inputStream); michael@0: nsresult GetOutputStream(uint32_t offset, nsIOutputStream ** outputStream); michael@0: michael@0: nsresult ClearBinding(); michael@0: michael@0: void IncrementInputStreamCount() { mInStreamCount++; } michael@0: void DecrementInputStreamCount() michael@0: { michael@0: mInStreamCount--; michael@0: NS_ASSERTION(mInStreamCount >= 0, "mInStreamCount has gone negative"); michael@0: } michael@0: michael@0: size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf); michael@0: michael@0: // GCC 2.95.2 requires this to be defined, although we never call it. michael@0: // and OS/2 requires that it not be private michael@0: nsDiskCacheStreamIO() { NS_NOTREACHED("oops"); } michael@0: michael@0: private: michael@0: nsresult OpenCacheFile(int flags, PRFileDesc ** fd); michael@0: nsresult ReadCacheBlocks(uint32_t bufferSize); michael@0: nsresult FlushBufferToFile(); michael@0: void UpdateFileSize(); michael@0: void DeleteBuffer(); michael@0: nsresult CloseOutputStream(); michael@0: nsresult SeekAndTruncate(uint32_t offset); michael@0: michael@0: nsDiskCacheBinding * mBinding; // not an owning reference michael@0: nsDiskCacheDevice * mDevice; michael@0: mozilla::Atomic mInStreamCount; michael@0: PRFileDesc * mFD; michael@0: michael@0: uint32_t mStreamEnd; // current size of data michael@0: uint32_t mBufSize; // current end of buffer michael@0: char * mBuffer; michael@0: bool mOutputStreamIsOpen; michael@0: }; michael@0: michael@0: #endif // _nsDiskCacheStreams_h_