Back to index

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

#include <nsUUIDGenerator.h>

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

List of all members.

Public Member Functions

 nsUUIDGenerator ()
virtual ~nsUUIDGenerator ()
NS_DECL_ISUPPORTS
NS_DECL_NSIUUIDGENERATOR
nsresult 
Init ()
nsIDPtr generateUUID ()
 Obtains a new UUID using appropriate platform-specific methods to obtain a nsID that can be considered to be globally unique.
void generateUUIDInPlace (in nsNonConstIDPtr id)
 Obtain a new UUID like the generateUUID method, but place it in the provided nsID pointer instead of allocating a new nsID.

Protected Attributes

PRLockmLock
char mState [32]
char * mSavedState
PRUint8 mRBytes

Detailed Description

Definition at line 45 of file nsUUIDGenerator.h.


Constructor & Destructor Documentation

Definition at line 57 of file nsUUIDGenerator.cpp.

    : mLock(nsnull)
{
}

Definition at line 62 of file nsUUIDGenerator.cpp.

{
    if (mLock) {
        PR_DestroyLock(mLock);
    }
}

Here is the call graph for this function:


Member Function Documentation

nsIDPtr nsIUUIDGenerator::generateUUID ( ) [inherited]

Obtains a new UUID using appropriate platform-specific methods to obtain a nsID that can be considered to be globally unique.

Returns:
an nsID filled in with a new UUID.
Exceptions:
NS_ERROR_FAILUREif a UUID cannot be generated (e.g. if an underlying source of randomness is not available)

Obtain a new UUID like the generateUUID method, but place it in the provided nsID pointer instead of allocating a new nsID.

Parameters:
idan existing nsID pointer where the UUID will be stored.
Exceptions:
NS_ERROR_FAILUREif a UUID cannot be generated (e.g. if an underlying source of randomness is not available)

Definition at line 70 of file nsUUIDGenerator.cpp.

{
    mLock = PR_NewLock();

    NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);

    // No need to acquire our lock while we mess with stuff here.  If we can't
    // depend on reasonable locking around Init we're screwed with the
    // assign-and-check above, anyway.
    
#if !defined(XP_WIN) && !defined(XP_MACOSX)
    /* initialize random number generator using NSPR random noise */
    unsigned int seed;

    PRSize bytes = 0;
    while (bytes < sizeof(seed)) {
        PRSize nbytes = PR_GetRandomNoise(((unsigned char *)&seed)+bytes,
                                          sizeof(seed)-bytes);
        if (nbytes == 0) {
            return NS_ERROR_FAILURE;
        }
        bytes += nbytes;
    }

    /* Initialize a new RNG state, and immediately switch
     * back to the previous one -- we want to use mState
     * only for our own calls to random().
     */
    mSavedState = initstate(seed, mState, sizeof(mState));
    setstate(mSavedState);

    mRBytes = 4;
#ifdef RAND_MAX
    if ((unsigned long) RAND_MAX < (unsigned long)0xffffffff)
        mRBytes = 3;
    if ((unsigned long) RAND_MAX < (unsigned long)0x00ffffff)
        mRBytes = 2;
    if ((unsigned long) RAND_MAX < (unsigned long)0x0000ffff)
        mRBytes = 1;
    if ((unsigned long) RAND_MAX < (unsigned long)0x000000ff)
        return NS_ERROR_FAILURE;
#endif

#endif /* non XP_WIN and non XP_MACOSX */

    return NS_OK;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 58 of file nsUUIDGenerator.h.

Definition at line 62 of file nsUUIDGenerator.h.

char* nsUUIDGenerator::mSavedState [protected]

Definition at line 61 of file nsUUIDGenerator.h.

char nsUUIDGenerator::mState[32] [protected]

Definition at line 60 of file nsUUIDGenerator.h.


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