|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Offers interface to IPTV Epg database* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <badesca.h> // CDesCArrayFlat |
|
22 #include <bautils.h> // file helpers |
|
23 #include <d32dbms.h> |
|
24 #include <eikenv.h> |
|
25 #include "CIptvEpgLatestEpgAvailable.h" |
|
26 #include "IptvLiveLogger.h" |
|
27 |
|
28 #include "CIptvEpgDatabase.h" |
|
29 #include "CIptvEpgChannel.h" |
|
30 #include "CIptvEpgProgram.h" |
|
31 #include "CIptvEpgProgramWithSchedule.h" |
|
32 #include "CIptvEpgSchedule.h" |
|
33 #include "CIptvEpgScheduleSearch.h" |
|
34 |
|
35 // CONSTANTS |
|
36 |
|
37 // constant for program guide: day changes at 04:00 AM |
|
38 // Note: If you modify this, the range is 0-23, otherwise |
|
39 // USER 3 panic will happen in GetSchedulesByChannelAndDayL |
|
40 const TInt KIptvDefaultDayOffsetHours( 4 ); |
|
41 const TInt KIptvDefaultUriCount( 5 ); |
|
42 |
|
43 // ============================ MEMBER FUNCTIONS =============================== |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CIptvEpgDatabase::CIptvEpgDatabase |
|
47 // C++ default constructor can NOT contain any code, that |
|
48 // might leave. |
|
49 // ----------------------------------------------------------------------------- |
|
50 CIptvEpgDatabase::CIptvEpgDatabase( const TFileName& aDbFile ) : |
|
51 iDbFile( aDbFile ), iLocalState( EReady ) |
|
52 { |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CIptvEpgDatabase::ConstructL |
|
57 // Second phase construction. Leaves, if RFs session cannot be created. |
|
58 // ----------------------------------------------------------------------------- |
|
59 void CIptvEpgDatabase::ConstructL() |
|
60 { |
|
61 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::ConstructL()")); |
|
62 User::LeaveIfError( iFsSession.Connect() ); |
|
63 MakeSqlStrings(); |
|
64 |
|
65 // Create database and connect into it |
|
66 CreateDbL(); |
|
67 |
|
68 TRAPD( error, CreateMulticastDbSessionL()); |
|
69 if ( error != KErrNone ) |
|
70 { |
|
71 LIVE_TV_TRACE2(_L("CIptvEpgDatabase:: Could not open session to db (%d)"), error); |
|
72 |
|
73 if ( error != KErrNoMemory && |
|
74 error != KErrLocked && |
|
75 error != KErrDisMounted && |
|
76 error != KErrDiskFull && |
|
77 error != KErrNotReady ) |
|
78 { |
|
79 // Delete and recreate database file. Cannot recover other way. |
|
80 LIVE_TV_TRACE1(_L("CIptvEpgDatabase:: fatal error occured while opening db, recreating db")); |
|
81 |
|
82 iFsSession.Delete( iDbFile ); //ignore error |
|
83 |
|
84 TRAP( error, CreateDbL() ); |
|
85 if ( error != KErrNone ) |
|
86 { |
|
87 LIVE_TV_TRACE2(_L("CIptvEpgDatabase:: couldnt recreate db (%d), leaving."), error); |
|
88 User::Leave( error ); |
|
89 } |
|
90 |
|
91 TRAP( error, CreateMulticastDbSessionL() ); |
|
92 if ( error != KErrNone ) |
|
93 { |
|
94 LIVE_TV_TRACE2(_L("CIptvEpgDatabase:: couldnt open session to db (%d), leaving."), error); |
|
95 User::Leave( error ); |
|
96 } |
|
97 |
|
98 } |
|
99 else |
|
100 { |
|
101 LIVE_TV_TRACE1(_L("CIptvEpgDatabase:: temporary error occured while opening db, leaving db intact, leaving.")); |
|
102 User::Leave( error ); |
|
103 } |
|
104 } |
|
105 |
|
106 iLocalState = EReady; |
|
107 |
|
108 // Register to listen the file for backup |
|
109 iBackupWrapper = CBaBackupSessionWrapper::NewL(); |
|
110 iBackupWrapper->RegisterFileL( iDbFile, *this ); |
|
111 |
|
112 iActiveWait = new (ELeave) CActiveSchedulerWait(); |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CIptvEpgDatabase::NewL |
|
117 // Two-phased constructor. |
|
118 // ----------------------------------------------------------------------------- |
|
119 EXPORT_C CIptvEpgDatabase* CIptvEpgDatabase::NewL(const TFileName& aDbFile) |
|
120 { |
|
121 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::NewL()")); |
|
122 CIptvEpgDatabase* self = new ( ELeave ) CIptvEpgDatabase( aDbFile ); |
|
123 CleanupStack::PushL( self ); |
|
124 self->ConstructL(); |
|
125 CleanupStack::Pop( self ); |
|
126 return self; |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CIptvEpgDatabase::~CIptvEpgDatabase() |
|
131 // Destructor |
|
132 // ----------------------------------------------------------------------------- |
|
133 CIptvEpgDatabase::~CIptvEpgDatabase() |
|
134 { |
|
135 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::~CIptvEpgDatabase in")); |
|
136 if ( iBackupWrapper ) |
|
137 { |
|
138 iBackupWrapper->DeregisterFile( iDbFile ); |
|
139 } |
|
140 delete iBackupWrapper; |
|
141 iFsSession.Close(); |
|
142 CloseMulticastDbSession(); |
|
143 |
|
144 if ( iActiveWait && iActiveWait->IsStarted() ) |
|
145 { |
|
146 iActiveWait->AsyncStop(); |
|
147 } |
|
148 delete iActiveWait; |
|
149 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::~CIptvEpgDatabase out")); |
|
150 } |
|
151 |
|
152 // --------------------------------------------------------------------------- |
|
153 // CIptvEpgDatabase::CreateDbL() |
|
154 // |
|
155 // Create a new database. |
|
156 // --------------------------------------------------------------------------- |
|
157 void CIptvEpgDatabase::CreateDbL() |
|
158 { |
|
159 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::CreateDbL()")); |
|
160 if ( !BaflUtils::FileExists( iFsSession, iDbFile ) ) |
|
161 { |
|
162 LIVE_TV_TRACE1( _L("Database file wasn't found, creating new")); |
|
163 RDbNamedDatabase database; |
|
164 CleanupClosePushL( database ); |
|
165 BaflUtils::EnsurePathExistsL( iFsSession, iDbFile ); |
|
166 User::LeaveIfError( database.Create( iFsSession, iDbFile ) ); |
|
167 |
|
168 CreateChannelTableL( database ); |
|
169 |
|
170 CreateProgramTableL( database ); |
|
171 |
|
172 CreateScheduleTableL( database ); |
|
173 |
|
174 CreateLatestEpgAvailableTableL( database ); |
|
175 |
|
176 CreateLastModifiedTableL( database ); |
|
177 |
|
178 CleanupStack::PopAndDestroy( &database ); |
|
179 } |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // CIptvEpgDatabase::CreateMulticastDbSessionL() |
|
184 // |
|
185 // Open a new database session and the database |
|
186 // --------------------------------------------------------------------------- |
|
187 void CIptvEpgDatabase::CreateMulticastDbSessionL() |
|
188 { |
|
189 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::CreateMulticastDbSessionL()")); |
|
190 User::LeaveIfError( iMulticastDbSession.Connect() ); |
|
191 User::LeaveIfError( iMulticastDb.Open( iMulticastDbSession, iDbFile ) ); |
|
192 User::LeaveIfError( iMulticastDb.Compact() ); |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // CIptvEpgDatabase::CloseMulticastDbSession() |
|
197 // |
|
198 // Closes a database session and the database |
|
199 // --------------------------------------------------------------------------- |
|
200 void CIptvEpgDatabase::CloseMulticastDbSession() |
|
201 { |
|
202 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::CloseMulticastDbSession()")); |
|
203 iMulticastDb.Close(); |
|
204 iMulticastDbSession.Close(); |
|
205 } |
|
206 |
|
207 // --------------------------------------------------------------------------- |
|
208 // CIptvEpgDatabase::CreateScheduleTableL() |
|
209 // |
|
210 // Creates schedule database table |
|
211 // --------------------------------------------------------------------------- |
|
212 void CIptvEpgDatabase::CreateScheduleTableL( RDbNamedDatabase& aDatabase ) const |
|
213 { |
|
214 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::CreateScheduleTableL()")); |
|
215 TDbCol keyCol( KIptvEpgScheduleTableKeyCol, EDbColUint32 ); |
|
216 keyCol.iAttributes = TDbCol::EAutoIncrement; |
|
217 |
|
218 TDbCol serviceIdCol( KIptvEpgScheduleServiceProviderIdCol, EDbColUint32 ); |
|
219 |
|
220 TDbCol channelIdCol( KIptvEpgScheduleChannelIdCol, EDbColInt64 ); |
|
221 |
|
222 TDbCol programIdCol( KIptvEpgScheduleProgramIdCol, EDbColInt64 ); |
|
223 |
|
224 TDbCol startTimeCol( KIptvEpgScheduleStartTimeCol, EDbColDateTime ); |
|
225 |
|
226 TDbCol endTimeCol( KIptvEpgScheduleEndTimeCol, EDbColDateTime ); |
|
227 |
|
228 CDbColSet* scheduleColSet = CDbColSet::NewLC(); |
|
229 scheduleColSet->AddL( keyCol ); |
|
230 scheduleColSet->AddL( serviceIdCol ); |
|
231 scheduleColSet->AddL( channelIdCol ); |
|
232 scheduleColSet->AddL( programIdCol ); |
|
233 scheduleColSet->AddL( startTimeCol ); |
|
234 scheduleColSet->AddL( endTimeCol ); |
|
235 |
|
236 User::LeaveIfError( aDatabase.CreateTable( KIptvEpgScheduleTable, *scheduleColSet ) ); |
|
237 CleanupStack::PopAndDestroy( scheduleColSet ); |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // CIptvEpgDatabase::CreateChannelProgramTableL() |
|
242 // |
|
243 // Creates ChannelProgram table. Leaves, if the table cannot be created. |
|
244 // --------------------------------------------------------------------------- |
|
245 void CIptvEpgDatabase::CreateChannelProgramTableL( |
|
246 RDbNamedDatabase& /*aDatabase*/ ) const |
|
247 { |
|
248 } |
|
249 |
|
250 // --------------------------------------------------------------------------- |
|
251 // CIptvEpgDatabase::CreateProgramTableL() |
|
252 // |
|
253 // Creates Program table. Leaves, if the table cannot be created. |
|
254 // --------------------------------------------------------------------------- |
|
255 void CIptvEpgDatabase::CreateProgramTableL( RDbNamedDatabase& aDatabase ) const |
|
256 { |
|
257 LIVE_TV_TRACE1( _L("CIptvEpgDatabase::CreateProgramTableL" ) ); |
|
258 // Key |
|
259 TDbCol keyCol( KIptvEpgProgramDbKeyCol, EDbColUint32 ); |
|
260 keyCol.iAttributes = TDbCol::EAutoIncrement; |
|
261 |
|
262 TDbCol idCol( KIptvEpgProgramIdCol, EDbColInt64 ); |
|
263 |
|
264 TDbCol channelIdCol( KIptvEpgProgramChannelId, EDbColInt64 ); |
|
265 |
|
266 TDbCol servProvIdCol( KIptvEpgProgramServProviderIdCol, EDbColUint32 ); |
|
267 |
|
268 TDbCol uriCol( KIptvEpgProgramURICol, EDbColText, KIptvEpgUriMaxLength ); |
|
269 |
|
270 TDbCol genreCol( KIptvEpgProgramGenreCol, EDbColText ); |
|
271 |
|
272 TDbCol nameCol( KIptvEpgProgramNameCol, EDbColText, KIptvEpgProgramMaxLength ); |
|
273 |
|
274 TDbCol descriptionCol( KIptvEpgProgramDescriptionCol, EDbColLongText ); |
|
275 |
|
276 TDbCol languageCol( KIptvEpgProgramLanguageCol, EDbColText ); |
|
277 |
|
278 TDbCol parentalCol( KIptvEpgProgramParentalRatingCol, EDbColText ); |
|
279 |
|
280 CDbColSet* programColSet = CDbColSet::NewLC(); |
|
281 programColSet->AddL( keyCol ); |
|
282 programColSet->AddL( idCol ); |
|
283 programColSet->AddL( channelIdCol ); |
|
284 programColSet->AddL( servProvIdCol ); |
|
285 programColSet->AddL( uriCol ); |
|
286 programColSet->AddL( genreCol ); |
|
287 programColSet->AddL( nameCol ); |
|
288 programColSet->AddL( descriptionCol ); |
|
289 programColSet->AddL( languageCol ); |
|
290 programColSet->AddL( parentalCol ); |
|
291 |
|
292 TInt error = aDatabase.CreateTable( KIptvEpgProgramTable, |
|
293 *programColSet ); |
|
294 if ( error != KErrNone ) |
|
295 { |
|
296 LIVE_TV_TRACE2( _L("\t\tCIptvEpgDatabase::CreateProgramTableL CreateTable returned %d"), error ); |
|
297 User::Leave( error ); |
|
298 } |
|
299 |
|
300 CleanupStack::PopAndDestroy( programColSet ); |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // CIptvEpgDatabase::CreateChannelTableL() |
|
305 // |
|
306 // Creates Channel table. Leaves, if the table cannot be created. |
|
307 // --------------------------------------------------------------------------- |
|
308 void CIptvEpgDatabase::CreateChannelTableL( RDbNamedDatabase& aDatabase ) const |
|
309 { |
|
310 LIVE_TV_TRACE1( _L("CIptvEpgDatabase::CreateChannelTableL" ) ); |
|
311 // Key |
|
312 TDbCol keyCol( KIptvEpgChannelDbKeyCol, EDbColUint32 ); |
|
313 keyCol.iAttributes = TDbCol::EAutoIncrement; |
|
314 |
|
315 TDbCol idCol( KIptvEpgChannelIdCol, EDbColInt64 ); |
|
316 |
|
317 TDbCol servProvIdCol( KIptvEpgChannelServProviderIdCol, EDbColUint32 ); |
|
318 |
|
319 TDbCol nameCol( KIptvEpgChannelNameCol, EDbColText, KIptvEpgChannelNameMaxLength ); |
|
320 |
|
321 TDbCol logoPathCol( KIptvEpgChannelLogoPathCol, EDbColText, KIptvEpgLogoPathMaxLength ); |
|
322 |
|
323 TDbCol descriptionCol( KIptvEpgChannelDescriptionCol, EDbColText, |
|
324 KIptvEpgDescrMaxLength ); |
|
325 |
|
326 TDbCol uriCol( KIptvEpgChannelURICol, EDbColText, KIptvEpgUriMaxLength ); |
|
327 |
|
328 TDbCol sdpCol( KIptvEpgChannelSDPCol, EDbColLongText ); |
|
329 |
|
330 TDbCol orderCol( KIptvEpgChannelOrderCol, EDbColUint32 ); |
|
331 |
|
332 // Create column set and add defined columns in to the set |
|
333 CDbColSet* channelColSet = CDbColSet::NewLC(); |
|
334 channelColSet->AddL( keyCol ); |
|
335 channelColSet->AddL( idCol ); |
|
336 channelColSet->AddL( servProvIdCol ); |
|
337 channelColSet->AddL( nameCol ); |
|
338 channelColSet->AddL( logoPathCol ); |
|
339 channelColSet->AddL( descriptionCol ); |
|
340 channelColSet->AddL( uriCol ); |
|
341 channelColSet->AddL( sdpCol ); |
|
342 channelColSet->AddL( orderCol ); |
|
343 |
|
344 // Create new table to the database with created columnset |
|
345 TInt error = aDatabase.CreateTable( KIptvEpgChannelTable, |
|
346 *channelColSet ); |
|
347 if ( error != KErrNone ) |
|
348 { |
|
349 LIVE_TV_TRACE2( _L("\n\t\tCIptvEpgDatabase::CreateChannelTableL: CreateTable returned %d" ), error ); |
|
350 User::Leave( error ); |
|
351 } |
|
352 |
|
353 CleanupStack::PopAndDestroy( channelColSet ); |
|
354 } |
|
355 |
|
356 // --------------------------------------------------------------------------- |
|
357 // CIptvEpgDatabase::CreateLastModifiedTableL() |
|
358 // |
|
359 // Creates table for last modified data |
|
360 // --------------------------------------------------------------------------- |
|
361 void CIptvEpgDatabase::CreateLastModifiedTableL( RDbNamedDatabase& aDatabase ) const |
|
362 { |
|
363 // First create columns |
|
364 TDbCol keyCol( KIptvEpgLastModifiedTableKeyCol, EDbColUint32 ); |
|
365 keyCol.iAttributes = TDbCol::EAutoIncrement; |
|
366 TDbCol serviceIdCol( KIptvEpgLastModifiedTableServiceIdCol, EDbColUint32 ); |
|
367 TDbCol eTagCol( KIptvEpgLastModifiedTableETagCol, EDbColText ); |
|
368 TDbCol lastModifiedDateTime( KIptvEpgLastModifiedTableTimeCol, EDbColText ); |
|
369 |
|
370 CDbColSet* lastModifiedColSet = CDbColSet::NewLC(); |
|
371 lastModifiedColSet->AddL( keyCol ); |
|
372 lastModifiedColSet->AddL( serviceIdCol ); |
|
373 lastModifiedColSet->AddL( eTagCol ); |
|
374 lastModifiedColSet->AddL( lastModifiedDateTime ); |
|
375 |
|
376 TInt error = aDatabase.CreateTable( KIptvEpgLastModifiedTable, *lastModifiedColSet ); |
|
377 |
|
378 CleanupStack::PopAndDestroy( lastModifiedColSet ); |
|
379 |
|
380 if ( error != KErrNone ) |
|
381 { |
|
382 LIVE_TV_TRACE2( _L("aDatabase.CreateTable for last modified table caused leave: %d"), error ); |
|
383 User::Leave( error ); |
|
384 } |
|
385 } |
|
386 |
|
387 |
|
388 // SET OF GETTERS FOR CHANNEL AND PROGRAM DATA |
|
389 |
|
390 // --------------------------------------------------------------------------- |
|
391 // CIptvEpgDatabase::GetChannelsL() |
|
392 // |
|
393 // --------------------------------------------------------------------------- |
|
394 // |
|
395 EXPORT_C void CIptvEpgDatabase::GetChannelsL( const TUint32 aServiceProviderId, |
|
396 RPointerArray<CIptvEpgChannel>* |
|
397 aResultArray ) |
|
398 { |
|
399 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::GetChannelsL()")); |
|
400 |
|
401 if ( iLocalState == EBackup ) |
|
402 { |
|
403 return; |
|
404 } |
|
405 |
|
406 if ( !aResultArray ) |
|
407 { |
|
408 User::Leave( KErrArgument ); |
|
409 } |
|
410 TBuf<KCustomSqlLength> sqlStatement; |
|
411 sqlStatement.Append( _L("SELECT * FROM ")); |
|
412 sqlStatement.Append( KIptvEpgChannelTable ); |
|
413 sqlStatement.Append( _L(" WHERE ") ); |
|
414 sqlStatement.Append( KIptvEpgChannelServProviderIdCol ); |
|
415 sqlStatement.Append( _L(" = ") ); |
|
416 sqlStatement.AppendNum( aServiceProviderId ); |
|
417 DoGetChannelsL( sqlStatement, aResultArray ); |
|
418 } |
|
419 |
|
420 // --------------------------------------------------------------------------- |
|
421 // CIptvEpgDatabase::DoGetChannelsL() |
|
422 // |
|
423 // --------------------------------------------------------------------------- |
|
424 // |
|
425 void CIptvEpgDatabase::DoGetChannelsL( const TDesC& aQuery, |
|
426 RPointerArray<CIptvEpgChannel>* |
|
427 aResultArray ) |
|
428 { |
|
429 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::DoGetChannelsL() in")); |
|
430 |
|
431 if ( iLocalState == EBackup ) |
|
432 { |
|
433 return; |
|
434 } |
|
435 |
|
436 TInt err( KErrNone ); |
|
437 |
|
438 if ( !aResultArray ) |
|
439 { |
|
440 User::Leave( KErrArgument ); |
|
441 } |
|
442 |
|
443 RDbView view; |
|
444 CleanupClosePushL( view ); |
|
445 LIVE_TV_TRACE1( _L("CIptvEpgDatabase::DoGetChannelsL about to prepare") ); |
|
446 err = view.Prepare( iMulticastDb, |
|
447 TDbQuery(aQuery), |
|
448 TDbWindow::EUnlimited, |
|
449 RDbView::EReadOnly ); |
|
450 LIVE_TV_TRACE2( _L("CIptvEpgDatabase::DoGetChannelsL prepare = %d"), err ); |
|
451 User::LeaveIfError ( err ); |
|
452 LIVE_TV_TRACE1( _L("CIptvEpgDatabase::DoGetChannelsL about to eval") ); |
|
453 User::LeaveIfError( view.EvaluateAll() ); |
|
454 LIVE_TV_TRACE1( _L("CIptvEpgDatabase::DoGetChannelsL about to get colset ") ); |
|
455 CDbColSet* colSet = view.ColSetL(); |
|
456 CleanupStack::PushL( colSet ); |
|
457 TInt idColNo = colSet->ColNo( KIptvEpgChannelIdCol ); |
|
458 TInt servProbIdColNo = colSet->ColNo( KIptvEpgChannelServProviderIdCol ); |
|
459 TInt nameColNo = colSet->ColNo( KIptvEpgChannelNameCol ); |
|
460 TInt logoColNo = colSet->ColNo( KIptvEpgChannelLogoPathCol ); |
|
461 TInt descrColNo = colSet->ColNo( KIptvEpgChannelDescriptionCol ); |
|
462 TInt uriColNo = colSet->ColNo( KIptvEpgChannelURICol ); |
|
463 TInt sdpColNo = colSet->ColNo( KIptvEpgChannelSDPCol ); |
|
464 TInt orderColNo = colSet->ColNo( KIptvEpgChannelOrderCol ); |
|
465 |
|
466 CleanupStack::PopAndDestroy( colSet ); |
|
467 LIVE_TV_TRACE1( _L("CIptvEpgDatabase::DoGetChannelsL getting first") ); |
|
468 view.FirstL(); |
|
469 while ( view.AtRow() ) |
|
470 { |
|
471 view.GetL(); |
|
472 CIptvEpgChannel* channel = CIptvEpgChannel::NewL(); |
|
473 CleanupStack::PushL( channel ); |
|
474 |
|
475 channel->SetChannelId( view.ColInt64( idColNo ) ); |
|
476 channel->SetServiceId( view.ColUint32( servProbIdColNo ) ); |
|
477 channel->SetChannelName( view.ColDes( nameColNo ).AllocL() ); |
|
478 channel->SetChannelLogoPath( view.ColDes( logoColNo ).AllocL() ); |
|
479 channel->SetChannelDescription( view.ColDes( descrColNo ).AllocL() ); |
|
480 channel->SetChannelURI( view.ColDes( uriColNo ).AllocL() ); |
|
481 |
|
482 // SDP data is stored in long text field, so it needs to be read |
|
483 // through stream |
|
484 TInt sdpLength = view.ColLength( sdpColNo ); |
|
485 HBufC* temp = HBufC::NewL( sdpLength ); |
|
486 CleanupStack::PushL( temp ); |
|
487 RDbColReadStream read; |
|
488 read.OpenLC( view, sdpColNo ); |
|
489 TPtr ptr = temp->Des(); |
|
490 read.ReadL( ptr, sdpLength ); |
|
491 read.Close(); |
|
492 CleanupStack::PopAndDestroy(); // read; |
|
493 channel->SetChannelSDP( temp ); // Ownership transferred |
|
494 CleanupStack::Pop( temp ); |
|
495 |
|
496 channel->SetChannelOrder( view.ColUint32( orderColNo ) ); |
|
497 |
|
498 TLinearOrder<CIptvEpgChannel> order( |
|
499 CIptvEpgChannel::LinearOrderByOrderNum ); |
|
500 // Insert the channel to the array ordered by |
|
501 // CIptvEpgChannel::LinearOrderByOrderNum function |
|
502 User::LeaveIfError( aResultArray->InsertInOrderAllowRepeats( channel, |
|
503 order ) ); |
|
504 |
|
505 CleanupStack::Pop( channel ); // ownership transferred to aResultArray |
|
506 view.NextL(); |
|
507 } |
|
508 |
|
509 LIVE_TV_TRACE2( _L("Added %d channels to aResultArray"), aResultArray->Count() ); |
|
510 |
|
511 CleanupStack::PopAndDestroy( &view ); // closes view |
|
512 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::DoGetChannelsL() out")); |
|
513 } |
|
514 |
|
515 // --------------------------------------------------------------------------- |
|
516 // CIptvEpgDatabase::GetProgramsByChannelIdL() |
|
517 // |
|
518 // --------------------------------------------------------------------------- |
|
519 // |
|
520 EXPORT_C void CIptvEpgDatabase::GetProgramsByChannelIdL( |
|
521 const TUint32 aServiceProviderId, |
|
522 const TInt64 aChannelKey, |
|
523 RPointerArray<CIptvEpgProgram>* aResultArray ) |
|
524 { |
|
525 LIVE_TV_TRACE3(_L("CIptvEpgDatabase::GetProgramsByChannelIdL() ser %d cha %Li"), (int)aServiceProviderId, aChannelKey); |
|
526 |
|
527 if ( iLocalState == EBackup ) |
|
528 { |
|
529 return; |
|
530 } |
|
531 |
|
532 if ( !aResultArray ) |
|
533 { |
|
534 User::Leave( KErrArgument ); |
|
535 } |
|
536 TBuf<KCustomSqlLength> sqlStatement; |
|
537 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
538 sqlStatement.Append( KIptvEpgProgramTable ); |
|
539 sqlStatement.Append( _L(" WHERE ") ); |
|
540 sqlStatement.Append( KIptvEpgProgramChannelId ); |
|
541 sqlStatement.Append( _L(" = ") ); |
|
542 sqlStatement.AppendNum( aChannelKey ); |
|
543 sqlStatement.Append( _L(" AND ") ); |
|
544 sqlStatement.Append( KIptvEpgProgramServProviderIdCol ); |
|
545 sqlStatement.Append( _L(" = ") ); |
|
546 sqlStatement.AppendNum( aServiceProviderId ); |
|
547 |
|
548 LIVE_TV_TRACE2(_L("query >%S<"), &sqlStatement); |
|
549 |
|
550 FetchProgramsFromTableL( sqlStatement, aResultArray ); |
|
551 |
|
552 } |
|
553 |
|
554 // --------------------------------------------------------------------------- |
|
555 // CIptvEpgDatabase::GetNextProgramL() |
|
556 // |
|
557 // --------------------------------------------------------------------------- |
|
558 // |
|
559 EXPORT_C CIptvEpgSchedule* CIptvEpgDatabase::GetNextProgramL( |
|
560 const TUint32 aServiceProviderId, |
|
561 const TInt64 aChannelKey, |
|
562 const TTime& aRefTime ) |
|
563 { |
|
564 LIVE_TV_TRACE3(_L("CIptvEpgDatabase::GetNextProgramL() ser %d cha %Li"), (int)aServiceProviderId, aChannelKey); |
|
565 |
|
566 if ( iLocalState == EBackup ) |
|
567 { |
|
568 return NULL; |
|
569 } |
|
570 |
|
571 TBuf<KCustomSqlLength> sqlStatement; |
|
572 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
573 sqlStatement.Append( KIptvEpgScheduleTable ); |
|
574 sqlStatement.Append( _L(" WHERE ") ); |
|
575 sqlStatement.Append( KIptvEpgScheduleChannelIdCol ); |
|
576 sqlStatement.Append( _L(" = ") ); |
|
577 sqlStatement.AppendNum( aChannelKey ); |
|
578 sqlStatement.Append( _L(" AND ") ); |
|
579 sqlStatement.Append( KIptvEpgScheduleServiceProviderIdCol ); |
|
580 sqlStatement.Append( _L(" = ") ); |
|
581 sqlStatement.AppendNum( aServiceProviderId ); |
|
582 LIVE_TV_TRACE2(_L("query >%S<"), &sqlStatement); |
|
583 |
|
584 CIptvEpgSchedule* retval = NULL; |
|
585 |
|
586 RPointerArray<CIptvEpgSchedule> resultArray; |
|
587 CleanupClosePushL( resultArray ); |
|
588 TRAPD( err, FetchSchedulesFromTableL( sqlStatement, &resultArray ) ); |
|
589 if ( err != KErrNone ) |
|
590 { |
|
591 LIVE_TV_TRACE2(_L("CIptvEpgDatabase::GetNextProgramL: FetchSchedulesFromTableL FAILED: %d"), err); |
|
592 resultArray.ResetAndDestroy(); |
|
593 User::Leave( err ); |
|
594 } |
|
595 |
|
596 const TInt cnt( resultArray.Count() ); |
|
597 TInt index( KErrNotFound ); |
|
598 for ( TInt i( 0 ); i < cnt; i++ ) |
|
599 { |
|
600 // quit looping when the 1st prg which starting time is greater |
|
601 // than current time |
|
602 if ( resultArray[i]->GetStartTime() > aRefTime ) |
|
603 { |
|
604 retval = resultArray[i]; |
|
605 index = i; |
|
606 i = cnt; // quit looping |
|
607 } |
|
608 } |
|
609 |
|
610 if ( cnt > 0 ) |
|
611 { |
|
612 for ( TInt j( 0 ); j < cnt; j++ ) // note, starts from 1, not 0. |
|
613 { |
|
614 if ( j != index ) |
|
615 { |
|
616 delete resultArray[j]; |
|
617 resultArray[j] = NULL; |
|
618 } |
|
619 } |
|
620 |
|
621 if ( index < 0 ) |
|
622 { |
|
623 resultArray.Reset(); |
|
624 CleanupStack::PopAndDestroy( &resultArray ); // closes array |
|
625 return retval; |
|
626 } |
|
627 if ( retval ) |
|
628 { |
|
629 // match the found schedule with correct program data, query program table |
|
630 TBuf<KCustomSqlLength> sqlStatementForPrograms; |
|
631 sqlStatementForPrograms.Append( _L("SELECT * FROM ") ); |
|
632 sqlStatementForPrograms.Append( KIptvEpgProgramTable ); |
|
633 sqlStatementForPrograms.Append( _L(" WHERE ") ); |
|
634 sqlStatementForPrograms.Append( KIptvEpgProgramChannelId ); |
|
635 sqlStatementForPrograms.Append( _L(" = ") ); |
|
636 sqlStatementForPrograms.AppendNum( aChannelKey ); |
|
637 sqlStatementForPrograms.Append( _L(" AND ") ); |
|
638 sqlStatementForPrograms.Append( KIptvEpgProgramServProviderIdCol ); |
|
639 sqlStatementForPrograms.Append( _L(" = ") ); |
|
640 sqlStatementForPrograms.AppendNum( aServiceProviderId ); |
|
641 sqlStatementForPrograms.Append( _L(" AND ") ); |
|
642 sqlStatementForPrograms.Append( KIptvEpgProgramIdCol ); |
|
643 sqlStatementForPrograms.Append( _L(" = ") ); |
|
644 sqlStatementForPrograms.AppendNum( retval->GetProgramId() ); |
|
645 |
|
646 RPointerArray<CIptvEpgProgram> resultProgArray; |
|
647 CleanupClosePushL( resultProgArray ); |
|
648 |
|
649 TRAP( err, FetchProgramsFromTableL( sqlStatementForPrograms, |
|
650 &resultProgArray ) ); |
|
651 if ( err != KErrNone ) |
|
652 { |
|
653 LIVE_TV_TRACE2(_L("FetchProgramsFromTableL FAILED: %d"), err); |
|
654 resultArray.ResetAndDestroy(); |
|
655 resultProgArray.ResetAndDestroy(); |
|
656 User::Leave( err ); |
|
657 } |
|
658 |
|
659 const TInt cntProg( resultProgArray.Count() ); |
|
660 if ( cntProg > 0 ) |
|
661 { |
|
662 retval->iProgram = resultProgArray[0];// note, index 0 is the matching prog |
|
663 for ( TInt k( 1 ); k < cntProg; k++ ) // note, starts from 1, not 0. |
|
664 { |
|
665 delete resultProgArray[k]; |
|
666 resultProgArray[k] = NULL; |
|
667 } |
|
668 } |
|
669 else |
|
670 { |
|
671 // no matching program found |
|
672 } |
|
673 resultProgArray.Reset(); |
|
674 CleanupStack::PopAndDestroy( &resultProgArray ); // closes array |
|
675 } |
|
676 } |
|
677 |
|
678 |
|
679 resultArray.Reset(); |
|
680 CleanupStack::PopAndDestroy( &resultArray ); // closes array |
|
681 return retval; |
|
682 } |
|
683 |
|
684 // --------------------------------------------------------------------------- |
|
685 // CIptvEpgDatabase::GetProgramL() |
|
686 // |
|
687 // --------------------------------------------------------------------------- |
|
688 // |
|
689 EXPORT_C CIptvEpgSchedule* CIptvEpgDatabase::GetProgramL( |
|
690 const TUint32 aServiceProviderId, |
|
691 const TInt64 aChannelId, |
|
692 const TInt64 aProgramId ) |
|
693 { |
|
694 LIVE_TV_TRACE4(_L("CIptvEpgDatabase::GetProgramL() in aServiceProviderId %d aChannelId %Li, aProgramId %Li"), (int)aServiceProviderId, aChannelId, aProgramId); |
|
695 |
|
696 if ( iLocalState == EBackup ) |
|
697 { |
|
698 return NULL; |
|
699 } |
|
700 |
|
701 TBuf<KCustomSqlLength> sqlStatement; |
|
702 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
703 sqlStatement.Append( KIptvEpgScheduleTable ); |
|
704 sqlStatement.Append( _L(" WHERE ") ); |
|
705 sqlStatement.Append( KIptvEpgScheduleChannelIdCol ); |
|
706 sqlStatement.Append( _L(" = ") ); |
|
707 sqlStatement.AppendNum( aChannelId ); |
|
708 sqlStatement.Append( _L(" AND ") ); |
|
709 sqlStatement.Append( KIptvEpgScheduleServiceProviderIdCol ); |
|
710 sqlStatement.Append( _L(" = ") ); |
|
711 sqlStatement.AppendNum( aServiceProviderId ); |
|
712 sqlStatement.Append( _L(" AND ") ); |
|
713 sqlStatement.Append( KIptvEpgScheduleProgramIdCol ); |
|
714 sqlStatement.Append( _L(" = ") ); |
|
715 sqlStatement.AppendNum( aProgramId ); |
|
716 |
|
717 CIptvEpgSchedule* retval = NULL; |
|
718 |
|
719 RPointerArray<CIptvEpgSchedule> resultArray; |
|
720 CleanupClosePushL( resultArray ); |
|
721 TRAPD( err, FetchSchedulesFromTableL( sqlStatement, &resultArray ) ); |
|
722 if ( err != KErrNone ) |
|
723 { |
|
724 LIVE_TV_TRACE2(_L("FetchSchedulesFromTableL FAILED: %d"), err); |
|
725 resultArray.ResetAndDestroy(); |
|
726 User::Leave( err ); |
|
727 } |
|
728 |
|
729 if ( resultArray.Count() > 0 ) |
|
730 { |
|
731 // Select first one found |
|
732 retval = resultArray[0]; |
|
733 resultArray.Remove( 0 ); |
|
734 } |
|
735 resultArray.ResetAndDestroy(); |
|
736 CleanupStack::PopAndDestroy( &resultArray ); |
|
737 |
|
738 TBuf<KCustomSqlLength> sqlStatementForPrograms; |
|
739 sqlStatementForPrograms.Append( _L("SELECT * FROM ") ); |
|
740 sqlStatementForPrograms.Append( KIptvEpgProgramTable ); |
|
741 sqlStatementForPrograms.Append( _L(" WHERE ") ); |
|
742 sqlStatementForPrograms.Append( KIptvEpgProgramChannelId ); |
|
743 sqlStatementForPrograms.Append( _L(" = ") ); |
|
744 sqlStatementForPrograms.AppendNum( aChannelId ); |
|
745 sqlStatementForPrograms.Append( _L(" AND ") ); |
|
746 sqlStatementForPrograms.Append( KIptvEpgProgramServProviderIdCol ); |
|
747 sqlStatementForPrograms.Append( _L(" = ") ); |
|
748 sqlStatementForPrograms.AppendNum( aServiceProviderId ); |
|
749 sqlStatementForPrograms.Append( _L(" AND ") ); |
|
750 sqlStatementForPrograms.Append( KIptvEpgProgramIdCol ); |
|
751 sqlStatementForPrograms.Append( _L(" = ") ); |
|
752 sqlStatementForPrograms.AppendNum( aProgramId ); |
|
753 |
|
754 RPointerArray<CIptvEpgProgram> resultProgArray; |
|
755 CleanupClosePushL( resultProgArray ); |
|
756 |
|
757 TRAP( err, FetchProgramsFromTableL( sqlStatementForPrograms, |
|
758 &resultProgArray ) ); |
|
759 if ( err != KErrNone ) |
|
760 { |
|
761 LIVE_TV_TRACE2(_L("FetchProgramsFromTableL FAILED: %d"), err); |
|
762 resultProgArray.ResetAndDestroy(); |
|
763 User::Leave( err ); |
|
764 } |
|
765 if ( resultProgArray.Count() > 0 && retval ) |
|
766 { |
|
767 retval->iProgram = resultProgArray[0]; |
|
768 resultProgArray.Remove( 0 ); |
|
769 } |
|
770 resultProgArray.ResetAndDestroy(); |
|
771 CleanupStack::PopAndDestroy( &resultProgArray ); // closes array |
|
772 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::GetProgramL out")); |
|
773 return retval; |
|
774 } |
|
775 |
|
776 |
|
777 // --------------------------------------------------------------------------- |
|
778 // CIptvEpgDatabase::GetProgramNamesByServiceIdL() |
|
779 // |
|
780 // --------------------------------------------------------------------------- |
|
781 // |
|
782 void CIptvEpgDatabase::GetProgramNamesByServiceIdL( |
|
783 const TUint32 aServiceProviderId, |
|
784 RPointerArray<CIptvEpgProgram>* aResultArray ) |
|
785 { |
|
786 LIVE_TV_TRACE2(_L("CIptvEpgDatabase::GetProgramsByServiceIdL() ser %d"), (TInt)aServiceProviderId); |
|
787 |
|
788 if ( iLocalState == EBackup ) |
|
789 { |
|
790 return; |
|
791 } |
|
792 |
|
793 if ( !aResultArray ) |
|
794 { |
|
795 User::Leave( KErrArgument ); |
|
796 } |
|
797 TBuf<KCustomSqlLength> sqlStatement; |
|
798 sqlStatement.Append( _L("SELECT ") ); |
|
799 sqlStatement.Append( KIptvEpgProgramIdCol ); |
|
800 sqlStatement.Append( _L(", ") ); |
|
801 sqlStatement.Append( KIptvEpgProgramNameCol ); |
|
802 sqlStatement.Append( _L(" FROM ")); |
|
803 sqlStatement.Append( KIptvEpgProgramTable ); |
|
804 sqlStatement.Append( _L(" WHERE ") ); |
|
805 sqlStatement.Append( KIptvEpgProgramServProviderIdCol ); |
|
806 sqlStatement.Append( _L(" = ") ); |
|
807 sqlStatement.AppendNum( aServiceProviderId ); |
|
808 |
|
809 LIVE_TV_TRACE2(_L("query >%S<"), &sqlStatement); |
|
810 |
|
811 FetchProgramNamesFromTableL( sqlStatement, aResultArray ); |
|
812 |
|
813 } |
|
814 |
|
815 // --------------------------------------------------------------------------- |
|
816 // CIptvEpgDatabase::GetSchedulesByServiceIdL() |
|
817 // |
|
818 // --------------------------------------------------------------------------- |
|
819 // |
|
820 EXPORT_C void CIptvEpgDatabase::GetSchedulesByServiceIdL( |
|
821 const TUint32 aServiceProviderId, |
|
822 RPointerArray<CIptvEpgScheduleSearch>* aResultArray ) |
|
823 { |
|
824 LIVE_TV_TRACE2(_L("CIptvEpgDatabase::GetSchedulesByServiceIdL() ser %d"), (TInt)aServiceProviderId); |
|
825 |
|
826 if ( iLocalState == EBackup ) |
|
827 { |
|
828 return; |
|
829 } |
|
830 |
|
831 if ( !aResultArray ) |
|
832 { |
|
833 User::Leave( KErrArgument ); |
|
834 } |
|
835 |
|
836 CIptvEpgProgram* programToUseForFinding = CIptvEpgProgram::NewL(); |
|
837 CleanupStack::PushL( programToUseForFinding ); |
|
838 |
|
839 RPointerArray<CIptvEpgProgram> programs; |
|
840 CleanupClosePushL( programs ); |
|
841 TRAPD( err, GetProgramNamesByServiceIdL( aServiceProviderId, &programs ) ); |
|
842 if ( err != KErrNone ) |
|
843 { |
|
844 LIVE_TV_TRACE2(_L("GetProgramNamesByServiceIdL FAILED: %d"), err); |
|
845 programs.ResetAndDestroy(); |
|
846 User::Leave( err ); |
|
847 } |
|
848 TLinearOrder<CIptvEpgProgram> o( |
|
849 CIptvEpgProgram::LinearOrderOfProgramsById ); |
|
850 programs.Sort( o ); |
|
851 |
|
852 TBuf<KCustomSqlLength> sqlStatement; |
|
853 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
854 sqlStatement.Append( KIptvEpgScheduleTable ); |
|
855 sqlStatement.Append( _L(" WHERE ") ); |
|
856 sqlStatement.Append( KIptvEpgScheduleServiceProviderIdCol ); |
|
857 sqlStatement.Append( _L(" = ") ); |
|
858 sqlStatement.AppendNum( aServiceProviderId ); |
|
859 LIVE_TV_TRACE2(_L("query >%S<"), &sqlStatement); |
|
860 |
|
861 TRAP( err, FetchSearchSchedulesFromTableL( sqlStatement, aResultArray ) ); |
|
862 if ( err != KErrNone ) |
|
863 { |
|
864 LIVE_TV_TRACE2(_L("FetchSearchSchedulesFromTableL FAILED: %d"), err); |
|
865 programs.ResetAndDestroy(); |
|
866 User::Leave( err ); |
|
867 } |
|
868 |
|
869 TInt indexFound( KErrNone ); |
|
870 TInt i( 0 ); |
|
871 TInt64 programId( 0 ); |
|
872 for ( i = 0; i < aResultArray->Count(); i++ ) |
|
873 { |
|
874 programId = ((*aResultArray)[i])->iProgramId; |
|
875 programToUseForFinding->SetProgramId( programId ); |
|
876 indexFound = programs.FindInOrder( programToUseForFinding, o ); |
|
877 if ( indexFound != KErrNotFound && indexFound < programs.Count() ) |
|
878 { |
|
879 ((*aResultArray)[i])->iProgramName = |
|
880 programs[indexFound]->ProgramName().AllocL(); |
|
881 } |
|
882 } |
|
883 |
|
884 TLinearOrder<CIptvEpgScheduleSearch> order( |
|
885 CIptvEpgScheduleSearch::LinearOrderOfSchedulesByName ); |
|
886 aResultArray->Sort( order ); |
|
887 |
|
888 for ( i = 0; i < programs.Count(); i++ ) |
|
889 { |
|
890 delete programs[i]; |
|
891 programs[i] = NULL; |
|
892 } |
|
893 programs.Reset(); |
|
894 CleanupStack::PopAndDestroy( &programs ); |
|
895 CleanupStack::PopAndDestroy( programToUseForFinding ); |
|
896 LIVE_TV_TRACE2(_L("CIptvEpgDatabase::GetSchedulesByServiceIdL out, return %d items"), aResultArray->Count() ); |
|
897 } |
|
898 |
|
899 |
|
900 // --------------------------------------------------------------------------- |
|
901 // CIptvEpgDatabase::GetSchedulesByChannelIdL() |
|
902 // |
|
903 // --------------------------------------------------------------------------- |
|
904 // |
|
905 EXPORT_C void CIptvEpgDatabase::GetSchedulesByChannelIdL( |
|
906 const TUint32 aServiceProviderId, |
|
907 const TInt64 aChannelKey, |
|
908 RPointerArray<CIptvEpgSchedule>* aResultArray ) |
|
909 { |
|
910 LIVE_TV_TRACE3(_L("CIptvEpgDatabase::GetSchedulesByChannelIdL() ser %d cha %Li"), (int)aServiceProviderId, aChannelKey); |
|
911 |
|
912 if ( iLocalState == EBackup ) |
|
913 { |
|
914 return; |
|
915 } |
|
916 |
|
917 if ( !aResultArray ) |
|
918 { |
|
919 User::Leave( KErrArgument ); |
|
920 } |
|
921 |
|
922 TInt i,c; |
|
923 CIptvEpgProgram* programToUseForFinding = CIptvEpgProgram::NewL(); |
|
924 CleanupStack::PushL(programToUseForFinding); |
|
925 LIVE_TV_TRACE1(_L("GetSchedulesByChannelIdL starting get prog")); |
|
926 RPointerArray<CIptvEpgProgram> programs; |
|
927 CleanupClosePushL( programs ); |
|
928 TRAPD( err, GetProgramsByChannelIdL(aServiceProviderId, aChannelKey, &programs ) ); |
|
929 if ( err != KErrNone ) |
|
930 { |
|
931 LIVE_TV_TRACE2(_L("GetProgramsByChannelIdL FAILED: %d"), err); |
|
932 programs.ResetAndDestroy(); |
|
933 User::Leave( err ); |
|
934 } |
|
935 LIVE_TV_TRACE2(_L("GetSchedulesByChannelIdL starting sort n = %d"),programs.Count()); |
|
936 TLinearOrder<CIptvEpgProgram> o(CIptvEpgProgram::LinearOrderOfProgramsById); |
|
937 programs.Sort( o ); |
|
938 LIVE_TV_TRACE1(_L("GetSchedulesByChannelIdL starting fetch schedules")); |
|
939 |
|
940 TBuf<KCustomSqlLength> sqlStatement; |
|
941 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
942 sqlStatement.Append( KIptvEpgScheduleTable ); |
|
943 sqlStatement.Append( _L(" WHERE ") ); |
|
944 sqlStatement.Append( KIptvEpgScheduleChannelIdCol ); |
|
945 sqlStatement.Append( _L(" = ") ); |
|
946 sqlStatement.AppendNum( aChannelKey ); |
|
947 sqlStatement.Append( _L(" AND ") ); |
|
948 sqlStatement.Append( KIptvEpgScheduleServiceProviderIdCol ); |
|
949 sqlStatement.Append( _L(" = ") ); |
|
950 sqlStatement.AppendNum( aServiceProviderId ); |
|
951 LIVE_TV_TRACE2(_L("query >%S<"), &sqlStatement); |
|
952 |
|
953 TRAP( err, FetchSchedulesFromTableL( sqlStatement, aResultArray ) ); |
|
954 if ( err != KErrNone ) |
|
955 { |
|
956 LIVE_TV_TRACE2(_L("FetchSchedulesFromTableL FAILED: %d"), err); |
|
957 programs.ResetAndDestroy(); |
|
958 User::Leave( err ); |
|
959 } |
|
960 TLinearOrder<CIptvEpgSchedule> order(CIptvEpgSchedule::LinearOrderOfSchedulesByTime); |
|
961 aResultArray->Sort(order); |
|
962 c = aResultArray->Count(); |
|
963 TInt indexFound; |
|
964 TInt programsFound = 0; |
|
965 LIVE_TV_TRACE2(_L("GetSchedulesByChannelIdL staring finding programs for %d schedules"),c); |
|
966 TInt64 programId( 0 ); |
|
967 for ( i = 0; i < c; i ++ ) |
|
968 { |
|
969 programId = ((*aResultArray)[i])->GetProgramId(); |
|
970 programToUseForFinding->SetProgramId( programId ); |
|
971 indexFound = programs.FindInOrder( programToUseForFinding, o ); |
|
972 if ( indexFound != KErrNotFound && indexFound < programs.Count() ) |
|
973 { |
|
974 if ( programs[indexFound]->ServiceId() == aServiceProviderId && |
|
975 programs[indexFound]->ChannelId() == aChannelKey ) |
|
976 { |
|
977 ((*aResultArray)[i])->iProgram = programs[indexFound]; |
|
978 programs.Remove( indexFound ); |
|
979 programsFound++; |
|
980 } |
|
981 } |
|
982 } |
|
983 programs.ResetAndDestroy(); |
|
984 CleanupStack::PopAndDestroy( &programs ); |
|
985 CleanupStack::PopAndDestroy( programToUseForFinding ); |
|
986 LIVE_TV_TRACE2(_L("GetSchedulesByChannelIdL matched %d programs "),programsFound); |
|
987 } |
|
988 |
|
989 // --------------------------------------------------------------------------- |
|
990 // CIptvEpgDatabase::GetSchedulesByChannelAndDayL() |
|
991 // |
|
992 // --------------------------------------------------------------------------- |
|
993 // |
|
994 EXPORT_C void CIptvEpgDatabase::GetSchedulesByChannelAndDayL( |
|
995 const TUint32 aServiceProviderId, |
|
996 const TInt64 aChannelKey, |
|
997 const TTime& aStartTime, |
|
998 RPointerArray<CIptvEpgSchedule>* aResultArray ) |
|
999 { |
|
1000 LIVE_TV_TRACE3(_L("CIptvEpgDatabase::GetSchedulesByChannelIdL() ser %d cha %Li"), (int)aServiceProviderId, aChannelKey); |
|
1001 |
|
1002 if ( iLocalState == EBackup ) |
|
1003 { |
|
1004 return; |
|
1005 } |
|
1006 |
|
1007 if ( !aResultArray ) |
|
1008 { |
|
1009 User::Leave( KErrArgument ); |
|
1010 } |
|
1011 // Assume aStartTime is set to HomeTime() (+ possible day offset) |
|
1012 TTime startTime( aStartTime ); |
|
1013 |
|
1014 // fix for error JAIA-7FAF4U: if clock is less than 4 AM, |
|
1015 // we're showing still the previous day's programs |
|
1016 startTime -= TTimeIntervalHours( KIptvDefaultDayOffsetHours ); |
|
1017 TTime endTime( startTime ); |
|
1018 // For some reason we need to set endTime to two days from home time to get |
|
1019 // programs of tommorow from database |
|
1020 endTime += TTimeIntervalDays( 2 ); |
|
1021 |
|
1022 startTime -= TTimeIntervalDays( 1 ); |
|
1023 TDateTime startDateTime( startTime.DateTime() ); |
|
1024 startDateTime.SetHour( 0 ); |
|
1025 startDateTime.SetMinute( 0 ); |
|
1026 startDateTime.SetSecond( 0 ); |
|
1027 startDateTime.SetMicroSecond( 0 ); |
|
1028 startTime = startDateTime; |
|
1029 startTime += TTimeIntervalHours( KIptvDefaultDayOffsetHours ); |
|
1030 |
|
1031 TBuf<100> startTimeBuf; |
|
1032 |
|
1033 _LIT( KDateTimeFormat,"#%1%/1%2%/2%3#" ); |
|
1034 startTime.FormatL(startTimeBuf, KDateTimeFormat); |
|
1035 |
|
1036 TBuf<100> endTimeBuf; |
|
1037 |
|
1038 endTime.FormatL(endTimeBuf, KDateTimeFormat); |
|
1039 |
|
1040 TInt i,c; |
|
1041 CIptvEpgProgram* programToUseForFinding = CIptvEpgProgram::NewL(); |
|
1042 CleanupStack::PushL(programToUseForFinding); |
|
1043 |
|
1044 RPointerArray<CIptvEpgProgram> programs; |
|
1045 CleanupClosePushL( programs ); |
|
1046 LIVE_TV_TRACE1(_L("GetSchedulesByChannelIdL starting get prog")); |
|
1047 TRAPD( err, GetProgramsByChannelIdL( aServiceProviderId, aChannelKey, &programs ) ); |
|
1048 if ( err != KErrNone ) |
|
1049 { |
|
1050 LIVE_TV_TRACE2(_L("CIptvEpgDatabase::GetSchedulesByChannelAndDayL GetProgramsByChannelIdL FAILED: %d"), err); |
|
1051 programs.ResetAndDestroy(); |
|
1052 User::Leave( err ); |
|
1053 } |
|
1054 |
|
1055 TLinearOrder<CIptvEpgProgram> o(CIptvEpgProgram::LinearOrderOfProgramsById); |
|
1056 programs.Sort( o ); |
|
1057 LIVE_TV_TRACE1(_L("GetSchedulesByChannelIdL starting fetch schedules")); |
|
1058 TBuf<KCustomSqlLength> sqlStatement; |
|
1059 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
1060 sqlStatement.Append( KIptvEpgScheduleTable ); |
|
1061 sqlStatement.Append( _L(" WHERE ") ); |
|
1062 sqlStatement.Append( KIptvEpgScheduleChannelIdCol ); |
|
1063 sqlStatement.Append( _L(" = ") ); |
|
1064 sqlStatement.AppendNum( aChannelKey ); |
|
1065 sqlStatement.Append( _L(" AND ") ); |
|
1066 sqlStatement.Append( KIptvEpgScheduleServiceProviderIdCol ); |
|
1067 sqlStatement.Append( _L(" = ") ); |
|
1068 sqlStatement.AppendNum( aServiceProviderId ); |
|
1069 sqlStatement.Append( _L(" AND ") ); |
|
1070 sqlStatement.Append( KIptvEpgScheduleStartTimeCol ); |
|
1071 sqlStatement.Append( _L(" >= ") ); |
|
1072 sqlStatement.Append( startTimeBuf ); |
|
1073 sqlStatement.Append( _L(" AND ") ); |
|
1074 sqlStatement.Append( KIptvEpgScheduleStartTimeCol ); |
|
1075 sqlStatement.Append( _L(" <= ") ); |
|
1076 sqlStatement.Append( endTimeBuf ); |
|
1077 |
|
1078 LIVE_TV_TRACE2(_L("query >%S<"), &sqlStatement); |
|
1079 |
|
1080 TRAP( err, FetchSchedulesFromTableL( sqlStatement, aResultArray ) ); |
|
1081 if ( err != KErrNone ) |
|
1082 { |
|
1083 LIVE_TV_TRACE2(_L("CIptvEpgDatabase::GetSchedulesByChannelAndDayL: FetchSchedulesFromTableL FAILED: %d"), err); |
|
1084 programs.ResetAndDestroy(); |
|
1085 User::Leave( err ); |
|
1086 } |
|
1087 TTime progStartTime; |
|
1088 TTime progEndTime; |
|
1089 // Remove schedules from aResultArray that do not belong for today |
|
1090 // taking hour offset into account (e.g. when the day changes) |
|
1091 if ( aResultArray->Count() > 0 ) |
|
1092 { |
|
1093 TTime endT( endTime - TTimeIntervalDays( 1 ) ); |
|
1094 TDateTime endTDate = endT.DateTime(); |
|
1095 endTDate.SetHour( KIptvDefaultDayOffsetHours ); |
|
1096 endTDate.SetMinute( 0 ); |
|
1097 endTDate.SetSecond( 0 ); |
|
1098 endTDate.SetMicroSecond( 0 ); |
|
1099 endT = endTDate; |
|
1100 const TTime startT( startTime + TTimeIntervalDays( 1 ) ); |
|
1101 for ( i = aResultArray->Count() - 1; i >= 0; i-- ) |
|
1102 { |
|
1103 progStartTime = (*aResultArray)[i]->GetStartTime() + |
|
1104 User::UTCOffset(); |
|
1105 progEndTime = (*aResultArray)[i]->GetEndTime() + User::UTCOffset(); |
|
1106 |
|
1107 if ( progStartTime >= endT ) |
|
1108 { |
|
1109 delete (*aResultArray)[i]; |
|
1110 (*aResultArray)[i] = NULL; |
|
1111 aResultArray->Remove( i ); |
|
1112 } |
|
1113 else if ( progStartTime < startT && progEndTime <= startT ) |
|
1114 { |
|
1115 delete (*aResultArray)[i]; |
|
1116 (*aResultArray)[i] = NULL; |
|
1117 aResultArray->Remove( i ); |
|
1118 } |
|
1119 } |
|
1120 aResultArray->Compress(); |
|
1121 } |
|
1122 |
|
1123 TLinearOrder<CIptvEpgSchedule> order( CIptvEpgSchedule::LinearOrderOfSchedulesByTime ); |
|
1124 aResultArray->Sort( order ); |
|
1125 c = aResultArray->Count(); |
|
1126 TInt indexFound; |
|
1127 TInt programsFound = 0; |
|
1128 LIVE_TV_TRACE2(_L("GetSchedulesByChannelIdL starting to find programs for %d schedules"),c); |
|
1129 TInt64 programId( 0 ); |
|
1130 for ( i = 0; i < c; i ++ ) |
|
1131 { |
|
1132 programId = ((*aResultArray)[i])->GetProgramId(); |
|
1133 programToUseForFinding->SetProgramId( programId ); |
|
1134 indexFound = programs.FindInOrder( programToUseForFinding, o ); |
|
1135 if ( indexFound != KErrNotFound ) |
|
1136 { |
|
1137 ((*aResultArray)[i])->iProgram = programs[indexFound]; |
|
1138 programs.Remove( indexFound ); |
|
1139 programsFound ++; |
|
1140 } |
|
1141 else |
|
1142 { |
|
1143 LIVE_TV_TRACE1(_L("Program not found in iProgramsPointedBySchedules!")); |
|
1144 } |
|
1145 } |
|
1146 programs.ResetAndDestroy(); |
|
1147 CleanupStack::PopAndDestroy( &programs ); |
|
1148 CleanupStack::PopAndDestroy( programToUseForFinding ); |
|
1149 LIVE_TV_TRACE2(_L("GetSchedulesByChannelIdL matched %d programs "),programsFound); |
|
1150 } |
|
1151 |
|
1152 // ----------------------------------------------------------------------------- |
|
1153 // CIptvEpgDatabase::GetProgramByTimeL() |
|
1154 // ----------------------------------------------------------------------------- |
|
1155 // |
|
1156 EXPORT_C CIptvEpgSchedule* CIptvEpgDatabase::GetProgramByTimeL( |
|
1157 const TUint32 aServiceProviderId, |
|
1158 const TInt64 aChannelKey, |
|
1159 const TTime& aStartTime ) |
|
1160 { |
|
1161 LIVE_TV_TRACE3(_L("CIptvEpgDatabase::GetProgramByTimeL() ser %d cha %Li"), (TInt)aServiceProviderId, aChannelKey); |
|
1162 |
|
1163 if ( iLocalState == EBackup ) |
|
1164 { |
|
1165 return NULL; |
|
1166 } |
|
1167 |
|
1168 CIptvEpgSchedule* retval = NULL; |
|
1169 |
|
1170 TBuf<100> startTimeBuf; |
|
1171 |
|
1172 // If date separator is set to ':' then the database will |
|
1173 // return KErrArgument (for some reason) if we use ':' also |
|
1174 // as time separator. |
|
1175 // Avoid the error by selecting time format based on current |
|
1176 // date separator locale setting. |
|
1177 TLocale locale; |
|
1178 TChar dateSeparator = locale.DateSeparator( 1 ); |
|
1179 _LIT( KDateTimeFormatDoubleDot,"#%1%/1%2%/2%3 %H:%T:%S#" ); |
|
1180 _LIT( KDateTimeFormatSingleDot,"#%1%/1%2%/2%3 %H.%T.%S#" ); |
|
1181 TBuf<64> dateTimeFormat; |
|
1182 if ( dateSeparator == ':' ) |
|
1183 { |
|
1184 dateTimeFormat = KDateTimeFormatSingleDot(); |
|
1185 } |
|
1186 else |
|
1187 { |
|
1188 dateTimeFormat = KDateTimeFormatDoubleDot(); |
|
1189 } |
|
1190 |
|
1191 aStartTime.FormatL(startTimeBuf, dateTimeFormat); |
|
1192 |
|
1193 // query the schedules table for the correct schedule |
|
1194 // that covers the given time in its duration |
|
1195 TBuf<KCustomSqlLength> sqlStatement; |
|
1196 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
1197 sqlStatement.Append( KIptvEpgScheduleTable ); |
|
1198 sqlStatement.Append( _L(" WHERE ") ); |
|
1199 sqlStatement.Append( KIptvEpgScheduleChannelIdCol ); |
|
1200 sqlStatement.Append( _L(" = ") ); |
|
1201 sqlStatement.AppendNum( aChannelKey ); |
|
1202 sqlStatement.Append( _L(" AND ") ); |
|
1203 sqlStatement.Append( KIptvEpgScheduleServiceProviderIdCol ); |
|
1204 sqlStatement.Append( _L(" = ") ); |
|
1205 sqlStatement.AppendNum( aServiceProviderId ); |
|
1206 sqlStatement.Append( _L(" AND ") ); |
|
1207 sqlStatement.Append( KIptvEpgScheduleStartTimeCol ); |
|
1208 sqlStatement.Append( _L(" <= ") ); |
|
1209 sqlStatement.Append( startTimeBuf ); |
|
1210 sqlStatement.Append( _L(" AND ") ); |
|
1211 sqlStatement.Append( KIptvEpgScheduleEndTimeCol ); |
|
1212 sqlStatement.Append( _L(" > ") ); |
|
1213 sqlStatement.Append( startTimeBuf ); |
|
1214 LIVE_TV_TRACE2(_L("query >%S<"), &sqlStatement); |
|
1215 |
|
1216 RPointerArray<CIptvEpgSchedule> resultArray; |
|
1217 CleanupClosePushL( resultArray ); |
|
1218 TRAPD( err, FetchSchedulesFromTableL( sqlStatement, &resultArray ) ); |
|
1219 if ( err != KErrNone ) |
|
1220 { |
|
1221 LIVE_TV_TRACE2(_L("FetchSchedulesFromTableL FAILED: %d"), err); |
|
1222 resultArray.ResetAndDestroy(); |
|
1223 User::Leave( err ); |
|
1224 } |
|
1225 |
|
1226 const TInt cnt( resultArray.Count() ); |
|
1227 |
|
1228 if ( cnt > 0 ) |
|
1229 { |
|
1230 retval = resultArray[0]; // note, index 0 is the retval, not deleted |
|
1231 for ( TInt j( 1 ); j < cnt; j++ ) // note, starts from 1, not 0. |
|
1232 { |
|
1233 delete resultArray[j]; |
|
1234 resultArray[j] = NULL; |
|
1235 } |
|
1236 // match the found schedule with correct program data, query program table |
|
1237 TBuf<KCustomSqlLength> sqlStatementForPrograms; |
|
1238 sqlStatementForPrograms.Append( _L("SELECT * FROM ") ); |
|
1239 sqlStatementForPrograms.Append( KIptvEpgProgramTable ); |
|
1240 sqlStatementForPrograms.Append( _L(" WHERE ") ); |
|
1241 sqlStatementForPrograms.Append( KIptvEpgProgramChannelId ); |
|
1242 sqlStatementForPrograms.Append( _L(" = ") ); |
|
1243 sqlStatementForPrograms.AppendNum( aChannelKey ); |
|
1244 sqlStatementForPrograms.Append( _L(" AND ") ); |
|
1245 sqlStatementForPrograms.Append( KIptvEpgProgramServProviderIdCol ); |
|
1246 sqlStatementForPrograms.Append( _L(" = ") ); |
|
1247 sqlStatementForPrograms.AppendNum( aServiceProviderId ); |
|
1248 sqlStatementForPrograms.Append( _L(" AND ") ); |
|
1249 sqlStatementForPrograms.Append( KIptvEpgProgramIdCol ); |
|
1250 sqlStatementForPrograms.Append( _L(" = ") ); |
|
1251 sqlStatementForPrograms.AppendNum( retval->GetProgramId() ); |
|
1252 |
|
1253 RPointerArray<CIptvEpgProgram> resultProgArray; |
|
1254 CleanupClosePushL( resultProgArray ); |
|
1255 |
|
1256 TRAP( err, FetchProgramsFromTableL( sqlStatementForPrograms, |
|
1257 &resultProgArray ) ); |
|
1258 if ( err != KErrNone ) |
|
1259 { |
|
1260 LIVE_TV_TRACE2(_L("FetchProgramsFromTableL FAILED: %d"), err); |
|
1261 resultArray.ResetAndDestroy(); |
|
1262 resultProgArray.ResetAndDestroy(); |
|
1263 User::Leave( err ); |
|
1264 } |
|
1265 |
|
1266 const TInt cntProg( resultProgArray.Count() ); |
|
1267 |
|
1268 if ( cntProg > 0 ) |
|
1269 { |
|
1270 |
|
1271 retval->iProgram = resultProgArray[0];// note, index 0 is the matching prog |
|
1272 for ( TInt k( 1 ); k < cntProg; k++ ) // note, starts from 1, not 0. |
|
1273 { |
|
1274 delete resultProgArray[k]; |
|
1275 resultProgArray[k] = NULL; |
|
1276 } |
|
1277 } |
|
1278 else |
|
1279 { |
|
1280 // no matching program found |
|
1281 } |
|
1282 resultProgArray.Reset(); |
|
1283 CleanupStack::PopAndDestroy( &resultProgArray ); // closes array |
|
1284 } |
|
1285 else |
|
1286 { |
|
1287 // no schedule found for the given time |
|
1288 } |
|
1289 resultArray.Reset(); |
|
1290 CleanupStack::PopAndDestroy( &resultArray ); // closes array |
|
1291 return retval; |
|
1292 } |
|
1293 |
|
1294 // --------------------------------------------------------------------------- |
|
1295 // CIptvEpgDatabase::FetchProgramsFromTableL() |
|
1296 // |
|
1297 // --------------------------------------------------------------------------- |
|
1298 void CIptvEpgDatabase::FetchProgramsFromTableL( const TDesC& aSqlStatement, |
|
1299 RPointerArray<CIptvEpgProgram>* aResultArray ) |
|
1300 { |
|
1301 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::FetchProgramsFromTableL in")); |
|
1302 |
|
1303 if ( iLocalState == EBackup || !aResultArray ) |
|
1304 { |
|
1305 return; |
|
1306 } |
|
1307 |
|
1308 RDbView view; |
|
1309 CleanupClosePushL( view ); |
|
1310 |
|
1311 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
1312 TDbQuery( aSqlStatement ) ) ); |
|
1313 User::LeaveIfError( view.EvaluateAll() ); |
|
1314 |
|
1315 CDbColSet* colSet = view.ColSetL(); |
|
1316 CleanupStack::PushL( colSet ); |
|
1317 TInt programIdColNo = colSet->ColNo( KIptvEpgProgramIdCol ); |
|
1318 TInt channelIdColNo = colSet->ColNo( KIptvEpgProgramChannelId ); |
|
1319 TInt serviceIdColNo = colSet->ColNo( KIptvEpgProgramServProviderIdCol ); |
|
1320 TInt uriColNo = colSet->ColNo( KIptvEpgProgramURICol ); |
|
1321 TInt genreColNo = colSet->ColNo( KIptvEpgProgramGenreCol ); |
|
1322 TInt nameColNo = colSet->ColNo( KIptvEpgProgramNameCol ); |
|
1323 TInt descrColNo = colSet->ColNo( KIptvEpgProgramDescriptionCol ); |
|
1324 TInt languageColNo = colSet->ColNo( KIptvEpgProgramLanguageCol ); |
|
1325 TInt parentalColNo = colSet->ColNo( KIptvEpgProgramParentalRatingCol ); |
|
1326 CleanupStack::PopAndDestroy( colSet ); |
|
1327 |
|
1328 view.FirstL(); |
|
1329 while ( view.AtRow() ) |
|
1330 { |
|
1331 view.GetL(); |
|
1332 CIptvEpgProgram* program = CIptvEpgProgram::NewL(); |
|
1333 CleanupStack::PushL( program ); |
|
1334 program->SetProgramId( view.ColInt64( programIdColNo ) ); |
|
1335 program->SetChannelId( view.ColInt64( channelIdColNo ) ); |
|
1336 program->SetServiceId( view.ColUint32( serviceIdColNo ) ); |
|
1337 program->SetProgramURI (view.ColDes( uriColNo ).AllocL() ); |
|
1338 program->SetProgramGenre( view.ColDes( genreColNo ).AllocL() ); |
|
1339 program->SetProgramName( view.ColDes( nameColNo ).AllocL() ); |
|
1340 program->SetProgramLanguage( view.ColDes( languageColNo ).AllocL() ); |
|
1341 program->SetProgramParentalRating( view.ColDes( parentalColNo ).AllocL() ); |
|
1342 |
|
1343 // Description data is stored in long text field, so it needs to be read |
|
1344 // through stream |
|
1345 TInt descrLength = view.ColLength( descrColNo ); |
|
1346 HBufC* temp = HBufC::NewL( descrLength ); |
|
1347 CleanupStack::PushL( temp ); |
|
1348 RDbColReadStream read; |
|
1349 read.OpenLC( view, descrColNo ); |
|
1350 TPtr ptr = temp->Des(); |
|
1351 read.ReadL( ptr, descrLength ); |
|
1352 read.Close(); |
|
1353 CleanupStack::PopAndDestroy(); // read; |
|
1354 |
|
1355 program->SetProgramDescription( temp ); // Ownership transferred |
|
1356 CleanupStack::Pop( temp ); |
|
1357 |
|
1358 // Since now ownership of CIptvEpgProgram object is in RPointerArray |
|
1359 aResultArray->AppendL( program ); |
|
1360 |
|
1361 CleanupStack::Pop( program ); |
|
1362 |
|
1363 view.NextL(); |
|
1364 } |
|
1365 CleanupStack::PopAndDestroy( &view ); // closes view |
|
1366 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::FetchProgramsFromTableL out")); |
|
1367 } |
|
1368 |
|
1369 // --------------------------------------------------------------------------- |
|
1370 // CIptvEpgDatabase::FetchProgramNamesFromTableL() |
|
1371 // |
|
1372 // --------------------------------------------------------------------------- |
|
1373 void CIptvEpgDatabase::FetchProgramNamesFromTableL( const TDesC& aSqlStatement, |
|
1374 RPointerArray<CIptvEpgProgram>* aResultArray ) |
|
1375 { |
|
1376 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::FetchProgramNamesFromTableL in")); |
|
1377 |
|
1378 if ( iLocalState == EBackup ) |
|
1379 { |
|
1380 return; |
|
1381 } |
|
1382 |
|
1383 if ( !aResultArray ) |
|
1384 { |
|
1385 User::Leave( KErrArgument ); |
|
1386 } |
|
1387 RDbView view; |
|
1388 CleanupClosePushL( view ); |
|
1389 |
|
1390 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
1391 TDbQuery( aSqlStatement ) ) ); |
|
1392 User::LeaveIfError( view.EvaluateAll() ); |
|
1393 |
|
1394 CDbColSet* colSet = view.ColSetL(); |
|
1395 CleanupStack::PushL( colSet ); |
|
1396 TInt programIdColNo = colSet->ColNo( KIptvEpgProgramIdCol ); |
|
1397 TInt nameColNo = colSet->ColNo( KIptvEpgProgramNameCol ); |
|
1398 CleanupStack::PopAndDestroy( colSet ); |
|
1399 |
|
1400 view.FirstL(); |
|
1401 TInt err( KErrNone ); |
|
1402 TLinearOrder<CIptvEpgProgram> order( |
|
1403 CIptvEpgProgram::LinearOrderOfProgramsByName ); |
|
1404 CIptvEpgProgram* program = NULL; |
|
1405 |
|
1406 while ( view.AtRow() ) |
|
1407 { |
|
1408 view.GetL(); |
|
1409 program = CIptvEpgProgram::NewL(); |
|
1410 CleanupStack::PushL( program ); |
|
1411 program->SetProgramId( view.ColInt64( programIdColNo ) ); |
|
1412 program->SetProgramName( view.ColDes( nameColNo ).AllocL() ); |
|
1413 |
|
1414 err = aResultArray->InsertInOrder( program, order ); |
|
1415 if ( err != KErrNone ) |
|
1416 { |
|
1417 LIVE_TV_TRACE2(_L("CIptvEpgDatabase::FetchProgramNamesFromTableL() InsertInOrder FAILED: %d"), err); |
|
1418 // KErrAlreadyExists == duplicate entry |
|
1419 if ( err != KErrAlreadyExists ) |
|
1420 { |
|
1421 CleanupStack::PopAndDestroy( program ); |
|
1422 User::Leave( err ); |
|
1423 } |
|
1424 else |
|
1425 { |
|
1426 TInt index( aResultArray->FindInOrder( program, order ) ); |
|
1427 if ( index != KErrNotFound ) |
|
1428 { |
|
1429 User::LeaveIfError( aResultArray->Insert( program, index ) ); |
|
1430 } |
|
1431 else |
|
1432 { |
|
1433 LIVE_TV_TRACE1(_L("aResultArray->FindInOrder( program, order ) == KErrNotFound!)")); |
|
1434 } |
|
1435 } |
|
1436 |
|
1437 } |
|
1438 CleanupStack::Pop( program ); |
|
1439 view.NextL(); |
|
1440 } |
|
1441 CleanupStack::PopAndDestroy( &view ); // closes view |
|
1442 LIVE_TV_TRACE2(_L("CIptvEpgDatabase::FetchProgramNamesFromTableL out, return %d items"), aResultArray->Count() ); |
|
1443 } |
|
1444 |
|
1445 |
|
1446 // --------------------------------------------------------------------------- |
|
1447 // CIptvEpgDatabase::FetchSchedulesFromTableL() |
|
1448 // |
|
1449 // --------------------------------------------------------------------------- |
|
1450 void CIptvEpgDatabase::FetchSchedulesFromTableL( const TDesC& aSqlStatement, |
|
1451 RPointerArray<CIptvEpgSchedule>* aResultArray ) |
|
1452 { |
|
1453 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::FetchSchedulesFromTableL in")); |
|
1454 |
|
1455 if ( iLocalState == EBackup ) |
|
1456 { |
|
1457 return; |
|
1458 } |
|
1459 |
|
1460 if ( !aResultArray ) |
|
1461 { |
|
1462 User::Leave( KErrArgument ); |
|
1463 } |
|
1464 RDbView view; |
|
1465 CleanupClosePushL( view ); |
|
1466 |
|
1467 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
1468 TDbQuery( aSqlStatement ) ) ); |
|
1469 |
|
1470 User::LeaveIfError( view.EvaluateAll() ); |
|
1471 |
|
1472 CDbColSet* colSet = view.ColSetL(); |
|
1473 CleanupStack::PushL( colSet ); |
|
1474 TInt programIdColNo = colSet->ColNo( KIptvEpgScheduleProgramIdCol ); |
|
1475 TInt channelIdColNo = colSet->ColNo( KIptvEpgScheduleChannelIdCol ); |
|
1476 TInt serviceIdColNo = colSet->ColNo( KIptvEpgScheduleServiceProviderIdCol ); |
|
1477 TInt startTimeColNo = colSet->ColNo( KIptvEpgScheduleStartTimeCol ); |
|
1478 TInt endTimeColNo = colSet->ColNo( KIptvEpgScheduleEndTimeCol ); |
|
1479 CleanupStack::PopAndDestroy( colSet ); |
|
1480 |
|
1481 view.FirstL(); |
|
1482 while ( view.AtRow() ) |
|
1483 { |
|
1484 view.GetL(); |
|
1485 CIptvEpgSchedule* schedule= CIptvEpgSchedule::NewL(); |
|
1486 CleanupStack::PushL( schedule ); |
|
1487 schedule->iProgramId = view.ColInt64( programIdColNo ); |
|
1488 schedule->iChannelId = view.ColInt64( channelIdColNo ); |
|
1489 schedule->iServiceId = view.ColUint32( serviceIdColNo ); |
|
1490 schedule->iStartTime = view.ColTime( startTimeColNo ); |
|
1491 schedule->iEndTime = view.ColTime( endTimeColNo ); |
|
1492 |
|
1493 // Since now ownership of CIptvEpgProgram object is in RPointerArray |
|
1494 aResultArray->AppendL( schedule ); |
|
1495 |
|
1496 CleanupStack::Pop( schedule ); |
|
1497 |
|
1498 view.NextL(); |
|
1499 } |
|
1500 |
|
1501 CleanupStack::PopAndDestroy( &view ); // closes view |
|
1502 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::FetchSchedulesFromTableL out")); |
|
1503 } |
|
1504 |
|
1505 // --------------------------------------------------------------------------- |
|
1506 // CIptvEpgDatabase::FetchSearchSchedulesFromTableL() |
|
1507 // |
|
1508 // --------------------------------------------------------------------------- |
|
1509 void CIptvEpgDatabase::FetchSearchSchedulesFromTableL( const TDesC& aSqlStatement, |
|
1510 RPointerArray<CIptvEpgScheduleSearch>* aResultArray ) |
|
1511 { |
|
1512 |
|
1513 if ( iLocalState == EBackup ) |
|
1514 { |
|
1515 return; |
|
1516 } |
|
1517 |
|
1518 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::FetchSearchSchedulesFromTableL in")); |
|
1519 if ( !aResultArray ) |
|
1520 { |
|
1521 User::Leave( KErrArgument ); |
|
1522 } |
|
1523 RDbView view; |
|
1524 CleanupClosePushL( view ); |
|
1525 |
|
1526 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
1527 TDbQuery( aSqlStatement ) ) ); |
|
1528 |
|
1529 User::LeaveIfError( view.EvaluateAll() ); |
|
1530 |
|
1531 CDbColSet* colSet = view.ColSetL(); |
|
1532 CleanupStack::PushL( colSet ); |
|
1533 TInt programIdColNo = colSet->ColNo( KIptvEpgScheduleProgramIdCol ); |
|
1534 TInt channelIdColNo = colSet->ColNo( KIptvEpgScheduleChannelIdCol ); |
|
1535 //TInt serviceIdColNo = colSet->ColNo( KIptvEpgScheduleServiceProviderIdCol ); |
|
1536 TInt startTimeColNo = colSet->ColNo( KIptvEpgScheduleStartTimeCol ); |
|
1537 TInt endTimeColNo = colSet->ColNo( KIptvEpgScheduleEndTimeCol ); |
|
1538 |
|
1539 CleanupStack::PopAndDestroy( colSet ); |
|
1540 |
|
1541 CIptvEpgScheduleSearch* scheduleSearch = NULL; |
|
1542 |
|
1543 view.FirstL(); |
|
1544 while ( view.AtRow() ) |
|
1545 { |
|
1546 view.GetL(); |
|
1547 scheduleSearch = CIptvEpgScheduleSearch::NewL(); |
|
1548 CleanupStack::PushL( scheduleSearch ); |
|
1549 scheduleSearch->iProgramId = view.ColInt64( programIdColNo ); |
|
1550 scheduleSearch->iChannelId = view.ColInt64( channelIdColNo ); |
|
1551 //scheduleSearch->iServiceId = view.ColUint32( serviceIdColNo ); |
|
1552 scheduleSearch->iStartTime = view.ColTime( startTimeColNo ); |
|
1553 scheduleSearch->iEndTime = view.ColTime( endTimeColNo ); |
|
1554 aResultArray->AppendL( scheduleSearch ); |
|
1555 // Since now ownership of object is in RPointerArray |
|
1556 CleanupStack::Pop( scheduleSearch ); |
|
1557 |
|
1558 view.NextL(); |
|
1559 } |
|
1560 CleanupStack::PopAndDestroy( &view ); // closes view |
|
1561 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::FetchSearchSchedulesFromTableL out")); |
|
1562 } |
|
1563 |
|
1564 |
|
1565 // --------------------------------------------------------------------------- |
|
1566 // CIptvEpgDatabase::InsertOrUpdateScheduleL() |
|
1567 // |
|
1568 // --------------------------------------------------------------------------- |
|
1569 EXPORT_C void CIptvEpgDatabase::InsertOrUpdateScheduleL( const CIptvEpgSchedule& aSchedule ) |
|
1570 { |
|
1571 |
|
1572 if ( iLocalState == EBackup ) |
|
1573 { |
|
1574 return; |
|
1575 } |
|
1576 |
|
1577 // Just add schedule because we are updating the epg to an empty database |
|
1578 AddScheduleL( aSchedule ); |
|
1579 } |
|
1580 // --------------------------------------------------------------------------- |
|
1581 // CIptvEpgDatabase::AddScheduleL() |
|
1582 // |
|
1583 // --------------------------------------------------------------------------- |
|
1584 EXPORT_C void CIptvEpgDatabase::AddScheduleL( const CIptvEpgSchedule& aSchedule ) |
|
1585 { |
|
1586 |
|
1587 if ( iLocalState == EBackup ) |
|
1588 { |
|
1589 return; |
|
1590 } |
|
1591 |
|
1592 TBuf<50> sqlStatement; |
|
1593 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
1594 sqlStatement.Append( KIptvEpgScheduleTable ); |
|
1595 RDbView view; |
|
1596 CleanupClosePushL( view ); |
|
1597 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
1598 TDbQuery( sqlStatement ), |
|
1599 TDbWindow::EUnlimited, |
|
1600 RDbView::EInsertOnly ) ); |
|
1601 view.InsertL(); |
|
1602 |
|
1603 CDbColSet* scheduleColSet = view.ColSetL(); |
|
1604 // Ownership of CDbColSet object is now here! |
|
1605 CleanupStack::PushL( scheduleColSet ); |
|
1606 view.SetColL( scheduleColSet->ColNo( KIptvEpgScheduleServiceProviderIdCol ), |
|
1607 aSchedule.iServiceId ); |
|
1608 view.SetColL( scheduleColSet->ColNo( KIptvEpgScheduleChannelIdCol ), |
|
1609 aSchedule.iChannelId ); |
|
1610 view.SetColL( scheduleColSet->ColNo( KIptvEpgScheduleProgramIdCol ), |
|
1611 aSchedule.iProgramId ); |
|
1612 view.SetColL( scheduleColSet->ColNo( KIptvEpgScheduleStartTimeCol ), |
|
1613 aSchedule.iStartTime ); |
|
1614 view.SetColL( scheduleColSet->ColNo( KIptvEpgScheduleEndTimeCol ), |
|
1615 aSchedule.iEndTime ); |
|
1616 |
|
1617 CleanupStack::PopAndDestroy( scheduleColSet ); |
|
1618 view.PutL(); |
|
1619 |
|
1620 CleanupStack::PopAndDestroy( &view ); // closes view |
|
1621 } |
|
1622 |
|
1623 // --------------------------------------------------------------------------- |
|
1624 // CIptvEpgDatabase::InsertOrUpdateChannelL() |
|
1625 // |
|
1626 // --------------------------------------------------------------------------- |
|
1627 EXPORT_C void CIptvEpgDatabase::InsertOrUpdateChannelL( |
|
1628 const CIptvEpgChannel& aChannel, |
|
1629 TUint32& aChannelKey ) |
|
1630 { |
|
1631 |
|
1632 if ( iLocalState == EBackup ) |
|
1633 { |
|
1634 return; |
|
1635 } |
|
1636 |
|
1637 // Just call AddChannelL because we are using an empty database |
|
1638 AddChannelL( aChannel, aChannelKey ); |
|
1639 } |
|
1640 |
|
1641 // --------------------------------------------------------------------------- |
|
1642 // CIptvEpgDatabase::AddSchedulesL() |
|
1643 // |
|
1644 // --------------------------------------------------------------------------- |
|
1645 // |
|
1646 EXPORT_C void CIptvEpgDatabase::AddSchedulesL( const RPointerArray<CIptvEpgSchedule>& aSchedules ) |
|
1647 { |
|
1648 |
|
1649 if ( iLocalState == EBackup ) |
|
1650 { |
|
1651 return; |
|
1652 } |
|
1653 |
|
1654 TBuf<50> sqlStatement; |
|
1655 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
1656 sqlStatement.Append( KIptvEpgScheduleTable ); |
|
1657 RDbView view; |
|
1658 CleanupClosePushL( view ); |
|
1659 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
1660 TDbQuery( sqlStatement ), |
|
1661 TDbWindow::EUnlimited, |
|
1662 RDbView::EInsertOnly ) ); |
|
1663 |
|
1664 CIptvEpgSchedule* schedule = NULL; |
|
1665 LIVE_TV_TRACE2( _L("About to enter loop to insert %d schedules"), aSchedules.Count() ); |
|
1666 for( TInt i = 0; i < aSchedules.Count(); i++ ) |
|
1667 { |
|
1668 schedule = aSchedules[i]; |
|
1669 view.InsertL(); |
|
1670 |
|
1671 CDbColSet* scheduleColSet = view.ColSetL(); |
|
1672 // Ownership of CDbColSet object is now here! |
|
1673 CleanupStack::PushL( scheduleColSet ); |
|
1674 view.SetColL( scheduleColSet->ColNo( KIptvEpgScheduleServiceProviderIdCol ), |
|
1675 schedule->iServiceId ); |
|
1676 view.SetColL( scheduleColSet->ColNo( KIptvEpgScheduleChannelIdCol ), |
|
1677 schedule->iChannelId ); |
|
1678 view.SetColL( scheduleColSet->ColNo( KIptvEpgScheduleProgramIdCol ), |
|
1679 schedule->iProgramId ); |
|
1680 view.SetColL( scheduleColSet->ColNo( KIptvEpgScheduleStartTimeCol ), |
|
1681 schedule->iStartTime ); |
|
1682 view.SetColL( scheduleColSet->ColNo( KIptvEpgScheduleEndTimeCol ), |
|
1683 schedule->iEndTime ); |
|
1684 |
|
1685 CleanupStack::PopAndDestroy( scheduleColSet ); |
|
1686 view.PutL(); |
|
1687 } |
|
1688 |
|
1689 // Compact database |
|
1690 iMulticastDb.Compact(); |
|
1691 |
|
1692 CleanupStack::PopAndDestroy( &view ); // closes view |
|
1693 } |
|
1694 |
|
1695 |
|
1696 // --------------------------------------------------------------------------- |
|
1697 // CIptvEpgDatabase::AddChannelL() |
|
1698 // |
|
1699 // --------------------------------------------------------------------------- |
|
1700 EXPORT_C void CIptvEpgDatabase::AddChannelL( const CIptvEpgChannel& aChannel, |
|
1701 TUint32& aChannelKey ) |
|
1702 { |
|
1703 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::AddChannelL()") ); |
|
1704 LIVE_TV_TRACE2( _L("aChannel.iChannelId = %Li"), aChannel.ChannelId() ); |
|
1705 |
|
1706 if ( iLocalState == EBackup ) |
|
1707 { |
|
1708 return; |
|
1709 } |
|
1710 |
|
1711 RDbView view; |
|
1712 CleanupClosePushL( view ); |
|
1713 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
1714 TDbQuery( iSqlChannel ), |
|
1715 TDbWindow::EUnlimited, |
|
1716 RDbView::EInsertOnly ) ); |
|
1717 view.InsertL(); |
|
1718 |
|
1719 CDbColSet* channelColSet = view.ColSetL(); |
|
1720 // Ownership of CDbColSet object is now here! |
|
1721 CleanupStack::PushL( channelColSet ); |
|
1722 view.SetColL( channelColSet->ColNo( KIptvEpgChannelIdCol ), |
|
1723 aChannel.ChannelId() ); |
|
1724 view.SetColL( channelColSet->ColNo( KIptvEpgChannelServProviderIdCol ), |
|
1725 aChannel.ServiceId() ); |
|
1726 if ( aChannel.ChannelName().Length() > KIptvEpgChannelNameMaxLength ) |
|
1727 { |
|
1728 // Channel name is too long, cut it |
|
1729 TBuf <KIptvEpgChannelNameMaxLength> channelName = |
|
1730 aChannel.ChannelName().Left( KIptvEpgChannelNameMaxLength ); |
|
1731 view.SetColL( channelColSet->ColNo( KIptvEpgChannelNameCol ), |
|
1732 channelName ); |
|
1733 } |
|
1734 else |
|
1735 { |
|
1736 view.SetColL( channelColSet->ColNo( KIptvEpgChannelNameCol ), |
|
1737 aChannel.ChannelName() ); |
|
1738 } |
|
1739 |
|
1740 view.SetColL( channelColSet->ColNo( KIptvEpgChannelLogoPathCol ), |
|
1741 aChannel.ChannelLogoPath() ); |
|
1742 |
|
1743 if ( aChannel.ChannelDescription().Length() > KIptvEpgDescrMaxLength ) |
|
1744 { |
|
1745 // Channel description is too long, cut it |
|
1746 TBuf<KIptvEpgDescrMaxLength> channelDesc = |
|
1747 aChannel.ChannelDescription().Left( KIptvEpgDescrMaxLength ); |
|
1748 view.SetColL( channelColSet->ColNo( KIptvEpgChannelDescriptionCol ), |
|
1749 channelDesc ); |
|
1750 } |
|
1751 else |
|
1752 { |
|
1753 view.SetColL( channelColSet->ColNo( KIptvEpgChannelDescriptionCol ), |
|
1754 aChannel.ChannelDescription() ); |
|
1755 } |
|
1756 |
|
1757 view.SetColL( channelColSet->ColNo( KIptvEpgChannelURICol ), |
|
1758 aChannel.ChannelURI() ); |
|
1759 |
|
1760 // SDP is long one, it needs to be handled by stream |
|
1761 RDbColWriteStream write; |
|
1762 write.OpenLC( view, channelColSet->ColNo( KIptvEpgChannelSDPCol ) ); |
|
1763 write.WriteL( aChannel.ChannelSDP() ); |
|
1764 write.Close(); |
|
1765 CleanupStack::PopAndDestroy(); // write |
|
1766 |
|
1767 TInt keyColumnNo = channelColSet->ColNo( KIptvEpgChannelDbKeyCol ); |
|
1768 |
|
1769 // Order |
|
1770 view.SetColL( channelColSet->ColNo( KIptvEpgChannelOrderCol ), |
|
1771 aChannel.ChannelOrder() ); |
|
1772 CleanupStack::PopAndDestroy( channelColSet ); |
|
1773 view.PutL(); |
|
1774 |
|
1775 // Get new channel key |
|
1776 aChannelKey = view.ColUint32( keyColumnNo ); |
|
1777 |
|
1778 CleanupStack::PopAndDestroy( &view ); // closes view |
|
1779 |
|
1780 // Finally update order numbers because new channel was addded |
|
1781 UpdateChannelOrdersL( aChannel.ServiceId() ); |
|
1782 } |
|
1783 |
|
1784 // --------------------------------------------------------------------------- |
|
1785 // CIptvEpgDatabase::InsertOrUpdateProgramL() |
|
1786 // |
|
1787 // --------------------------------------------------------------------------- |
|
1788 EXPORT_C void CIptvEpgDatabase::InsertOrUpdateProgramL( |
|
1789 const CIptvEpgProgram& aProgram, |
|
1790 TUint32& aProgramKey ) |
|
1791 { |
|
1792 if ( iLocalState == EBackup ) |
|
1793 { |
|
1794 return; |
|
1795 } |
|
1796 |
|
1797 // Just add program because we are using an empty db |
|
1798 AddProgramL( aProgram, aProgramKey ); |
|
1799 } |
|
1800 |
|
1801 |
|
1802 // --------------------------------------------------------------------------- |
|
1803 // CIptvEpgDatabase::AddProgramL() |
|
1804 // |
|
1805 // --------------------------------------------------------------------------- |
|
1806 EXPORT_C void CIptvEpgDatabase::AddProgramL( const CIptvEpgProgram& aProgram, |
|
1807 TUint32& aProgramKey ) |
|
1808 { |
|
1809 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::AddProgramL() in")); |
|
1810 if ( iLocalState == EBackup ) |
|
1811 { |
|
1812 return; |
|
1813 } |
|
1814 |
|
1815 RDbView view; |
|
1816 TInt err = KErrNone; |
|
1817 CleanupClosePushL( view ); |
|
1818 err = view.Prepare( iMulticastDb, |
|
1819 TDbQuery( iSqlProgram ), |
|
1820 TDbWindow::EUnlimited, |
|
1821 RDbView::EInsertOnly ); |
|
1822 if ( err != KErrNone ) |
|
1823 { |
|
1824 LIVE_TV_TRACE1( _L("")); |
|
1825 LIVE_TV_TRACE2( _L("CIptvEpgDatabase::AddProgramL FAILED with code %d"), err ); |
|
1826 LIVE_TV_TRACE1( _L("")); |
|
1827 User::Leave( err ); |
|
1828 } |
|
1829 view.InsertL(); |
|
1830 |
|
1831 CDbColSet* programColSet = view.ColSetL(); |
|
1832 CleanupStack::PushL( programColSet ); |
|
1833 |
|
1834 view.SetColL( programColSet->ColNo( KIptvEpgProgramIdCol ), |
|
1835 aProgram.ProgramId() ); |
|
1836 view.SetColL( programColSet->ColNo( KIptvEpgProgramChannelId ), |
|
1837 aProgram.ChannelId() ); |
|
1838 view.SetColL( programColSet->ColNo( KIptvEpgProgramServProviderIdCol ), |
|
1839 aProgram.ServiceId() ); |
|
1840 view.SetColL( programColSet->ColNo( KIptvEpgProgramURICol ), |
|
1841 aProgram.ProgramURI() ); |
|
1842 view.SetColL( programColSet->ColNo( KIptvEpgProgramGenreCol ), |
|
1843 aProgram.ProgramGenre() ); |
|
1844 if ( aProgram.ProgramName().Length() > KIptvEpgProgramMaxLength ) |
|
1845 { |
|
1846 TBuf<KIptvEpgProgramMaxLength> programName = |
|
1847 aProgram.ProgramName().Left( KIptvEpgProgramMaxLength ); |
|
1848 view.SetColL( programColSet->ColNo( KIptvEpgProgramNameCol ), |
|
1849 programName ); |
|
1850 } |
|
1851 else |
|
1852 { |
|
1853 view.SetColL( programColSet->ColNo( KIptvEpgProgramNameCol ), |
|
1854 aProgram.ProgramName() ); |
|
1855 } |
|
1856 |
|
1857 view.SetColL( programColSet->ColNo( KIptvEpgProgramLanguageCol ), |
|
1858 aProgram.ProgramLanguage() ); |
|
1859 view.SetColL( programColSet->ColNo( KIptvEpgProgramParentalRatingCol ), |
|
1860 aProgram.ProgramParentalRating() ); |
|
1861 |
|
1862 // Description is long one, it needs to be handled by stream |
|
1863 RDbColWriteStream write; |
|
1864 write.OpenLC( view, programColSet->ColNo( KIptvEpgProgramDescriptionCol ) ); |
|
1865 write.WriteL( aProgram.ProgramDescription() ); |
|
1866 write.Close(); |
|
1867 CleanupStack::PopAndDestroy(); // write |
|
1868 |
|
1869 TInt keyColumnNo = programColSet->ColNo( KIptvEpgProgramDbKeyCol ); |
|
1870 CleanupStack::PopAndDestroy( programColSet ); |
|
1871 view.PutL(); |
|
1872 |
|
1873 // Get new program key |
|
1874 aProgramKey = view.ColUint32( keyColumnNo ); |
|
1875 CleanupStack::PopAndDestroy( &view ); // closes view |
|
1876 |
|
1877 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::AddProgramL() out")); |
|
1878 } |
|
1879 |
|
1880 // --------------------------------------------------------------------------- |
|
1881 // CIptvEpgDatabase::AddProgramsL() |
|
1882 // |
|
1883 // --------------------------------------------------------------------------- |
|
1884 // |
|
1885 EXPORT_C void CIptvEpgDatabase::AddProgramsL( |
|
1886 const RPointerArray<CIptvEpgProgram>& aPrograms ) |
|
1887 { |
|
1888 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::AddProgramsL() in")); |
|
1889 |
|
1890 if ( iLocalState == EBackup ) |
|
1891 { |
|
1892 return; |
|
1893 } |
|
1894 |
|
1895 RDbView view; |
|
1896 TInt err = KErrNone; |
|
1897 CleanupClosePushL( view ); |
|
1898 err = view.Prepare( iMulticastDb, |
|
1899 TDbQuery( iSqlProgram ), |
|
1900 TDbWindow::EUnlimited, |
|
1901 RDbView::EInsertOnly ); |
|
1902 if ( err != KErrNone ) |
|
1903 { |
|
1904 LIVE_TV_TRACE1( _L("")); |
|
1905 LIVE_TV_TRACE2( _L("CIptvEpgDatabase::AddProgramsL FAILED with code %d"), err ); |
|
1906 LIVE_TV_TRACE1( _L("")); |
|
1907 User::Leave( err ); |
|
1908 } |
|
1909 |
|
1910 CIptvEpgProgram* program = NULL; |
|
1911 LIVE_TV_TRACE2( _L("About to enter loop to insert %d programs to the database"), aPrograms.Count() ); |
|
1912 for( TInt i = 0; i < aPrograms.Count(); i++ ) |
|
1913 { |
|
1914 view.InsertL(); |
|
1915 program = aPrograms[i]; |
|
1916 |
|
1917 CDbColSet* programColSet = view.ColSetL(); |
|
1918 CleanupStack::PushL( programColSet ); |
|
1919 |
|
1920 view.SetColL( programColSet->ColNo( KIptvEpgProgramIdCol ), |
|
1921 program->ProgramId() ); |
|
1922 view.SetColL( programColSet->ColNo( KIptvEpgProgramChannelId ), |
|
1923 program->ChannelId() ); |
|
1924 view.SetColL( programColSet->ColNo( KIptvEpgProgramServProviderIdCol ), |
|
1925 program->ServiceId() ); |
|
1926 view.SetColL( programColSet->ColNo( KIptvEpgProgramURICol ), |
|
1927 program->ProgramURI() ); |
|
1928 view.SetColL( programColSet->ColNo( KIptvEpgProgramGenreCol ), |
|
1929 program->ProgramGenre() ); |
|
1930 |
|
1931 if ( program->ProgramName().Length() > KIptvEpgProgramMaxLength ) |
|
1932 { |
|
1933 TBuf<KIptvEpgProgramMaxLength> programName = |
|
1934 program->ProgramName().Left( KIptvEpgProgramMaxLength ); |
|
1935 view.SetColL( programColSet->ColNo( KIptvEpgProgramNameCol ), |
|
1936 programName ); |
|
1937 } |
|
1938 else |
|
1939 { |
|
1940 view.SetColL( programColSet->ColNo( KIptvEpgProgramNameCol ), |
|
1941 program->ProgramName() ); |
|
1942 } |
|
1943 view.SetColL( programColSet->ColNo( KIptvEpgProgramLanguageCol ), |
|
1944 program->ProgramLanguage() ); |
|
1945 view.SetColL( programColSet->ColNo( KIptvEpgProgramParentalRatingCol ), |
|
1946 program->ProgramParentalRating() ); |
|
1947 |
|
1948 // Description is long one, it needs to be handled by stream |
|
1949 RDbColWriteStream write; |
|
1950 write.OpenLC( view, programColSet->ColNo( KIptvEpgProgramDescriptionCol ) ); |
|
1951 write.WriteL( program->ProgramDescription() ); |
|
1952 write.Close(); |
|
1953 CleanupStack::PopAndDestroy(); // write |
|
1954 CleanupStack::PopAndDestroy( programColSet ); |
|
1955 view.PutL(); |
|
1956 } |
|
1957 CleanupStack::PopAndDestroy( &view ); // closes view |
|
1958 |
|
1959 iMulticastDb.Compact(); |
|
1960 |
|
1961 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::AddProgramsL() out")); |
|
1962 } |
|
1963 |
|
1964 // --------------------------------------------------------------------------- |
|
1965 // CIptvEpgDatabase::AddProgramWithScheduleL() |
|
1966 // |
|
1967 // --------------------------------------------------------------------------- |
|
1968 // |
|
1969 EXPORT_C void CIptvEpgDatabase::AddProgramWithScheduleL( |
|
1970 CIptvEpgProgramWithSchedule& aProgramWithSchedule, |
|
1971 TUint32& aProgramKey ) |
|
1972 { |
|
1973 if ( iLocalState == EBackup ) |
|
1974 { |
|
1975 return; |
|
1976 } |
|
1977 |
|
1978 AddProgramL( aProgramWithSchedule, aProgramKey ); |
|
1979 AddScheduleL( aProgramWithSchedule.Schedule() ); |
|
1980 } |
|
1981 |
|
1982 // --------------------------------------------------------------------------- |
|
1983 // CIptvEpgDatabase::AddProgramsWithSchedulesL() |
|
1984 // |
|
1985 // --------------------------------------------------------------------------- |
|
1986 // |
|
1987 EXPORT_C void CIptvEpgDatabase::AddProgramsWithSchedulesL( |
|
1988 const RPointerArray<CIptvEpgProgramWithSchedule>& aProgramsWithSchedules ) |
|
1989 { |
|
1990 if ( iLocalState == EBackup ) |
|
1991 { |
|
1992 return; |
|
1993 } |
|
1994 |
|
1995 RPointerArray<CIptvEpgSchedule> scheduleArray; |
|
1996 CleanupClosePushL( scheduleArray ); |
|
1997 RPointerArray<CIptvEpgProgram> programArray; |
|
1998 CleanupClosePushL( programArray ); |
|
1999 |
|
2000 CIptvEpgProgramWithSchedule* progWithSchedule = NULL; |
|
2001 TInt err( KErrNone ); |
|
2002 for ( TInt i = 0; i < aProgramsWithSchedules.Count() && err == KErrNone; i++ ) |
|
2003 { |
|
2004 progWithSchedule = aProgramsWithSchedules[i]; |
|
2005 CIptvEpgSchedule& schedule = progWithSchedule->Schedule(); |
|
2006 err = scheduleArray.Append( &schedule ); |
|
2007 if ( err == KErrNone ) |
|
2008 { |
|
2009 err = programArray.Append( progWithSchedule ); |
|
2010 } |
|
2011 } |
|
2012 if ( err != KErrNone ) |
|
2013 { |
|
2014 LIVE_TV_TRACE2(_L("CIptvEpgDatabase::AddProgramsWithSchedulesL: Append in for-loop FAILED: %d"), err); |
|
2015 scheduleArray.Reset(); |
|
2016 programArray.Reset(); |
|
2017 User::Leave( err ); |
|
2018 } |
|
2019 if ( programArray.Count() > 0 ) |
|
2020 { |
|
2021 AddProgramsL( programArray ); |
|
2022 if ( scheduleArray.Count() > 0 ) |
|
2023 { |
|
2024 AddSchedulesL( scheduleArray ); |
|
2025 } |
|
2026 } |
|
2027 programArray.Reset(); |
|
2028 scheduleArray.Reset(); |
|
2029 CleanupStack::PopAndDestroy( &programArray ); |
|
2030 CleanupStack::PopAndDestroy( &scheduleArray ); |
|
2031 } |
|
2032 |
|
2033 // --------------------------------------------------------- |
|
2034 // CIptvEpgDatabase::UpdateChannelOrderL() |
|
2035 // |
|
2036 // --------------------------------------------------------- |
|
2037 EXPORT_C void CIptvEpgDatabase::UpdateChannelOrderL( const TUint32 aServiceId, |
|
2038 const TInt64 aChannelId, |
|
2039 const TUint32 aOrder ) |
|
2040 { |
|
2041 if ( iLocalState == EBackup ) |
|
2042 { |
|
2043 return; |
|
2044 } |
|
2045 |
|
2046 LIVE_TV_TRACE4(_L("CIptvEpgDatabase::UpdateChannelOrderL in, aServiceId: %u, aChannelId: %Li, aOrder:%u"), aServiceId, aChannelId, aOrder ); |
|
2047 TBuf<KCustomSqlLength> sqlStatement; |
|
2048 sqlStatement.Append( _L("SELECT ") ); |
|
2049 sqlStatement.Append( KIptvEpgChannelOrderCol ); |
|
2050 sqlStatement.Append( _L(" FROM ") ); |
|
2051 sqlStatement.Append( KIptvEpgChannelTable ); |
|
2052 sqlStatement.Append( _L(" WHERE ") ); |
|
2053 sqlStatement.Append( KIptvEpgChannelIdCol ); |
|
2054 sqlStatement.Append( _L(" = ") ); |
|
2055 sqlStatement.AppendNum( aChannelId ); |
|
2056 sqlStatement.Append( _L(" AND ") ); |
|
2057 sqlStatement.Append( KIptvEpgChannelServProviderIdCol ); |
|
2058 sqlStatement.Append( _L(" = ") ); |
|
2059 sqlStatement.AppendNum( aServiceId ); |
|
2060 |
|
2061 RDbView view; |
|
2062 CleanupClosePushL( view ); |
|
2063 User::LeaveIfError( iMulticastDb.Begin() ); |
|
2064 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
2065 TDbQuery( sqlStatement ) ) ); |
|
2066 User::LeaveIfError( view.EvaluateAll() ); |
|
2067 |
|
2068 // Ownership of this pointer is now here. It needs to be deleted also |
|
2069 CDbColSet* channelColSet = view.ColSetL(); |
|
2070 CleanupStack::PushL( channelColSet ); |
|
2071 |
|
2072 // sql statement found a row from table |
|
2073 if ( view.FirstL() ) |
|
2074 { |
|
2075 view.UpdateL(); |
|
2076 |
|
2077 view.SetColL( channelColSet->ColNo( KIptvEpgChannelOrderCol ), |
|
2078 aOrder ); |
|
2079 |
|
2080 view.PutL(); |
|
2081 } |
|
2082 CleanupStack::PopAndDestroy( channelColSet ); |
|
2083 CleanupStack::PopAndDestroy( &view ); // closes view |
|
2084 User::LeaveIfError( iMulticastDb.Commit() ); |
|
2085 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::UpdateChannelOrderL() out")); |
|
2086 } |
|
2087 |
|
2088 // --------------------------------------------------------------------------- |
|
2089 // CIptvEpgDatabase::DeleteChannelL() |
|
2090 // |
|
2091 // --------------------------------------------------------------------------- |
|
2092 EXPORT_C void CIptvEpgDatabase::DeleteChannelL( |
|
2093 const TUint32 aServiceProviderId, |
|
2094 const TInt64 aChannelId ) |
|
2095 { |
|
2096 if ( iLocalState == EBackup ) |
|
2097 { |
|
2098 return; |
|
2099 } |
|
2100 |
|
2101 // First of all we need to delete all the programs which belongs to |
|
2102 // channel identified by aServiceProviderId and aChannelId |
|
2103 TBuf<KCustomSqlLength> sqlStatement; |
|
2104 sqlStatement.Append( _L("SELECT ") ); |
|
2105 sqlStatement.Append( KIptvEpgProgramIdCol ); |
|
2106 sqlStatement.Append( _L(" FROM ") ); |
|
2107 sqlStatement.Append( KIptvEpgProgramTable ); |
|
2108 sqlStatement.Append( _L(" WHERE ") ); |
|
2109 sqlStatement.Append( KIptvEpgProgramChannelId ); |
|
2110 sqlStatement.Append( _L(" = ") ); |
|
2111 sqlStatement.AppendNum( aChannelId ); |
|
2112 sqlStatement.Append( _L(" AND ") ); |
|
2113 sqlStatement.Append( KIptvEpgProgramServProviderIdCol ); |
|
2114 sqlStatement.Append( _L(" = ") ); |
|
2115 sqlStatement.AppendNum( aServiceProviderId ); |
|
2116 |
|
2117 RDbView view; |
|
2118 CleanupClosePushL( view ); |
|
2119 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
2120 TDbQuery( sqlStatement ) ) ); |
|
2121 User::LeaveIfError( view.EvaluateAll() ); |
|
2122 view.FirstL(); |
|
2123 CDbColSet* colSet = view.ColSetL(); |
|
2124 CleanupStack::PushL( colSet ); |
|
2125 TInt programIdColNo = colSet->ColNo( KIptvEpgProgramIdCol ); |
|
2126 CleanupStack::PopAndDestroy( colSet ); |
|
2127 |
|
2128 RArray<TInt64> programIdArray; |
|
2129 CleanupClosePushL( programIdArray ); |
|
2130 while ( view.AtRow() ) |
|
2131 { |
|
2132 view.GetL(); |
|
2133 User::LeaveIfError( programIdArray.Append( |
|
2134 view.ColInt64( programIdColNo ) ) ); |
|
2135 view.NextL(); |
|
2136 } |
|
2137 for ( TInt i = 0; i < programIdArray.Count(); i++ ) |
|
2138 { |
|
2139 DeleteProgramL( aServiceProviderId, programIdArray[i] ); |
|
2140 } |
|
2141 programIdArray.Reset(); |
|
2142 CleanupStack::PopAndDestroy( &programIdArray ); // closes programIdArray |
|
2143 CleanupStack::PopAndDestroy( &view ); // closes view |
|
2144 |
|
2145 // Handle channel removal |
|
2146 sqlStatement.Zero(); |
|
2147 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
2148 sqlStatement.Append( KIptvEpgChannelTable ); |
|
2149 sqlStatement.Append( _L(" WHERE ") ); |
|
2150 sqlStatement.Append( KIptvEpgChannelIdCol ); |
|
2151 sqlStatement.Append( _L(" = ") ); |
|
2152 sqlStatement.AppendNum( aChannelId ); |
|
2153 sqlStatement.Append( _L(" AND ") ); |
|
2154 sqlStatement.Append( KIptvEpgChannelServProviderIdCol ); |
|
2155 sqlStatement.Append( _L(" = ") ); |
|
2156 sqlStatement.AppendNum( aServiceProviderId ); |
|
2157 |
|
2158 User::LeaveIfError( iMulticastDb.Begin() ); |
|
2159 CleanupClosePushL( view ); |
|
2160 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
2161 TDbQuery( sqlStatement ) ) ); |
|
2162 User::LeaveIfError( view.EvaluateAll() ); |
|
2163 |
|
2164 while ( view.NextL() ) |
|
2165 { |
|
2166 view.DeleteL(); |
|
2167 } |
|
2168 CleanupStack::PopAndDestroy( &view ); // Closes view |
|
2169 User::LeaveIfError( iMulticastDb.Commit() ); |
|
2170 |
|
2171 // Update the channel order numbers |
|
2172 UpdateChannelOrdersL( aServiceProviderId ); |
|
2173 } |
|
2174 |
|
2175 |
|
2176 // --------------------------------------------------------------------------- |
|
2177 // CIptvEpgDatabase::UpdateChannelOrdersL() |
|
2178 // |
|
2179 // --------------------------------------------------------------------------- |
|
2180 void CIptvEpgDatabase::UpdateChannelOrdersL( const TUint32 aServiceProviderId ) |
|
2181 { |
|
2182 if ( iLocalState == EBackup ) |
|
2183 { |
|
2184 return; |
|
2185 } |
|
2186 |
|
2187 TBuf<KCustomSqlLength> sqlStatement; |
|
2188 sqlStatement.Append( _L("SELECT " ) ); |
|
2189 sqlStatement.Append( KIptvEpgChannelServProviderIdCol ); |
|
2190 sqlStatement.Append( _L(", ")); |
|
2191 sqlStatement.Append( KIptvEpgChannelIdCol ); |
|
2192 sqlStatement.Append( _L(", ")); |
|
2193 sqlStatement.Append( KIptvEpgChannelURICol ); |
|
2194 sqlStatement.Append( _L(", ")); |
|
2195 sqlStatement.Append( KIptvEpgChannelOrderCol ); |
|
2196 sqlStatement.Append( _L(" FROM ") ); |
|
2197 sqlStatement.Append( KIptvEpgChannelTable ); |
|
2198 sqlStatement.Append( _L(" WHERE ") ); |
|
2199 sqlStatement.Append( KIptvEpgChannelServProviderIdCol ); |
|
2200 sqlStatement.Append( _L(" = ") ); |
|
2201 sqlStatement.AppendNum( aServiceProviderId ); |
|
2202 sqlStatement.Append( _L(" ORDER BY ") ); |
|
2203 sqlStatement.Append( KIptvEpgChannelOrderCol ); |
|
2204 |
|
2205 RDbView view; |
|
2206 CleanupClosePushL( view ); |
|
2207 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
2208 TDbQuery( sqlStatement ) ) ); |
|
2209 User::LeaveIfError( view.EvaluateAll() ); |
|
2210 view.FirstL(); |
|
2211 CDbColSet* colSetOrder = view.ColSetL(); |
|
2212 CleanupStack::PushL( colSetOrder ); |
|
2213 const TInt serviceColNo = colSetOrder->ColNo( KIptvEpgChannelServProviderIdCol ); |
|
2214 const TInt channelIdColNo = colSetOrder->ColNo( KIptvEpgChannelIdCol ); |
|
2215 const TInt orderColNo = colSetOrder->ColNo( KIptvEpgChannelOrderCol ); |
|
2216 const TInt uriColNo = colSetOrder->ColNo( KIptvEpgChannelURICol ); |
|
2217 CleanupStack::PopAndDestroy( colSetOrder ); |
|
2218 |
|
2219 RArray<TUint32> orderArray; |
|
2220 CleanupClosePushL( orderArray ); |
|
2221 RArray<TUint32> serviceArray; |
|
2222 CleanupClosePushL( serviceArray ); |
|
2223 RArray<TInt64> channelIdArray; |
|
2224 CleanupClosePushL( channelIdArray ); |
|
2225 CDesCArray* uriArray = new ( ELeave ) CDesCArrayFlat( KIptvDefaultUriCount ); |
|
2226 CleanupStack::PushL( uriArray ); |
|
2227 |
|
2228 while ( view.AtRow() ) |
|
2229 { |
|
2230 view.GetL(); |
|
2231 User::LeaveIfError( orderArray.Append( |
|
2232 view.ColUint32( orderColNo ) ) ); |
|
2233 User::LeaveIfError( serviceArray.Append( |
|
2234 view.ColUint32( serviceColNo ) ) ); |
|
2235 User::LeaveIfError( channelIdArray.Append( |
|
2236 view.ColInt64( channelIdColNo ) ) ); |
|
2237 uriArray->AppendL( view.ColDes( uriColNo ) ); |
|
2238 view.NextL(); |
|
2239 } |
|
2240 |
|
2241 RArray<TUint32> zeroServiceIdArray; |
|
2242 CleanupClosePushL( zeroServiceIdArray ); |
|
2243 RArray<TInt64> zeroChanIdArray; |
|
2244 CleanupClosePushL( zeroChanIdArray ); |
|
2245 CDesCArray* zeroUriArray = new ( ELeave ) CDesCArrayFlat( KIptvDefaultUriCount ); |
|
2246 CleanupStack::PushL( zeroUriArray ); |
|
2247 |
|
2248 // Get all channels whose order is zero |
|
2249 for ( TInt i = orderArray.Count() - 1; i >= 0; i-- ) |
|
2250 { |
|
2251 if ( orderArray[i] == 0 ) |
|
2252 { |
|
2253 if ( i < serviceArray.Count() && i < channelIdArray.Count() && |
|
2254 i < uriArray->MdcaCount() ) |
|
2255 { |
|
2256 zeroServiceIdArray.AppendL( serviceArray[i] ); |
|
2257 zeroChanIdArray.AppendL( channelIdArray[i] ); |
|
2258 zeroUriArray->AppendL( uriArray->MdcaPoint( i ) ); |
|
2259 } |
|
2260 orderArray.Remove( i ); |
|
2261 serviceArray.Remove( i ); |
|
2262 channelIdArray.Remove( i ); |
|
2263 uriArray->Delete( i ); |
|
2264 } |
|
2265 } |
|
2266 TUint32 prev( 0 ); |
|
2267 TUint32 current( 0 ); |
|
2268 // remove all deactivated channels |
|
2269 // by default all channels are active so if there are |
|
2270 // any channels that have been deactivated, it means that user |
|
2271 // has deactivated them -> we don't need to care about |
|
2272 // channels that have no stream URL |
|
2273 for ( TInt j = orderArray.Count() - 1; j >= 0; j-- ) |
|
2274 { |
|
2275 current = orderArray[j]; |
|
2276 if ( current == KMaxTUint32 ) |
|
2277 { |
|
2278 orderArray.Remove( j ); |
|
2279 serviceArray.Remove( j ); |
|
2280 channelIdArray.Remove( j ); |
|
2281 uriArray->Delete( j ); |
|
2282 } |
|
2283 else if ( j < uriArray->Count() && uriArray->MdcaPoint( j ).Length() == 0 ) |
|
2284 { |
|
2285 // Channel has no stream URL, put those also to zero array |
|
2286 // they are handled later |
|
2287 zeroServiceIdArray.AppendL( serviceArray[j] ); |
|
2288 zeroChanIdArray.AppendL( channelIdArray[j] ); |
|
2289 zeroUriArray->AppendL( uriArray->MdcaPoint( j ) ); |
|
2290 orderArray.Remove( j ); |
|
2291 serviceArray.Remove( j ); |
|
2292 channelIdArray.Remove( j ); |
|
2293 uriArray->Delete( j ); |
|
2294 } |
|
2295 } |
|
2296 // now orderArray should contain only activated channels |
|
2297 // check if channel orders are "in order" i.e. UI does not want to see |
|
2298 // orders like 1, 2, 4, 5, 6 if one channel has been deleted. |
|
2299 for ( TInt k = 0; k < orderArray.Count(); k++ ) |
|
2300 { |
|
2301 current = orderArray[k]; |
|
2302 if ( k == 0 && current != 1 ) |
|
2303 { |
|
2304 // First one is not number 1, fix |
|
2305 orderArray[k] = 1; |
|
2306 UpdateChannelOrderL( serviceArray[k], channelIdArray[k], |
|
2307 orderArray[k] ); |
|
2308 } |
|
2309 if ( k > 0 ) |
|
2310 { |
|
2311 prev = orderArray[k-1]; |
|
2312 } |
|
2313 |
|
2314 if ( current < KMaxTUint32 && k > 0 && |
|
2315 prev < KMaxTUint32 ) |
|
2316 { |
|
2317 const TInt offset( TInt( current - prev ) ); |
|
2318 |
|
2319 if ( offset != 1 ) |
|
2320 { |
|
2321 // channel orders have gone wrong, fix |
|
2322 orderArray[k] = prev + 1; |
|
2323 UpdateChannelOrderL( serviceArray[k], channelIdArray[k], |
|
2324 orderArray[k] ); |
|
2325 } |
|
2326 } |
|
2327 } |
|
2328 |
|
2329 // now set channel order for channels whose order is 0 and |
|
2330 // stream URL is available |
|
2331 TUint32 max( 0 ); |
|
2332 if ( orderArray.Count() > 0 ) |
|
2333 { |
|
2334 max = orderArray[orderArray.Count()-1]; |
|
2335 } |
|
2336 TInt l( 0 ); |
|
2337 for ( l = zeroServiceIdArray.Count() - 1; l >= 0; l-- ) |
|
2338 { |
|
2339 if ( max < ( KMaxTUint32 - 1 ) ) |
|
2340 { |
|
2341 if ( zeroUriArray->MdcaPoint( l ).Length() > 0 && |
|
2342 max < ( KMaxTUint32 - 1 ) ) |
|
2343 { |
|
2344 max++; |
|
2345 UpdateChannelOrderL( zeroServiceIdArray[l], zeroChanIdArray[l], |
|
2346 max ); |
|
2347 zeroServiceIdArray.Remove( l ); |
|
2348 zeroChanIdArray.Remove( l ); |
|
2349 zeroUriArray->Delete( l ); |
|
2350 } |
|
2351 } |
|
2352 } |
|
2353 // Let's move the channels that have no stream URL to last position |
|
2354 // in active channel list |
|
2355 for ( l = 0; l < zeroServiceIdArray.Count() && l < zeroUriArray->MdcaCount() && |
|
2356 l < zeroChanIdArray.Count(); l++ ) |
|
2357 { |
|
2358 if ( zeroUriArray->MdcaPoint( l ).Length() == 0 && max < ( KMaxTUint32 - 1 ) ) |
|
2359 { |
|
2360 max++; |
|
2361 UpdateChannelOrderL( zeroServiceIdArray[l], zeroChanIdArray[l], |
|
2362 max ); |
|
2363 } |
|
2364 } |
|
2365 |
|
2366 zeroServiceIdArray.Reset(); |
|
2367 zeroChanIdArray.Reset(); |
|
2368 orderArray.Reset(); |
|
2369 channelIdArray.Reset(); |
|
2370 serviceArray.Reset(); |
|
2371 |
|
2372 CleanupStack::PopAndDestroy( zeroUriArray ); |
|
2373 CleanupStack::PopAndDestroy( &zeroChanIdArray ); |
|
2374 CleanupStack::PopAndDestroy( &zeroServiceIdArray ); |
|
2375 CleanupStack::PopAndDestroy( uriArray ); |
|
2376 CleanupStack::PopAndDestroy( &channelIdArray ); // Closes array |
|
2377 CleanupStack::PopAndDestroy( &serviceArray ); // Closes array |
|
2378 CleanupStack::PopAndDestroy( &orderArray ); // Closes array |
|
2379 CleanupStack::PopAndDestroy( &view ); // Closes view |
|
2380 } |
|
2381 // --------------------------------------------------------------------------- |
|
2382 // CIptvEpgDatabase::DeleteProgramL() |
|
2383 // |
|
2384 // --------------------------------------------------------------------------- |
|
2385 EXPORT_C void CIptvEpgDatabase::DeleteProgramL( |
|
2386 const TUint32 aServiceProviderId, |
|
2387 const TInt64 aProgramId ) |
|
2388 { |
|
2389 if ( iLocalState == EBackup ) |
|
2390 { |
|
2391 return; |
|
2392 } |
|
2393 |
|
2394 TBuf<KCustomSqlLength> sqlStatement; |
|
2395 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
2396 sqlStatement.Append( KIptvEpgProgramTable ); |
|
2397 sqlStatement.Append( _L(" WHERE ") ); |
|
2398 sqlStatement.Append( KIptvEpgProgramIdCol ); |
|
2399 sqlStatement.Append( _L(" = ") ); |
|
2400 sqlStatement.AppendNum( aProgramId ); |
|
2401 sqlStatement.Append( _L(" AND ") ); |
|
2402 sqlStatement.Append( KIptvEpgProgramServProviderIdCol ); |
|
2403 sqlStatement.Append( _L(" = ") ); |
|
2404 sqlStatement.AppendNum( aServiceProviderId ); |
|
2405 |
|
2406 User::LeaveIfError( iMulticastDb.Begin() ); |
|
2407 |
|
2408 RDbView view; |
|
2409 CleanupClosePushL( view ); |
|
2410 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
2411 TDbQuery( sqlStatement ) ) ); |
|
2412 User::LeaveIfError( view.EvaluateAll() ); |
|
2413 |
|
2414 while ( view.NextL() ) |
|
2415 { |
|
2416 view.DeleteL(); |
|
2417 } |
|
2418 CleanupStack::PopAndDestroy( &view ); // closes view |
|
2419 User::LeaveIfError( iMulticastDb.Commit() ); |
|
2420 } |
|
2421 |
|
2422 // --------------------------------------------------------------------------- |
|
2423 // CIptvEpgDatabase::ClearChannelTableL() |
|
2424 // |
|
2425 // --------------------------------------------------------------------------- |
|
2426 void CIptvEpgDatabase::ClearChannelTableL( const TUint32 aServiceId ) |
|
2427 { |
|
2428 if ( iLocalState == EBackup ) |
|
2429 { |
|
2430 return; |
|
2431 } |
|
2432 |
|
2433 TBuf<KCustomSqlLength> sqlStatement; |
|
2434 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
2435 sqlStatement.Append( KIptvEpgChannelTable ); |
|
2436 sqlStatement.Append( _L(" WHERE ") ); |
|
2437 sqlStatement.Append( KIptvEpgChannelServProviderIdCol ); |
|
2438 sqlStatement.Append( _L(" = " ) ); |
|
2439 sqlStatement.AppendNum( aServiceId ); |
|
2440 |
|
2441 RDbView view; |
|
2442 CleanupClosePushL( view ); |
|
2443 User::LeaveIfError( iMulticastDb.Begin() ); |
|
2444 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
2445 TDbQuery( sqlStatement ) ) ); |
|
2446 User::LeaveIfError( view.EvaluateAll() ); |
|
2447 |
|
2448 while ( view.NextL() ) |
|
2449 { |
|
2450 view.DeleteL(); |
|
2451 } |
|
2452 CleanupStack::PopAndDestroy( &view ); // closes view |
|
2453 User::LeaveIfError( iMulticastDb.Commit() ); |
|
2454 } |
|
2455 |
|
2456 // --------------------------------------------------------------------------- |
|
2457 // CIptvEpgDatabase::ClearProgramTableL() |
|
2458 // |
|
2459 // --------------------------------------------------------------------------- |
|
2460 void CIptvEpgDatabase::ClearProgramTableL( const TUint32 aServiceId ) |
|
2461 { |
|
2462 if ( iLocalState == EBackup ) |
|
2463 { |
|
2464 return; |
|
2465 } |
|
2466 |
|
2467 TBuf<KCustomSqlLength> sqlStatement; |
|
2468 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
2469 sqlStatement.Append( KIptvEpgProgramTable ); |
|
2470 sqlStatement.Append( _L(" WHERE ") ); |
|
2471 sqlStatement.Append( KIptvEpgProgramServProviderIdCol ); |
|
2472 sqlStatement.Append( _L(" = " ) ); |
|
2473 sqlStatement.AppendNum( aServiceId ); |
|
2474 |
|
2475 |
|
2476 RDbView view; |
|
2477 CleanupClosePushL( view ); |
|
2478 User::LeaveIfError( iMulticastDb.Begin() ); |
|
2479 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
2480 TDbQuery( sqlStatement ) ) ); |
|
2481 User::LeaveIfError( view.EvaluateAll() ); |
|
2482 while ( view.NextL() ) |
|
2483 { |
|
2484 view.DeleteL(); |
|
2485 } |
|
2486 CleanupStack::PopAndDestroy( &view ); // closes view |
|
2487 User::LeaveIfError( iMulticastDb.Commit() ); |
|
2488 } |
|
2489 |
|
2490 // --------------------------------------------------------------------------- |
|
2491 // CIptvEpgDatabase::ClearScheduleTableL() |
|
2492 // |
|
2493 // --------------------------------------------------------------------------- |
|
2494 void CIptvEpgDatabase::ClearScheduleTableL( const TUint32 aServiceId ) |
|
2495 { |
|
2496 |
|
2497 if ( iLocalState == EBackup ) |
|
2498 { |
|
2499 return; |
|
2500 } |
|
2501 |
|
2502 TBuf<KCustomSqlLength> sqlStatement; |
|
2503 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
2504 sqlStatement.Append( KIptvEpgScheduleTable ); |
|
2505 sqlStatement.Append( _L(" WHERE ") ); |
|
2506 sqlStatement.Append( KIptvEpgScheduleServiceProviderIdCol ); |
|
2507 sqlStatement.Append( _L(" = " ) ); |
|
2508 sqlStatement.AppendNum( aServiceId ); |
|
2509 |
|
2510 |
|
2511 RDbView view; |
|
2512 CleanupClosePushL( view ); |
|
2513 User::LeaveIfError( iMulticastDb.Begin() ); |
|
2514 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
2515 TDbQuery( sqlStatement ) ) ); |
|
2516 User::LeaveIfError( view.EvaluateAll() ); |
|
2517 while ( view.NextL() ) |
|
2518 { |
|
2519 view.DeleteL(); |
|
2520 } |
|
2521 CleanupStack::PopAndDestroy( &view ); // closes view |
|
2522 User::LeaveIfError( iMulticastDb.Commit() ); |
|
2523 } |
|
2524 |
|
2525 // --------------------------------------------------------------------------- |
|
2526 // CIptvEpgDatabase::ClearLatestEpgTableL() |
|
2527 // |
|
2528 // --------------------------------------------------------------------------- |
|
2529 void CIptvEpgDatabase::ClearLatestEpgTableL( const TUint32 aServiceId ) |
|
2530 { |
|
2531 if ( iLocalState == EBackup ) |
|
2532 { |
|
2533 return; |
|
2534 } |
|
2535 |
|
2536 TBuf<KCustomSqlLength> sqlStatement; |
|
2537 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
2538 sqlStatement.Append( KIptvEpgLatestEpgAvailableTable ); |
|
2539 sqlStatement.Append( _L(" WHERE ") ); |
|
2540 sqlStatement.Append( KIptvEpgLatestEpgAvailableServiceProviderIdCol ); |
|
2541 sqlStatement.Append( _L(" = " ) ); |
|
2542 sqlStatement.AppendNum( aServiceId ); |
|
2543 |
|
2544 RDbView view; |
|
2545 CleanupClosePushL( view ); |
|
2546 User::LeaveIfError( iMulticastDb.Begin() ); |
|
2547 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
2548 TDbQuery( sqlStatement ) ) ); |
|
2549 User::LeaveIfError( view.EvaluateAll() ); |
|
2550 while ( view.NextL() ) |
|
2551 { |
|
2552 view.DeleteL(); |
|
2553 } |
|
2554 CleanupStack::PopAndDestroy( &view ); // closes view |
|
2555 User::LeaveIfError( iMulticastDb.Commit() ); |
|
2556 } |
|
2557 |
|
2558 // --------------------------------------------------------------------------- |
|
2559 // CIptvEpgDatabase::ClearLastModifiedTableL() |
|
2560 // |
|
2561 // --------------------------------------------------------------------------- |
|
2562 void CIptvEpgDatabase::ClearLastModifiedTableL( const TUint32 aServiceId ) |
|
2563 { |
|
2564 if ( iLocalState == EBackup ) |
|
2565 { |
|
2566 return; |
|
2567 } |
|
2568 TBuf<KCustomSqlLength> sqlStatement; |
|
2569 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
2570 sqlStatement.Append( KIptvEpgLastModifiedTable ); |
|
2571 sqlStatement.Append( _L(" WHERE ") ); |
|
2572 sqlStatement.Append( KIptvEpgLastModifiedTableServiceIdCol ); |
|
2573 sqlStatement.Append( _L(" = ") ); |
|
2574 sqlStatement.AppendNum( aServiceId ); |
|
2575 |
|
2576 RDbView view; |
|
2577 CleanupClosePushL( view ); |
|
2578 User::LeaveIfError( iMulticastDb.Begin() ); |
|
2579 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
2580 TDbQuery( sqlStatement ) ) ); |
|
2581 User::LeaveIfError( view.EvaluateAll() ); |
|
2582 while ( view.NextL() ) |
|
2583 { |
|
2584 view.DeleteL(); |
|
2585 } |
|
2586 CleanupStack::PopAndDestroy( &view ); |
|
2587 User::LeaveIfError( iMulticastDb.Commit() ); |
|
2588 } |
|
2589 |
|
2590 |
|
2591 // --------------------------------------------------------------------------- |
|
2592 // CIptvEpgDatabase::MakeSqlStrings() |
|
2593 // |
|
2594 // --------------------------------------------------------------------------- |
|
2595 void CIptvEpgDatabase::MakeSqlStrings() |
|
2596 { |
|
2597 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::MakeSqlStrings()")); |
|
2598 // Channel |
|
2599 iSqlChannel.Zero(); |
|
2600 iSqlChannel.Append( _L("SELECT * FROM " ) ); |
|
2601 iSqlChannel.Append( KIptvEpgChannelTable ); |
|
2602 |
|
2603 // Program |
|
2604 iSqlProgram.Zero(); |
|
2605 iSqlProgram.Append( _L("SELECT * FROM ") ); |
|
2606 iSqlProgram.Append( KIptvEpgProgramTable ); |
|
2607 } |
|
2608 |
|
2609 // --------------------------------------------------------------------------- |
|
2610 // CIptvEpgDatabase::GetChannelL() |
|
2611 // |
|
2612 // --------------------------------------------------------------------------- |
|
2613 EXPORT_C CIptvEpgChannel* CIptvEpgDatabase::GetChannelL( TInt aService, |
|
2614 TInt64 aChannel ) |
|
2615 { |
|
2616 if ( iLocalState == EBackup ) |
|
2617 { |
|
2618 return NULL; |
|
2619 } |
|
2620 |
|
2621 CIptvEpgChannel* retval = NULL; |
|
2622 TBuf<KCustomSqlLength> sqlStatement; |
|
2623 sqlStatement.Append( _L("SELECT * FROM ")); |
|
2624 sqlStatement.Append( KIptvEpgChannelTable ); |
|
2625 sqlStatement.Append( _L(" WHERE ") ); |
|
2626 sqlStatement.Append( KIptvEpgChannelServProviderIdCol ); |
|
2627 sqlStatement.Append( _L(" = ") ); |
|
2628 sqlStatement.AppendNum( aService ); |
|
2629 sqlStatement.Append( _L(" AND ") ); |
|
2630 sqlStatement.Append( KIptvEpgChannelIdCol ); |
|
2631 sqlStatement.Append( _L(" = ") ); |
|
2632 sqlStatement.AppendNum( aChannel ); |
|
2633 |
|
2634 RPointerArray<CIptvEpgChannel> resultArray; |
|
2635 CleanupClosePushL( resultArray ); |
|
2636 TRAPD( err, DoGetChannelsL( sqlStatement, &resultArray ) ); |
|
2637 if ( err != KErrNone ) |
|
2638 { |
|
2639 LIVE_TV_TRACE2(_L("DoGetChannelsL FAILED: %d"), err); |
|
2640 resultArray.ResetAndDestroy(); |
|
2641 User::Leave( err ); |
|
2642 } |
|
2643 const TInt c = resultArray.Count(); |
|
2644 if ( c > 0 ) |
|
2645 { |
|
2646 retval = resultArray[0]; // note, index 0 is the retval, not deleted |
|
2647 for ( TInt i( 1 ); i < c; i++ ) // note, starts from 1, not 0. |
|
2648 { |
|
2649 delete resultArray[i]; |
|
2650 resultArray[i] = NULL; |
|
2651 } |
|
2652 } |
|
2653 CleanupStack::PopAndDestroy( &resultArray ); // closes array |
|
2654 return retval; |
|
2655 } |
|
2656 |
|
2657 // --------------------------------------------------------------------------- |
|
2658 // CIptvEpgDatabase::UpdateChannelIconPathL() |
|
2659 // |
|
2660 // --------------------------------------------------------------------------- |
|
2661 EXPORT_C void CIptvEpgDatabase::UpdateChannelIconPathL( const TUint32 aServiceId, |
|
2662 const TInt64 aChannelId, |
|
2663 const TDesC& aIconPath ) |
|
2664 { |
|
2665 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::UpdateChannelIconPathL() in") ); |
|
2666 |
|
2667 if ( iLocalState == EBackup ) |
|
2668 { |
|
2669 return; |
|
2670 } |
|
2671 |
|
2672 TBuf<KCustomSqlLength> sqlStatement; |
|
2673 sqlStatement.Append( _L("SELECT ") ); |
|
2674 sqlStatement.Append( KIptvEpgChannelLogoPathCol ); |
|
2675 sqlStatement.Append( _L(" FROM ") ); |
|
2676 sqlStatement.Append( KIptvEpgChannelTable ); |
|
2677 sqlStatement.Append( _L(" WHERE ") ); |
|
2678 sqlStatement.Append( KIptvEpgChannelIdCol ); |
|
2679 sqlStatement.Append( _L(" = ") ); |
|
2680 sqlStatement.AppendNum( aChannelId ); |
|
2681 sqlStatement.Append( _L(" AND ") ); |
|
2682 sqlStatement.Append( KIptvEpgChannelServProviderIdCol ); |
|
2683 sqlStatement.Append( _L(" = ") ); |
|
2684 sqlStatement.AppendNum( aServiceId ); |
|
2685 |
|
2686 RDbView view; |
|
2687 CleanupClosePushL( view ); |
|
2688 User::LeaveIfError( iMulticastDb.Begin() ); |
|
2689 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
2690 TDbQuery( sqlStatement ) ) ); |
|
2691 User::LeaveIfError( view.EvaluateAll() ); |
|
2692 |
|
2693 // Ownership of this pointer is now here. It needs to be deleted also |
|
2694 CDbColSet* channelColSet = view.ColSetL(); |
|
2695 CleanupStack::PushL( channelColSet ); |
|
2696 |
|
2697 // sql statement found a row from table |
|
2698 if ( view.FirstL() ) |
|
2699 { |
|
2700 view.UpdateL(); |
|
2701 view.SetColL( channelColSet->ColNo( KIptvEpgChannelLogoPathCol ), |
|
2702 aIconPath ); |
|
2703 view.PutL(); |
|
2704 } |
|
2705 CleanupStack::PopAndDestroy( channelColSet ); |
|
2706 CleanupStack::PopAndDestroy( &view ); // closes view |
|
2707 User::LeaveIfError( iMulticastDb.Commit() ); |
|
2708 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::UpdateChannelIconPathL() out") ); |
|
2709 } |
|
2710 |
|
2711 // METHODS FOR LATEST EPG AVAILABLE TABLE |
|
2712 |
|
2713 // --------------------------------------------------------------------------- |
|
2714 // CIptvEpgDatabase::CreateLatestEpgAvailableTableL() |
|
2715 // |
|
2716 // Creates database table for holding the start time of the latest epg data |
|
2717 // available for each service provider |
|
2718 // --------------------------------------------------------------------------- |
|
2719 void CIptvEpgDatabase::CreateLatestEpgAvailableTableL( |
|
2720 RDbNamedDatabase& aDatabase ) const |
|
2721 { |
|
2722 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::CreateLatestEpgAvailableTableL")); |
|
2723 TDbCol keyCol( KIptvEpgLatestEpgAvailableTableKeyCol, EDbColUint32 ); |
|
2724 keyCol.iAttributes = TDbCol::EAutoIncrement; |
|
2725 |
|
2726 TDbCol serviceIdCol( KIptvEpgLatestEpgAvailableServiceProviderIdCol, EDbColUint32 ); |
|
2727 |
|
2728 TDbCol startTimeCol( KIptvEpgLatestEpgAvailableStartTimeCol, EDbColDateTime ); |
|
2729 |
|
2730 CDbColSet* latestEpgAvailableColSet = CDbColSet::NewLC(); |
|
2731 latestEpgAvailableColSet->AddL( keyCol ); |
|
2732 latestEpgAvailableColSet->AddL( serviceIdCol ); |
|
2733 latestEpgAvailableColSet->AddL( startTimeCol ); |
|
2734 |
|
2735 |
|
2736 User::LeaveIfError( aDatabase.CreateTable( KIptvEpgLatestEpgAvailableTable, |
|
2737 *latestEpgAvailableColSet ) ); |
|
2738 CleanupStack::PopAndDestroy( latestEpgAvailableColSet ); |
|
2739 } |
|
2740 |
|
2741 // --------------------------------------------------------------------------- |
|
2742 // CIptvEpgDatabase::AddLatestEpgAvailableL |
|
2743 // |
|
2744 // --------------------------------------------------------------------------- |
|
2745 void CIptvEpgDatabase::AddLatestEpgAvailableL |
|
2746 ( CIptvEpgLatestEpgAvailable& aLatestEpgAvailable ) |
|
2747 { |
|
2748 if ( iLocalState == EBackup ) |
|
2749 { |
|
2750 return; |
|
2751 } |
|
2752 |
|
2753 TBuf<50> sqlStatement; |
|
2754 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
2755 sqlStatement.Append( KIptvEpgLatestEpgAvailableTable ); |
|
2756 RDbView view; |
|
2757 CleanupClosePushL( view ); |
|
2758 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
2759 TDbQuery( sqlStatement ), |
|
2760 TDbWindow::EUnlimited, |
|
2761 RDbView::EInsertOnly ) ); |
|
2762 view.InsertL(); |
|
2763 |
|
2764 CDbColSet* latestEpgAvailableColSet = view.ColSetL(); |
|
2765 // Ownership of CDbColSet object is now here! |
|
2766 CleanupStack::PushL( latestEpgAvailableColSet ); |
|
2767 view.SetColL( latestEpgAvailableColSet->ColNo( KIptvEpgLatestEpgAvailableServiceProviderIdCol ), |
|
2768 aLatestEpgAvailable.iServiceId ); |
|
2769 |
|
2770 view.SetColL( latestEpgAvailableColSet->ColNo( KIptvEpgLatestEpgAvailableStartTimeCol ), |
|
2771 aLatestEpgAvailable.iStartTime ); |
|
2772 |
|
2773 CleanupStack::PopAndDestroy( latestEpgAvailableColSet ); |
|
2774 view.PutL(); |
|
2775 |
|
2776 CleanupStack::PopAndDestroy( &view ); // closes view |
|
2777 } |
|
2778 |
|
2779 // --------------------------------------------------------------------------- |
|
2780 // CIptvEpgDatabase::InsertOrUpdateLatestEpgAvailableL() |
|
2781 // |
|
2782 // --------------------------------------------------------------------------- |
|
2783 EXPORT_C void CIptvEpgDatabase::InsertOrUpdateLatestEpgAvailableL |
|
2784 ( CIptvEpgLatestEpgAvailable& aLatestEpgAvailable ) |
|
2785 { |
|
2786 if ( iLocalState == EBackup ) |
|
2787 { |
|
2788 return; |
|
2789 } |
|
2790 |
|
2791 TBuf<KCustomSqlLength> sqlStatement; |
|
2792 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
2793 sqlStatement.Append( KIptvEpgLatestEpgAvailableTable ); |
|
2794 sqlStatement.Append( _L(" WHERE ") ); |
|
2795 sqlStatement.Append( KIptvEpgLatestEpgAvailableServiceProviderIdCol ); |
|
2796 sqlStatement.Append( _L(" = ")); |
|
2797 sqlStatement.AppendNum( aLatestEpgAvailable.GetServiceId() ); |
|
2798 |
|
2799 RDbView view; |
|
2800 CleanupClosePushL( view ); |
|
2801 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
2802 TDbQuery( sqlStatement ) ) ); |
|
2803 User::LeaveIfError( view.EvaluateAll() ); |
|
2804 |
|
2805 // Ownership of this pointer is now here. It needs to be deleted also |
|
2806 CDbColSet* latestEpgAvailableColSet = view.ColSetL(); |
|
2807 CleanupStack::PushL( latestEpgAvailableColSet ); |
|
2808 |
|
2809 // sql statement found a row from table |
|
2810 if ( view.FirstL() ) // Update |
|
2811 { |
|
2812 view.UpdateL(); |
|
2813 |
|
2814 view.SetColL( latestEpgAvailableColSet->ColNo |
|
2815 ( KIptvEpgLatestEpgAvailableServiceProviderIdCol ), |
|
2816 aLatestEpgAvailable.GetServiceId() ); |
|
2817 |
|
2818 view.SetColL( latestEpgAvailableColSet->ColNo( KIptvEpgLatestEpgAvailableStartTimeCol ), |
|
2819 aLatestEpgAvailable.GetStartTime() ); |
|
2820 |
|
2821 view.PutL(); |
|
2822 } |
|
2823 |
|
2824 else |
|
2825 { |
|
2826 AddLatestEpgAvailableL( aLatestEpgAvailable ); |
|
2827 } |
|
2828 |
|
2829 CleanupStack::PopAndDestroy( latestEpgAvailableColSet ); |
|
2830 CleanupStack::PopAndDestroy( &view ); // closes view |
|
2831 } |
|
2832 |
|
2833 // --------------------------------------------------------------------------- |
|
2834 // CIptvEpgDatabase::GetLatestScheduleTimeL |
|
2835 // |
|
2836 // --------------------------------------------------------------------------- |
|
2837 EXPORT_C TTime CIptvEpgDatabase::GetLatestScheduleTimeL( const TUint32 aServiceId ) |
|
2838 { |
|
2839 LIVE_TV_TRACE1( _L("CIptvEpgDatabase::GetLatestScheduleTimeL IN") ); |
|
2840 if ( iLocalState == EBackup ) |
|
2841 { |
|
2842 return TTime( 0 ); |
|
2843 } |
|
2844 |
|
2845 TBuf<KCustomSqlLength> sqlStatement; |
|
2846 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
2847 sqlStatement.Append( KIptvEpgLatestEpgAvailableTable ); |
|
2848 sqlStatement.Append( _L(" WHERE ") ); |
|
2849 sqlStatement.Append( KIptvEpgLatestEpgAvailableServiceProviderIdCol ); |
|
2850 sqlStatement.Append( _L(" = ")); |
|
2851 sqlStatement.AppendNum( aServiceId ); |
|
2852 |
|
2853 RDbView view; |
|
2854 CleanupClosePushL( view ); |
|
2855 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
2856 TDbQuery( sqlStatement ) ) ); |
|
2857 User::LeaveIfError( view.EvaluateAll() ); |
|
2858 |
|
2859 // Ownership of this pointer is now here. It needs to be deleted also |
|
2860 CDbColSet* latestEpgAvailableColSet = view.ColSetL(); |
|
2861 CleanupStack::PushL( latestEpgAvailableColSet ); |
|
2862 TInt startTimeColNo = latestEpgAvailableColSet->ColNo( KIptvEpgLatestEpgAvailableStartTimeCol ); |
|
2863 |
|
2864 TTime latestTime; |
|
2865 // sql statement found a row from table,fetch that |
|
2866 if ( view.FirstL() ) |
|
2867 { |
|
2868 view.GetL(); |
|
2869 |
|
2870 latestTime = view.ColTime( startTimeColNo ); |
|
2871 } |
|
2872 else |
|
2873 { |
|
2874 User::Leave( KErrNotFound ); |
|
2875 } |
|
2876 |
|
2877 CleanupStack::PopAndDestroy( latestEpgAvailableColSet ); |
|
2878 CleanupStack::PopAndDestroy( &view ); // closes view |
|
2879 return latestTime; |
|
2880 } |
|
2881 |
|
2882 // --------------------------------------------------------------------------- |
|
2883 // CIptvEpgDatabase::RemoveScheduledDataFromChannelL |
|
2884 // |
|
2885 // --------------------------------------------------------------------------- |
|
2886 void CIptvEpgDatabase::RemoveScheduledDataFromChannelL( const CIptvEpgChannel& aChannel ) |
|
2887 { |
|
2888 LIVE_TV_TRACE1( _L("CIptvEpgDatabase::RemoveScheduledDataFromChannelL IN") ); |
|
2889 if ( iLocalState == EBackup ) |
|
2890 { |
|
2891 return; |
|
2892 } |
|
2893 |
|
2894 TBuf<KCustomSqlLength> sqlStatement; |
|
2895 _LIT(KDeleteStatementTemplate, "SELECT %S FROM %S WHERE %S = %u AND %S = %Li"); |
|
2896 sqlStatement.Format( KDeleteStatementTemplate, |
|
2897 &KIptvEpgScheduleServiceProviderIdCol, |
|
2898 &KIptvEpgScheduleTable, |
|
2899 &KIptvEpgScheduleServiceProviderIdCol, |
|
2900 aChannel.ServiceId(), |
|
2901 &KIptvEpgScheduleChannelIdCol, |
|
2902 aChannel.ChannelId() ); |
|
2903 RDbView view; |
|
2904 CleanupClosePushL( view ); |
|
2905 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
2906 TDbQuery( sqlStatement ) ) ); |
|
2907 User::LeaveIfError( view.EvaluateAll() ); |
|
2908 User::LeaveIfError( iMulticastDb.Begin() ); |
|
2909 view.FirstL(); |
|
2910 #if defined(LIVE_TV_FILE_TRACE) || defined(LIVE_TV_RDEBUG_TRACE) |
|
2911 TInt deleteCount = 0; |
|
2912 #endif |
|
2913 while ( view.AtRow() ) |
|
2914 { |
|
2915 view.DeleteL(); |
|
2916 view.NextL(); |
|
2917 #if defined(LIVE_TV_FILE_TRACE) || defined(LIVE_TV_RDEBUG_TRACE) |
|
2918 deleteCount++; |
|
2919 #endif |
|
2920 } |
|
2921 #if defined(LIVE_TV_FILE_TRACE) || defined(LIVE_TV_RDEBUG_TRACE) |
|
2922 LIVE_TV_TRACE2(_L("RemoveScheduledDataFromChannelL removed %d schedules"), deleteCount ); |
|
2923 #endif |
|
2924 CleanupStack::PopAndDestroy( &view ); // closes the view |
|
2925 // iMulticastDb.Compact(); |
|
2926 User::LeaveIfError( iMulticastDb.Commit() ); |
|
2927 } |
|
2928 |
|
2929 // --------------------------------------------------------------------------- |
|
2930 // CIptvEpgDatabase::GetSchedulesByProgIdL() |
|
2931 // |
|
2932 // --------------------------------------------------------------------------- |
|
2933 // |
|
2934 EXPORT_C void CIptvEpgDatabase::GetSchedulesByProgIdL( |
|
2935 const TUint32 aServiceProviderId, |
|
2936 const TInt64 aChannelKey, |
|
2937 const TInt64 aProgId, |
|
2938 RPointerArray<CIptvEpgSchedule>* aResultArray ) |
|
2939 { |
|
2940 LIVE_TV_TRACE3(_L("CIptvEpgDatabase::GetSchedulesByProgIdL() ser %d program id %Li"), (int)aServiceProviderId, aProgId ); |
|
2941 |
|
2942 if ( iLocalState == EBackup ) |
|
2943 { |
|
2944 return; |
|
2945 } |
|
2946 |
|
2947 if ( !aResultArray ) |
|
2948 { |
|
2949 User::Leave( KErrArgument ); |
|
2950 } |
|
2951 RPointerArray<CIptvEpgProgram> programs; |
|
2952 CleanupClosePushL( programs ); |
|
2953 TRAPD( err, GetProgramsByChannelIdL( aServiceProviderId, aChannelKey, |
|
2954 &programs ) ); |
|
2955 if ( err != KErrNone ) |
|
2956 { |
|
2957 LIVE_TV_TRACE2(_L("GetProgramsByChannelIdL FAILED: %d"), err) ; |
|
2958 programs.ResetAndDestroy(); |
|
2959 User::Leave( err ); |
|
2960 } |
|
2961 TLinearOrder<CIptvEpgProgram> o( CIptvEpgProgram::LinearOrderOfProgramsById ); |
|
2962 programs.Sort( o ); |
|
2963 |
|
2964 TBuf<KCustomSqlLength> sqlStatement; |
|
2965 sqlStatement.Append( _L("SELECT * FROM ") ); |
|
2966 sqlStatement.Append( KIptvEpgScheduleTable ); |
|
2967 sqlStatement.Append( _L(" WHERE ") ); |
|
2968 sqlStatement.Append( KIptvEpgScheduleServiceProviderIdCol ); |
|
2969 sqlStatement.Append( _L(" = ") ); |
|
2970 sqlStatement.AppendNum( aServiceProviderId ); |
|
2971 sqlStatement.Append( _L(" AND ") ); |
|
2972 sqlStatement.Append( KIptvEpgScheduleChannelIdCol ); |
|
2973 sqlStatement.Append( _L(" = ") ); |
|
2974 sqlStatement.AppendNum( aChannelKey ); |
|
2975 sqlStatement.Append( _L(" AND ") ); |
|
2976 sqlStatement.Append( KIptvEpgScheduleProgramIdCol ); |
|
2977 sqlStatement.Append( _L(" = ") ); |
|
2978 sqlStatement.AppendNum( aProgId ); |
|
2979 |
|
2980 LIVE_TV_TRACE2(_L("query >%S<"), &sqlStatement); |
|
2981 |
|
2982 FetchSchedulesFromTableL( sqlStatement, aResultArray ); |
|
2983 |
|
2984 const TInt c = aResultArray->Count(); |
|
2985 |
|
2986 CIptvEpgProgram* programToUseForFinding = CIptvEpgProgram::NewL(); |
|
2987 CleanupStack::PushL( programToUseForFinding ); |
|
2988 |
|
2989 TInt indexFound( KErrNotFound ); |
|
2990 TInt64 programId( 0 ); |
|
2991 for ( TInt i = 0; i < c; i ++ ) |
|
2992 { |
|
2993 programId = ((*aResultArray)[i])->GetProgramId(); |
|
2994 programToUseForFinding->SetProgramId( programId ); |
|
2995 indexFound = programs.FindInOrder( programToUseForFinding, o ); |
|
2996 if ( indexFound != KErrNotFound ) |
|
2997 { |
|
2998 ((*aResultArray)[i])->iProgram = programs[indexFound]; |
|
2999 programs.Remove( indexFound ); |
|
3000 } |
|
3001 } |
|
3002 programs.ResetAndDestroy(); |
|
3003 CleanupStack::PopAndDestroy( programToUseForFinding ); |
|
3004 CleanupStack::PopAndDestroy( &programs ); |
|
3005 LIVE_TV_TRACE2(_L("GetSchedulesByProgIdL getting %d schedules"),c); |
|
3006 } |
|
3007 |
|
3008 // METHODS FOR LAST MODIFIED TABLE |
|
3009 // --------------------------------------------------------------------------- |
|
3010 // CIptvEpgDatabase::GetLastModifiedDataL |
|
3011 // |
|
3012 // --------------------------------------------------------------------------- |
|
3013 EXPORT_C void CIptvEpgDatabase::GetLastModifiedDataL( const TUint32 aServiceId, |
|
3014 TDes& aETag, |
|
3015 TDes& aLastModifiedDateTime ) |
|
3016 { |
|
3017 LIVE_TV_TRACE1( _L("CIptvEpgDatabase::GetLastModifiedDataL IN") ); |
|
3018 TBuf<KCustomSqlLength> sqlStatement; |
|
3019 sqlStatement.Append( _L("SELECT ") ); |
|
3020 sqlStatement.Append( KIptvEpgLastModifiedTableETagCol ); |
|
3021 sqlStatement.Append( _L(" , ") ); |
|
3022 sqlStatement.Append( KIptvEpgLastModifiedTableTimeCol ); |
|
3023 sqlStatement.Append( _L(" FROM ") ); |
|
3024 sqlStatement.Append( KIptvEpgLastModifiedTable ); |
|
3025 sqlStatement.Append( _L(" WHERE ") ); |
|
3026 sqlStatement.Append( KIptvEpgLastModifiedTableServiceIdCol ); |
|
3027 sqlStatement.Append( _L(" = " ) ); |
|
3028 sqlStatement.AppendNum( aServiceId ); |
|
3029 |
|
3030 LIVE_TV_TRACE2( _L("SQL-statement = %S"), &sqlStatement ); |
|
3031 |
|
3032 RDbView view; |
|
3033 CleanupClosePushL( view ); |
|
3034 TInt err( KErrNone ); |
|
3035 err = view.Prepare( iMulticastDb, TDbQuery( sqlStatement ) ); |
|
3036 LIVE_TV_TRACE2( _L("view.Prepare returned %d"), err ); |
|
3037 if ( err != KErrNone ) |
|
3038 { |
|
3039 User::Leave( err ); |
|
3040 } |
|
3041 err = view.EvaluateAll(); |
|
3042 LIVE_TV_TRACE2( _L("view.EvaluateAll() returned %d"), err ); |
|
3043 if ( err != KErrNone ) |
|
3044 { |
|
3045 User::Leave( err ); |
|
3046 } |
|
3047 |
|
3048 |
|
3049 // Ownership of this pointer is now here. It needs to be deleted also |
|
3050 CDbColSet* lastModifiedColSet = view.ColSetL(); |
|
3051 CleanupStack::PushL( lastModifiedColSet ); |
|
3052 TInt lastModifiedDateTimeColNo = lastModifiedColSet->ColNo( KIptvEpgLastModifiedTableTimeCol ); |
|
3053 TInt eTagColNo = lastModifiedColSet->ColNo( KIptvEpgLastModifiedTableETagCol ); |
|
3054 |
|
3055 // sql statement found a row from table,fetch that |
|
3056 if ( view.FirstL() ) |
|
3057 { |
|
3058 view.GetL(); |
|
3059 |
|
3060 aLastModifiedDateTime = view.ColDes( lastModifiedDateTimeColNo ); |
|
3061 aETag = view.ColDes( eTagColNo ); |
|
3062 } |
|
3063 |
|
3064 CleanupStack::PopAndDestroy( lastModifiedColSet ); |
|
3065 CleanupStack::PopAndDestroy( &view ); // closes view |
|
3066 LIVE_TV_TRACE3( _L("on return aETag = %S and aLastModifiedDateTime = %S"), &aETag, &aLastModifiedDateTime ); |
|
3067 LIVE_TV_TRACE1( _L("CIptvEpgDatabase::GetLastModifiedDataL OUT") ); |
|
3068 } |
|
3069 |
|
3070 // --------------------------------------------------------------------------- |
|
3071 // CIptvEpgDatabase::SetLastModifiedDataL |
|
3072 // |
|
3073 // --------------------------------------------------------------------------- |
|
3074 EXPORT_C void CIptvEpgDatabase::SetLastModifiedDataL( const TUint32 aServiceId, |
|
3075 const TDesC& aETag, |
|
3076 const TDesC& aLastModifiedDateTime ) |
|
3077 { |
|
3078 LIVE_TV_TRACE1( _L("CIptvEpgDatabase::SetLastModifiedDataL IN") ); |
|
3079 if ( iLocalState == EBackup ) |
|
3080 { |
|
3081 return; |
|
3082 } |
|
3083 |
|
3084 LIVE_TV_TRACE3( _L("aETag = %S, aLastModifiedDateTime = %S"), &aETag, &aLastModifiedDateTime ); |
|
3085 |
|
3086 // We can safely clear this because there is (or at least should) only one row |
|
3087 // in this table. This is because there is individual database for each and |
|
3088 // every service, one service has only one service address. |
|
3089 ClearLastModifiedTableL( aServiceId ); |
|
3090 |
|
3091 TBuf<KCustomSqlLength> sqlStatement; |
|
3092 sqlStatement.Append( _L("SELECT ") ); |
|
3093 sqlStatement.Append( KIptvEpgLastModifiedTableServiceIdCol ); |
|
3094 sqlStatement.Append( _L(" , ") ); |
|
3095 sqlStatement.Append( KIptvEpgLastModifiedTableETagCol ); |
|
3096 sqlStatement.Append( _L(" , ") ); |
|
3097 sqlStatement.Append( KIptvEpgLastModifiedTableTimeCol ); |
|
3098 sqlStatement.Append( _L(" FROM ") ); |
|
3099 sqlStatement.Append( KIptvEpgLastModifiedTable ); |
|
3100 RDbView view; |
|
3101 CleanupClosePushL( view ); |
|
3102 User::LeaveIfError( view.Prepare( iMulticastDb, |
|
3103 TDbQuery( sqlStatement ), |
|
3104 TDbWindow::EUnlimited, |
|
3105 RDbView::EInsertOnly ) ); |
|
3106 view.InsertL(); |
|
3107 |
|
3108 // Ownership of CDbColSet object is now here! |
|
3109 CDbColSet* lastModifiedColSet = view.ColSetL(); |
|
3110 CleanupStack::PushL( lastModifiedColSet ); |
|
3111 |
|
3112 // Get the column numbers we need here |
|
3113 TInt servIdColNo = lastModifiedColSet->ColNo( KIptvEpgLastModifiedTableServiceIdCol ); |
|
3114 TInt eTagColNo = lastModifiedColSet->ColNo( KIptvEpgLastModifiedTableETagCol ); |
|
3115 TInt lastModifiedDateTimeCol = lastModifiedColSet->ColNo( KIptvEpgLastModifiedTableTimeCol ); |
|
3116 |
|
3117 // Set values to the columns |
|
3118 view.SetColL( servIdColNo, aServiceId ); |
|
3119 view.SetColL( eTagColNo, aETag ); |
|
3120 view.SetColL( lastModifiedDateTimeCol, aLastModifiedDateTime ); |
|
3121 |
|
3122 // Delete allocated object |
|
3123 CleanupStack::PopAndDestroy( lastModifiedColSet ); |
|
3124 |
|
3125 // Commit changes to the database |
|
3126 view.PutL(); |
|
3127 |
|
3128 CleanupStack::PopAndDestroy( &view ); |
|
3129 LIVE_TV_TRACE1( _L("CIptvEpgDatabase::SetLastModifiedDataL OUT") ); |
|
3130 } |
|
3131 |
|
3132 // --------------------------------------------------------------------------- |
|
3133 // CIptvEpgDatabase::ClearServiceEPGDataL |
|
3134 // |
|
3135 // --------------------------------------------------------------------------- |
|
3136 EXPORT_C void CIptvEpgDatabase::ClearServiceEPGDataL( const TUint32 aServiceId ) |
|
3137 { |
|
3138 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::ClearServiceEPGDataL in")); |
|
3139 |
|
3140 if ( iLocalState == EBackup ) |
|
3141 { |
|
3142 return; |
|
3143 } |
|
3144 |
|
3145 ClearChannelTableL( aServiceId ); |
|
3146 |
|
3147 ClearProgramTableL( aServiceId ); |
|
3148 |
|
3149 ClearScheduleTableL( aServiceId ); |
|
3150 |
|
3151 ClearLatestEpgTableL( aServiceId ); |
|
3152 |
|
3153 ClearLastModifiedTableL( aServiceId ); |
|
3154 |
|
3155 User::LeaveIfError( iMulticastDb.Compact() ); |
|
3156 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::ClearServiceEPGDataL out")); |
|
3157 } |
|
3158 |
|
3159 // --------------------------------------------------------------------------- |
|
3160 // CIptvEpgDatabase::ChangeFileLockL |
|
3161 // |
|
3162 // --------------------------------------------------------------------------- |
|
3163 void CIptvEpgDatabase::ChangeFileLockL( const TDesC& aFileName, TFileLockFlags aFlags ) |
|
3164 { |
|
3165 LIVE_TV_TRACE1( _L("CIptvEpgDatabase::ChangeFileLockL IN") ); |
|
3166 if ( aFileName.Compare( iDbFile ) == 0 ) |
|
3167 { |
|
3168 switch( aFlags ) |
|
3169 { |
|
3170 case MBackupObserver::ETakeLock: |
|
3171 { |
|
3172 LIVE_TV_TRACE1( _L("aFlags = MBackupObserver::ETakeLock") ); |
|
3173 CreateDbL(); |
|
3174 CreateMulticastDbSessionL(); |
|
3175 iLocalState = EReady; |
|
3176 LIVE_TV_TRACE1( _L("Setting iLocalState to EReady") ); |
|
3177 if ( iActiveWait->IsStarted() ) |
|
3178 { |
|
3179 LIVE_TV_TRACE1( _L("Stopping iActiveWait") ); |
|
3180 iActiveWait->AsyncStop(); |
|
3181 } |
|
3182 } |
|
3183 break; |
|
3184 case MBackupObserver::EReleaseLockNoAccess: |
|
3185 { |
|
3186 LIVE_TV_TRACE1( _L("aFlags = MBackupObserver::EReleaseLockNoAccess") ); |
|
3187 CloseMulticastDbSession(); |
|
3188 LIVE_TV_TRACE1( _L("Setting iLocalState to EBackup") ); |
|
3189 iLocalState = EBackup; |
|
3190 } |
|
3191 break; |
|
3192 default: |
|
3193 break; |
|
3194 } |
|
3195 } |
|
3196 LIVE_TV_TRACE1( _L("CIptvEpgDatabase::ChangeFileLockL OUT") ); |
|
3197 } |
|
3198 |
|
3199 // --------------------------------------------------------------------------- |
|
3200 // CIptvEpgDatabase::CheckBackupStatus |
|
3201 // |
|
3202 // --------------------------------------------------------------------------- |
|
3203 void CIptvEpgDatabase::CheckBackupStatus() |
|
3204 { |
|
3205 LIVE_TV_TRACE1( _L("CIptvEpgDatabase::CheckBackupStatus IN") ); |
|
3206 if ( iLocalState == EBackup ) |
|
3207 { |
|
3208 // Start waiting to see backup ending to continue. |
|
3209 if ( !iActiveWait->IsStarted() ) |
|
3210 { |
|
3211 LIVE_TV_TRACE1( _L("iLocalState == EBackup -> starting active wait") ); |
|
3212 iActiveWait->Start(); |
|
3213 } |
|
3214 else |
|
3215 { |
|
3216 LIVE_TV_TRACE1(_L("CIptvEpgDatabase::CheckBackupStatus: iActiveWait already started!")); |
|
3217 } |
|
3218 } |
|
3219 LIVE_TV_TRACE1( _L("CIptvEpgDatabase::CheckBackupStatus OUT") ); |
|
3220 } |
|
3221 |
|
3222 // End of File |