Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

nsIObserverService

« XPCOM API Reference

この文書は翻訳中です。他国語のままの部分などがあるのはその為です。
是非お気軽に MDN に登録して翻訳に参加し、私たちの手助けをして下さい!

概要

nsIObserverService インタフェースは、様々な通知を受けるオブザーバを追加、削除、通知、列挙するためのメソッドを提供します。

Please add a summary to this article.
  最終更新: Gecko 0.9.6
詳しくは バグ 99163 をご覧ください

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

XPCOM の nsObserverService はこのインタフェースを実装して、様々なサブシステムのためのグローバル通知を提供しています。

メソッドの概要

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 );

メソッド

addObserver()

特定のトピックに関する通知を受けるために指定したリスナーの登録を行います。

 void addObserver( in nsIObserver anObserver,
                   in string aTopic,
                   in boolean ownsWeak);
引数
anObserver
通知を受けるインタフェースポインタ。
aTopic
通知のトピックまたはサブジェクト。
ownsWeak
false に設定した場合、nsIObserverServiceanObserver に対する強力な参照を保持します。true に設定し、なおかつ anObservernsIWeakReference インタフェースをサポートしている場合、弱い参照が保持されます。そうでない場合、エラーが返されます。

removeObserver()

特定のトピックに関する通知を受けるために指定したリスナーの登録を解除します。

 void removeObserver( in nsIObserver anObserver,
                      in string aTopic );
引数
anObserver
通知を受けるのを停止するインタフェースポインタ。
aTopic
通知のトピックまたはサブジェクト。

notifyObservers()

指定されたトピックについて登録されたすべてのリスナーに通知を行います。

 void notifyObservers( in nsISupports aSubject, 
                       in string aTopic, 
                       in wstring someData );
引数
aSubject
通知固有のインタフェースポインタ。
aTopic
通知のトピックまたはサブジェクト。
someData
通知固有のワイド文字列。

enumerateObservers()

登録されたすべてのリスナの列挙を返します。

 nsISimpleEnumerator enumerateObservers( in string aTopic );
引数
aTopic
通知のトピックまたはサブジェクト。
戻り値

登録されたすべてのリスナの列挙を返します。

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 nsIObservers watching the "myTopicID" topic with an additional data parameter.

Components.classes["@mozilla.org/observer-service;1"]
          .getService(Components.interfaces.nsIObserverService)
          .notifyObservers(null, "myTopicID", "someAdditionalInformationPassedAs'Data'Parameter");

関連記事

ドキュメントのタグと貢献者

 このページの貢献者: teoli, ethertank, nobuoka, Kohei
 最終更新者: teoli,