vdr
2.0.4
Main Page
Namespaces
Classes
Files
File List
File Members
filter.c
Go to the documentation of this file.
1
/*
2
* filter.c: Section filter
3
*
4
* See the main source file 'vdr.c' for copyright information and
5
* how to reach the author.
6
*
7
* $Id: filter.c 2.0 2004/01/11 13:31:34 kls Exp $
8
*/
9
10
#include "
filter.h
"
11
#include "
sections.h
"
12
13
// --- cSectionSyncer --------------------------------------------------------
14
15
cSectionSyncer::cSectionSyncer
(
void
)
16
{
17
Reset
();
18
}
19
20
void
cSectionSyncer::Reset
(
void
)
21
{
22
lastVersion
= 0xFF;
23
synced
=
false
;
24
}
25
26
bool
cSectionSyncer::Sync
(
uchar
Version,
int
Number,
int
LastNumber)
27
{
28
if
(Version ==
lastVersion
)
29
return
false
;
30
if
(!
synced
) {
31
if
(Number != 0)
32
return
false
;
// sync on first section
33
synced
=
true
;
34
}
35
if
(Number == LastNumber)
36
lastVersion
= Version;
37
return
synced
;
38
}
39
40
// --- cFilterData -----------------------------------------------------------
41
42
cFilterData::cFilterData
(
void
)
43
{
44
pid
= 0;
45
tid
= 0;
46
mask
= 0;
47
sticky
=
false
;
48
}
49
50
cFilterData::cFilterData
(u_short Pid,
u_char
Tid,
u_char
Mask,
bool
Sticky)
51
{
52
pid
= Pid;
53
tid
= Tid;
54
mask
= Mask;
55
sticky
= Sticky;
56
}
57
58
bool
cFilterData::Is
(u_short Pid,
u_char
Tid,
u_char
Mask)
59
{
60
return
pid
== Pid &&
tid
== Tid &&
mask
== Mask;
61
}
62
63
bool
cFilterData::Matches
(u_short Pid,
u_char
Tid)
64
{
65
return
pid
== Pid &&
tid
== (Tid &
mask
);
66
}
67
68
// --- cFilter ---------------------------------------------------------------
69
70
cFilter::cFilter
(
void
)
71
{
72
sectionHandler
= NULL;
73
on
=
false
;
74
}
75
76
cFilter::cFilter
(u_short Pid,
u_char
Tid,
u_char
Mask)
77
{
78
sectionHandler
= NULL;
79
on
=
false
;
80
Set
(Pid, Tid, Mask);
81
}
82
83
cFilter::~cFilter
()
84
{
85
if
(
sectionHandler
)
86
sectionHandler
->
Detach
(
this
);
87
}
88
89
int
cFilter::Source
(
void
)
90
{
91
return
sectionHandler
?
sectionHandler
->
Source
() : 0;
92
}
93
94
int
cFilter::Transponder
(
void
)
95
{
96
return
sectionHandler
?
sectionHandler
->
Transponder
() : 0;
97
}
98
99
const
cChannel
*
cFilter::Channel
(
void
)
100
{
101
return
sectionHandler
?
sectionHandler
->
Channel
() : NULL;
102
}
103
104
void
cFilter::SetStatus
(
bool
On)
105
{
106
if
(
sectionHandler
&&
on
!= On) {
107
cFilterData
*fd =
data
.
First
();
108
while
(fd) {
109
if
(On)
110
sectionHandler
->
Add
(fd);
111
else
{
112
sectionHandler
->
Del
(fd);
113
if
(!fd->
sticky
) {
114
cFilterData
*
next
=
data
.
Next
(fd);
115
data
.
Del
(fd);
116
fd =
next
;
117
continue
;
118
}
119
}
120
fd =
data
.
Next
(fd);
121
}
122
on
= On;
123
}
124
}
125
126
bool
cFilter::Matches
(u_short Pid,
u_char
Tid)
127
{
128
if
(
on
) {
129
for
(
cFilterData
*fd =
data
.
First
(); fd; fd =
data
.
Next
(fd)) {
130
if
(fd->Matches(Pid, Tid))
131
return
true
;
132
}
133
}
134
return
false
;
135
}
136
137
void
cFilter::Set
(u_short Pid,
u_char
Tid,
u_char
Mask)
138
{
139
Add
(Pid, Tid, Mask,
true
);
140
}
141
142
void
cFilter::Add
(u_short Pid,
u_char
Tid,
u_char
Mask,
bool
Sticky)
143
{
144
cFilterData
*fd =
new
cFilterData
(Pid, Tid, Mask, Sticky);
145
data
.
Add
(fd);
146
if
(
sectionHandler
&&
on
)
147
sectionHandler
->
Add
(fd);
148
}
149
150
void
cFilter::Del
(u_short Pid,
u_char
Tid,
u_char
Mask)
151
{
152
for
(
cFilterData
*fd =
data
.
First
(); fd; fd =
data
.
Next
(fd)) {
153
if
(fd->Is(Pid, Tid, Mask)) {
154
if
(
sectionHandler
&&
on
)
155
sectionHandler
->
Del
(fd);
156
data
.
Del
(fd);
157
return
;
158
}
159
}
160
}
161
Generated by
1.8.3.1