1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jalle19\StatusManager\Instance; |
4
|
|
|
|
5
|
|
|
use Jalle19\StatusManager\Subscription\StateChange; |
6
|
|
|
use Jalle19\tvheadend\model\ConnectionStatus; |
7
|
|
|
use Jalle19\tvheadend\model\InputStatus; |
8
|
|
|
use Jalle19\tvheadend\model\SubscriptionStatus; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class InstanceStatus |
12
|
|
|
* @package Jalle19\StatusManager\Instance |
13
|
|
|
* @copyright Copyright © Sam Stenvall 2015- |
14
|
|
|
* @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v2.0 |
15
|
|
|
*/ |
16
|
|
|
class InstanceStatus implements \JsonSerializable |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string the name of the instance |
21
|
|
|
*/ |
22
|
|
|
private $_instanceName; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var InputStatus[] |
26
|
|
|
*/ |
27
|
|
|
private $_inputs; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var SubscriptionStatus[] |
31
|
|
|
*/ |
32
|
|
|
private $_subscriptions; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var ConnectionStatus[] |
36
|
|
|
*/ |
37
|
|
|
private $_connections; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var StateChange[] |
41
|
|
|
*/ |
42
|
|
|
private $_subscriptionStateChanges; |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* BroadcastMessage constructor. |
47
|
|
|
* |
48
|
|
|
* @param string $instanceName |
49
|
|
|
* @param InputStatus[] $inputs |
50
|
|
|
* @param SubscriptionStatus[] $subscriptions |
51
|
|
|
* @param ConnectionStatus[] $connections |
52
|
|
|
* @param StateChange[] $subscriptionStateChanges |
53
|
|
|
* |
54
|
|
|
*/ |
55
|
|
|
public function __construct( |
56
|
|
|
$instanceName, |
57
|
|
|
array $inputs, |
58
|
|
|
array $subscriptions, |
59
|
|
|
array $connections, |
60
|
|
|
array $subscriptionStateChanges |
61
|
|
|
) { |
62
|
|
|
$this->_instanceName = $instanceName; |
63
|
|
|
$this->_inputs = $inputs; |
64
|
|
|
$this->_subscriptions = $subscriptions; |
65
|
|
|
$this->_connections = $connections; |
66
|
|
|
$this->_subscriptionStateChanges = $subscriptionStateChanges; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
public function getInstanceName() |
74
|
|
|
{ |
75
|
|
|
return $this->_instanceName; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return ConnectionStatus[] |
81
|
|
|
*/ |
82
|
|
|
public function getConnections() |
83
|
|
|
{ |
84
|
|
|
return $this->_connections; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return \Jalle19\tvheadend\model\InputStatus[] |
90
|
|
|
*/ |
91
|
|
|
public function getInputs() |
92
|
|
|
{ |
93
|
|
|
return $this->_inputs; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return SubscriptionStatus[] |
99
|
|
|
*/ |
100
|
|
|
public function getSubscriptions() |
101
|
|
|
{ |
102
|
|
|
return $this->_subscriptions; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return StateChange[] |
108
|
|
|
*/ |
109
|
|
|
public function getSubscriptionStateChanges() |
110
|
|
|
{ |
111
|
|
|
return $this->_subscriptionStateChanges; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return array aggregate input/output bandwidth of all subscriptions |
117
|
|
|
*/ |
118
|
|
|
public function getSubscriptionAggregates() |
119
|
|
|
{ |
120
|
|
|
$aggregates = [ |
121
|
|
|
'input' => 0, |
122
|
|
|
'output' => 0, |
123
|
|
|
]; |
124
|
|
|
|
125
|
|
|
foreach ($this->_subscriptions as $subscription) |
126
|
|
|
{ |
127
|
|
|
// Bandwidth may be null from time to time |
128
|
|
|
if (is_numeric($subscription->in)) |
129
|
|
|
$aggregates['input'] += $subscription->in; |
130
|
|
|
if (is_numeric($subscription->out)) |
131
|
|
|
$aggregates['output'] += $subscription->out; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
return $aggregates; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @inheritdoc |
140
|
|
|
*/ |
141
|
|
|
public function jsonSerialize() |
142
|
|
|
{ |
143
|
|
|
return [ |
144
|
|
|
'instanceName' => $this->_instanceName, |
145
|
|
|
'inputs' => $this->_inputs, |
146
|
|
|
'subscriptions' => $this->_subscriptions, |
147
|
|
|
'connections' => $this->_connections, |
148
|
|
|
'subscriptionStateChanges' => $this->_subscriptionStateChanges, |
149
|
|
|
'subscriptionAggregates' => $this->getSubscriptionAggregates(), |
150
|
|
|
]; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
} |
154
|
|
|
|