fix warning
[enigma2.git] / lib / dvb / esection.h
1 #ifndef __esection_h
2 #define __esection_h
3
4 #include <lib/dvb/idemux.h>
5 #include <set>
6
7 class eGTable: public iObject, public Object
8 {
9 DECLARE_REF(eGTable);
10 private:
11         ePtr<iDVBSectionReader> m_reader;
12         eDVBTableSpec m_table;
13         
14         unsigned int m_tries;
15         
16         eTimer *m_timeout;
17
18         void sectionRead(const __u8 *data);
19         void timeout();
20         ePtr<eConnection> m_sectionRead_conn;
21 protected:
22         virtual int createTable(int nr, const __u8 *data, unsigned int max)=0;
23 public:
24         Signal1<void, int> tableReady;
25         eGTable();
26         RESULT start(iDVBSectionReader *reader, const eDVBTableSpec &table);
27         RESULT start(iDVBDemux *reader, const eDVBTableSpec &table);
28         RESULT getSpec(eDVBTableSpec &spec) { spec = m_table; return 0; }
29         virtual ~eGTable();
30         int error;
31         int ready;
32 };
33
34 template <class Section>
35 class eTable: public eGTable
36 {
37 private:
38         std::vector<Section*> sections;
39         std::set<int> avail;
40 protected:
41         int createTable(int nr, const __u8 *data, unsigned int max)
42         {
43                 if (avail.find(nr) != avail.end())
44                         delete sections[nr];
45                 sections.resize(max);
46                 
47                 sections[nr] = new Section(data);
48                 avail.insert(nr);
49
50                 for (unsigned int i = 0; i < max; ++i)
51                         if (avail.find(i) != avail.end())
52                                 printf("+");
53                         else
54                                 printf("-");
55                                 
56                 printf(" %d/%d TID %02x\n", avail.size(), max, data[0]);
57
58                 if (avail.size() == max)
59                 {
60                         printf("done!\n");
61                         return 1;
62                 } else
63                         return 0;
64         }
65 public:
66         std::vector<Section*> &getSections() { return sections; }
67         eTable(): eGTable()
68         {
69         }
70         ~eTable()
71         {
72                 for (typename std::vector<Section*>::iterator i(sections.begin()); i != sections.end(); ++i)
73                         delete *i;
74         }
75 };
76
77 class eAUGTable: public Object
78 {
79 protected:
80         void slotTableReady(int);
81 public:
82         Signal1<void, int> tableReady;
83         virtual void getNext(int err)=0;
84 };
85
86 template <class Table>
87 class eAUTable: public eAUGTable
88 {
89         ePtr<Table> current, next;              // current is READY AND ERRORFREE, next is not yet ready
90         int first;
91         ePtr<iDVBDemux> m_demux;
92         eMainloop *ml;
93 public:
94
95         eAUTable()
96         {
97         }
98
99         ~eAUTable()
100         {
101                 stop();
102         }
103         
104         void stop()
105         {
106                 current = next = 0;
107         }
108         
109         int begin(eMainloop *m, const eDVBTableSpec &spec, ePtr<iDVBDemux> demux)
110         {
111                 ml = m;
112                 m_demux = demux;
113                 first= 1;
114                 current = 0;
115                 next = new Table();
116                 CONNECT(next->tableReady, eAUTable::slotTableReady);
117                 next->start(demux, spec);
118                 return 0;
119         }
120         
121         int get()
122         {
123                 if (current)
124                 {
125                         /*emit*/ tableReady(0);
126                         return 0;
127                 } else if (!next)
128                 {
129                         /*emit*/ tableReady(-1);
130                         return 0;
131                 } else
132                         return 1;
133         }
134         
135         RESULT getCurrent(ePtr<Table> &ptr)
136         {
137                 if (!current)
138                         return -1;
139                 ptr = current;
140                 return 0;
141         }
142
143 #if 0   
144         void abort()
145         {
146                 eDebug("eAUTable: aborted!");
147                 if (next)
148                         next->abort();
149                 delete next;
150                 next=0;
151         }
152 #endif
153
154         int ready()
155         {
156                 return !!current;
157         }
158         
159         void inject(Table *t)
160         {
161                 next=t;
162                 getNext(0);
163         }
164
165         void getNext(int error)
166         {
167                 current = 0;
168                 if (error)
169                 {
170                         next=0;
171                         if (first)
172                                 /*emit*/ tableReady(error);
173                         first=0;
174                         return;
175                 } else
176                         current=next;
177
178                 next=0;
179                 first=0;
180                 
181                 assert(current->ready);
182                         
183                 /*emit*/ tableReady(0);
184                 
185                 eDVBTableSpec spec;
186
187                 if (current && (!current->getSpec(spec)))
188                 {
189                         next = new Table();
190                         CONNECT(next->tableReady, eAUTable::slotTableReady);
191                         spec.flags &= ~(eDVBTableSpec::tfAnyVersion|eDVBTableSpec::tfThisVersion|eDVBTableSpec::tfHaveTimeout);
192                         next->eGTable::start(m_demux, spec);
193                 }
194         }
195 };
196
197 #endif