add epgcache
[enigma2.git] / lib / dvb / dvbtime.h
1 #ifndef __LIB_DVB_DVBTIME_H_
2 #define __LIB_DVB_DVBTIME_H_
3
4 #include <lib/base/eerror.h>
5 #include <lib/dvb/esection.h>
6 #include <lib/dvb_si/tdt.h>
7
8 class eDVBChannel;
9
10 inline int fromBCD(int bcd)
11 {
12         if ((bcd&0xF0)>=0xA0)
13                 return -1;
14         if ((bcd&0xF)>=0xA)
15                 return -1;
16         return ((bcd&0xF0)>>4)*10+(bcd&0xF);
17 }
18
19 time_t parseDVBtime(__u8 t1, __u8 t2, __u8 t3, __u8 t4, __u8 t5);
20
21 class TDT: public eGTable
22 {
23         eDVBChannel *chan;
24         ePtr<iDVBDemux> demux;
25         eTimer m_interval_timer;
26         int createTable(int nr, const __u8 *data, unsigned int max);
27         void ready(int);
28 public:
29         TDT(eDVBChannel *chan);
30         void start();
31         void startTimer(int interval);
32 };
33
34 class eDVBLocalTimeHandler: public Object
35 {
36         friend class TDT;
37         DECLARE_REF(eDVBLocalTimeHandler)
38         std::map<iDVBChannel*, TDT*> m_active_tables;
39         std::map<eDVBChannelID,int> m_timeOffsetMap;
40         ePtr<eConnection> m_chanAddedConn;
41         ePtr<eConnection> m_chanRemovedConn;
42         ePtr<eConnection> m_chanRunningConn;
43         bool m_time_ready;
44         int m_time_difference;
45         int m_last_tp_time_difference;
46         void DVBChannelAdded(eDVBChannel*);
47         void DVBChannelRemoved(eDVBChannel*);
48         void DVBChannelRunning(iDVBChannel*);
49         void readTimeOffsetData(const char*);
50         void writeTimeOffsetData(const char*);
51         void updateTime(time_t tp_time, eDVBChannel*);
52         static eDVBLocalTimeHandler *instance;
53 public:
54         PSignal0<void> m_timeUpdated;
55         eDVBLocalTimeHandler();
56         ~eDVBLocalTimeHandler();
57         bool ready() const { return m_time_ready; }
58         int difference() const { return m_time_difference; }
59         static eDVBLocalTimeHandler *getInstance() { return instance; }
60 };
61
62 #endif // __LIB_DVB_DVBTIME_H_