Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Attributes | Private Attributes
nsReader Class Reference
Inheritance diagram for nsReader:
Inheritance graph
[legend]
Collaboration diagram for nsReader:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS NS_IMETHOD Run ()
 Defines an entry point for a newly created thread.
 nsReader ()
virtual ~nsReader ()
nsresult Init (nsIThread *thread)
NS_IMETHOD OnStartRequest (nsIRequest *request, nsISupports *context)
NS_IMETHOD OnDataAvailable (nsIRequest *request, nsISupports *context, nsIInputStream *aIStream, PRUint32 aSourceOffset, PRUint32 aLength)
NS_IMETHOD OnStopRequest (nsIRequest *request, nsISupports *context, nsresult aStatus)
void run ()
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.

Protected Attributes

nsIEventQueuemEventQueue
PRIntervalTime mStartTime
nsIThreadmThread
PRUint32 mBytesRead

Private Attributes

PRMonitormMonitor

Detailed Description

Definition at line 80 of file TestFileInput.cpp.


Constructor & Destructor Documentation

nsReader::nsReader ( ) [inline]

Definition at line 102 of file TestFileInput.cpp.

Here is the call graph for this function:

virtual nsReader::~nsReader ( ) [inline, virtual]

Definition at line 108 of file TestFileInput.cpp.

Here is the call graph for this function:


Member Function Documentation

nsresult nsReader::Init ( nsIThread thread) [inline]

Definition at line 114 of file TestFileInput.cpp.

                                     {
        nsresult rv;
        mThread = thread;
        NS_ADDREF(mThread);
        PRThread* prthread;
        thread->GetPRThread(&prthread);
        PR_EnterMonitor(mMonitor);
        nsCOMPtr<nsIEventQueueService> eventQService =
                 do_GetService(kEventQueueServiceCID, &rv);
        if (NS_SUCCEEDED(rv)) {
          rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &mEventQueue);
        }

        if (NS_FAILED(rv)) return rv;

        // wake up event loop
        PR_Notify(mMonitor);
        PR_ExitMonitor(mMonitor);

        return NS_OK;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

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.

NS_IMETHOD nsReader::OnDataAvailable ( nsIRequest request,
nsISupports *  context,
nsIInputStream aIStream,
PRUint32  aSourceOffset,
PRUint32  aLength 
) [inline]

Definition at line 145 of file TestFileInput.cpp.

                                                 {
        PR_EnterMonitor(mMonitor);
        char buf[1025];
        while (aLength > 0) {
            PRUint32 amt;
            /*nsresult rv = */aIStream->Read(buf, 1024, &amt);
            if (amt == 0) break;
            buf[amt] = '\0';
            printf(buf);
            aLength -= amt;
            mBytesRead += amt;
            gVolume += amt;
        }
        PR_ExitMonitor(mMonitor);
        return NS_OK;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

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:

NS_IMETHOD nsReader::OnStartRequest ( nsIRequest request,
nsISupports *  context 
) [inline]

Definition at line 136 of file TestFileInput.cpp.

                                                    {
        PR_EnterMonitor(mMonitor);
        printf("start binding\n"); 
        mStartTime = PR_IntervalNow();
        PR_ExitMonitor(mMonitor);
        return NS_OK;
    }

Here is the call graph for this function:

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:

NS_IMETHOD nsReader::OnStopRequest ( nsIRequest request,
nsISupports *  context,
nsresult  aStatus 
) [inline]

Definition at line 166 of file TestFileInput.cpp.

                                               {
        nsresult rv;
        PR_EnterMonitor(mMonitor);
        PRIntervalTime endTime = PR_IntervalNow();
        gDuration += (endTime - mStartTime);
        printf("stop binding, %d\n", aStatus);
        if (NS_FAILED(aStatus)) printf("channel failed.\n");
        printf("read %d bytes\n", mBytesRead);
        PR_ExitMonitor(mMonitor);

        // get me out of my event loop
        rv = mThread->Interrupt();
        if (NS_FAILED(rv)) return rv;

        return rv;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIRunnable::run ( ) [inherited]

Defines an entry point for a newly created thread.

Implements nsIRunnable.

Definition at line 84 of file TestFileInput.cpp.

                     {
        printf("waiting\n");
        if (!mMonitor)
            return NS_ERROR_OUT_OF_MEMORY;
        PR_EnterMonitor(mMonitor);
        if (mEventQueue == nsnull) 
            PR_CWait(this, PR_INTERVAL_NO_TIMEOUT);

        PR_ExitMonitor(mMonitor);

        printf("running\n");

        mEventQueue->EventLoop();

        printf("quitting\n");
        return NS_OK;
    }

Here is the call graph for this function:


Member Data Documentation

Definition at line 188 of file TestFileInput.cpp.

Definition at line 185 of file TestFileInput.cpp.

Definition at line 191 of file TestFileInput.cpp.

Definition at line 186 of file TestFileInput.cpp.

Definition at line 187 of file TestFileInput.cpp.


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