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