blob: 7fd69264a8fcadef12086667134d3a425e147cec
1 | // |
2 | // |
3 | // amlogic 2013 |
4 | // |
5 | // @ Project : tv |
6 | // @ File Name : CTvEvent.cpp |
7 | // @ Date : 2013-11 |
8 | // @ Author : |
9 | // |
10 | #define LOG_TAG "CTvEvent" |
11 | |
12 | #include "CTvEvent.h" |
13 | #include "CTvDatabase.h" |
14 | #include "CTvProgram.h" |
15 | #include <stdlib.h> |
16 | |
17 | void CTvEvent::InitFromCursor(CTvDatabase::Cursor &c) |
18 | { |
19 | int col; |
20 | |
21 | col = c.getColumnIndex("db_id"); |
22 | this->id = c.getInt(col); |
23 | |
24 | col = c.getColumnIndex("event_id"); |
25 | this->dvbEventID = c.getInt(col); |
26 | |
27 | col = c.getColumnIndex("name"); |
28 | this->name = c.getString(col); |
29 | |
30 | col = c.getColumnIndex("start"); |
31 | this->start = (long)c.getInt(col); |
32 | |
33 | col = c.getColumnIndex("end"); |
34 | this->end = (long)c.getInt(col) ; |
35 | |
36 | col = c.getColumnIndex("nibble_level"); |
37 | this->dvbContent = c.getInt(col); |
38 | |
39 | col = c.getColumnIndex("parental_rating"); |
40 | this->dvbViewAge = c.getInt(col); |
41 | |
42 | col = c.getColumnIndex("sub_flag"); |
43 | this->sub_flag = c.getInt(col); |
44 | |
45 | col = c.getColumnIndex("db_srv_id"); |
46 | this->programID = c.getInt(col); |
47 | |
48 | col = c.getColumnIndex("rrt_ratings"); |
49 | String8 rrtRatings = c.getString(col); |
50 | char *tmp; |
51 | Vector<String8> ratings; |
52 | int l = 0; |
53 | char *pSave; |
54 | tmp = strtok_r(rrtRatings.lockBuffer(rrtRatings.size()), ",", &pSave); |
55 | LOGD("TV, %d, %s", __LINE__, tmp); |
56 | while (tmp != NULL) { |
57 | ratings.push_back(String8(tmp)); |
58 | tmp = strtok_r(NULL, ",", &pSave); |
59 | } |
60 | rrtRatings.unlockBuffer(); |
61 | rating_len = ratings.size(); |
62 | if (!ratings.isEmpty()) { |
63 | for (int i = 0; i < (int)ratings.size(); i++) { |
64 | Vector<String8> rating; |
65 | tmp = strtok_r(ratings.editItemAt(i).lockBuffer(ratings.editItemAt(i).length()), " ", &pSave); |
66 | while (tmp != NULL) { |
67 | rating.push_back(String8(tmp)); |
68 | tmp = strtok_r(NULL, " ", &pSave); |
69 | } |
70 | ratings.editItemAt(i).unlockBuffer(); |
71 | if (rating.size() >= 3) { |
72 | int re = atoi(rating[0]); |
73 | int dm = atoi(rating[1]); |
74 | int vl = atoi(rating[2]); |
75 | vchipRatings.add( new CTvDimension::VChipRating(re, dm, vl)); |
76 | } else |
77 | vchipRatings.add(NULL); |
78 | } |
79 | } |
80 | |
81 | col = c.getColumnIndex("descr"); |
82 | this->description = c.getString(col); |
83 | |
84 | col = c.getColumnIndex("ext_descr"); |
85 | this->extDescription = c.getString(col); |
86 | } |
87 | |
88 | //id; CTvChannel.MODE_ATSC sourceid , other id |
89 | int CTvEvent::getProgPresentEvent(int progSrc, int progID, long nowTime, CTvEvent &ev) |
90 | { |
91 | String8 cmd; |
92 | CTvDatabase::Cursor c; |
93 | |
94 | cmd = String8("select * from evt_table where evt_table."); |
95 | |
96 | if (progSrc == CTvChannel::MODE_ATSC) { |
97 | cmd += String8("source_id = ") + String8::format("%d", progID); |
98 | } else { |
99 | cmd += String8("db_srv_id = ") + String8::format("%d", progID); |
100 | } |
101 | |
102 | cmd += String8(" and evt_table.start <= ") + String8::format("%ld", nowTime) + String8(" and evt_table.end > ") + String8::format("%ld", nowTime); |
103 | |
104 | int ret = CTvDatabase::GetTvDb()->select(cmd, c); |
105 | |
106 | if (c.moveToFirst()) { |
107 | ev.InitFromCursor(c); |
108 | } else { |
109 | c.close(); |
110 | return -1; |
111 | } |
112 | |
113 | c.close(); |
114 | |
115 | return 0; |
116 | } |
117 | |
118 | int CTvEvent::getProgScheduleEvents(int progSrc, int progID, long start, long duration, Vector<sp<CTvEvent> > &vEv) |
119 | { |
120 | String8 cmd; |
121 | long begin = start; |
122 | long end = start + duration; |
123 | |
124 | cmd = String8("select * from evt_table where evt_table."); |
125 | if (progSrc == CTvChannel::MODE_ATSC) { |
126 | cmd += String8("source_id = ") + String8::format("%d", progID); |
127 | } else { |
128 | cmd += String8("db_srv_id = ") + String8::format("%d", progID); |
129 | } |
130 | cmd += String8(" and "); |
131 | cmd += String8(" ((start < ") + String8::format("%ld", begin) + String8(" and end > ") + String8::format("%ld", begin) + String8(") ||"); |
132 | cmd += String8(" (start >= ") + String8::format("%ld", begin) + String8(" and start < ") + String8::format("%ld", end) + String8("))"); |
133 | cmd += String8(" order by evt_table.start"); |
134 | |
135 | CTvDatabase::Cursor c; |
136 | int ret = CTvDatabase::GetTvDb()->select(cmd, c); |
137 | |
138 | if (c.moveToFirst()) { |
139 | do { |
140 | vEv.add(new CTvEvent(c)); |
141 | } while (c.moveToNext()); |
142 | |
143 | } else { |
144 | c.close(); |
145 | return -1; |
146 | } |
147 | |
148 | c.close(); |
149 | return 0; |
150 | } |
151 | int CTvEvent::getATVProgEvent(int progSrc, int progID, CTvEvent &ev) |
152 | { |
153 | String8 cmd; |
154 | CTvDatabase::Cursor c; |
155 | |
156 | cmd = String8("select * from evt_table where evt_table."); |
157 | |
158 | if (progSrc == CTvChannel::MODE_ATSC) { |
159 | LOGD("%s, %d MODE_ATSC", "TV", __LINE__); |
160 | cmd += String8("source_id = ") + String8::format("%d", progID); |
161 | } else { |
162 | LOGD("%s, %d MODE_ANALOG", "TV", __LINE__); |
163 | cmd += String8("db_srv_id = ") + String8::format("%d", progID); |
164 | } |
165 | |
166 | //cmd += String8(" and evt_table.start <= ") + String8::format("%ld", nowTime) + String8(" and evt_table.end > ") + String8::format("%ld", nowTime); |
167 | |
168 | int ret = CTvDatabase::GetTvDb()->select(cmd, c); |
169 | |
170 | if (c.moveToFirst()) { |
171 | ev.InitFromCursor(c); |
172 | } else { |
173 | c.close(); |
174 | return -1; |
175 | } |
176 | |
177 | c.close(); |
178 | |
179 | return 0; |
180 | } |
181 | |
182 | int CTvEvent::CleanAllEvent() |
183 | { |
184 | CTvDatabase::GetTvDb()->exeSql("delete from evt_table"); |
185 | return 0; |
186 | } |
187 | |
188 | int CTvEvent::selectByID(int id, CTvEvent &evt) |
189 | { |
190 | CTvDatabase::Cursor c; |
191 | String8 sql; |
192 | |
193 | sql = String8("select * from evt_table where evt_table.db_id = ") + String8::format("%d", id); |
194 | CTvDatabase::GetTvDb()->select(sql.string(), c); |
195 | if (c.moveToFirst()) { |
196 | evt.InitFromCursor(c); |
197 | } else { |
198 | c.close(); |
199 | return -1; |
200 | } |
201 | |
202 | c.close(); |
203 | return 0; |
204 | } |
205 | |
206 | int CTvEvent::bookEvent(int evtId, bool bBookFlag) |
207 | { |
208 | String8 cmd; |
209 | |
210 | cmd = String8("update evt_table set sub_flag=") + String8::format("%d", bBookFlag) |
211 | + String8(" where event_id=") + String8::format("%d", evtId); |
212 | |
213 | CTvDatabase::GetTvDb()->exeSql(cmd.string()); |
214 | |
215 | return 0; |
216 | } |
217 | |
218 | CTvEvent::CTvEvent(CTvDatabase::Cursor &c) |
219 | { |
220 | InitFromCursor(c); |
221 | } |
222 | |
223 | CTvEvent::CTvEvent() |
224 | { |
225 | } |
226 | |
227 | CTvEvent::~CTvEvent() |
228 | { |
229 | int size = vchipRatings.size(); |
230 | for (int i = 0; i < size; i++) |
231 | delete vchipRatings[i]; |
232 | } |
233 | Vector<CTvDimension::VChipRating *> CTvEvent::getVChipRatings() |
234 | { |
235 | return vchipRatings; |
236 | } |
237 | |
238 |