use menu source/converter
[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         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         struct channel_data
50         {
51                 TDT *tdt;
52                 ePtr<eDVBChannel> channel;
53                 ePtr<eConnection> m_stateChangedConn;
54                 int m_prevChannelState;
55         };
56         friend class TDT;
57         DECLARE_REF(eDVBLocalTimeHandler)
58         std::map<iDVBChannel*, channel_data> m_knownChannels;
59         std::map<eDVBChannelID,int> m_timeOffsetMap;
60         ePtr<eConnection> m_chanAddedConn;
61         bool m_time_ready;
62         int m_time_difference;
63         int m_last_tp_time_difference;
64         void DVBChannelAdded(eDVBChannel*);
65         void DVBChannelStateChanged(iDVBChannel*);
66         void readTimeOffsetData(const char*);
67         void writeTimeOffsetData(const char*);
68         void updateTime(time_t tp_time, eDVBChannel*, int updateCount);
69         static eDVBLocalTimeHandler *instance;
70 #ifdef SWIG
71         eDVBLocalTimeHandler();
72         ~eDVBLocalTimeHandler();
73 #endif
74 public:
75 #ifndef SWIG
76         eDVBLocalTimeHandler();
77         ~eDVBLocalTimeHandler();
78 #endif
79         PSignal0<void> m_timeUpdated;
80         time_t nowTime() const { return m_time_ready ? ::time(0)+m_time_difference : -1; }
81         bool ready() const { return m_time_ready; }
82         int difference() const { return m_time_difference; }
83         static eDVBLocalTimeHandler *getInstance() { return instance; }
84 };
85
86 #endif // __LIB_DVB_DVBTIME_H_