-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathService.pm
executable file
·178 lines (150 loc) · 4.2 KB
/
Service.pm
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/perl
##########################################################################
# Service object
# Copyright (C) 2012 Tomonobu Saito All Rights Reserverd.
package Service;
use strict;
use Carp qw(croak);
use integer;
use LCN;
sub new {
my $pkg = shift;
my $tsid = shift;
my $onid = shift;
my $svcid = shift;
bless {
transport_stream_id => $tsid,
original_network_id => $onid,
service_id => $svcid,
origin => 0,
actual => "",
service_type => -1,
service_provider_name => "",
service_name => "",
EIT_schedule => -1,
EIT_pf => -1,
running_status => -1,
free_CA => -1,
ref_lcn_list => [], # reference of no-name array.
}, $pkg;
}
sub IsSame {
my $self = shift;
my $tsid = shift;
my $onid = shift;
my $svcid = shift;
return
$tsid == $self->{ transport_stream_id } &&
$onid == $self->{ original_network_id } &&
$svcid == $self->{ service_id };
}
# static method
sub DumpHeaderLine{
print "[Service]\n\n";
print "tsid onid svcid lcn vf org act type EIT run CA\n";
print "------ ------ ------ ---- -- --- --- ---- --- --- --\n"
}
sub Dump {
my $self = shift;
# default LCN object
my $default_lcn = $self->find_lcn_entry("default");
printf "0x%04x 0x%04x 0x%04x %4d %2d %s%s%s %s %4d %s%s %3d %2d %s\n",
$self->{ transport_stream_id },
$self->{ original_network_id },
$self->{ service_id },
$default_lcn->{ lcn },
$default_lcn->{ visible_service_flag },
(0 != (0x01 & $self->{ origin }) ? "N" : " "), # from NIT
(0 != (0x02 & $self->{ origin }) ? "B" : " "), # from BAT
(0 != (0x04 & $self->{ origin }) ? "S" : " "), # from SDT
("a" eq $self->{ actual } ? "act" : " "),
$self->{ service_type },
(1 == $self->{ EIT_schedule } ? "s" : " " ),
(1 == $self->{ EIT_pf } ? "pf" : " "),
$self->{ running_status },
$self->{ free_CA },
$self->{ service_name };
# LCN
my $ref_list = $self->{ ref_lcn_list };
my @lcn_list = @$ref_list;
foreach my $lcn (@lcn_list) {
unless ($lcn->IsSame("default")) {
printf " other lcn %4d %2d (%s)\n",
$lcn->{ lcn }, #
$lcn->{ visible_service_flag },
$lcn->{ identifier };
}
}
}
#
# Setter
#
sub FromNIT {
my $self = shift;
$self->{ origin } |= 0x01;
}
sub FromBAT {
my $self = shift;
$self->{ origin } |= 0x02;
}
sub FromSDT {
my $self = shift;
$self->{ origin } |= 0x04;
}
sub SetActual {
my $self = shift;
$self->{ actual } = shift;
}
sub SetServiceType {
my $self = shift;
$self->{ service_type } = shift;
}
sub SetServiceProviderName {
my $self = shift;
$self->{ service_provider_name } = shift;
}
sub SetServiceName {
my $self = shift;
$self->{ service_name } = shift;
}
sub SetEitFlag {
my $self = shift;
$self->{ EIT_schedule } = shift;
$self->{ EIT_pf } = shift;
}
sub SetRunningStatus {
my $self = shift;
$self->{ running_status } = shift;
}
sub SetFreeCA {
my $self = shift;
$self->{ free_CA } = shift;
}
sub SetVisibleServiceFlag {
my $self = shift;
my $lcn = $self->find_lcn_entry(shift);
$lcn->SetVisibleServiceFlag(shift);
}
sub SetLCN {
my $self = shift;
my $lcn = $self->find_lcn_entry(shift);
$lcn->SetLCN(shift);
}
sub find_lcn_entry {
my $self = shift;
my $ident = shift;
my $ref_list = $self->{ ref_lcn_list };
my @lcn_list = @$ref_list;
foreach my $lcn (@lcn_list) {
if ($lcn->IsSame($ident)) {
return $lcn;
}
}
my $new_lcn = new LCN($ident);
push(@lcn_list, $new_lcn);
$self->{ ref_lcn_list } = \@lcn_list; # copy back
return $new_lcn;
}
1;