Merge branch 'master' of git.opendreambox.org:/git/enigma2
[enigma2.git] / lib / dvb / dvbtime.h
1 #ifndef __LIB_DVB_DVBTIME_H_
2 #define __LIB_DVB_DVBTIME_H_
3
4 #ifndef SWIG
5
6 #include <lib/base/eerror.h>
7 #include <lib/dvb/esection.h>
8 #include <dvbsi++/time_date_section.h>
9
10 class eDVBChannel;
11
12 inline int fromBCD(int bcd)
13 {
14         if ((bcd&0xF0)>=0xA0)
15                 return -1;
16         if ((bcd&0xF)>=0xA)
17                 return -1;
18         return ((bcd&0xF0)>>4)*10+(bcd&0xF);
19 }
20
21 inline int toBCD(int dec)
22 {
23         if (dec >= 100)
24                 return -1;
25         return int(dec/10)*0x10 + dec%10;
26 }
27
28 time_t parseDVBtime(__u8 t1, __u8 t2, __u8 t3, __u8 t4, __u8 t5);
29
30 class TDT: public eGTable
31 {
32         eDVBChannel *chan;
33         ePtr<iDVBDemux> demux;
34         ePtr<eTimer> m_interval_timer;
35         int createTable(unsigned int nr, const __u8 *data, unsigned int max);
36         void ready(int);
37         int update_count;
38 public:
39         TDT(eDVBChannel *chan, int update_count=0);
40         void start();
41         void startTimer(int interval);
42         int getUpdateCount() { return update_count; }
43 };
44
45 #endif  // SWIG
46
47 class eDVBLocalTimeHandler: public Object
48 {
49         DECLARE_REF(eDVBLocalTimeHandler);
50         struct channel_data
51         {
52                 ePtr<TDT> tdt;
53                 ePtr<eDVBChannel> channel;
54                 ePtr<eConnection> m_stateChangedConn;
55                 int m_prevChannelState;
56         };
57         ePtr<eTimer> m_updateNonTunedTimer;
58         friend class TDT;
59         std::map<iDVBChannel*, channel_data> m_knownChannels;
60         std::map<eDVBChannelID,int> m_timeOffsetMap;
61         ePtr<eConnection> m_chanAddedConn;
62         bool m_time_ready;
63         int m_time_difference;
64         int m_last_tp_time_difference;
65         void DVBChannelAdded(eDVBChannel*);
66         void DVBChannelStateChanged(iDVBChannel*);
67         void readTimeOffsetData(const char*);
68         void writeTimeOffsetData(const char*);
69         void updateTime(time_t tp_time, eDVBChannel*, int updateCount);
70         void updateNonTuned();
71         static eDVBLocalTimeHandler *instance;
72 #ifdef SWIG
73         eDVBLocalTimeHandler();
74         ~eDVBLocalTimeHandler();
75 #endif
76 public:
77 #ifndef SWIG
78         eDVBLocalTimeHandler();
79         ~eDVBLocalTimeHandler();
80 #endif
81         PSignal0<void> m_timeUpdated;
82         bool ready() const { return m_time_ready; }
83         static eDVBLocalTimeHandler *getInstance() { return instance; }
84 };
85
86 #endif // __LIB_DVB_DVBTIME_H_