blob: d43bbd84c20c5bbd98a655a51ba9334d9de3bed6
1 | // |
2 | // |
3 | // amlogic 2013 |
4 | // |
5 | // @ Project : tv |
6 | // @ File Name : CTvChannel.h |
7 | // @ Date : 2013-11 |
8 | // @ Author : |
9 | // |
10 | // |
11 | #include <utils/Timers.h> |
12 | #include "CTvLog.h" |
13 | #include <time.h> |
14 | //#include <cutils/tztime.h> |
15 | #include <sys/times.h> |
16 | #include <sys/sysinfo.h> |
17 | |
18 | #define LOG_TAG "CTVTIME" |
19 | /** |
20 | *TV时间管理 |
21 | */ |
22 | class CTvTime |
23 | { |
24 | public: |
25 | CTvTime() |
26 | { |
27 | mDiff = 0; |
28 | mHZ = sysconf( _SC_CLK_TCK ); |
29 | } |
30 | |
31 | /** |
32 | *设定当前时间 |
33 | *@param time 当前时间(毫秒单位) |
34 | */ |
35 | long getSysUTCTime() |
36 | { |
37 | //struct tm tm; |
38 | //time_t t; |
39 | //int64_t r = mktime_tz(&(tm), NULL); |
40 | //time_t t = time(NULL); |
41 | //LOGD("---------utc t = %ld time t=%ld", r, t); |
42 | return 0; |
43 | } |
44 | void setTime(long t) |
45 | { |
46 | //long utcMS; |
47 | //time(&utcMS); |
48 | //nsecs_t ns = systemTime(CLOCK_REALTIME); |
49 | //nsecs_t tm = ns2s(ns); |
50 | //unsigned long ticks = times(NULL); |
51 | //long tm = ticks/mHZ; |
52 | struct sysinfo s_info; |
53 | int error; |
54 | error = sysinfo(&s_info); |
55 | |
56 | mDiff = t - s_info.uptime; |
57 | LOGD("--- mDiff=%ld", mDiff); |
58 | } |
59 | |
60 | /** |
61 | *取得当前时间 |
62 | *@return 返回当前时间 |
63 | */ |
64 | long getTime() |
65 | { |
66 | //long utcMS; |
67 | //time(&utcMS); |
68 | //nsecs_t ns = systemTime(CLOCK_REALTIME); |
69 | //nsecs_t sec = ns2s(ns); |
70 | |
71 | //unsigned long ticks = times(NULL); |
72 | //long sec = ticks/mHZ; |
73 | struct sysinfo s_info; |
74 | int error; |
75 | error = sysinfo(&s_info); |
76 | |
77 | |
78 | LOGD("--- mDiff=%ld, sec=%ld", mDiff, s_info.uptime); |
79 | return s_info.uptime + mDiff; |
80 | } |
81 | |
82 | /** |
83 | *取得TDT/STT与系统时间的差值 |
84 | *@return 返回差值时间 |
85 | */ |
86 | long getDiffTime() |
87 | { |
88 | return mDiff; |
89 | } |
90 | |
91 | /** |
92 | *设置TDT/STT与系统时间的差值 |
93 | */ |
94 | void setDiffTime(long diff) |
95 | { |
96 | this->mDiff = diff; |
97 | } |
98 | |
99 | private: |
100 | long mDiff; |
101 | unsigned long mHZ; |
102 | }; |
103 |