Back to index

enigmail  1.4.3
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes
nsIPCBuffer Class Reference

#include <nsIPCBuffer.h>

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

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIPIPELISTENER
NS_DECL_NSIIPCBUFFER
NS_DECL_NSIINPUTSTREAM
NS_DECL_NSIRUNNABLE 
nsIPCBuffer ()
virtual ~nsIPCBuffer ()
void open (in long maxBytes, in boolean overflowFile)
 Opens byte buffer.
void openURI (in nsIURI aURI, in long maxBytes, in boolean synchronous, in nsIRequestObserver observer, in nsISupports ctxt, in boolean overflowFile)
 Loads an URI into the console buffer (use instead of the open method)
nsIInputStream openInputStream ()
 Opens an input stream to access buffer data; should be called only after the OnStopRequest call to streamListener.
string getData ()
 Returns data from buffer (as a NUL-terminated string)
void observe (in nsIRequestObserver observer, in nsISupports ctxt)
 Observes any asynchronous request associated with console.
void join ()
 Close input pipe and blocks for console logging thread to terminate, ensuring that all data already written to the console pipe is available for reading from console buffer.
void shutdown ()
 Shuts down listener (without blocking).
void getByteData (out unsigned long count,[retval, size_is(count)] out string data)
 Accesses buffer data as a string of arbitrary bytes, including NUL characters.
void write (in string str)
 Writes a string into the buffer.
void writeBuf (in string buf, in unsigned long count)
 Writes data into the buffer.

Static Public Member Functions

static NS_METHOD Create (nsISupports *aOuter, REFNSIID aIID, void **aResult)

Public Attributes

readonly attribute boolean stopped
 True if onStopRequest method of StreamListener has been invoked.
readonly attribute unsigned long totalBytes
 Count of total bytes in buffer (or overflow file)
readonly attribute boolean joinable
 true if console pipe thread may be terminated
readonly attribute boolean overflowed
 True if data has been lost (i.e., getByteData does not return all data)

Protected Member Functions

nsresult Finalize (IPCBool destructor)
nsresult Init ()
nsresult CreateTempFile ()
nsresult CloseTempOutStream ()
nsresult WriteTempOutStream (const char *buf, PRUint32 count)
nsresult OpenTempInStream ()
nsresult CloseTempInStream ()
nsresult RemoveTempFile ()
NS_IMETHODIMP GetFileDesc (IPCFileDesc **_retval)

Protected Attributes

IPCBool mFinalized
IPCBool mInitialized
IPCBool mThreadJoined
IPCBool mOverflowed
IPCBool mOverflowFile
IPCBool mRequestStarted
IPCBool mRequestStopped
mozilla::Mutex mLock
PRInt32 mMaxBytes
PRUint32 mByteCount
PRUint32 mStreamOffset
nsCString mByteBuf
IPCFileDescmPipeWrite
IPCFileDescmPipeRead
nsCOMPtr< nsIFile > mTempFile
nsCOMPtr< nsIFileOutputStream > mTempOutStream
nsCOMPtr< nsIFileInputStream > mTempInStream
nsCOMPtr< nsIThread > mPipeThread
nsCOMPtr< nsIRequestObserver > mObserver
nsCOMPtr< nsISupports > mObserverContext

Detailed Description

Definition at line 69 of file nsIPCBuffer.h.


Constructor & Destructor Documentation

NS_DECL_ISUPPORTS NS_DECL_NSIREQUESTOBSERVER NS_DECL_NSISTREAMLISTENER NS_DECL_NSIPIPELISTENER NS_DECL_NSIIPCBUFFER NS_DECL_NSIINPUTSTREAM NS_DECL_NSIRUNNABLE nsIPCBuffer::nsIPCBuffer ( )

Definition at line 125 of file nsIPCBuffer.cpp.

{
#ifdef FORCE_PR_LOG
  nsCOMPtr<nsIThread> myThread;
  IPC_GET_THREAD(myThread);
  DEBUG_LOG(("nsIPCBuffer:: >>>>>>>>> DTOR(%p): myThread=%p\n",
         this, myThread.get()));
#endif

  Finalize(PR_TRUE);

}

Member Function Documentation

nsresult nsIPCBuffer::CloseTempInStream ( ) [protected]

Definition at line 452 of file nsIPCBuffer.cpp.

{
  DEBUG_LOG(("nsIPCBuffer::CloseTempInStream: \n"));
  nsresult rv = NS_OK;

  if (mTempInStream) {
    rv = mTempInStream->Close();
    mTempInStream = nsnull;
  }

  return rv;
}
nsresult nsIPCBuffer::CloseTempOutStream ( ) [protected]

Definition at line 409 of file nsIPCBuffer.cpp.

{
  nsresult rv = NS_OK;

  DEBUG_LOG(("nsIPCBuffer::CloseTempOutStream: \n"));

  if (mTempOutStream) {
    nsresult flushRV = mTempOutStream->Flush();
    rv = mTempOutStream->Close();

    if (NS_SUCCEEDED(rv) && NS_FAILED(flushRV))
      rv = flushRV;
    mTempOutStream = nsnull;
  }

  return rv;
}
static NS_METHOD nsIPCBuffer::Create ( nsISupports *  aOuter,
REFNSIID  aIID,
void **  aResult 
) [static]
nsresult nsIPCBuffer::CreateTempFile ( ) [protected]

Definition at line 350 of file nsIPCBuffer.cpp.

{
  nsresult rv;

  DEBUG_LOG(("nsIPCBuffer::CreateTempFile: \n"));

  if (mTempFile)
    return NS_ERROR_FILE_ALREADY_EXISTS;

  nsCOMPtr<nsIProperties> directoryService =
    do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
  directoryService->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile),
    getter_AddRefs(mTempFile));

  NS_ABORT_IF_FALSE(mTempFile, "No temp folder?");

  if (! mTempFile)
    return NS_ERROR_UNEXPECTED;

  mTempFile->AppendNative(nsDependentCString(SAFE_TMP_FILENAME));
  rv = mTempFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 00600);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCAutoString nativePath;
  mTempFile->GetNativePath(nativePath);

  DEBUG_LOG(("nsIPCBuffer::CreateTempFile: %s\n",
            nativePath.get()));

  mTempOutStream = do_CreateInstance(
    "@mozilla.org/network/file-output-stream;1",
    &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = mTempOutStream->Init(mTempFile, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE,
    00600, 0);
  return rv;
}
nsresult nsIPCBuffer::Finalize ( IPCBool  destructor) [protected]

Definition at line 149 of file nsIPCBuffer.cpp.

{
  DEBUG_LOG(("nsIPCBuffer::Finalize: \n"));

  if (mFinalized)
    return NS_OK;

  mFinalized = PR_TRUE;

  nsCOMPtr<nsIIPCBuffer> self;
  if (!destructor) {
    // Hold a reference to ourselves to prevent our DTOR from being called
    // while finalizing. Automatically released upon returning.
    self = this;
  }

  // Close write pipe
  if (mPipeWrite) {
    IPC_Close(mPipeWrite);
    mPipeWrite = IPC_NULL_HANDLE;
  }

  // Release owning refs
  mPipeThread = nsnull;
  mObserver = nsnull;
  mObserverContext = nsnull;

  RemoveTempFile();

  // Clear console
  mByteBuf.Assign("");

  return NS_OK;
}
void nsIPipeListener::getByteData ( out unsigned long  count,
[retval, size_is(count)] out string  data 
) [inherited]

Accesses buffer data as a string of arbitrary bytes, including NUL characters.

string nsIIPCBuffer::getData ( ) [inherited]

Returns data from buffer (as a NUL-terminated string)

NS_IMETHODIMP nsIPCBuffer::GetFileDesc ( IPCFileDesc **  _retval) [protected]

Definition at line 734 of file nsIPCBuffer.cpp.

{
  NS_ENSURE_FALSE(mFinalized, NS_ERROR_NOT_AVAILABLE);
  NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);

  nsresult rv;

  MutexAutoLock lock(mLock);

  DEBUG_LOG(("nsIPCBuffer::GetFileDesc:\n"));

  NS_ENSURE_ARG_POINTER(_retval);

  if (!mFinalized && !mPipeThread) {
    // Create pipe pair
    PRStatus status = IPC_CreateInheritablePipe(&mPipeRead, &mPipeWrite,
                                              PR_FALSE, PR_TRUE);
    if (status != PR_SUCCESS) {
      ERROR_LOG(("nsIPCBuffer::GetFileDesc: IPC_CreateInheritablePipe failed\n"));
      return NS_ERROR_FAILURE;
    }

    // Spin up a new thread to handle STDOUT polling
    rv = NS_NewThread(getter_AddRefs(mPipeThread), this);

    NS_ENSURE_SUCCESS(rv, rv);
  }

  if (mPipeWrite == IPC_NULL_HANDLE)
    return NS_ERROR_FAILURE;

  *_retval = mPipeWrite;
  return NS_OK;
}

Here is the call graph for this function:

nsresult nsIPCBuffer::Init ( ) [protected]

Definition at line 185 of file nsIPCBuffer.cpp.

{
  DEBUG_LOG(("nsIPCBuffer::Init: \n"));

  mInitialized = PR_TRUE;

  return NS_OK;
}
void nsIPipeListener::join ( ) [inherited]

Close input pipe and blocks for console logging thread to terminate, ensuring that all data already written to the console pipe is available for reading from console buffer.

void nsIPipeListener::observe ( in nsIRequestObserver  observer,
in nsISupports  ctxt 
) [inherited]

Observes any asynchronous request associated with console.

(E.g., when console is used to capture stdout from nsIPipeTransport.execAsync)

Parameters:
observerThe nsIRequestObserver object
ctxtA user-defined context value that is passed to the observer.
void nsIIPCBuffer::open ( in long  maxBytes,
in boolean  overflowFile 
) [inherited]

Opens byte buffer.

Parameters:
maxBytesmaximum number of bytes to be read (maxBytes <= 0 --> unlimited buffer size)
overflowFiledetermines if a temporary file should be created if the data to hold in the buffer grows larger than maxBytes. If false and the buffer reached maxBytes then reading will block until data is read from the buffer.
nsIInputStream nsIIPCBuffer::openInputStream ( ) [inherited]

Opens an input stream to access buffer data; should be called only after the OnStopRequest call to streamListener.

Note: On closing the stream, the buffer will be cleared

nsresult nsIPCBuffer::OpenTempInStream ( ) [protected]

Definition at line 428 of file nsIPCBuffer.cpp.

{
  nsresult rv;

  DEBUG_LOG(("nsIPCBuffer::OpenTempInStream: \n"));

  if (!mTempFile)
    return NS_ERROR_NOT_AVAILABLE;

  if (mTempOutStream) {
    ERROR_LOG(("nsIPCBuffer::OpenTempInStream: ERROR - TempOutStream still open!\n"));
    return NS_ERROR_UNEXPECTED;
  }

  mTempInStream  = do_CreateInstance("@mozilla.org/network/file-input-stream;1",
    &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = mTempInStream->Init(mTempFile, PR_RDONLY, 00600, 0);
  return rv;
}
void nsIIPCBuffer::openURI ( in nsIURI  aURI,
in long  maxBytes,
in boolean  synchronous,
in nsIRequestObserver  observer,
in nsISupports  ctxt,
in boolean  overflowFile 
) [inherited]

Loads an URI into the console buffer (use instead of the open method)

Parameters:
aURIURI to be loaded
maxBytesmaximum number of bytes to be read (maxBytes <= 0 --> unlimited buffer size)
synchronousdetermines whether to load synchronously (NOTE: This DOESN'T WORK if the input stream operates on the same thread -- reading and writing are both blocking operations)
observera request observer (same as if defined via observe())
ctxtopaque parameter passed to listener methods
overflowFiledetermines if a temporary file should be created (see open() for details)
nsresult nsIPCBuffer::RemoveTempFile ( ) [protected]

Definition at line 468 of file nsIPCBuffer.cpp.

{
  DEBUG_LOG(("nsIPCBuffer::RemoveTempFile: \n"));

  nsresult rv;

  if (mTempOutStream) {
    // Close overflow file
    CloseTempOutStream();
  }

  if (mTempInStream) {
    // Close overflow file
    CloseTempInStream();
  }

  if (mTempFile) {
    // delete temp file
    nsCAutoString nativePath;
    mTempFile->GetNativePath(nativePath);
    DEBUG_LOG(("nsIPCBuffer::RemoveTempFile: Removing %s\n",
                nativePath.get()));

    rv = mTempFile->Remove(PR_FALSE);
    NS_ENSURE_SUCCESS(rv, rv);

    mTempFile = nsnull;
  }

  return NS_OK;
}
void nsIPipeListener::shutdown ( ) [inherited]

Shuts down listener (without blocking).

Any data already written to the input pipe is discarded.

void nsIPipeListener::write ( in string  str) [inherited]

Writes a string into the buffer.

void nsIPipeListener::writeBuf ( in string  buf,
in unsigned long  count 
) [inherited]

Writes data into the buffer.

Data is a string of arbitrary bytes including NUL characters.

nsresult nsIPCBuffer::WriteTempOutStream ( const char *  buf,
PRUint32  count 
) [protected]

Definition at line 391 of file nsIPCBuffer.cpp.

{
  if (!mTempOutStream)
    return NS_ERROR_NOT_AVAILABLE;

  if (!count)
    return NS_OK;

  PRUint32 writeCount;
  nsresult rv = mTempOutStream->Write(buf, count, &writeCount);

  if (writeCount != count)
    return NS_ERROR_FAILURE;

  return rv;
}

Member Data Documentation

readonly attribute boolean nsIPipeListener::joinable [inherited]

true if console pipe thread may be terminated

Definition at line 65 of file nsIPipeListener.idl.

nsCString nsIPCBuffer::mByteBuf [protected]

Definition at line 115 of file nsIPCBuffer.h.

PRUint32 nsIPCBuffer::mByteCount [protected]

Definition at line 112 of file nsIPCBuffer.h.

Definition at line 100 of file nsIPCBuffer.h.

Definition at line 101 of file nsIPCBuffer.h.

mozilla::Mutex nsIPCBuffer::mLock [protected]

Definition at line 109 of file nsIPCBuffer.h.

PRInt32 nsIPCBuffer::mMaxBytes [protected]

Definition at line 111 of file nsIPCBuffer.h.

nsCOMPtr<nsIRequestObserver> nsIPCBuffer::mObserver [protected]

Definition at line 126 of file nsIPCBuffer.h.

nsCOMPtr<nsISupports> nsIPCBuffer::mObserverContext [protected]

Definition at line 127 of file nsIPCBuffer.h.

Definition at line 103 of file nsIPCBuffer.h.

Definition at line 104 of file nsIPCBuffer.h.

Definition at line 118 of file nsIPCBuffer.h.

nsCOMPtr<nsIThread> nsIPCBuffer::mPipeThread [protected]

Definition at line 125 of file nsIPCBuffer.h.

Definition at line 117 of file nsIPCBuffer.h.

Definition at line 106 of file nsIPCBuffer.h.

Definition at line 107 of file nsIPCBuffer.h.

PRUint32 nsIPCBuffer::mStreamOffset [protected]

Definition at line 113 of file nsIPCBuffer.h.

nsCOMPtr<nsIFile> nsIPCBuffer::mTempFile [protected]

Definition at line 120 of file nsIPCBuffer.h.

nsCOMPtr<nsIFileInputStream> nsIPCBuffer::mTempInStream [protected]

Definition at line 122 of file nsIPCBuffer.h.

nsCOMPtr<nsIFileOutputStream> nsIPCBuffer::mTempOutStream [protected]

Definition at line 121 of file nsIPCBuffer.h.

Definition at line 102 of file nsIPCBuffer.h.

readonly attribute boolean nsIPipeListener::overflowed [inherited]

True if data has been lost (i.e., getByteData does not return all data)

Definition at line 90 of file nsIPipeListener.idl.

readonly attribute boolean nsIIPCBuffer::stopped [inherited]

True if onStopRequest method of StreamListener has been invoked.

Definition at line 113 of file nsIIPCBuffer.idl.

readonly attribute unsigned long nsIIPCBuffer::totalBytes [inherited]

Count of total bytes in buffer (or overflow file)

Definition at line 118 of file nsIIPCBuffer.idl.


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