From fee79568ba288ac94805c6550ebfedc40c66dff3 Mon Sep 17 00:00:00 2001 From: "darin%netscape.com" Date: Wed, 7 Mar 2001 12:54:45 +0000 Subject: [PATCH] [not part of the build] Added implementation files for nsIStreamListenerTee. --- netwerk/base/src/Makefile.in | 4 ++ netwerk/base/src/nsStreamListenerTee.cpp | 64 ++++++++++++++++++++++++ netwerk/base/src/nsStreamListenerTee.h | 26 ++++++++++ 3 files changed, 94 insertions(+) create mode 100644 netwerk/base/src/nsStreamListenerTee.cpp create mode 100644 netwerk/base/src/nsStreamListenerTee.h diff --git a/netwerk/base/src/Makefile.in b/netwerk/base/src/Makefile.in index d850b72553c..3aecee052e1 100644 --- a/netwerk/base/src/Makefile.in +++ b/netwerk/base/src/Makefile.in @@ -62,6 +62,10 @@ CPPSRCS = \ nsStorageTransport.cpp \ $(NULL) +ifdef MOZ_NEW_CACHE +CPPSRCS += nsStreamListenerTee.cpp +endif + # we don't want the shared lib, but we want to force the creation of a # static lib. override NO_SHARED_LIB=1 diff --git a/netwerk/base/src/nsStreamListenerTee.cpp b/netwerk/base/src/nsStreamListenerTee.cpp new file mode 100644 index 00000000000..f4b02532fda --- /dev/null +++ b/netwerk/base/src/nsStreamListenerTee.cpp @@ -0,0 +1,64 @@ +#include "nsStreamListenerTee.h" + +NS_IMPL_ISUPPORTS2(nsStreamListenerTee, + nsIStreamListener, + nsIStreamListenerTee) + +NS_IMETHODIMP +nsStreamListenerTee::OnStartRequest(nsIRequest *request, + nsISupports *context) +{ + NS_ENSURE_TRUE(mListener, NS_ERROR_NOT_INITIALIZED); + return mListener->OnStartRequest(request, context); +} + +NS_IMETHODIMP +nsStreamListenerTee::OnStopRequest(nsIRequest *request, + nsISupports *context, + nsresult status, + const PRUnichar *statusText) +{ + NS_ENSURE_TRUE(mListener, NS_ERROR_NOT_INITIALIZED); + return mListener->OnStopRequest(request, context, status, statusText); +} + +NS_IMETHODIMP +nsStreamListenerTee::OnDataAvailable(nsIRequest *request, + nsISupports *context, + nsIInputStream *input, + PRUint32 offset, + PRUint32 count) +{ + NS_ENSURE_TRUE(mListener, NS_ERROR_NOT_INITIALIZED); + NS_ENSURE_TRUE(mSink, NS_ERROR_NOT_INITIALIZED); + + nsCOMPtr tee; + nsresult rv; + + if (!mInputTee) { + rv = NS_NewInputStreamTee(getter_AddRefs(tee), input, mSink); + if (NS_FAILED(rv)) return rv; + + mInputTee = do_QueryInterface(tee, &rv); + if (NS_FAILED(rv)) return rv; + } + else { + // re-initialize the input tee since the input stream may have changed. + rv = mInputTee->Init(input, mSink); + if (NS_FAILED(rv)) return rv; + + tee = do_QueryInterface(mInputTee, &rv); + if (NS_FAILED(rv)) return rv; + } + + return mListener->OnDataAvailable(request, context, tee, offset, count); +} + +NS_IMETHODIMP +nsStreamListenerTee::Init(nsIStreamListener *listener, + nsIOutputStream *sink) +{ + mListener = listener; + mSink = sink; + return NS_OK; +} diff --git a/netwerk/base/src/nsStreamListenerTee.h b/netwerk/base/src/nsStreamListenerTee.h new file mode 100644 index 00000000000..4586caf3224 --- /dev/null +++ b/netwerk/base/src/nsStreamListenerTee.h @@ -0,0 +1,26 @@ +#ifndef nsStreamListenerTee_h__ +#define nsStreamListenerTee_h__ + +#include "nsIStreamListener.h" +#include "nsIInputStreamTee.h" +#include "nsIOutputStream.h" +#include "nsCOMPtr.h" + +class nsStreamListenerTee : public nsIStreamListenerTee +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSISTREAMOBSERVER + NS_DECL_NSISTREAMLISTENER + NS_DECL_NSISTREAMLISTENERTEE + + nsStreamListenerTee() { NS_INIT_ISUPPORTS(); } + virtual ~nsStreamListenerTee() { } + +private: + nsCOMPtr mInputTee; + nsCOMPtr mListener; + nsCOMPtr mSink; +}; + +#endif