Visit Mozilla.org

nsIObserverService

From MDC

« XPCOM API Reference

Contents

[edit] Summary

The nsIObserverService interface provides methods to add, remove, notify, and enumerate observers of various notifications. nsIObserverService is defined in xpcom/ds/nsIObserverService.idl. It is scriptable and has been frozen since Mozilla 0.9.6. See bug 99163 for details.

 #include "nsIObserverService.h"
 [scriptable, uuid=(D07F5192-E3D1-11d2-8ACD-00105A1B8860)]
 interface nsIObserverService : nsISupports { ... };

The XPCOM nsObserverService implements this interface to provide global notifications for a variety of subsystems.

[edit] Method overview

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

[edit] Methods

[edit] addObserver()

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

 void addObserver( in nsIObserver anObserver,
                   in string aTopic,
                   in boolean ownsWeak);
[edit] Parameters
anObserver
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.

[edit] removeObserver()

Unregisters a given listener from notifications regarding the specified topic.

 void removeObserver( in nsIObserver anObserver,
                      in string aTopic );
[edit] Parameters
anObserver
The interface pointer which will stop receiving notifications.
aTopic
The notification topic or subject.

[edit] notifyObservers()

Notifies all registered listeners of the given topic.

 void notifyObservers( in nsISupports aSubject, 
                       in string aTopic, 
                       in wstring someData );
[edit] Parameters
aSubject
Notification specific interface pointer.
aTopic
The notification topic or subject.
someData
Notification specific wide string.

[edit] enumerateObservers()

Returns an enumeration of all registered listeners.

 nsISimpleEnumerator enumerateObservers( in string aTopic );
[edit] Parameters
aTopic
The notification topic or subject.
[edit] Return value

Returns an enumeration of all registered listeners.

[edit] See Also