ObserverUtils.jsm
Go to the documentation of this file.
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4 //
5 // BEGIN SONGBIRD GPL
6 //
7 // This file is part of the Songbird web player.
8 //
9 // Copyright(c) 2005-2008 POTI, Inc.
10 // http://songbirdnest.com
11 //
12 // This file may be licensed under the terms of of the
13 // GNU General Public License Version 2 (the "GPL").
14 //
15 // Software distributed under the License is distributed
16 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
17 // express or implied. See the GPL for the specific language
18 // governing rights and limitations.
19 //
20 // You should have received a copy of the GPL along with this
21 // program. If not, go to http://www.gnu.org/licenses/gpl.html
22 // or write to the Free Software Foundation, Inc.,
23 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 // END SONGBIRD GPL
26 //
27 */
28 
34 //------------------------------------------------------------------------------
35 //
36 // Observer utilities configuration.
37 //
38 //------------------------------------------------------------------------------
39 
40 EXPORTED_SYMBOLS = [ "ObserverSet" ];
41 
42 
43 //------------------------------------------------------------------------------
44 //
45 // Observer utility defs.
46 //
47 //------------------------------------------------------------------------------
48 
49 const Cc = Components.classes;
50 const Ci = Components.interfaces;
51 const Cr = Components.results
52 const Cu = Components.utils
53 
54 
55 //------------------------------------------------------------------------------
56 //
57 // Observer set services.
58 //
59 // These services may be used to maintain a set of observers and to facilitate
60 // the removal of them.
61 //
62 //------------------------------------------------------------------------------
63 
68 function ObserverSet()
69 {
70  // Get the observer services.
71  this._observerSvc = Cc["@mozilla.org/observer-service;1"]
72  .getService(Ci.nsIObserverService);
73 
74  // Initialize some fields.
75  this._observerList = {};
76 }
77 
78 // Define the class.
79 ObserverSet.prototype = {
80  // Set the constructor.
81  constructor: ObserverSet,
82 
83  //
84  // Observer set fields.
85  //
86  // _observerSvc Mozilla observer service.
87  // _observerList List of observers.
88  // _nextObserverID Next observer ID.
89  //
90 
91  _observerSvc: null,
92  _observerList: null,
93  _nextObserverID: 0,
94 
95 
112  add: function ObserverSet_add(aObserver,
113  aTopic,
114  aOwnsWeak,
115  aIsOneShot) {
116  // Create the observer set entry object.
117  var observerEntry = {};
118  observerEntry.id = this._nextObserverID++;
119  observerEntry.observer = aObserver;
120  observerEntry.topic = aTopic;
121  observerEntry.ownsWeak = aOwnsWeak;
122  observerEntry.isOneShot = aIsOneShot;
123 
124  // Use one-shot observer wrapper if observer is one-shot.
125  var observer = observerEntry.observer;
126  if (observerEntry.isOneShot) {
127  var _this = this;
128  observer = {
129  observe: function(aSubject, aTopic, aData) {
130  return _this._doOneShot(observerEntry, aSubject, aTopic, aData);
131  }
132  };
133  }
134  observerEntry.addedObserver = observer;
135 
136  // Add the observer.
137  this._observerSvc.addObserver(observerEntry.addedObserver,
138  observerEntry.topic,
139  observerEntry.ownsWeak);
140  this._observerList[observerEntry.id] = observerEntry;
141 
142  return observerEntry.id;
143  },
144 
145 
152  remove: function ObserverSet_remove(aObserverID) {
153  // Get the observer set entry. Do nothing if not found.
154  var observerEntry = this._observerList[aObserverID];
155  if (!observerEntry)
156  return;
157 
158  // Remove the observer.
159  this._observerSvc.removeObserver(observerEntry.addedObserver,
160  observerEntry.topic,
161  observerEntry.ownsWeak);
162  delete this._observerList[aObserverID];
163  },
164 
165 
170  removeAll: function ObserverSet_removeAll() {
171  // Remove all observers.
172  for (var id in this._observerList) {
173  this.remove(id);
174  }
175  this._observerList = {};
176  },
177 
178 
179  //----------------------------------------------------------------------------
180  //
181  // Internal observer set services.
182  //
183  //----------------------------------------------------------------------------
184 
195  _doOneShot: function ObserverSet__doOneShot(aObserverEntry,
196  aSubject,
197  aTopic,
198  aData) {
199  // Dispatch event to observer.
200  return aObserverEntry.observer.observe(aSubject, aTopic, aData);
201  }
202 };
203 
204 
const Cu
const Cr
menuItem id
Definition: FeedWriter.js:971
EXPORTED_SYMBOLS
ui plugin add("draggable","cursor",{start:function(e, ui){var t=$('body');if(t.css("cursor")) ui.options._cursor=t.css("cursor");t.css("cursor", ui.options.cursor);}, stop:function(e, ui){if(ui.options._cursor)$('body').css("cursor", ui.options._cursor);}})
DataRemote prototype constructor
var _this
const Ci
return null
Definition: FeedWriter.js:1143
const Cc
let observer
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe