nsIObserverService
来源:互联网 发布:猴王水果竞猜php源码 编辑:程序博客网 时间:2024/04/30 00:57
xpcom/ds/nsIObserverService.idl
ScriptableInherits from:
nsISupports
Last changed in Gecko 0.9.6The XPCOM nsObserverService
implements this interface to provide global notifications for a variety of subsystems.
Implemented by @mozilla.org/observer-service;1
as a service:
var observerService = Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService);
Method overview
void addObserver( in nsIObserver anObserver, in string aTopic, in boolean ownsWeak);
nsISimpleEnumerator enumerateObservers( in string aTopic );
void notifyObservers( in nsISupports aSubject, in string aTopic, in wstring someData );
void removeObserver( in nsIObserver anObserver, in string aTopic );
Methods
addObserver()
Registers a given listener for a notifications regarding the specified topic. See nsIObserver
for a JavaScript example.
void addObserver( in nsIObserver anObserver, in string aTopic, in boolean ownsWeak);
Parameters
anObserver
- The
nsIInterface
object which will receive notifications. aTopic
- The notification topic or subject.
ownsWeak
- If set to
false
, thensIObserverService
will hold a strong reference toanObserver
. If set totrue
andanObserver
supports thensIWeakReference
interface, a weak reference will be held. Otherwise an error will be returned. (In most cases, you should usefalse
.)
enumerateObservers()
Called to enumerate all observers registered for a particular topic.
nsISimpleEnumerator enumerateObservers( in string aTopic );
Parameters
aTopic
- The notification topic or subject.
Return value
Returns an enumeration of all registered listeners. See nsISimpleEnumerator
.
notifyObservers()
This method is called to notify all observers for a particular topic. See Example.
void notifyObservers( in nsISupports aSubject, in string aTopic, in wstring someData );
Parameters
aSubject
- A notification specific interface pointer. This usually corresponds to the source of the notification, but could be defined differently depending on the notification topic and may even be
null
. aTopic
- The notification topic. This string-valued key uniquely identifies the notification. This parameter must not be
null
. someData
- A notification specific string value. The meaning of this parameter is dependent on the topic. It may be
null
.
removeObserver()
This method is called to unregister an observer for a particular topic.
void removeObserver( in nsIObserver anObserver, in string aTopic );
Parameters
anObserver
- The
nsIObserver
instance to remove. aTopic
- The notification topic or subject. This string-valued key uniquely identifies the notification. This parameter must not be
null
.
Example
This notifies all nsIObserver
s watching the "myTopicID" topic with an additional data parameter.
1
Components.classes[
"@mozilla.org/observer-service;1"
]
2
.getService(Components.interfaces.nsIObserverService)
3
.notifyObservers(
null
,
"myTopicID"
,
"someAdditionalInformationPassedAs'Data'Parameter"
);
See also
nsObserverService
- Observer Notifications provides an overview of observers and a list of built-in notifications fired by Mozilla.
- Usage examples are provided in the
nsIObserver
documentation.
- nsIObserverService
- nsIObserverService
- javascript中字符串替换函数replace()方法详解
- IE6中用了float:left之后导致margin-left加倍
- 托管C++的String^类型与非托管C++的char*类型之间的转换
- Using XMLHttpRequest
- 使用FxCop做代码检查和优化
- nsIObserverService
- xen虚拟机的启动(引导)方式
- Ambarella公司申请首次公开招股
- 各种数据库产品数据按某字段Order by时null的位置问题
- java.net.BindException: Address already in use: JVM_Bind
- Visual Studio的配色方案,支持vs2005、vs2008、vs2010
- Visual Studio 2008 每日小窍门 【持续发布ing~】 Tips:028
- [WaterDrops]std::map中判断并删除元素
- 自动设置ip的dns的window脚本