Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
nsConsoleService Class Reference

#include <nsConsoleService.h>

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

List of all members.

Public Member Functions

 nsConsoleService ()
nsresult Init ()
void reset ()
 Clear the message buffer (e.g.
void logMessage (in nsIConsoleMessage message)
void logStringMessage (in wstring message)
 Convenience method for logging simple messages.
void getMessageArray ([array, size_is(count)] out nsIConsoleMessage messages, out PRUint32 count)
 Get an array of all the messages logged so far.
void registerListener (in nsIConsoleListener listener)
 To guard against stack overflows from listeners that could log messages (it's easy to do this inadvertently from listeners implemented in JavaScript), we don't call any listeners when another error is already being logged.
void unregisterListener (in nsIConsoleListener listener)
 Each registered listener should also be unregistered.

Private Member Functions

 ~nsConsoleService ()
nsresult GetProxyForListener (nsIConsoleListener *aListener, nsIConsoleListener **aProxy)

Private Attributes

nsIConsoleMessage ** mMessages
PRUint32 mBufferSize
PRUint32 mCurrent
PRBool mFull
nsSupportsHashtable mListeners
PRBool mListening
PRLockmLock

Detailed Description

Definition at line 51 of file nsConsoleService.h.


Constructor & Destructor Documentation

Definition at line 63 of file nsConsoleService.cpp.

    : mMessages(nsnull), mCurrent(0), mFull(PR_FALSE), mListening(PR_FALSE), mLock(nsnull)
{
    // XXX grab this from a pref!
    // hm, but worry about circularity, bc we want to be able to report
    // prefs errs...
    mBufferSize = 250;
}

Definition at line 72 of file nsConsoleService.cpp.

{
    PRUint32 i = 0;
    while (i < mBufferSize && mMessages[i] != nsnull) {
        NS_RELEASE(mMessages[i]);
        i++;
    }

#ifdef DEBUG_mccabe
    if (mListeners.Count() != 0) {
        fprintf(stderr, 
            "WARNING - %d console error listeners still registered!\n"
            "More calls to nsIConsoleService::UnregisterListener needed.\n",
            mListeners.Count());
    }
    
#endif

    if (mMessages)
        nsMemory::Free(mMessages);
    if (mLock)
        PR_DestroyLock(mLock);
}

Here is the call graph for this function:


Member Function Documentation

void nsIConsoleService::getMessageArray ( [array, size_is(count)] out nsIConsoleMessage  messages,
out PRUint32  count 
) [inherited]

Get an array of all the messages logged so far.

If no messages are logged, this function will return a count of 0, but still will allocate one word for messages, so as to show up as a 0-length array when called from script.

Definition at line 313 of file nsConsoleService.cpp.

{
    nsresult rv;
    *aProxy = nsnull;

    nsCOMPtr<nsIProxyObjectManager> proxyManager =
        (do_GetService(NS_XPCOMPROXY_CONTRACTID));

    if (proxyManager == nsnull)
        return NS_ERROR_NOT_AVAILABLE;

    /*
     * NOTE this will fail if the calling thread doesn't have an eventQ.
     *
     * Would it be better to catch that case and leave the listener unproxied?
     */
    rv = proxyManager->GetProxyForObject(NS_CURRENT_EVENTQ,
                                         NS_GET_IID(nsIConsoleListener),
                                         aListener,
                                         PROXY_ASYNC | PROXY_ALWAYS,
                                         (void**) aProxy);
    return rv;
}

Here is the call graph for this function:

Definition at line 97 of file nsConsoleService.cpp.

{
    mMessages = (nsIConsoleMessage **)
        nsMemory::Alloc(mBufferSize * sizeof(nsIConsoleMessage *));
    if (!mMessages)
        return NS_ERROR_OUT_OF_MEMORY;

    // Array elements should be 0 initially for circular buffer algorithm.
    memset(mMessages, 0, mBufferSize * sizeof(nsIConsoleMessage *));

    mLock = PR_NewLock();
    if (!mLock)
        return NS_ERROR_OUT_OF_MEMORY;

    return NS_OK;
}

Here is the call graph for this function:

void nsIConsoleService::logStringMessage ( in wstring  message) [inherited]

Convenience method for logging simple messages.

To guard against stack overflows from listeners that could log messages (it's easy to do this inadvertently from listeners implemented in JavaScript), we don't call any listeners when another error is already being logged.

Clear the message buffer (e.g.

for privacy reasons).

Each registered listener should also be unregistered.


Member Data Documentation

Definition at line 72 of file nsConsoleService.h.

Definition at line 75 of file nsConsoleService.h.

Definition at line 78 of file nsConsoleService.h.

nsSupportsHashtable nsConsoleService::mListeners [private]

Definition at line 81 of file nsConsoleService.h.

Definition at line 85 of file nsConsoleService.h.

Definition at line 88 of file nsConsoleService.h.

Definition at line 69 of file nsConsoleService.h.


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