Back to index

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

#include <nsObserverService.h>

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

List of all members.

Public Member Functions

 nsObserverService ()
void addObserver (in nsIObserver anObserver, in string aTopic, in boolean ownsWeak)
 AddObserver.
void removeObserver (in nsIObserver anObserver, in string aTopic)
 removeObserver
void notifyObservers (in nsISupports aSubject, in string aTopic, in wstring someData)
 notifyObservers
nsISimpleEnumerator enumerateObservers (in string aTopic)
 enumerateObservers

Static Public Member Functions

NS_DECL_ISUPPORTS static
NS_DECL_NSIOBSERVERSERVICE
NS_METHOD 
Create (nsISupports *outer, const nsIID &aIID, void **aInstancePtr)

Private Member Functions

 ~nsObserverService (void)
nsresult GetObserverList (const char *aTopic, nsObserverList **anObserverList)

Private Attributes

nsObjectHashtable * mObserverTopicTable

Detailed Description

Definition at line 53 of file nsObserverService.h.


Constructor & Destructor Documentation

Definition at line 72 of file nsObserverService.cpp.

Here is the caller graph for this function:

Definition at line 77 of file nsObserverService.cpp.


Member Function Documentation

void nsIObserverService::addObserver ( in nsIObserver  anObserver,
in string  aTopic,
in boolean  ownsWeak 
) [inherited]

AddObserver.

Registers a given listener for a notifications regarding the specified topic.

Parameters:
anObserve: The interface pointer which will receive notifications.
aTopic: The notification topic or subject.
ownsWeak: If set to false, the nsIObserverService will hold a strong reference to |anObserver|. If set to true and |anObserver| supports the nsIWeakReference interface, a weak reference will be held. Otherwise an error will be returned.
NS_METHOD nsObserverService::Create ( nsISupports *  outer,
const nsIID aIID,
void **  aInstancePtr 
) [static]

Definition at line 84 of file nsObserverService.cpp.

{
#if defined(PR_LOGGING)
    if (!observerServiceLog)
        observerServiceLog = PR_NewLogModule("ObserverService");
#endif

    nsresult rv;
    nsObserverService* os = new nsObserverService();
    if (os == nsnull)
        return NS_ERROR_OUT_OF_MEMORY;
    NS_ADDREF(os);
    rv = os->QueryInterface(aIID, aInstancePtr);
    NS_RELEASE(os);
    return rv;
}

Here is the call graph for this function:

enumerateObservers

Returns an enumeration of all registered listeners.

Parameters:
aTopic: The notification topic or subject.
nsresult nsObserverService::GetObserverList ( const char *  aTopic,
nsObserverList **  anObserverList 
) [private]

Definition at line 109 of file nsObserverService.cpp.

{
    if (anObserverList == nsnull)
        return NS_ERROR_NULL_POINTER;
    
    if(mObserverTopicTable == nsnull) 
    {
        mObserverTopicTable = new nsObjectHashtable(nsnull, 
                                                    nsnull,   // should never be cloned
                                                    ReleaseObserverList, 
                                                    nsnull,
                                                    256, 
                                                    PR_TRUE);
        if (mObserverTopicTable == nsnull)
            return NS_ERROR_OUT_OF_MEMORY;
    }
    

    nsCStringKey key(aTopic);

    nsObserverList *topicObservers;
    topicObservers = (nsObserverList *) mObserverTopicTable->Get(&key);

    if (topicObservers) 
    {
        *anObserverList = topicObservers;    
        return NS_OK;
    }

    topicObservers = new nsObserverList();
    if (!topicObservers)
        return NS_ERROR_OUT_OF_MEMORY;
    
    *anObserverList = topicObservers;
    mObserverTopicTable->Put(&key, topicObservers);
    
    return NS_OK;
}

Here is the call graph for this function:

void nsIObserverService::notifyObservers ( in nsISupports  aSubject,
in string  aTopic,
in wstring  someData 
) [inherited]

notifyObservers

Notifies all registered listeners of the given topic.

Parameters:
aSubject: Notification specific interface pointer.
aTopic: The notification topic or subject.
someData: Notification specific wide string.
void nsIObserverService::removeObserver ( in nsIObserver  anObserver,
in string  aTopic 
) [inherited]

removeObserver

Unregisters a given listener from notifications regarding the specified topic.

Parameters:
anObserver: The interface pointer which will stop recieving notifications.
aTopic: The notification topic or subject.

Member Data Documentation

nsObjectHashtable* nsObserverService::mObserverTopicTable [private]

Definition at line 68 of file nsObserverService.h.


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