SBTimer.jsm
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
27 EXPORTED_SYMBOLS = ["SBTimer"];
28 
29 const Cc = Components.classes;
30 const Ci = Components.interfaces;
31 const Cr = Components.results
32 
33 //------------------------------------------------------------------------------
34 //
35 // SBTimer class.
36 //
37 // SBTimer objects provide a wrapper for XPCOM nsITimer objects to allow
38 // functions with closures to be called when the timer expires, much like
39 // window.setInterval. However, SBTimer objects have the same precision as
40 // nsITimer and can be used from XPCOM components.
41 //
42 //------------------------------------------------------------------------------
43 
55 function SBTimer(aFunc, aDelay, aType) {
56  // Create the timer XPCOM object.
57  this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
58 
59  // Set up the timer object fields.
60  this._timerFunc = aFunc;
61 
62  // Initialize the timer XPCOM object.
63  this._timer.init(this, aDelay, aType);
64 }
65 
66 SBTimer.prototype = {
67  //
68  // Timer object fields.
69  //
70  // _timer Timer nsITimer XPCOM object.
71  // _timerFunc Function to call upon timer expiration.
72  //
73 
74  _timer: null,
75  _timerFunc: null,
76 
77 
78  //----------------------------------------------------------------------------
79  //
80  // Public timer functions.
81  //
82  //----------------------------------------------------------------------------
83 
88  cancel: function SBTimer_cancel() {
89  this._timer.cancel();
90  this._timer = null;
91  this._timerFunc = null;
92  },
93 
94 
101  setDelay: function SBTimer_setDelay(aDelay) {
102  this._timer.delay = aDelay;
103  },
104 
105 
106  //----------------------------------------------------------------------------
107  //
108  // Timer nsIObserver functions.
109  //
110  //----------------------------------------------------------------------------
111 
116  observe: function SBTimer_observe(aSubject, aTopic, aData) {
117  // Handle the timer event.
118  this._timerFunc.apply(null);
119  }
120 };
121 
const Cr
Definition: SBTimer.jsm:31
EXPORTED_SYMBOLS
Definition: SBTimer.jsm:27
saveStateDelayed aDelay
sbDeviceFirmwareAutoCheckForUpdate prototype _timer
const Ci
Definition: SBTimer.jsm:30
const Cc
Definition: SBTimer.jsm:29
return null
Definition: FeedWriter.js:1143
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe