Subversion Repositories HomeAutomation

Rev

Rev 974 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. function Interval(callback, timeout)
  3. {
  4.     this.myCallback = callback;
  5.     this.myTimeout = timeout;
  6.     this.myIsRunning = false;
  7. }
  8.  
  9. Interval.myIntervals = new Array();
  10. Interval.prototype.myIsRunning = null;
  11. Interval.prototype.myId = null;
  12. Interval.prototype.myTimeout = null;
  13. Interval.prototype.myCallback = null;
  14.  
  15. Interval.triggerIntervalCallback = function(id)
  16. {
  17.     if (Interval.myIntervals[id])
  18.     {
  19.         Interval.myIntervals[id].triggerCallback();
  20.     }
  21.     else
  22.     {
  23.         log("Interval:" + id + "> Encountered a thread that have no javascript Interval object. This is not supposed to be possible, report this.\n");
  24.         stopIntervalThread(id);
  25.     }
  26. }
  27.  
  28. Interval.prototype.triggerCallback = function()
  29. {
  30.     this.myCallback();
  31. }
  32.  
  33. Interval.prototype.setTimeout = function(timeout)
  34. {
  35.     var isRunning = this.myIsRunning;
  36.     if (isRunning)
  37.     {
  38.         this.stop();
  39.     }
  40.  
  41.     this.myTimeout = timeout;
  42.    
  43.     if (isRunning)
  44.     {
  45.         this.start();
  46.     }
  47. }
  48.  
  49. Interval.prototype.setCallback = function(callback)
  50. {
  51.     this.myCallback = callback;
  52. }
  53.  
  54. Interval.prototype.start = function()
  55. {
  56.     this.myIsRunning = true;
  57.     this.myId = startIntervalThread(this.myTimeout)
  58.     Interval.myIntervals[this.myId] = this;
  59. }
  60.  
  61. Interval.prototype.stop = function()
  62. {
  63.     this.myIsRunning = false;
  64.     stopIntervalThread(this.myId);
  65.     delete Interval.myIntervals[this.myId];
  66.     this.myId = null;
  67. }
  68.