Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes
TestConverter Class Reference

#include <Converters.h>

Inheritance diagram for TestConverter:
Inheritance graph
[legend]
Collaboration diagram for TestConverter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER 
TestConverter ()
virtual ~TestConverter ()
NS_IMETHOD Convert (nsIInputStream *aFromStream, const char *aFromType, const char *aToType, nsISupports *ctxt, nsIInputStream **_retval)
NS_IMETHOD AsyncConvertData (const char *aFromType, const char *aToType, nsIStreamListener *aListener, nsISupports *ctxt)
nsIInputStream convert (in nsIInputStream aFromStream, in string aFromType, in string aToType, in nsISupports aCtxt)
 SYNCRONOUS VERSION Converts a stream of one type, to a stream of another type.
void asyncConvertData (in string aFromType, in string aToType, in nsIStreamListener aListener, in nsISupports aCtxt)
 ASYNCRONOUS VERSION Converts data arriving via the converter's nsIStreamListener::OnDataAvailable() method from one type to another, pushing the converted data out to the caller via aListener::OnDataAvailable().
void onDataAvailable (in nsIRequest aRequest, in nsISupports aContext, in nsIInputStream aInputStream, in unsigned long aOffset, in unsigned long aCount)
 Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.
void onStartRequest (in nsIRequest aRequest, in nsISupports aContext)
 Called to signify the beginning of an asynchronous request.
void onStopRequest (in nsIRequest aRequest, in nsISupports aContext, in nsresult aStatusCode)
 Called to signify the end of an asynchronous request.

Public Attributes

nsCOMPtr< nsIStreamListenermListener
nsCString fromType
nsCString toType

Detailed Description

Definition at line 22 of file Converters.h.


Constructor & Destructor Documentation

Definition at line 12 of file Converters.cpp.

                             {
}
virtual TestConverter::~TestConverter ( ) [inline, virtual]

Definition at line 29 of file Converters.h.

{}

Member Function Documentation

NS_IMETHODIMP TestConverter::AsyncConvertData ( const char *  aFromType,
const char *  aToType,
nsIStreamListener aListener,
nsISupports *  ctxt 
)

Definition at line 53 of file Converters.cpp.

                                                   {
    NS_ASSERTION(aListener, "null listener");

    mListener = aListener;

    // based on these types, setup internal state to handle the appropriate conversion.
    fromType = aFromType;
    toType = aToType;

    return NS_OK; 
}
void nsIStreamConverter::asyncConvertData ( in string  aFromType,
in string  aToType,
in nsIStreamListener  aListener,
in nsISupports  aCtxt 
) [inherited]

ASYNCRONOUS VERSION Converts data arriving via the converter's nsIStreamListener::OnDataAvailable() method from one type to another, pushing the converted data out to the caller via aListener::OnDataAvailable().

Use this method when you want to proxy (and convert) nsIStreamListener callbacks asynchronously.

Parameters:
aFromTypeThe MIME type of the original/raw data.
aToTypeThe MIME type of the converted data.
aListenerThe listener who receives the converted data.
aCtxtEither an opaque context, or a converter specific context (implementation specific).
NS_IMETHODIMP TestConverter::Convert ( nsIInputStream aFromStream,
const char *  aFromType,
const char *  aToType,
nsISupports *  ctxt,
nsIInputStream **  _retval 
)

Definition at line 19 of file Converters.cpp.

                                                 {
    char buf[1024+1];
    PRUint32 read;
    nsresult rv = aFromStream->Read(buf, 1024, &read);
    if (NS_FAILED(rv) || read == 0) return rv;

    // verify that the data we're converting matches the from type
    // if it doesn't then we're being handed the wrong data.
    char fromChar = *aFromType;

    if (fromChar != buf[0]) {
        printf("We're receiving %c, but are supposed to have %c.\n", buf[0], fromChar);
        return NS_ERROR_FAILURE;
    }


    // Get the first character 
    char toChar = *aToType;

    for (PRUint32 i = 0; i < read; i++) 
        buf[i] = toChar;

    buf[read] = '\0';

    return NS_NewCStringInputStream(_retval, nsDependentCString(buf));
}

Here is the call graph for this function:

nsIInputStream nsIStreamConverter::convert ( in nsIInputStream  aFromStream,
in string  aFromType,
in string  aToType,
in nsISupports  aCtxt 
) [inherited]

SYNCRONOUS VERSION Converts a stream of one type, to a stream of another type.

Use this method when you have a stream you want to convert.

Parameters:
aFromStreamThe stream representing the original/raw data.
aFromTypeThe MIME type of aFromStream.
aToTypeThe MIME type of the returned stream.
aCtxtEither an opaque context, or a converter specific context (implementation specific).
Returns:
The converted stream. NOTE: The returned stream may not already be converted. An efficient stream converter implementation will converter data on demand rather than buffering the converted data until it is used.
void nsIStreamListener::onDataAvailable ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsIInputStream  aInputStream,
in unsigned long  aOffset,
in unsigned long  aCount 
) [inherited]

Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.

The onDataAvailable impl must read exactly |aCount| bytes of data before returning.

Parameters:
aRequestrequest corresponding to the source of the data
aContextuser defined context
aInputStreaminput stream containing the data chunk
aOffsetNumber of bytes that were sent in previous onDataAvailable calls for this request. In other words, the sum of all previous count parameters. If that number is greater than or equal to 2^32, this parameter will be PR_UINT32_MAX (2^32 - 1).
aCountnumber of bytes available in the stream

NOTE: The aInputStream parameter must implement readSegments.

An exception thrown from onDataAvailable has the side-effect of causing the request to be canceled.

void nsIRequestObserver::onStartRequest ( in nsIRequest  aRequest,
in nsISupports  aContext 
) [inherited]

Called to signify the beginning of an asynchronous request.

Parameters:
aRequestrequest being observed
aContextuser defined context

An exception thrown from onStartRequest has the side-effect of causing the request to be canceled.

Here is the caller graph for this function:

void nsIRequestObserver::onStopRequest ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsresult  aStatusCode 
) [inherited]

Called to signify the end of an asynchronous request.

This call is always preceded by a call to onStartRequest.

Parameters:
aRequestrequest being observed
aContextuser defined context
aStatusCodereason for stopping (NS_OK if completed successfully)

An exception thrown from onStopRequest is generally ignored.

Here is the caller graph for this function:


Member Data Documentation

Definition at line 41 of file Converters.h.

Definition at line 40 of file Converters.h.

Definition at line 42 of file Converters.h.


The documentation for this class was generated from the following files: