4.3.1r21
[enigma2.git] / usr / include / enigma2 / 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, __u16 *hash=0);
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, int len, 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 iObject, public sigc::trackable
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         bool m_use_dvb_time;
58         ePtr<eTimer> m_updateNonTunedTimer;
59         friend class TDT;
60         std::map<iDVBChannel*, channel_data> m_knownChannels;
61         std::map<eDVBChannelID,int> m_timeOffsetMap;
62         ePtr<eConnection> m_chanAddedConn;
63         bool m_time_ready;
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         bool getUseDVBTime() { return m_use_dvb_time; }
82         void setUseDVBTime(bool b);
83         eSignal0<void> m_timeUpdated;
84         bool ready() const { return m_time_ready; }
85         static eDVBLocalTimeHandler *getInstance() { return instance; }
86 };
87
88 #endif // __LIB_DVB_DVBTIME_H_