Support turbo2.
[vuplus_dvbapp] / 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(uint16_t mjd, uint32_t stime_bcd);
29 time_t parseDVBtime(const uint8_t* data);
30 time_t parseDVBtime(const uint8_t* data, uint16_t *hash);
31
32 class TDT: public eGTable
33 {
34         eDVBChannel *chan;
35         ePtr<iDVBDemux> demux;
36         ePtr<eTimer> m_interval_timer;
37         int createTable(unsigned int nr, const __u8 *data, unsigned int max);
38         void ready(int);
39         int update_count;
40 public:
41         TDT(eDVBChannel *chan, int update_count=0);
42         void start();
43         void startTimer(int interval);
44         int getUpdateCount() { return update_count; }
45 };
46
47 #endif  // SWIG
48
49 class eDVBLocalTimeHandler: public Object
50 {
51         DECLARE_REF(eDVBLocalTimeHandler);
52         struct channel_data
53         {
54                 ePtr<TDT> tdt;
55                 ePtr<eDVBChannel> channel;
56                 ePtr<eConnection> m_stateChangedConn;
57                 int m_prevChannelState;
58         };
59         bool m_use_dvb_time;
60         ePtr<eTimer> m_updateNonTunedTimer;
61         friend class TDT;
62         std::map<iDVBChannel*, channel_data> m_knownChannels;
63         std::map<eDVBChannelID,int> m_timeOffsetMap;
64         ePtr<eConnection> m_chanAddedConn;
65         bool m_time_ready;
66         int m_time_difference;
67         int m_last_tp_time_difference;
68         void DVBChannelAdded(eDVBChannel*);
69         void DVBChannelStateChanged(iDVBChannel*);
70         void readTimeOffsetData(const char*);
71         void writeTimeOffsetData(const char*);
72         void updateTime(time_t tp_time, eDVBChannel*, int updateCount);
73         void updateNonTuned();
74         static eDVBLocalTimeHandler *instance;
75 #ifdef SWIG
76         eDVBLocalTimeHandler();
77         ~eDVBLocalTimeHandler();
78 #endif
79 public:
80 #ifndef SWIG
81         eDVBLocalTimeHandler();
82         ~eDVBLocalTimeHandler();
83 #endif
84         bool getUseDVBTime() { return m_use_dvb_time; }
85         void setUseDVBTime(bool b);
86         PSignal0<void> m_timeUpdated;
87         bool ready() const { return m_time_ready; }
88         static eDVBLocalTimeHandler *getInstance() { return instance; }
89 };
90
91 #endif // __LIB_DVB_DVBTIME_H_