blob: 9e1f2f610a936430a0a868c0bfe4c8c995d03e2a
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 | char *pSave; |
59 | tmp = strtok_r(rrtRatings.lockBuffer(rrtRatings.size()), ",", &pSave); |
60 | LOGD("%s, %d, %s", "TV", __LINE__, tmp); |
61 | while (tmp != NULL) { |
62 | ratings.push_back(String8(tmp)); |
63 | tmp = strtok_r(NULL, ",", &pSave); |
64 | } |
65 | rrtRatings.unlockBuffer(); |
66 | rating_len = ratings.size(); |
67 | if (!ratings.isEmpty()) { |
68 | for (int i = 0; i < ratings.size(); i++) { |
69 | Vector<String8> rating; |
70 | tmp = strtok_r(ratings.editItemAt(i).lockBuffer(ratings.editItemAt(i).length()), " ", &pSave); |
71 | while (tmp != NULL) { |
72 | rating.push_back(String8(tmp)); |
73 | tmp = strtok_r(NULL, " ", &pSave); |
74 | } |
75 | ratings.editItemAt(i).unlockBuffer(); |
76 | if (rating.size() >= 3) { |
77 | int re = atoi(rating[0]); |
78 | int dm = atoi(rating[1]); |
79 | int vl = atoi(rating[2]); |
80 | vchipRatings.add( new CTvDimension::VChipRating(re, dm, vl)); |
81 | } else |
82 | vchipRatings.add(NULL); |
83 | } |
84 | } |
85 | |
86 | col = c.getColumnIndex("descr"); |
87 | this->description = c.getString(col); |
88 | |
89 | col = c.getColumnIndex("ext_descr"); |
90 | this->extDescription = c.getString(col); |
91 | } |
92 | |
93 | //id; CTvChannel.MODE_ATSC sourceid , other id |
94 | int CTvEvent::getProgPresentEvent(int progSrc, int progID, long nowTime, CTvEvent &ev) |
95 | { |
96 | String8 cmd; |
97 | CTvDatabase::Cursor c; |
98 | |
99 | cmd = String8("select * from evt_table where evt_table."); |
100 | |
101 | if (progSrc == CTvChannel::MODE_ATSC) { |
102 | cmd += String8("source_id = ") + String8::format("%d", progID); |
103 | } else { |
104 | cmd += String8("db_srv_id = ") + String8::format("%d", progID); |
105 | } |
106 | |
107 | cmd += String8(" and evt_table.start <= ") + String8::format("%ld", nowTime) + String8(" and evt_table.end > ") + String8::format("%ld", nowTime); |
108 | |
109 | int ret = CTvDatabase::GetTvDb()->select(cmd, c); |
110 | |
111 | if (c.moveToFirst()) { |
112 | ev.InitFromCursor(c); |
113 | } else { |
114 | c.close(); |
115 | return -1; |
116 | } |
117 | |
118 | c.close(); |
119 | |
120 | return 0; |
121 | } |
122 | |
123 | int CTvEvent::getProgScheduleEvents(int progSrc, int progID, long start, long duration, Vector<sp<CTvEvent> > &vEv) |
124 | { |
125 | String8 cmd; |
126 | long begin = start; |
127 | long end = start + duration; |
128 | |
129 | cmd = String8("select * from evt_table where evt_table."); |
130 | if (progSrc == CTvChannel::MODE_ATSC) { |
131 | cmd += String8("source_id = ") + String8::format("%d", progID); |
132 | } else { |
133 | cmd += String8("db_srv_id = ") + String8::format("%d", progID); |
134 | } |
135 | cmd += String8(" and "); |
136 | cmd += String8(" ((start < ") + String8::format("%ld", begin) + String8(" and end > ") + String8::format("%ld", begin) + String8(") ||"); |
137 | cmd += String8(" (start >= ") + String8::format("%ld", begin) + String8(" and start < ") + String8::format("%ld", end) + String8("))"); |
138 | cmd += String8(" order by evt_table.start"); |
139 | |
140 | CTvDatabase::Cursor c; |
141 | int ret = CTvDatabase::GetTvDb()->select(cmd, c); |
142 | |
143 | if (c.moveToFirst()) { |
144 | do { |
145 | vEv.add(new CTvEvent(c)); |
146 | } while (c.moveToNext()); |
147 | |
148 | } else { |
149 | c.close(); |
150 | return -1; |
151 | } |
152 | |
153 | c.close(); |
154 | return 0; |
155 | } |
156 | int CTvEvent::getATVProgEvent(int progSrc, int progID, CTvEvent &ev) |
157 | { |
158 | String8 cmd; |
159 | CTvDatabase::Cursor c; |
160 | |
161 | cmd = String8("select * from evt_table where evt_table."); |
162 | |
163 | if (progSrc == CTvChannel::MODE_ATSC) { |
164 | LOGD("%s, %d MODE_ATSC", "TV", __LINE__); |
165 | cmd += String8("source_id = ") + String8::format("%d", progID); |
166 | } else { |
167 | LOGD("%s, %d MODE_ANALOG", "TV", __LINE__); |
168 | cmd += String8("db_srv_id = ") + String8::format("%d", progID); |
169 | } |
170 | |
171 | //cmd += String8(" and evt_table.start <= ") + String8::format("%ld", nowTime) + String8(" and evt_table.end > ") + String8::format("%ld", nowTime); |
172 | |
173 | int ret = CTvDatabase::GetTvDb()->select(cmd, c); |
174 | |
175 | if (c.moveToFirst()) { |
176 | ev.InitFromCursor(c); |
177 | } else { |
178 | c.close(); |
179 | return -1; |
180 | } |
181 | |
182 | c.close(); |
183 | |
184 | return 0; |
185 | } |
186 | |
187 | int CTvEvent::CleanAllEvent() |
188 | { |
189 | CTvDatabase::GetTvDb()->exeSql("delete from evt_table"); |
190 | return 0; |
191 | } |
192 | |
193 | int CTvEvent::selectByID(int id, CTvEvent &evt) |
194 | { |
195 | CTvDatabase::Cursor c; |
196 | String8 sql; |
197 | |
198 | sql = String8("select * from evt_table where evt_table.db_id = ") + String8::format("%d", id); |
199 | CTvDatabase::GetTvDb()->select(sql.string(), c); |
200 | if (c.moveToFirst()) { |
201 | evt.InitFromCursor(c); |
202 | } else { |
203 | c.close(); |
204 | return -1; |
205 | } |
206 | |
207 | c.close(); |
208 | return 0; |
209 | } |
210 | |
211 | int CTvEvent::bookEvent(int evtId, bool bBookFlag) |
212 | { |
213 | String8 cmd; |
214 | |
215 | cmd = String8("update evt_table set sub_flag=") + String8::format("%d", bBookFlag) |
216 | + String8(" where event_id=") + String8::format("%d", evtId); |
217 | |
218 | CTvDatabase::GetTvDb()->exeSql(cmd.string()); |
219 | |
220 | return 0; |
221 | } |
222 | |
223 | CTvEvent::CTvEvent(CTvDatabase::Cursor &c) |
224 | { |
225 | InitFromCursor(c); |
226 | } |
227 | |
228 | CTvEvent::CTvEvent() |
229 | { |
230 | } |
231 | |
232 | CTvEvent::~CTvEvent() |
233 | { |
234 | int size = vchipRatings.size(); |
235 | for (int i = 0; i < size; i++) |
236 | delete vchipRatings[i]; |
237 | } |
238 | Vector<CTvDimension::VChipRating *> CTvEvent::getVChipRatings() |
239 | { |
240 | return vchipRatings; |
241 | } |
242 | |
243 |