Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Friends
nsFastLoadFileUpdater Class Reference

Subclass of nsFastLoadFileWriter, friend of nsFastLoadFileReader which it wraps when a FastLoad file needs to be updated. More...

#include <nsFastLoadFile.h>

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

List of all members.

Public Member Functions

 nsFastLoadFileUpdater (nsIOutputStream *aOutputStream)
virtual ~nsFastLoadFileUpdater ()
void writeObject (in nsISupports aObject, in PRBool aIsStrongRef)
 Write the object whose "root" or XPCOM-identity nsISupports is aObject.
void writeSingleRefObject (in nsISupports aObject)
 Write an object referenced singly and strongly via its root nsISupports or a subclass of its root nsISupports.
void writeCompoundObject (in nsISupports aObject, in nsIIDRef aIID, in PRBool aIsStrongRef)
 Write the object referenced by an interface pointer at aObject that inherits from a non-primary nsISupports, i.e., a reference to one of the multiply inherited interfaces derived from an nsISupports other than the root or XPCOM-identity nsISupports; or a reference to an inner object in the case of true XPCOM aggregation.
void writeID (in nsIDRef aID)
charPtr getBuffer (in PRUint32 aLength, in PRUint32 aAlignMask)
 Optimized serialization support -- see nsIStreamBufferAccess.idl.
void putBuffer (in charPtr aBuffer, in PRUint32 aLength)
void setOutputStream (in nsIOutputStream aOutputStream)
void writeBoolean (in PRBool aBoolean)
void write8 (in PRUint8 aByte)
void write16 (in PRUint16 a16)
void write32 (in PRUint32 a32)
void write64 (in PRUint64 a64)
void writeFloat (in float aFloat)
void writeDouble (in double aDouble)
void writeStringZ (in string aString)
 Write a NUL-terminated 8-bit char* string to a binary stream.
void writeWStringZ (in wstring aString)
 Write a NUL-terminated 16-bit PRUnichar* string to a binary stream.
void writeUtf8Z (in wstring aString)
 Write a NUL-terminated UTF8-encoded string to a binary stream, produced from a NUL-terminated 16-bit PRUnichar* string argument.
void writeBytes ([size_is(aLength)] in string aString, in PRUint32 aLength)
 Write an opaque byte array to a binary stream.
void writeByteArray ([array, size_is(aLength)] in PRUint8 aBytes, in PRUint32 aLength)
 Write an opaque byte array to a binary stream.
void close ()
 Close the stream.
void flush ()
 Flush the stream.
unsigned long write (in string aBuf, in unsigned long aCount)
 Write data into the stream.
unsigned long writeFrom (in nsIInputStream aFromStream, in unsigned long aCount)
 Writes data into the stream from an input stream.
unsigned long writeSegments (in nsReadSegmentFun aReader, in voidPtr aClosure, in unsigned long aCount)
 Low-level write method that has access to the stream's underlying buffer.
boolean isNonBlocking ()
void addDependency (in nsIFile aFile)
 Add a file dependency of the FastLoad file (e.g., a .jar file) to the set of dependencies that trigger regeneration if any dependency has a last-modified-time greater than the FastLoad file's mtime.
void startMuxedDocument (in nsISupports aURI, in string aURISpec)
 Multiplexed document control methods.
nsISupports selectMuxedDocument (in nsISupports aURI)
void endMuxedDocument (in nsISupports aURI)
boolean hasMuxedDocument (in string aURISpec)
 Return true if aURISpec identifies a muxed document in the FastLoad file, false otherwise.
void seek (in long whence, in long long offset)
 seek
long long tell ()
 tell
void setEOF ()
 setEOF

Public Attributes

attribute PRUint32 checksum
 Get and set the recorded checksum value from the FastLoad file header.
const PRInt32 NS_SEEK_SET = 0
const PRInt32 NS_SEEK_CUR = 1
const PRInt32 NS_SEEK_END = 2

Protected Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIOUTPUTSTREAM
NS_DECL_NSIBINARYOUTPUTSTREAM
NS_DECL_NSIOBJECTOUTPUTSTREAM
nsresult 
WriteFully (const char *aBuf, PRUint32 aCount)

Protected Attributes

nsCOMPtr< nsIInputStreammInputStream
nsCOMPtr< nsISeekableStreammSeekableInput
nsCOMPtr< nsISeekableStreammSeekableOutput
nsFastLoadHeader mHeader
PLDHashTable mIDMap
PLDHashTable mObjectMap
PLDHashTable mDocumentMap
PLDHashTable mURIMap
PLDHashTable mDependencyMap
nsDocumentMapWriteEntrymCurrentDocumentMapEntry
nsCOMPtr< nsIFastLoadFileIOmFileIO
nsCOMPtr< nsIOutputStreammOutputStream
nsCOMPtr< nsIStreamBufferAccessmBufferAccess

Private Member Functions

NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIFASTLOADFILEIO
nsresult 
Open (nsFastLoadFileReader *aReader)
NS_IMETHOD Close ()

Static Private Member Functions

static PLDHashOperator PR_CALLBACK CopyReadDocumentMapEntryToUpdater (PLDHashTable *aTable, PLDHashEntryHdr *aHdr, PRUint32 aNumber, void *aData)

Private Attributes

readonly attribute nsIInputStream inputStream
readonly attribute nsIOutputStream outputStream

Friends

class nsFastLoadFileReader

Detailed Description

Subclass of nsFastLoadFileWriter, friend of nsFastLoadFileReader which it wraps when a FastLoad file needs to be updated.

The wrapped reader can be used to demulitplex data for documents already in the FastLoad file, while the updater writes new data over the old footer, then writes a new footer that maps all data on Close.

Definition at line 538 of file nsFastLoadFile.h.


Constructor & Destructor Documentation

Definition at line 543 of file nsFastLoadFile.h.

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

Definition at line 548 of file nsFastLoadFile.h.


Member Function Documentation

Add a file dependency of the FastLoad file (e.g., a .jar file) to the set of dependencies that trigger regeneration if any dependency has a last-modified-time greater than the FastLoad file's mtime.

void nsIOutputStream::close ( ) [inherited]

Close the stream.

Forces the output stream to flush any buffered data.

Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif unable to flush without blocking the calling thread (non-blocking mode only)

Reimplemented from nsFastLoadFileWriter.

Definition at line 2558 of file nsFastLoadFile.cpp.

{
    // Call base-class Close implementation, which uses mFileIO.
    nsresult rv = nsFastLoadFileWriter::Close();

    // Break degenerate cycle from this->mFileIO to this.
    mFileIO = nsnull;
    return rv;
}

Definition at line 2354 of file nsFastLoadFile.cpp.

{
    nsDocumentMapReadEntry* readEntry =
        NS_STATIC_CAST(nsDocumentMapReadEntry*, aHdr);
    nsFastLoadFileUpdater* updater =
        NS_REINTERPRET_CAST(nsFastLoadFileUpdater*, aData);

    void* spec = nsMemory::Clone(readEntry->mString,
                                 strlen(readEntry->mString) + 1);
    if (!spec)
        return PL_DHASH_STOP;

    nsDocumentMapWriteEntry* writeEntry =
        NS_STATIC_CAST(nsDocumentMapWriteEntry*,
                       PL_DHashTableOperate(&updater->mDocumentMap, spec,
                                            PL_DHASH_ADD));
    if (!writeEntry) {
        nsMemory::Free(spec);
        return PL_DHASH_STOP;
    }

    writeEntry->mString = NS_REINTERPRET_CAST(const char*, spec);
    writeEntry->mURI = nsnull;
    writeEntry->mInitialSegmentOffset = readEntry->mInitialSegmentOffset;
    writeEntry->mCurrentSegmentOffset = 0;
    return PL_DHASH_NEXT;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIFastLoadFileControl::endMuxedDocument ( in nsISupports  aURI) [inherited]
void nsIOutputStream::flush ( ) [inherited]

Flush the stream.

Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif unable to flush without blocking the calling thread (non-blocking mode only)
charPtr nsIObjectOutputStream::getBuffer ( in PRUint32  aLength,
in PRUint32  aAlignMask 
) [inherited]

Optimized serialization support -- see nsIStreamBufferAccess.idl.

Return true if aURISpec identifies a muxed document in the FastLoad file, false otherwise.

Returns:
true if stream is non-blocking

NOTE: writing to a blocking output stream will block the calling thread until all given data can be consumed by the stream.

Definition at line 2386 of file nsFastLoadFile.cpp.

{
    nsresult rv;
    rv = nsFastLoadFileWriter::Init();
    if (NS_FAILED(rv))
        return rv;

    PRUint32 i, n;

    // Map from dense, zero-based, uint32 NSFastLoadID in reader to 16-byte
    // nsID in updater.
    nsID* readIDMap = aReader->mFooter.mIDMap;
    for (i = 0, n = aReader->mFooter.mNumIDs; i < n; i++) {
        NSFastLoadID fastID;
        rv = MapID(readIDMap[i], &fastID);
        NS_ASSERTION(fastID == i + 1, "huh?");
        if (NS_FAILED(rv))
            return rv;
    }

    // Map from reader dense, zero-based MFL_OID_TO_SHARP_INDEX(oid) to sharp
    // object offset and refcnt information in updater.
    nsFastLoadFileReader::nsObjectMapEntry* readObjectMap =
        aReader->mFooter.mObjectMap;

    // Prepare to save aReader state in case we need to seek back and read a
    // singleton object that might otherwise get written by this updater.
    nsDocumentMapReadEntry* saveDocMapEntry = nsnull;
    nsISeekableStream* inputSeekable = nsnull;
    PRInt64 saveOffset = 0;

    for (i = 0, n = aReader->mFooter.mNumSharpObjects; i < n; i++) {
        nsFastLoadFileReader::nsObjectMapEntry* readEntry = &readObjectMap[i];

        NS_ASSERTION(readEntry->mCIDOffset != 0,
                     "fastload updater: mCIDOffset cannot be zero!");

        // If the reader didn't read this object but it's a singleton, we must
        // "deserialize" it now, to discover its one and only root nsISupports
        // address.  The object already exists in memory if it was created at
        // startup without resort to the FastLoad file.  The canonical example
        // is the system principal object held by all XUL JS scripts.

        nsISupports* obj = readEntry->mReadObject;
        if (!obj && MFL_GET_SINGLETON_FLAG(readEntry)) {
            if (!saveDocMapEntry) {
                inputSeekable = aReader->mSeekableInput;
                rv = inputSeekable->Tell(&saveOffset);
                if (NS_FAILED(rv))
                    return rv;

                saveDocMapEntry = aReader->mCurrentDocumentMapEntry;
                aReader->mCurrentDocumentMapEntry = nsnull;
            }

            rv = inputSeekable->Seek(nsISeekableStream::NS_SEEK_SET,
                                     readEntry->mCIDOffset);
            if (NS_FAILED(rv))
                return rv;

            rv = aReader
                 ->DeserializeObject(getter_AddRefs(readEntry->mReadObject));
            if (NS_FAILED(rv))
                return rv;
            obj = readEntry->mReadObject;

            // Don't forget to set mSkipOffset in case someone calls the reader
            // to "deserialize" (yet again) the object we just read.
            //
            // Say the singleton is the system principal, and the FastLoad file
            // contains data for navigator.xul including scripts and functions.
            // If we update the FastLoad file to contain data for messenger.xul
            // in a separate session started via mozilla -mail, *and during the
            // same FastLoad episode in this session* race to open a navigator
            // window, we will attempt to read all objects serialized in the
            // navigator.xul portion of the FastLoad file.
            //
            // mSkipOffset must be set in such a case so the reader can skip
            // the system principal's serialized data, because the updater for
            // messenger.xul being opened here has already read it.

            rv = inputSeekable->Tell(&readEntry->mSkipOffset);
            if (NS_FAILED(rv))
                return rv;
        }

        NSFastLoadOID oid = MFL_SHARP_INDEX_TO_OID(i);
        void* key = obj
                    ? NS_REINTERPRET_CAST(void*, obj)
                    : NS_REINTERPRET_CAST(void*, (oid | MFL_OBJECT_DEF_TAG));

        nsSharpObjectMapEntry* writeEntry =
            NS_STATIC_CAST(nsSharpObjectMapEntry*,
                           PL_DHashTableOperate(&mObjectMap, key,
                                                PL_DHASH_ADD));
        if (!writeEntry)
            return NS_ERROR_OUT_OF_MEMORY;

        // Hold the object if there is one, so that objmap_ClearEntry can
        // release the reference.
        NS_IF_ADDREF(obj);
        writeEntry->mObject = NS_REINTERPRET_CAST(nsISupports*, key);
        writeEntry->mOID = oid;
        writeEntry->mInfo.mCIDOffset = readEntry->mCIDOffset;
        writeEntry->mInfo.mStrongRefCnt = readEntry->mSaveStrongRefCnt;
        writeEntry->mInfo.mWeakRefCnt = readEntry->mSaveWeakRefCnt;
    }

    // If we had to read any singletons, restore aReader's saved state.
    if (saveDocMapEntry) {
        rv = inputSeekable->Seek(nsISeekableStream::NS_SEEK_SET, saveOffset);
        if (NS_FAILED(rv))
            return rv;

        aReader->mCurrentDocumentMapEntry = saveDocMapEntry;
    }

    // Copy URI spec string and initial segment offset in FastLoad file from
    // nsDocumentMapReadEntry in reader to nsDocumentMapWriteEntry in updater.
    // If we didn't enumerate all entries, we ran out of memory.
    n = PL_DHashTableEnumerate(&aReader->mFooter.mDocumentMap,
                               CopyReadDocumentMapEntryToUpdater,
                               this);
    if (n != aReader->mFooter.mDocumentMap.entryCount)
        return NS_ERROR_OUT_OF_MEMORY;

    // Copy source filename dependencies from reader to updater.
    nsISupportsArray* readDeps = aReader->mFooter.mDependencies;
    rv = readDeps->Count(&n);
    if (NS_FAILED(rv))
        return rv;

    for (i = 0; i < n; i++) {
        nsCOMPtr<nsIFile> file;
        rv = readDeps->GetElementAt(i, getter_AddRefs(file));
        if (NS_FAILED(rv))
            return rv;

        rv = AddDependency(file);
        if (NS_FAILED(rv))
            return rv;
    }

    // Seek to the reader's footer offset so we overwrite the footer.  First,
    // update the header to have a zero mFooterOffset, which will invalidate
    // the FastLoad file on next startup read attempt, should we crash before
    // completing this update.
    rv = mSeekableOutput->Seek(nsISeekableStream::NS_SEEK_SET,
                               offsetof(nsFastLoadHeader, mFooterOffset));
    if (NS_FAILED(rv))
        return rv;

    rv = Write32(0);
    if (NS_FAILED(rv))
        return rv;

    rv = mSeekableOutput->Seek(nsISeekableStream::NS_SEEK_SET,
                               aReader->mHeader.mFooterOffset);
    if (NS_FAILED(rv))
        return rv;

    // Avoid creating yet another object by implementing nsIFastLoadFileIO on
    // this updater, and save aReader's input stream so it can be returned by
    // GetInputStream called from nsFastLoadFileWriter::Close.  This requires
    // that we override Close to break the resulting zero-length cycle.
    mFileIO = this;
    mInputStream = aReader->mInputStream;
    mSeekableInput = aReader->mSeekableInput;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIObjectOutputStream::putBuffer ( in charPtr  aBuffer,
in PRUint32  aLength 
) [inherited]
void nsISeekableStream::seek ( in long  whence,
in long long  offset 
) [inherited]

seek

This method moves the stream offset of the steam implementing this interface.

Parameters:
whencespecifies how to interpret the 'offset' parameter in setting the stream offset associated with the implementing stream.
offsetspecifies a value, in bytes, that is used in conjunction with the 'whence' parameter to set the stream offset of the implementing stream. A negative value causes seeking in the reverse direction.
nsISupports nsIFastLoadFileControl::selectMuxedDocument ( in nsISupports  aURI) [inherited]

setEOF

This method truncates the stream at the current offset.

void nsIFastLoadFileControl::startMuxedDocument ( in nsISupports  aURI,
in string  aURISpec 
) [inherited]

Multiplexed document control methods.

A FastLoad file may contain multiple interleaved documents identified by a URI specifier string, and indexed for fast multiplexor select by an opaque URI object key. You StartMuxedDocument when initiating a document load, then Select before every batch of calls to (de)serialize document data, and End when the load completes.

Document multiplexing is necessary to support incremental FastLoad development in a non-blocking i/o architecture such as Mozilla, where some (but not all, at first, or for a while during development) of the results of parsing and compiling various inputs can be multiplexed to or from a FastLoad file.

Note: Select returns the previously selected URI object in case the caller is synchronously selecting and writing data to the FastLoad file, so the caller can reselect the previous URI and return to code the continues to write FastLoad data for the previous URI, unaware of the nested select/write/reselect.

tell

This method reports the current offset, in bytes, from the start of the stream.

unsigned long nsIOutputStream::write ( in string  aBuf,
in unsigned long  aCount 
) [inherited]

Write data into the stream.

Parameters:
aBufthe buffer containing the data to be written
aCountthe maximum number of bytes to be written
Returns:
number of bytes written (may be less than aCount)
Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif writing to the output stream would block the calling thread (non-blocking mode only)
<other-error>on failure
void nsIBinaryOutputStream::write8 ( in PRUint8  aByte) [inherited]
void nsIBinaryOutputStream::writeByteArray ( [array, size_is(aLength)] in PRUint8  aBytes,
in PRUint32  aLength 
) [inherited]

Write an opaque byte array to a binary stream.

void nsIBinaryOutputStream::writeBytes ( [size_is(aLength)] in string  aString,
in PRUint32  aLength 
) [inherited]

Write an opaque byte array to a binary stream.

void nsIObjectOutputStream::writeCompoundObject ( in nsISupports  aObject,
in nsIIDRef  aIID,
in PRBool  aIsStrongRef 
) [inherited]

Write the object referenced by an interface pointer at aObject that inherits from a non-primary nsISupports, i.e., a reference to one of the multiply inherited interfaces derived from an nsISupports other than the root or XPCOM-identity nsISupports; or a reference to an inner object in the case of true XPCOM aggregation.

aIID identifies this interface.

void nsIBinaryOutputStream::writeDouble ( in double  aDouble) [inherited]
void nsIBinaryOutputStream::writeFloat ( in float  aFloat) [inherited]
unsigned long nsIOutputStream::writeFrom ( in nsIInputStream  aFromStream,
in unsigned long  aCount 
) [inherited]

Writes data into the stream from an input stream.

Parameters:
aFromStreamthe stream containing the data to be written
aCountthe maximum number of bytes to be written
Returns:
number of bytes written (may be less than aCount)
Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif writing to the output stream would block the calling thread (non-blocking mode only)
<other-error>on failure

NOTE: This method is defined by this interface in order to allow the output stream to efficiently copy the data from the input stream into its internal buffer (if any). If this method was provided as an external facility, a separate char* buffer would need to be used in order to call the output stream's other Write method.

nsresult nsBinaryOutputStream::WriteFully ( const char *  aBuf,
PRUint32  aCount 
) [protected, inherited]

Definition at line 97 of file nsBinaryStream.cpp.

{
    nsresult rv;
    PRUint32 bytesWritten;

    rv = mOutputStream->Write(aBuf, aCount, &bytesWritten);
    if (NS_FAILED(rv)) return rv;
    if (bytesWritten != aCount)
        return NS_ERROR_FAILURE;
    return NS_OK;
}
void nsIObjectOutputStream::writeID ( in nsIDRef  aID) [inherited]
void nsIObjectOutputStream::writeObject ( in nsISupports  aObject,
in PRBool  aIsStrongRef 
) [inherited]

Write the object whose "root" or XPCOM-identity nsISupports is aObject.

The cause for writing this object is a strong or weak reference, so the aIsStrongRef argument must tell which kind of pointer is being followed here during serialization.

If the object has only one strong reference in the serialization and no weak refs, use writeSingleRefObject. This is a valuable optimization: it saves space in the stream, and cycles on both ends of the process.

If the reference being serialized is a pointer to an interface not on the primary inheritance chain ending in the root nsISupports, you must call writeCompoundObject instead of this method.

unsigned long nsIOutputStream::writeSegments ( in nsReadSegmentFun  aReader,
in voidPtr  aClosure,
in unsigned long  aCount 
) [inherited]

Low-level write method that has access to the stream's underlying buffer.

The reader function may be called multiple times for segmented buffers. WriteSegments is expected to keep calling the reader until either there is nothing left to write or the reader returns an error. WriteSegments should not call the reader with zero bytes to provide.

Parameters:
aReaderthe "provider" of the data to be written
aClosureopaque parameter passed to reader
aCountthe maximum number of bytes to be written
Returns:
number of bytes written (may be less than aCount)
Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif writing to the output stream would block the calling thread (non-blocking mode only)
<other-error>on failure

NOTE: this function may be unimplemented if a stream has no underlying buffer (e.g., socket output stream).

void nsIObjectOutputStream::writeSingleRefObject ( in nsISupports  aObject) [inherited]

Write an object referenced singly and strongly via its root nsISupports or a subclass of its root nsISupports.

There must not be other refs to aObject in memory, or in the serialization.

Write a NUL-terminated 8-bit char* string to a binary stream.

void nsIBinaryOutputStream::writeUtf8Z ( in wstring  aString) [inherited]

Write a NUL-terminated UTF8-encoded string to a binary stream, produced from a NUL-terminated 16-bit PRUnichar* string argument.

void nsIBinaryOutputStream::writeWStringZ ( in wstring  aString) [inherited]

Write a NUL-terminated 16-bit PRUnichar* string to a binary stream.


Friends And Related Function Documentation

friend class nsFastLoadFileReader [friend]

Definition at line 568 of file nsFastLoadFile.h.


Member Data Documentation

Get and set the recorded checksum value from the FastLoad file header.

Definition at line 63 of file nsIFastLoadFileControl.idl.

Definition at line 52 of file nsIFastLoadService.idl.

Definition at line 85 of file nsBinaryStream.h.

Definition at line 522 of file nsFastLoadFile.h.

Definition at line 520 of file nsFastLoadFile.h.

Definition at line 518 of file nsFastLoadFile.h.

Definition at line 523 of file nsFastLoadFile.h.

Definition at line 514 of file nsFastLoadFile.h.

Definition at line 516 of file nsFastLoadFile.h.

Definition at line 571 of file nsFastLoadFile.h.

Definition at line 517 of file nsFastLoadFile.h.

Definition at line 84 of file nsBinaryStream.h.

Definition at line 574 of file nsFastLoadFile.h.

Definition at line 512 of file nsFastLoadFile.h.

Definition at line 519 of file nsFastLoadFile.h.

Definition at line 62 of file nsISeekableStream.idl.

Definition at line 68 of file nsISeekableStream.idl.

Definition at line 56 of file nsISeekableStream.idl.

Definition at line 53 of file nsIFastLoadService.idl.


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