-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmonitors.js
90 lines (70 loc) · 2.04 KB
/
monitors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* Created by root on 24.06.17.
*/
module.exports = Monitors;
function Monitors() {
var Zones = require(__dirname + '/zones');
//var MonitorZones = new Zones();
var List = [];
this.Add = function (Mon) {
//List.push(Mon)
List.push({ Mon: Mon, State: -1,Zones : new Zones() });
}
this.AddOrUpdate = function(Mon, onStateChange) {
var Res = this.GetIndexByZoneMinderID(Mon.Id);
if (Res == -1) {
this.Add(Mon);
for (var key in Mon)
onStateChange(Mon,key,Mon[key],true);
}
else {
var ExistingMon = this.Get(Res);
for (var key in Mon)
if (Mon[key] != ExistingMon[key])
onStateChange(Mon,key,Mon[key],false);
this.Set(Res,Mon);
}
}
this.Count = function() {
return List.length;
}
this.Get = function(index) {
return List[index].Mon;
}
this.GetState = function(index) {
return List[index].State;
}
this.SetState = function(index,value) {
List[index].State = value;
}
this.Set = function(index, Mon) {
List[index].Mon = Mon;
}
this.Delete = function (index) {
List.splice(index, 1);
}
this.GetByZoneMinderID = function(id) {
for (var i = 0 ; i < List.length ; i++)
if (List[i].Mon.Id == id )
return List[i].Mon;
return null;
}
this.GetZonesByZoneMinderID = function(id) {
for (var i = 0 ; i < List.length ; i++)
if (List[i].Mon.Id == id )
return List[i].Zones;
return null;
}
this.GetIndexByZoneMinderID = function(id) {
for (var i = 0 ; i < List.length ; i++)
if (List[i].Mon.Id == id )
return i;
return -1;
}
this.GetIndexByMonitorName = function(MonitorName) {
for (var i = 0 ; i < List.length ; i++)
if (List[i].Mon.Name == MonitorName )
return i;
return -1;
}
}