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