[not part of the build] Added implementation files for nsIStreamListenerTee.

This commit is contained in:
darin%netscape.com 2001-03-07 12:54:45 +00:00
Родитель 95e4eaf8b4
Коммит fee79568ba
3 изменённых файлов: 94 добавлений и 0 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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<nsIInputStream> 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;
}

Просмотреть файл

@ -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<nsIInputStreamTee> mInputTee;
nsCOMPtr<nsIStreamListener> mListener;
nsCOMPtr<nsIOutputStream> mSink;
};
#endif