Subversion Repositories HomeAutomation

Rev

Rev 1042 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

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