Back to index

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

Inherit from the concrete class nsBinaryInputStream, which inherits from abstract nsIObjectInputStream but does not implement its direct methods. More...

#include <nsFastLoadFile.h>

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

List of all members.

Classes

struct  nsFastLoadFooter
 In-memory representation of the FastLoad file footer. More...
struct  nsObjectMapEntry
 In-memory representation of an indexed nsFastLoadSharpObjectInfo record. More...

Public Member Functions

 nsFastLoadFileReader (nsIInputStream *aStream)
virtual ~nsFastLoadFileReader ()
nsISupports readObject (in PRBool aIsStrongRef)
 Read an object from this stream to satisfy a strong or weak reference to one of its interfaces.
nsresult readID (out nsID aID)
charPtr getBuffer (in PRUint32 aLength, in PRUint32 aAlignMask)
 Optimized deserialization support -- see nsIStreamBufferAccess.idl.
void putBuffer (in charPtr aBuffer, in PRUint32 aLength)
void setInputStream (in nsIInputStream aInputStream)
PRBool readBoolean ()
PRUint8 read8 ()
PRUint16 read16 ()
PRUint32 read32 ()
PRUint64 read64 ()
float readFloat ()
double readDouble ()
ACString readCString ()
 Read a NUL-terminated 8-bit char* string from a binary stream.
AString readString ()
 Read a NUL-terminated 16-bit PRUnichar* string from a binary stream.
void readBytes (in PRUint32 aLength,[size_is(aLength), retval] out string aString)
 Read an opaque byte array from a binary stream.
void readByteArray (in PRUint32 aLength,[array, size_is(aLength), retval] out PRUint8 aBytes)
 Read an opaque byte array from a binary stream, storing the results as an array of PRUint8s.
void close ()
 Close the stream.
unsigned long available ()
unsigned long read (in charPtr aBuf, in unsigned long aCount)
 Read data from the stream.
unsigned long readSegments (in nsWriteSegmentFun aWriter, in voidPtr aClosure, in unsigned long aCount)
 Low-level read method that has access to the stream's underlying buffer.
boolean isNonBlocking ()
PRUint32 computeChecksum ()
 Computes the correct checksum of the FastLoad file, independent of the header's checksum value.
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

readonly attribute
nsISimpleEnumerator 
dependencies
 Get the collection of dependency nsIFile instances recorded during the FastLoad file write or read/update process, and checked during the read process to invalidate the FastLoad file if any dependencies are newer.
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 Attributes

nsCOMPtr< nsISeekableStreammSeekableInput
nsFastLoadHeader mHeader
nsFastLoadFooter mFooter
nsDocumentMapReadEntrymCurrentDocumentMapEntry
NS_DECL_ISUPPORTS
NS_DECL_NSIINPUTSTREAM
NS_DECL_NSIBINARYINPUTSTREAM
NS_DECL_NSIOBJECTINPUTSTREAM
nsCOMPtr< nsIInputStream
mInputStream
nsCOMPtr< nsIStreamBufferAccessmBufferAccess

Private Member Functions

NS_DECL_ISUPPORTS_INHERITED
NS_IMETHOD 
ReadObject (PRBool aIsStrongRef, nsISupports **_retval)
NS_IMETHOD ReadID (nsID *aResult)
NS_DECL_NSIFASTLOADFILECONTROL
NS_DECL_NSIFASTLOADREADCONTROL
NS_DECL_NSISEEKABLESTREAM
NS_IMETHOD 
Read (char *aBuffer, PRUint32 aCount, PRUint32 *aBytesRead)
NS_IMETHODIMP ReadSegments (nsWriteSegmentFun aWriter, void *aClosure, PRUint32 aCount, PRUint32 *aResult)
NS_IMETHOD SetInputStream (nsIInputStream *aInputStream)
nsresult ReadHeader (nsFastLoadHeader *aHeader)
nsresult ReadFooter (nsFastLoadFooter *aFooter)
nsresult ReadFooterPrefix (nsFastLoadFooterPrefix *aFooterPrefix)
nsresult ReadSlowID (nsID *aID)
nsresult ReadFastID (NSFastLoadID *aID)
nsresult ReadSharpObjectInfo (nsFastLoadSharpObjectInfo *aInfo)
nsresult ReadMuxedDocumentInfo (nsFastLoadMuxedDocumentInfo *aInfo)
nsresult DeserializeObject (nsISupports **aObject)
nsresult Open ()
NS_IMETHOD Close ()

Friends

class nsFastLoadFileUpdater

Detailed Description

Inherit from the concrete class nsBinaryInputStream, which inherits from abstract nsIObjectInputStream but does not implement its direct methods.

Though the names are not as clear as I'd like, this seems to be the best way to share nsBinaryStream.cpp code.

Definition at line 257 of file nsFastLoadFile.h.


Constructor & Destructor Documentation

Definition at line 264 of file nsFastLoadFile.h.

Here is the call graph for this function:

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

Definition at line 270 of file nsFastLoadFile.h.


Member Function Documentation

unsigned long nsIInputStream::available ( ) [inherited]
Returns:
number of bytes currently available in the stream
void nsIInputStream::close ( ) [inherited]

Close the stream.

Definition at line 990 of file nsFastLoadFile.cpp.

{
    // Give up our strong "keepalive" references, in case not all objects that
    // were deserialized were fully re-connected.
    //
    // This happens for sure when an nsFastLoadFileUpdater is created and wraps
    // an nsFastLoadFileReader whose data was already deserialized by an earlier
    // FastLoad episode.  The reader is useful in the second such episode during
    // a session not so much for reading objects as for its footer information,
    // which primes the updater's tables so that after the update completes, the
    // FastLoad file has a superset footer.

    for (PRUint32 i = 0, n = mFooter.mNumSharpObjects; i < n; i++) {
        nsObjectMapEntry* entry = &mFooter.mObjectMap[i];
        entry->mReadObject = nsnull;
    }

    return mInputStream->Close();
}

Computes the correct checksum of the FastLoad file, independent of the header's checksum value.

The header checksum field is treated as zero when computing the checksum.

nsresult nsFastLoadFileReader::DeserializeObject ( nsISupports **  aObject) [private]

Definition at line 1011 of file nsFastLoadFile.cpp.

{
    nsresult rv;
    NSFastLoadID fastCID;

    rv = ReadFastID(&fastCID);
    if (NS_FAILED(rv))
        return rv;

    const nsID& slowCID = mFooter.GetID(fastCID);
    nsCOMPtr<nsISupports> object(do_CreateInstance(slowCID, &rv));
    if (NS_FAILED(rv))
        return rv;

    nsCOMPtr<nsISerializable> serializable(do_QueryInterface(object));
    if (!serializable)
        return NS_ERROR_FAILURE;

    rv = serializable->Read(this);
    if (NS_FAILED(rv))
        return rv;

    *aObject = object;
    NS_ADDREF(*aObject);
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIFastLoadFileControl::endMuxedDocument ( in nsISupports  aURI) [inherited]
charPtr nsIObjectInputStream::getBuffer ( in PRUint32  aLength,
in PRUint32  aAlignMask 
) [inherited]

Optimized deserialization 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

Definition at line 941 of file nsFastLoadFile.cpp.

{
    nsresult rv;

    // Don't bother buffering the header, as we immediately seek to EOF.
    if (mBufferAccess)
        mBufferAccess->DisableBuffering();

    rv = ReadHeader(&mHeader);

    if (mBufferAccess)
        mBufferAccess->EnableBuffering();
    if (NS_FAILED(rv))
        return rv;

    if (mHeader.mVersion != MFL_FILE_VERSION)
        return NS_ERROR_UNEXPECTED;
    if (mHeader.mFooterOffset == 0)
        return NS_ERROR_UNEXPECTED;

    rv = mSeekableInput->Seek(nsISeekableStream::NS_SEEK_END, 0);
    if (NS_FAILED(rv))
        return rv;

    PRInt64 fileSize;
    rv = mSeekableInput->Tell(&fileSize);
    if (NS_FAILED(rv))
        return rv;

    nsInt64 fileSize64 = fileSize;
    const nsInt64 maxUint32 = PR_UINT32_MAX;
    NS_ASSERTION(fileSize64 <= maxUint32, "fileSize must fit in 32 bits");
    if ((PRUint32) fileSize64 != mHeader.mFileSize)
        return NS_ERROR_UNEXPECTED;

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

    rv = ReadFooter(&mFooter);
    if (NS_FAILED(rv))
        return rv;

    return mSeekableInput->Seek(nsISeekableStream::NS_SEEK_SET,
                                sizeof(nsFastLoadHeader));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIObjectInputStream::putBuffer ( in charPtr  aBuffer,
in PRUint32  aLength 
) [inherited]
unsigned long nsIInputStream::read ( in charPtr  aBuf,
in unsigned long  aCount 
) [inherited]

Read data from the stream.

Parameters:
aBufthe buffer into which the data is to be read
aCountthe maximum number of bytes to be read
Returns:
number of bytes read (may be less than aCount).
0 if reached end of file
Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif reading from the input stream would block the calling thread (non-blocking mode only)
<other-error>on failure
NS_IMETHODIMP nsFastLoadFileReader::Read ( char *  aBuffer,
PRUint32  aCount,
PRUint32 aBytesRead 
) [private]

Definition at line 534 of file nsFastLoadFile.cpp.

{
    nsresult rv;

    nsDocumentMapReadEntry* entry = mCurrentDocumentMapEntry;
    if (entry) {
        // Don't call our Seek wrapper, as it clears mCurrentDocumentMapEntry.
        if (entry->mNeedToSeek) {
            rv = mSeekableInput->Seek(nsISeekableStream::NS_SEEK_SET,
                                      entry->mSaveOffset);
            if (NS_FAILED(rv))
                return rv;

            entry->mNeedToSeek = PR_FALSE;
        }

        // Loop to handle empty segments, which may be generated by the
        // writer, given Start A; Start B; Select A; Select B; write B data;
        // multiplexing schedules, which do tend to occur given non-blocking
        // i/o with LIFO scheduling.  XXXbe investigate LIFO issues
        while (entry->mBytesLeft == 0) {
            // Check for unexpected end of multiplexed stream.
            NS_ASSERTION(entry->mNextSegmentOffset != 0,
                         "document demuxed from FastLoad file more than once?");
            if (entry->mNextSegmentOffset == 0)
                return NS_ERROR_UNEXPECTED;

            rv = mSeekableInput->Seek(nsISeekableStream::NS_SEEK_SET,
                                      entry->mNextSegmentOffset);
            if (NS_FAILED(rv))
                return rv;

            // Clear mCurrentDocumentMapEntry temporarily to avoid recursion.
            mCurrentDocumentMapEntry = nsnull;

            rv = Read32(&entry->mNextSegmentOffset);
            if (NS_SUCCEEDED(rv)) {
                PRUint32 bytesLeft = 0;
                rv = Read32(&bytesLeft);
                entry->mBytesLeft = bytesLeft;
            }

            mCurrentDocumentMapEntry = entry;
            if (NS_FAILED(rv))
                return rv;

            NS_ASSERTION(entry->mBytesLeft >= 8, "demux segment length botch!");
            entry->mBytesLeft -= 8;
        }
    }

    rv = mInputStream->Read(aBuffer, aCount, aBytesRead);

    if (NS_SUCCEEDED(rv) && entry) {
        NS_ASSERTION(entry->mBytesLeft >= *aBytesRead, "demux Read underflow!");
        entry->mBytesLeft -= *aBytesRead;

#ifdef NS_DEBUG
        // Invariant: !entry->mBytesLeft implies entry->mSaveOffset == 0.
        if (entry->mBytesLeft == 0)
            entry->mSaveOffset = 0;
#endif
    }
    return rv;
}

Here is the caller graph for this function:

void nsIBinaryInputStream::readByteArray ( in PRUint32  aLength,
[array, size_is(aLength), retval] out PRUint8  aBytes 
) [inherited]

Read an opaque byte array from a binary stream, storing the results as an array of PRUint8s.

void nsIBinaryInputStream::readBytes ( in PRUint32  aLength,
[size_is(aLength), retval] out string  aString 
) [inherited]

Read an opaque byte array from a binary stream.

ACString nsIBinaryInputStream::readCString ( ) [inherited]

Read a NUL-terminated 8-bit char* string from a binary stream.

double nsIBinaryInputStream::readDouble ( ) [inherited]

Definition at line 891 of file nsFastLoadFile.cpp.

{
    nsresult rv = Read32(aID);
    if (NS_SUCCEEDED(rv))
        *aID ^= MFL_ID_XOR_KEY;
    return rv;
}

Here is the caller graph for this function:

float nsIBinaryInputStream::readFloat ( ) [inherited]

Definition at line 717 of file nsFastLoadFile.cpp.

{
    nsresult rv;

    rv = ReadFooterPrefix(aFooter);
    if (NS_FAILED(rv))
        return rv;

    aFooter->mIDMap = new nsID[aFooter->mNumIDs];
    if (!aFooter->mIDMap)
        return NS_ERROR_OUT_OF_MEMORY;

    PRUint32 i, n;
    for (i = 0, n = aFooter->mNumIDs; i < n; i++) {
        rv = ReadSlowID(&aFooter->mIDMap[i]);
        if (NS_FAILED(rv))
            return rv;
    }

    aFooter->mObjectMap = new nsObjectMapEntry[aFooter->mNumSharpObjects];
    if (!aFooter->mObjectMap)
        return NS_ERROR_OUT_OF_MEMORY;

    for (i = 0, n = aFooter->mNumSharpObjects; i < n; i++) {
        nsObjectMapEntry* entry = &aFooter->mObjectMap[i];

        rv = ReadSharpObjectInfo(entry);
        if (NS_FAILED(rv))
            return rv;

        entry->mReadObject = nsnull;
        entry->mSkipOffset = 0;
        entry->mSaveStrongRefCnt = entry->mStrongRefCnt;
        entry->mSaveWeakRefCnt = entry->mWeakRefCnt;
    }

    if (!PL_DHashTableInit(&aFooter->mDocumentMap, &strmap_DHashTableOps,
                           (void *)this, sizeof(nsDocumentMapReadEntry),
                           aFooter->mNumMuxedDocuments)) {
        aFooter->mDocumentMap.ops = nsnull;
        return NS_ERROR_OUT_OF_MEMORY;
    }

    if (!PL_DHashTableInit(&aFooter->mURIMap, &objmap_DHashTableOps,
                           (void *)this, sizeof(nsURIMapReadEntry),
                           aFooter->mNumMuxedDocuments)) {
        aFooter->mURIMap.ops = nsnull;
        return NS_ERROR_OUT_OF_MEMORY;
    }

    for (i = 0, n = aFooter->mNumMuxedDocuments; i < n; i++) {
        nsFastLoadMuxedDocumentInfo info;

        rv = ReadMuxedDocumentInfo(&info);
        if (NS_FAILED(rv))
            return rv;

        nsDocumentMapReadEntry* entry =
            NS_STATIC_CAST(nsDocumentMapReadEntry*,
                           PL_DHashTableOperate(&aFooter->mDocumentMap,
                                                info.mURISpec,
                                                PL_DHASH_ADD));
        if (!entry) {
            nsMemory::Free((void*) info.mURISpec);
            return NS_ERROR_OUT_OF_MEMORY;
        }

        NS_ASSERTION(!entry->mString, "duplicate URISpec in MuxedDocumentMap");
        entry->mString = info.mURISpec;
        entry->mURI = nsnull;
        entry->mInitialSegmentOffset = info.mInitialSegmentOffset;
        entry->mNextSegmentOffset = info.mInitialSegmentOffset;
        entry->mBytesLeft = 0;
        entry->mNeedToSeek = PR_FALSE;
        entry->mSaveOffset = 0;
    }

    nsCOMPtr<nsISupportsArray> readDeps;
    rv = NS_NewISupportsArray(getter_AddRefs(readDeps));
    if (NS_FAILED(rv))
        return rv;

    nsCAutoString filename;
    for (i = 0, n = aFooter->mNumDependencies; i < n; i++) {
        rv = ReadCString(filename);
        if (NS_FAILED(rv))
            return rv;

        PRInt64 fastLoadMtime;
        rv = Read64(NS_REINTERPRET_CAST(PRUint64*, &fastLoadMtime));
        if (NS_FAILED(rv))
            return rv;

        nsCOMPtr<nsILocalFile> file;
        rv = NS_NewNativeLocalFile(filename, PR_TRUE, getter_AddRefs(file));
        if (NS_FAILED(rv))
            return rv;

        PRInt64 currentMtime;
        rv = file->GetLastModifiedTime(&currentMtime);
        if (NS_FAILED(rv))
            return rv;

        if (LL_NE(fastLoadMtime, currentMtime)) {
#ifdef DEBUG
            nsCAutoString path;
            file->GetNativePath(path);
            printf("%s mtime changed, invalidating FastLoad file\n",
                   path.get());
#endif
            return NS_ERROR_FAILURE;
        }

        rv = readDeps->AppendElement(file);
        if (NS_FAILED(rv))
            return rv;
    }

    aFooter->mDependencies = readDeps;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 840 of file nsFastLoadFile.cpp.

{
    nsresult rv;

    rv = Read32(&aFooterPrefix->mNumIDs);
    if (NS_FAILED(rv))
        return rv;

    rv = Read32(&aFooterPrefix->mNumSharpObjects);
    if (NS_FAILED(rv))
        return rv;

    rv = Read32(&aFooterPrefix->mNumMuxedDocuments);
    if (NS_FAILED(rv))
        return rv;

    rv = Read32(&aFooterPrefix->mNumDependencies);
    if (NS_FAILED(rv))
        return rv;

    return NS_OK;
}

Here is the caller graph for this function:

Here is the caller graph for this function:

Definition at line 1185 of file nsFastLoadFile.cpp.

{
    nsresult rv;
    NSFastLoadID fastID;

    rv = ReadFastID(&fastID);
    if (NS_FAILED(rv))
        return rv;

    *aResult = mFooter.GetID(fastID);
    return NS_OK;
}

Here is the call graph for this function:

Definition at line 923 of file nsFastLoadFile.cpp.

{
    nsresult rv;

    nsCAutoString spec;
    rv = ReadCString(spec);
    if (NS_FAILED(rv))
        return rv;

    rv = Read32(&aInfo->mInitialSegmentOffset);
    if (NS_FAILED(rv))
        return rv;

    aInfo->mURISpec = ToNewCString(spec);
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsISupports nsIObjectInputStream::readObject ( in PRBool  aIsStrongRef) [inherited]

Read an object from this stream to satisfy a strong or weak reference to one of its interfaces.

If the interface was not along the primary inheritance chain ending in the "root" or XPCOM-identity nsISupports, readObject will QueryInterface from the deserialized object root to the correct interface, which was specified when the object was serialized.

See also:
nsIObjectOutputStream
nsresult nsFastLoadFileReader::ReadObject ( PRBool  aIsStrongRef,
nsISupports **  _retval 
) [private]

Definition at line 1039 of file nsFastLoadFile.cpp.

{
    nsresult rv;
    NSFastLoadOID oid;

    rv = Read32(&oid);
    if (NS_FAILED(rv))
        return rv;
    oid ^= MFL_OID_XOR_KEY;

    nsCOMPtr<nsISupports> object;

    if (oid == MFL_DULL_OBJECT_OID) {
        // A very dull object, defined at point of single (strong) reference.
        NS_ASSERTION(aIsStrongRef, "dull object read via weak ref!");

        rv = DeserializeObject(getter_AddRefs(object));
        if (NS_FAILED(rv))
            return rv;
    } else {
        NS_ASSERTION((oid & MFL_WEAK_REF_TAG) ==
                     (aIsStrongRef ? 0 : MFL_WEAK_REF_TAG),
                     "strong vs. weak ref deserialization mismatch!");

        nsObjectMapEntry* entry = &mFooter.GetSharpObjectEntry(oid);

        // Check whether we've already deserialized the object for this OID.
        object = entry->mReadObject;
        if (!object) {
            PRInt64 saveOffset;
            nsDocumentMapReadEntry* saveDocMapEntry = nsnull;

            rv = mSeekableInput->Tell(&saveOffset);
            if (NS_FAILED(rv))
                return rv;

            PRUint32 saveOffset32 = saveOffset;
            if (entry->mCIDOffset != saveOffset32) {
                // We skipped deserialization of this object from its position
                // earlier in the input stream, presumably due to the reference
                // there being an nsFastLoadPtr, or (more likely) because the
                // object was muxed in another document, and deserialization
                // order does not match serialization order.  So we must seek
                // back and read it now.
                NS_ASSERTION(entry->mCIDOffset < saveOffset32,
                             "out of order object?!");

                // Ape our Seek wrapper by clearing mCurrentDocumentMapEntry.
                // This allows for a skipped object to be referenced from two
                // or more multiplexed documents in the FastLoad file.
                saveDocMapEntry = mCurrentDocumentMapEntry;
                mCurrentDocumentMapEntry = nsnull;
                rv = mSeekableInput->Seek(nsISeekableStream::NS_SEEK_SET,
                                          entry->mCIDOffset);
                if (NS_FAILED(rv))
                    return rv;
            }

            rv = DeserializeObject(getter_AddRefs(object));
            if (NS_FAILED(rv))
                return rv;

            if (entry->mCIDOffset != saveOffset32) {
                // Save the "skip offset" in case we need to skip this object
                // definition when reading forward, later on.
                rv = mSeekableInput->Tell(&entry->mSkipOffset);
                if (NS_FAILED(rv))
                    return rv;

                // Restore stream offset and mCurrentDocumentMapEntry in case
                // we're still reading forward through a part of the multiplex
                // to get object definitions eagerly.
                rv = mSeekableInput->Seek(nsISeekableStream::NS_SEEK_SET,
                                          saveOffset);
                if (NS_FAILED(rv))
                    return rv;
                mCurrentDocumentMapEntry = saveDocMapEntry;
            }

            // Save object until all refs have been deserialized.
            entry->mReadObject = object;
        } else {
            // What if we are at a definition that's already been read?  This
            // case arises when a sharp object's def is serialized before its
            // refs, while a non-defining ref is deserialized before the def.
            // We must skip over the object definition.
            if (oid & MFL_OBJECT_DEF_TAG) {
                NS_ASSERTION(entry->mSkipOffset != 0, "impossible! see above");

                // Since we are seeking within a muxed segment, we must adjust
                // mBytesLeft, so that Seek called from Read will be triggered
                // when mBytesLeft goes to zero.
                PRInt64 currentOffset;
                rv = mSeekableInput->Tell(&currentOffset);
                if (NS_FAILED(rv))
                    return rv;

                NS_ASSERTION(entry->mSkipOffset > (PRUint32)currentOffset,
                             "skipping backwards from object?!");
                NS_ASSERTION(mCurrentDocumentMapEntry->mBytesLeft >=
                             entry->mSkipOffset - (PRUint32)currentOffset,
                             "skipped object buffer underflow!");

                mCurrentDocumentMapEntry->mBytesLeft -=
                    entry->mSkipOffset - (PRUint32)currentOffset;

                rv = mSeekableInput->Seek(nsISeekableStream::NS_SEEK_SET,
                                          entry->mSkipOffset);
                if (NS_FAILED(rv))
                    return rv;
            }
        }

        if (aIsStrongRef) {
            NS_ASSERTION(entry->mStrongRefCnt != 0,
                         "mStrongRefCnt underflow!");
            --entry->mStrongRefCnt;
        } else {
            NS_ASSERTION(MFL_GET_WEAK_REFCNT(entry) != 0,
                         "mWeakRefCnt underflow!");
            MFL_DROP_WEAK_REFCNT(entry);
        }

        if (entry->mStrongRefCnt == 0 && MFL_GET_WEAK_REFCNT(entry) == 0)
            entry->mReadObject = nsnull;
    }

    if (oid & MFL_QUERY_INTERFACE_TAG) {
        NSFastLoadID iid;
        rv = ReadFastID(&iid);
        if (NS_FAILED(rv))
            return rv;

        rv = object->QueryInterface(mFooter.GetID(iid),
                                    NS_REINTERPRET_CAST(void**, aObject));
        if (NS_FAILED(rv))
            return rv;
    } else {
        *aObject = object;
        NS_ADDREF(*aObject);
    }

    return NS_OK;
}

Here is the call graph for this function:

unsigned long nsIInputStream::readSegments ( in nsWriteSegmentFun  aWriter,
in voidPtr  aClosure,
in unsigned long  aCount 
) [inherited]

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

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

Parameters:
aWriterthe "consumer" of the data to be read
aClosureopaque parameter passed to writer
aCountthe maximum number of bytes to be read
Returns:
number of bytes read (may be less than aCount)
0 if reached end of file (or if aWriter refused to consume data)
Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif reading from the input 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 input stream).

NS_IMETHODIMP nsFastLoadFileReader::ReadSegments ( nsWriteSegmentFun  aWriter,
void aClosure,
PRUint32  aCount,
PRUint32 aResult 
) [private]

Definition at line 601 of file nsFastLoadFile.cpp.

{
    nsDocumentMapReadEntry* entry = mCurrentDocumentMapEntry;

    NS_ASSERTION(!entry || (!entry->mNeedToSeek && entry->mBytesLeft != 0),
                 "ReadSegments called from above nsFastLoadFileReader layer?!");

    nsresult rv = nsBinaryInputStream::ReadSegments(aWriter, aClosure, aCount,
                                                    aResult);
    if (NS_SUCCEEDED(rv) && entry) {
        NS_ASSERTION(entry->mBytesLeft >= *aResult,
                     "demux ReadSegments underflow!");
        entry->mBytesLeft -= *aResult;

#ifdef NS_DEBUG
        // Invariant: !entry->mBytesLeft implies entry->mSaveOffset == 0.
        if (entry->mBytesLeft == 0)
            entry->mSaveOffset = 0;
#endif
    }
    return rv;
}

Definition at line 900 of file nsFastLoadFile.cpp.

{
    nsresult rv;

    rv = Read32(&aInfo->mCIDOffset);
    if (NS_FAILED(rv))
        return rv;

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

    rv = Read16(&aInfo->mStrongRefCnt);
    if (NS_FAILED(rv))
        return rv;

    rv = Read16(&aInfo->mWeakRefCnt);
    if (NS_FAILED(rv))
        return rv;

    return NS_OK;
}

Here is the caller graph for this function:

Definition at line 864 of file nsFastLoadFile.cpp.

{
    nsresult rv;

    rv = Read32(&aID->m0);
    if (NS_FAILED(rv))
        return rv;

    rv = Read16(&aID->m1);
    if (NS_FAILED(rv))
        return rv;

    rv = Read16(&aID->m2);
    if (NS_FAILED(rv))
        return rv;

    PRUint32 bytesRead;
    rv = Read(NS_REINTERPRET_CAST(char*, aID->m3), sizeof aID->m3, &bytesRead);
    if (NS_FAILED(rv))
        return rv;

    if (bytesRead != sizeof aID->m3)
        return NS_ERROR_FAILURE;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

AString nsIBinaryInputStream::readString ( ) [inherited]

Read a NUL-terminated 16-bit PRUnichar* string from a binary stream.

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.

Definition at line 626 of file nsFastLoadFile.cpp.

{
    nsresult rv = nsBinaryInputStream::SetInputStream(aInputStream);
    mSeekableInput = do_QueryInterface(aInputStream);
    NS_ASSERTION(!mInputStream || mSeekableInput,
                 "FastLoad requires a seekable input stream");
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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.


Friends And Related Function Documentation

friend class nsFastLoadFileUpdater [friend]

Definition at line 399 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.

Get the collection of dependency nsIFile instances recorded during the FastLoad file write or read/update process, and checked during the read process to invalidate the FastLoad file if any dependencies are newer.

Definition at line 111 of file nsIFastLoadFileControl.idl.

Definition at line 122 of file nsBinaryStream.h.

Definition at line 397 of file nsFastLoadFile.h.

Definition at line 395 of file nsFastLoadFile.h.

Definition at line 394 of file nsFastLoadFile.h.

NS_DECL_ISUPPORTS NS_DECL_NSIINPUTSTREAM NS_DECL_NSIBINARYINPUTSTREAM NS_DECL_NSIOBJECTINPUTSTREAM nsCOMPtr<nsIInputStream> nsBinaryInputStream::mInputStream [protected, inherited]

Definition at line 106 of file nsBinaryStream.h.

Definition at line 392 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.


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