vdr  2.2.0
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 3.0 2004/01/11 13:31:34 kls Exp $
8  */
9 
10 #include "filter.h"
11 #include "sections.h"
12 
13 // --- cSectionSyncer --------------------------------------------------------
14 
16 {
17  Reset();
18 }
19 
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 
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 
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 
84 {
85  if (sectionHandler)
86  sectionHandler->Detach(this);
87 }
88 
89 int cFilter::Source(void)
90 {
91  return sectionHandler ? sectionHandler->Source() : 0;
92 }
93 
95 {
96  return sectionHandler ? sectionHandler->Transponder() : 0;
97 }
98 
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 }
bool synced
Definition: filter.h:19
unsigned char uchar
Definition: tools.h:30
bool sticky
Definition: filter.h:31
cFilterData(void)
Definition: filter.c:42
bool Matches(u_short Pid, u_char Tid)
Definition: filter.c:63
int lastVersion
Definition: filter.h:18
void Add(u_short Pid, u_char Tid, u_char Mask=0xFF, bool Sticky=false)
Adds the given filter data to this filter.
Definition: filter.c:142
const cChannel * Channel(void)
Returns the channel of the data delivered to this filter.
Definition: filter.c:99
bool Sync(uchar Version, int Number, int LastNumber)
Definition: filter.c:26
cSectionSyncer(void)
Definition: filter.c:15
cFilter(void)
Definition: filter.c:70
bool Matches(u_short Pid, u_char Tid)
Indicates whether this filter wants to receive data from the given Pid/Tid.
Definition: filter.c:126
void Del(u_short Pid, u_char Tid, u_char Mask=0xFF)
Deletes the given filter data from this filter.
Definition: filter.c:150
cListObject * Next(void) const
Definition: tools.h:468
int Source(void)
Returns the source of the data delivered to this filter.
Definition: filter.c:89
bool Is(u_short Pid, u_char Tid, u_char Mask)
Definition: filter.c:58
virtual void SetStatus(bool On)
Turns this filter on or off, depending on the value of On.
Definition: filter.c:104
unsigned char u_char
Definition: headers.h:24
int Transponder(void)
Returns the transponder of the data delivered to this filter.
Definition: filter.c:94
void Set(u_short Pid, u_char Tid, u_char Mask=0xFF)
Sets the given filter data by calling Add() with Sticky = true.
Definition: filter.c:137
void Reset(void)
Definition: filter.c:20
virtual ~cFilter()
Definition: filter.c:83