videofeeds/livetvutils/inc/CIptvEpgDatabase.h
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:    header file for CIptvEpgDatabase class*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 #ifndef __CIPTVEPGDATABASE_H__
       
    21 #define __CIPTVEPGDATABASE_H__
       
    22 
       
    23 //  INCLUDES
       
    24 #include <e32std.h>
       
    25 #include <badesca.h>    // CDesCArrayFlat (cannot be forward declarated)
       
    26 #include <d32dbms.h>    // RDbStoreDatabase
       
    27 #include <f32file.h>    // RFs
       
    28 #include <babackup.h>	// For MBackupObserver && CBaBackupSessionWrapper
       
    29 
       
    30 // CONSTANTS
       
    31 const TInt KCustomSqlLength = 256;
       
    32 const TInt KIptvEpgProgramMaxLength = 255;
       
    33 const TInt KIptvEpgChannelNameMaxLength = 255;
       
    34 const TInt KIptvEpgLogoPathMaxLength = 255;
       
    35 const TInt KIptvEpgUriMaxLength = 255;
       
    36 const TInt KIptvEpgDescrMaxLength = 255;
       
    37 // Channel table
       
    38 _LIT( KIptvEpgChannelTable, 				"Channel" );   
       
    39 _LIT( KIptvEpgChannelDbKeyCol, 				"Key" );
       
    40 
       
    41 _LIT( KIptvEpgChannelIdCol,					"ChannelId" );
       
    42 _LIT( KIptvEpgChannelServProviderIdCol,		"ServiceProviderId" );
       
    43 _LIT( KIptvEpgChannelNameCol,				"ChannelName" );
       
    44 _LIT( KIptvEpgChannelLogoPathCol,			"ChannelLogoPath" );
       
    45 _LIT( KIptvEpgChannelDescriptionCol,		"ChannelDescription" );
       
    46 _LIT( KIptvEpgChannelURICol,				"ChannelURI" );
       
    47 _LIT( KIptvEpgChannelSDPCol,				"ChannelSDP" );
       
    48 _LIT( KIptvEpgChannelOrderCol,				"ChannelOrder" );
       
    49 
       
    50 // Program table
       
    51 _LIT( KIptvEpgProgramTable, 				"ProgramEvent" );
       
    52 _LIT( KIptvEpgProgramDbKeyCol, 				"Key" );
       
    53 _LIT( KIptvEpgProgramIdCol,					"ProgramId" );
       
    54 _LIT( KIptvEpgProgramChannelId,				"ProgramChannelId" );
       
    55 _LIT( KIptvEpgProgramServProviderIdCol, 	"ServiceProviderId" );
       
    56 _LIT( KIptvEpgProgramStartTimeCol,			"ProgramStartTime" );
       
    57 _LIT( KIptvEpgProgramEndTimeCol,			"ProgramEndTime" );
       
    58 _LIT( KIptvEpgProgramURICol,				"ProgramURI" );
       
    59 _LIT( KIptvEpgProgramGenreCol,				"ProgramGenre" );
       
    60 _LIT( KIptvEpgProgramNameCol,				"ProgramName" );
       
    61 _LIT( KIptvEpgProgramDescriptionCol,		"ProgramDescription" );
       
    62 _LIT( KIptvEpgProgramLanguageCol,			"ProgramLanguage" );
       
    63 _LIT( KIptvEpgProgramParentalRatingCol,		"ProgramParentalRating" );
       
    64 
       
    65 // Schedule table
       
    66 _LIT( KIptvEpgScheduleTable,				"Schedule" );
       
    67 _LIT( KIptvEpgScheduleTableKeyCol,			"ScheduleKey" );
       
    68 _LIT( KIptvEpgScheduleServiceProviderIdCol,	"ScheduleServiceProviderId" );
       
    69 _LIT( KIptvEpgScheduleChannelIdCol,			"ScheduleChannelId" );
       
    70 _LIT( KIptvEpgScheduleProgramIdCol,			"ScheduleProgramId" );
       
    71 _LIT( KIptvEpgScheduleStartTimeCol,			"ScheduleStartTime" );
       
    72 _LIT( KIptvEpgScheduleEndTimeCol,			"ScheduleEndTime" );
       
    73 
       
    74 // LatestEpgAvailable table
       
    75 _LIT( KIptvEpgLatestEpgAvailableTable,					"LatestEpgAvailable" );
       
    76 _LIT( KIptvEpgLatestEpgAvailableTableKeyCol,			"LatestEpgAvailableKey" );
       
    77 _LIT( KIptvEpgLatestEpgAvailableServiceProviderIdCol,	"LatestEpgAvailableServiceProviderId" );
       
    78 _LIT( KIptvEpgLatestEpgAvailableStartTimeCol,			"LatestEpgAvailableStartTime" );
       
    79 
       
    80 // Last modified table
       
    81 _LIT( KIptvEpgLastModifiedTable,			"LastModifiedMetadata" );
       
    82 _LIT( KIptvEpgLastModifiedTableKeyCol,		"LastModifiedMetadataKey" );
       
    83 _LIT( KIptvEpgLastModifiedTableServiceIdCol,"LastModifiedMetadataServiceId" );
       
    84 _LIT( KIptvEpgLastModifiedTableETagCol,		"LastModifiedMetadataETag" );
       
    85 _LIT( KIptvEpgLastModifiedTableTimeCol,		"LastModifiedMetadataTime" );
       
    86 
       
    87 // FORWARD DECLARATIONS
       
    88 // CLASS DECLARATION
       
    89 
       
    90 class CIptvEpgChannel;
       
    91 class CIptvEpgProgram;
       
    92 class CIptvEpgSchedule;
       
    93 class CIptvEpgScheduleSearch;
       
    94 class CIptvEpgLatestEpgAvailable;
       
    95 class CIptvEpgProgramWithSchedule;
       
    96 
       
    97 /**
       
    98  * Class:       CIptvEpgDatabase
       
    99  *
       
   100  * Description: An instance of class CIptvEpgDatabase provides Epg
       
   101  *              database access: creating & manipulating Epg database
       
   102  *              files and database entries (channels, and programs).
       
   103  *
       
   104  * Database definition:     
       
   105  *
       
   106  *              The Epg database contains one table as follows:
       
   107  *
       
   108  *              Table name: Channel
       
   109  *              	Column:				Type:			Length (bytes):   Desc:
       
   110  *                	------				-----          	-----------       -----
       
   111  *                 	Key                	EDbColUint32
       
   112  *					ChannelId			EDbColInt64
       
   113  *					ServiceProviderId	EDbColUint32
       
   114  *					ChannelName			EDbColText
       
   115  *					ChannelLogoPath		EDbColText
       
   116  *					ChannelDescription	EDbColText
       
   117  *					ChannelURI			EDbColText
       
   118  *					ChannelSDP			EDbColLongText
       
   119  *					ChannelOrder		EDbColUint32
       
   120  *
       
   121  *
       
   122  *              There is also index for Channel table with name "ChannelIndex".
       
   123  *				It consists of Key column.
       
   124  *
       
   125  *              Index provides quick find.
       
   126  *
       
   127  *
       
   128  * Database definition:
       
   129  *
       
   130  *              The Epg database contains one table as follows:
       
   131  *
       
   132  *              Table name: ProgramEvent
       
   133  *                 	Column:         		Type:         Length (bytes): Desc:
       
   134  *                 	------              	-----         -----------     -----
       
   135  *                 	Key                 	EDbColUint32
       
   136  *					ProgramId				EDbColInt64
       
   137  * 					ProgramChannelId		EDbColInt64
       
   138  *					ServiceProviderId		EDbColUint32
       
   139  *					ProgramStartTime		EDbColDateTime
       
   140  *					ProgramEndTime			EDbColDateTime
       
   141  *					ProgramURI				EDbColText
       
   142  *					ProgramSDP				EDbColLongText
       
   143  *					ProgramGenre			EDbColText
       
   144  *					ProgramName				EDbColText
       
   145  *					ProgramDescription		EDbColText
       
   146  *					ProgramLanguage			EDbColText
       
   147  *					ProgramParentalRating	EDbColText
       
   148  *
       
   149  *
       
   150  *              There is also index for Program table with name "ProgramIndex".
       
   151  *				It consists of Key column.
       
   152  *
       
   153  *              Index provides quick find.
       
   154  *
       
   155  * Database definition:
       
   156  *				The epg database contains one table as follows:
       
   157  *				Table name: Last modified
       
   158  *              Table name: ChannelProgram
       
   159  *                 	Column:             Type:          	Length (bytes): Desc:
       
   160  *                 	------              -----          	-----------     -----
       
   161  *                 	ServiceId           EDbColUint32   	
       
   162  *                 	LastModifedDateTime EDbColText
       
   163  *                 	ETag			 	EDbColText
       
   164  *
       
   165  * Database definition:
       
   166  *
       
   167  *              The Epg database contains one table as follows:
       
   168  *
       
   169  *              Table name: ChannelProgram
       
   170  *                 	Column:             Type:          	Length (bytes): Desc:
       
   171  *                 	------              -----          	-----------     -----
       
   172  *                 	ChannelKey          EDbColUint32   	4
       
   173  *                 	ProgramKey          EDbColUint32   	4
       
   174  *
       
   175  * 
       
   176  */
       
   177 class CIptvEpgDatabase : public CBase, public MBackupObserver
       
   178     {
       
   179     public:
       
   180     /**
       
   181     *	Enumeration for the database class internal state.
       
   182     */
       
   183     enum TIptvEpgDatabaseInternalState
       
   184     	{
       
   185     	EReady = 0, 	// This class is ready to be used
       
   186     	EBackup			// Database backup is ongoing -> no interaction allowed
       
   187     	};
       
   188     	
       
   189     public:  // Constructors and destructor
       
   190 
       
   191          /**
       
   192          * Two-phased constructor.
       
   193          * @param 
       
   194          */
       
   195         IMPORT_C static CIptvEpgDatabase* NewL( const TFileName& aDbFile );
       
   196     
       
   197         /**
       
   198          * Destructor.
       
   199          */
       
   200         virtual ~CIptvEpgDatabase();
       
   201         
       
   202     public: // From MBackupObserver
       
   203     	/**
       
   204     	*	Method to get called when file that this class has registered
       
   205     	*	to observe for backup is to be affected with backup operation.
       
   206     	*	This method is also called when it's allowed to re-open the
       
   207     	*	file for read/write.
       
   208     	*	@param	aFileName	Name of the file that needs to be closed
       
   209     	*						or can be re-opened
       
   210     	*	@param	aFlags		Flags identifying the operation to be happen
       
   211     	*	@return	None
       
   212     	*/
       
   213     	void ChangeFileLockL( const TDesC& aFileName, TFileLockFlags aFlags );    
       
   214     
       
   215 	public: // Public API for database operations
       
   216     
       
   217         /**
       
   218          *	Get channels.
       
   219          *
       
   220 		 *  @param  aServiceProviderId 	Service provider id.
       
   221          *	@param	aResultArray		Array of channels.         
       
   222          */
       
   223         IMPORT_C void GetChannelsL( const TUint32 aServiceProviderId, 
       
   224 									RPointerArray<CIptvEpgChannel>* 
       
   225 									aResultArray );
       
   226 
       
   227         /**
       
   228          *	Get programs.
       
   229          *
       
   230 		 *  @param aServiceProviderId Service provider id.
       
   231 		 *  @param aChannelKey      Channel id.
       
   232          *							aResultArray.
       
   233          *	@param 	aResultArray    Array where found results are put.
       
   234          */
       
   235         IMPORT_C void GetProgramsByChannelIdL( 
       
   236 											const TUint32 aServiceProviderId, 
       
   237 											const TInt64 aChannelKey,
       
   238         				   					RPointerArray<CIptvEpgProgram>* 
       
   239 											aResultArray );
       
   240 		
       
   241         /**
       
   242          *	Get next program by channel.
       
   243          *
       
   244 		 *  @param aServiceProviderId Service provider id.
       
   245 		 *  @param aChannelKey Channel id.
       
   246          *	@param aRefTime reference time 
       
   247          *	@return CIptvEpgSchedule* the found schedule
       
   248          */									
       
   249 		IMPORT_C CIptvEpgSchedule* GetNextProgramL( 
       
   250 								const TUint32 aServiceProviderId,
       
   251 								const TInt64 aChannelKey,
       
   252 								const TTime& aRefTime );
       
   253 
       
   254 		/**
       
   255          *	Get schedules (for search) by service id. 
       
   256          *
       
   257 		 *  @param aServiceProviderId Service provider id.
       
   258 		 *							aResultArray.
       
   259          *	@param 	aResultArray    Array where found results are put.
       
   260          *	@return                 None
       
   261          */
       
   262         IMPORT_C void GetSchedulesByServiceIdL( 
       
   263 					const TUint32 aServiceProviderId, 
       
   264 					RPointerArray<CIptvEpgScheduleSearch>* aResultArray );
       
   265 
       
   266         /**
       
   267          *	Get programs.
       
   268          *
       
   269 		 *  @param aServiceProviderId Service provider id.
       
   270 		 *  @param aChannelKey      Channel id.
       
   271          *							aResultArray.
       
   272          *	@param 	aResultArray    Array where found results are put.
       
   273          *	@return                 None
       
   274          */
       
   275         IMPORT_C void GetSchedulesByChannelIdL( 
       
   276 											const TUint32 aServiceProviderId, 
       
   277 											const TInt64 aChannelKey,
       
   278         				   					RPointerArray<CIptvEpgSchedule>* aResultArray );
       
   279         /**
       
   280          *	Get the programs for that channel and day
       
   281          *
       
   282 		 *  @param aServiceProviderId Service provider id.
       
   283 		 *  @param aChannelKey        Channel id.							
       
   284          *	@param aStartTime         start of the day
       
   285          *	@param 	aResultArray      Array where found results are put.
       
   286          *	@return 				  None 
       
   287          *	                  
       
   288          */					
       
   289 		IMPORT_C void GetSchedulesByChannelAndDayL( 
       
   290 								const TUint32 aServiceProviderId,
       
   291 								const TInt64 aChannelKey,
       
   292 								const TTime& aStartTime,
       
   293 								RPointerArray<CIptvEpgSchedule>* aResultArray );
       
   294 		
       
   295 		
       
   296         /**
       
   297          *	Get the program that covers the given start time
       
   298          *  in its time duration
       
   299          *
       
   300 		 *  @param aServiceProviderId Service provider id.
       
   301 		 *  @param aChannelKey        Channel id.							
       
   302          *	@param aStartTime 
       
   303          *	@return CIptvEpgSchedule*		  the found schedule  
       
   304          *	                  
       
   305          */	
       
   306          
       
   307          												
       
   308 		IMPORT_C CIptvEpgSchedule* GetProgramByTimeL(
       
   309 												  const TUint32 aServiceProviderId, 
       
   310 												  const TInt64 aChannelKey,
       
   311 												  const TTime& aStartTime
       
   312 												   );										
       
   313 		/**
       
   314 		*	Get channel specified by id
       
   315 		*	@param	aService		Service provider id
       
   316 		*	@param	aChannel	    Channel id
       
   317 		*	@return	CIptvEpgChannel or NULL if not found
       
   318 		*/
       
   319         IMPORT_C CIptvEpgChannel* GetChannelL( TInt aService,
       
   320         								       TInt64 aChannel );	
       
   321 		/**
       
   322 		*	Get latest schedule time in db
       
   323 		*	@param	aService		Service provider id
       
   324 		*   @param  aLatestScheduleTime, returns this
       
   325 		*	@return	Latest schedule time in database.
       
   326 		*/        								       
       
   327 		IMPORT_C TTime GetLatestScheduleTimeL( const TUint32 aServiceId );        								       									  
       
   328 
       
   329 		/**
       
   330 		*	Inserts or updates given channel to the database.
       
   331 		*	Each channel must have unique id inside one serivice providers
       
   332 		*	list of channels. Therefore is aChannel.iChannelId is found from
       
   333 		*	database and that database entry has aChannel.iServiceProviderId
       
   334 		*	existing data is update. Otherwise aChannel is added to the
       
   335 		*	database.
       
   336 		*	@param	aChannel	Object containing data to be inserted or
       
   337 		*						updated to the database
       
   338 		*	@param	aChannelKey	On return contains unique database id of
       
   339 		*						inserted or updated database entry
       
   340 		*/        
       
   341 		IMPORT_C void InsertOrUpdateChannelL( const CIptvEpgChannel& aChannel,
       
   342 											  TUint32& aChannelKey );
       
   343 		
       
   344         /**
       
   345         *	Delete channel from the database. This causes all programs which 
       
   346 		*	has	aChannelId in the program table to be deleted as well.
       
   347 		*   @param  aServiceProviderId Service provider id.
       
   348         *	@param	aChannelId	Channel id of the channel to be deleted
       
   349         *	@return	None
       
   350         */
       
   351         IMPORT_C void DeleteChannelL( const TUint32 aServiceProviderId,
       
   352 									  const TInt64 aChannelId );
       
   353         
       
   354         /**
       
   355         *	Inserts or updates given program to the database.
       
   356         *	Each program must have unique program id inside a channel. This
       
   357         *	function tries to find an entry from database which has
       
   358         *	aProgram.iProgramId and aProgram.iChannelId. If one is found from
       
   359         *	the database, then database is updated, otherwise new entry is
       
   360         *	made.
       
   361         *	@param	aProgram	Class containing the program data to be
       
   362         *						added or updated
       
   363 		*	@param	aProgramKey	On return contains unique database id of
       
   364 		*						inserted or updated database entry
       
   365         */
       
   366         IMPORT_C void InsertOrUpdateProgramL( const CIptvEpgProgram& aProgram,
       
   367         									  TUint32& aProgramKey );
       
   368 
       
   369 		IMPORT_C void InsertOrUpdateScheduleL( 
       
   370 								const CIptvEpgSchedule& aSchedule );
       
   371         /**
       
   372         *	Inserts or updates given latestEpgAvailable info to the database.
       
   373         *	@param	aLatestEpgAvailable	
       
   374 		*	@param	aInsert	boolean to decide insert or update
       
   375         */		
       
   376 		IMPORT_C void InsertOrUpdateLatestEpgAvailableL
       
   377 									( CIptvEpgLatestEpgAvailable& aLatestEpgAvailable );
       
   378 
       
   379         /**
       
   380         *	Delete program from the database.
       
   381 		*   @param  aServiceProviderId Service provider id.
       
   382         *	@param	aProgramId	Id of the program to be deleted from 
       
   383 		*			program table
       
   384         *	@return	None
       
   385         */
       
   386         IMPORT_C void DeleteProgramL( const TUint32 aServiceProviderId,
       
   387 									  const TInt64 aProgramId );
       
   388         
       
   389 		/**
       
   390          * Update channel order.
       
   391 		 *
       
   392          * @param aServiceId		 	Service provider id.
       
   393          * @param aChannelId           	Channel id.
       
   394 		 * @param aOrder				New order number.
       
   395 		 */
       
   396         IMPORT_C void UpdateChannelOrderL( const TUint32 aServiceId,
       
   397 										   const TInt64  aChannelId,
       
   398 										   const TUint32 aOrder );
       
   399         
       
   400 		/**
       
   401          * Update channel icon path.
       
   402 		 *
       
   403          * @param aServiceId		 	Service provider id.
       
   404          * @param aChannelId           	Channel id.
       
   405 		 * @param aIconPath				New icon path
       
   406 		 */
       
   407         IMPORT_C void UpdateChannelIconPathL( const TUint32 aServiceId,
       
   408 										   	  const TInt64  aChannelId,
       
   409 										   	  const TDesC&  aIconPath );
       
   410 		/**
       
   411          * Gets the schedules by program id
       
   412 		 *
       
   413          * @param aServiceId		 	Service provider id.
       
   414          * @param aChannelKey           Channel id.
       
   415 		 * @param aProgId				program id
       
   416 		 * @param aResultArray
       
   417 		 */										   	  
       
   418 		IMPORT_C void GetSchedulesByProgIdL( 
       
   419 								const TUint32 aServiceProviderId,
       
   420 								const TInt64 aChannelKey,
       
   421 								const TInt64 aProgId,
       
   422 								RPointerArray<CIptvEpgSchedule>* aResultArray );
       
   423 
       
   424 		/**
       
   425 		* Clear service specific EPG data from database.
       
   426 		* @param aServiceId Service id.
       
   427 		*/
       
   428 		IMPORT_C void ClearServiceEPGDataL( const TUint32 aServiceId );
       
   429 
       
   430 
       
   431         /**
       
   432          * Add new channel to database.
       
   433          *
       
   434          * @param aChannel             Reference to CIptvMulticastChannel 
       
   435 		 *							   object. 
       
   436          * @param aChannelKey          New channel key value is inserted to 
       
   437 		 *							   aChannelKey.
       
   438          */
       
   439         IMPORT_C void AddChannelL( const CIptvEpgChannel& aChannel, 
       
   440 								   TUint32& aChannelKey );
       
   441 								   
       
   442 		IMPORT_C void AddChannelsL( const RPointerArray<CIptvEpgChannel>& aChannels,
       
   443 									TUint32& aChannelKey );
       
   444 
       
   445 		/**
       
   446          * Add new program to database.
       
   447          *
       
   448          * @param aProgram             Reference to CIptvMulticastProgram 
       
   449 		 *							   object.
       
   450          * @param aProgramKey          New program key value
       
   451          */
       
   452         IMPORT_C void AddProgramL( const CIptvEpgProgram& aProgram, 
       
   453 						  TUint32& aProgramKey );
       
   454 
       
   455 		IMPORT_C void AddProgramsL( const RPointerArray<CIptvEpgProgram>& aPrograms );
       
   456 		
       
   457 
       
   458 		IMPORT_C void AddProgramWithScheduleL( CIptvEpgProgramWithSchedule& aProgramWithSchedule,
       
   459 											   TUint32& aProgramKey );
       
   460 		
       
   461 		IMPORT_C void AddProgramsWithSchedulesL(
       
   462 				const RPointerArray<CIptvEpgProgramWithSchedule>& aProgramsWithSchedules );
       
   463 
       
   464 		/**
       
   465 		*	Add schedule
       
   466 		*	@param	aSchedule	Schedule information to be added to the database
       
   467 		*	@return	None
       
   468 		*/
       
   469 		IMPORT_C void AddScheduleL( const CIptvEpgSchedule& aSchedule );
       
   470 		
       
   471 		IMPORT_C void AddSchedulesL( const RPointerArray<CIptvEpgSchedule>& aSchedules );
       
   472 
       
   473 		/**
       
   474 		* Get single program entry.
       
   475 		* @param aServiceProviderId Service id.
       
   476 		* @param aChannelId Channel id.
       
   477 		* @param aProgramId Program id.
       
   478 		* @return Found program entry or NULL if not found. NULL also returned
       
   479 		* if iLocalState == EBackup. Ownership is
       
   480 		* transferred to the caller.
       
   481 		*/
       
   482 		IMPORT_C CIptvEpgSchedule* GetProgramL( const TUint32 aServiceProviderId,
       
   483 												const TInt64 aChannelId,
       
   484 												const TInt64 aProgramId );
       
   485 		/*
       
   486 		*	Getter method for ETag and last modified date and time for the given service
       
   487 		*	@param	aServiceId				Service that we are looking for
       
   488 		*									last modified data
       
   489 		*	@param	aETag					On return contains the retrieved
       
   490 		*									etag value from the db
       
   491 		*	@param	aLastModifiedDateTime	On return contains the retrieved
       
   492 		*									last modified value from db
       
   493 		*	@return	None
       
   494 		*/
       
   495 		IMPORT_C void GetLastModifiedDataL( const TUint32 aServiceId,
       
   496 											TDes& aETag,
       
   497 											TDes& aLastModifiedDateTime );
       
   498 
       
   499 		/**
       
   500 		*	Setter method for last modified data to the database
       
   501 		*	@param	aServiceId				Id of the service we are assigning the
       
   502 		*									last modified data values
       
   503 		*	@param	aETag					ETag value to be stored to the db
       
   504 		*	@param	aLastModifiedDateTime	Last modified data to be stored to the db.
       
   505 		*									This value can be something like:
       
   506 		*									"Sun, 23 Jan 2007 08:20:37 GMT"
       
   507 		*	@return	None
       
   508 		*/
       
   509 		IMPORT_C void SetLastModifiedDataL( const TUint32 aServiceId,
       
   510 											const TDesC& aETag,
       
   511 											const TDesC& aLastModifiedDateTime );
       
   512 
       
   513     private:
       
   514         /**
       
   515         *	Constructor
       
   516         *	@param	aDbFile		Filename of the database to be used
       
   517         */
       
   518         CIptvEpgDatabase( const TFileName& aDbFile );
       
   519 
       
   520         /**
       
   521         *	Symbian second phase constructor. All code that might leave
       
   522         *	during construction is placed in here.
       
   523         *	@param	None
       
   524         *	@return	None
       
   525         */
       
   526     	void ConstructL();
       
   527 
       
   528         /**
       
   529         *	Removes all rows from channel table  in the epg database
       
   530 		*   using given service id.
       
   531         *	@param	aServiceId Service id.
       
   532         *	@return	None
       
   533         */
       
   534         void ClearChannelTableL( const TUint32 aServiceId );
       
   535 
       
   536 
       
   537 		/**
       
   538         *	Removes all service specific rows from program table in 
       
   539 		*   the epg database.
       
   540         *	@param	aServiceId Service id.
       
   541         *	@return	None
       
   542         */
       
   543         void ClearProgramTableL( const TUint32 aServiceId );
       
   544 
       
   545 		/**
       
   546         *	Removes all service specific rows from schedule table in 
       
   547 		*   the epg database.
       
   548         *	@param	aServiceId Service id.
       
   549         *	@return	None
       
   550         */
       
   551         void ClearScheduleTableL( const TUint32 aServiceId );
       
   552 
       
   553 
       
   554 		/**
       
   555         *	Removes all service specific rows from latest epg table in 
       
   556 		*   the epg database.
       
   557         *	@param	aServiceId Service id.
       
   558         *	@return	None
       
   559         */
       
   560         void ClearLatestEpgTableL( const TUint32 aServiceId );
       
   561 
       
   562 		/**
       
   563 		*	Removes all service specific rows from last modified table.
       
   564 		*	@param	aServiceId	Service id which rows are to be removed
       
   565 		*	@return	None
       
   566 		*/
       
   567 		void ClearLastModifiedTableL( const TUint32 aServiceId );
       
   568 
       
   569 		/**
       
   570 		*	Add LatestEpgAvailable
       
   571 		*	@param	aLatestEpgAvailable	LatestEpgAvailable for a service information 
       
   572 		*   to be added to the database
       
   573 		*	@return	None
       
   574 		*/
       
   575 		void AddLatestEpgAvailableL( CIptvEpgLatestEpgAvailable& aLatestEpgAvailable );
       
   576 	
       
   577     	/**
       
   578     	* Create channel table
       
   579     	*/
       
   580     	void CreateChannelTableL( RDbNamedDatabase& aDatabase ) const;
       
   581     	
       
   582     	/**
       
   583     	* Create program table
       
   584     	*/
       
   585     	void CreateProgramTableL( RDbNamedDatabase& aDatabase) const;
       
   586     	    
       
   587     	/**
       
   588     	*	Create last modified table. This table consist of service id, ETag value
       
   589     	*	and last modified date (ETag and last modified are optional values)
       
   590     	*	@param	aDatabase	Reference to the database where the table is
       
   591     	*						created.
       
   592     	*	@return	None
       
   593     	*/
       
   594     	void CreateLastModifiedTableL( RDbNamedDatabase& aDatabase ) const;
       
   595     	    	
       
   596     	/**
       
   597     	* Create ChannelProgram table
       
   598     	*/
       
   599     	void CreateChannelProgramTableL( RDbNamedDatabase& aDatabase ) const;
       
   600     	
       
   601     	/**
       
   602     	* Create Schedule table
       
   603     	*/
       
   604     	void CreateScheduleTableL( RDbNamedDatabase& aDatabase ) const;
       
   605     	
       
   606     	/**
       
   607     	* Create LatestEpgAvailable table
       
   608     	*/    	
       
   609     	void CreateLatestEpgAvailableTableL( RDbNamedDatabase& aDatabase ) const;
       
   610     	
       
   611     	/**
       
   612     	*	Gets each and every row from view and parses the data to result 
       
   613 		*	array. If aResultArray is NULL, this function leaves with 
       
   614 		*	KErrArgument.
       
   615     	*	@param	aSqlStatement	SQL statement to be used for database.
       
   616     	*	@param	aResultArray	Array where parsed database stuff is 
       
   617 		*   put into.
       
   618     	*	@return	None
       
   619     	*/
       
   620     	void FetchProgramsFromTableL( const TDesC& aSqlStatement,
       
   621     						RPointerArray<CIptvEpgProgram>* aResultArray );
       
   622     						
       
   623     	
       
   624 		/**
       
   625     	*	Gets program names and program ids from program table.
       
   626 		*	If aResultArray is NULL, this function leaves with 
       
   627 		*	KErrArgument.
       
   628     	*	@param	aSqlStatement	SQL statement to be used for database.
       
   629     	*	@param	aResultArray	Array where parsed database stuff is 
       
   630 		*   put into.
       
   631     	*	@return	None
       
   632     	*/
       
   633 		void FetchProgramNamesFromTableL( const TDesC& aSqlStatement,
       
   634 							RPointerArray<CIptvEpgProgram>* aResultArray );				
       
   635     	/**
       
   636     	*	Gets each and every row from view and parses the data to result 
       
   637 		*	array. If aResultArray is NULL, this function leaves with 
       
   638 		*	KErrArgument.
       
   639     	*	@param	aSqlStatement	SQL statement to be used for database.
       
   640     	*	@param	aResultArray	Array where parsed database stuff is 
       
   641 		*   put into.
       
   642     	*	@return	None
       
   643     	*/
       
   644     	void FetchSchedulesFromTableL( const TDesC& aSqlStatement,
       
   645     						RPointerArray<CIptvEpgSchedule>* aResultArray );    	
       
   646 
       
   647 
       
   648 		/**
       
   649     	*	Gets rows from schedule table using given sql statement and puts
       
   650 		*   results to aResultArray. If aResultArray is NULL, this function 
       
   651 		*   leaves with KErrArgument.
       
   652     	*	@param	aSqlStatement	SQL statement to be used for database.
       
   653     	*	@param	aResultArray	Array where parsed database stuff is 
       
   654 		*   put into.
       
   655     	*	@return	None
       
   656     	*/	
       
   657 		void FetchSearchSchedulesFromTableL( 
       
   658 						const TDesC& aSqlStatement,
       
   659 						RPointerArray<CIptvEpgScheduleSearch>* aResultArray );
       
   660 
       
   661         /**
       
   662          *	Get channels. The actual workhorse. Called from public
       
   663          *  channel-getting methods. 
       
   664          *
       
   665 		 *  @param  aQuery              Contains SQL that is supposed to return the channels
       
   666          *	@param	aResultArray		Array of channels.         
       
   667          */
       
   668         void DoGetChannelsL( const TDesC& aQuery, 
       
   669 						     RPointerArray<CIptvEpgChannel>* 
       
   670 							 aResultArray );
       
   671 
       
   672         /**
       
   673          * 
       
   674          * Create new database if DB file is not found. 
       
   675          */
       
   676         void CreateDbL();
       
   677 
       
   678         /**        
       
   679          * Creates session to iptv database
       
   680          */
       
   681         void CreateMulticastDbSessionL();
       
   682     
       
   683         /**        
       
   684          * Closes the session to iptv database
       
   685          */
       
   686         void CloseMulticastDbSession();
       
   687 
       
   688 		/**
       
   689 		 * Update channel order numbers so that they are consistent.
       
   690 		 * @param aServiceProviderId Service id.
       
   691 		 */
       
   692 		void UpdateChannelOrdersL( const TUint32 aServiceProviderId );
       
   693 
       
   694     	/**
       
   695 		*   Method for deleting all schedule data for given channel. 
       
   696     	*	@param	aChannel	Specifies the channel whose schedules will be
       
   697     	*                       thrown away. 
       
   698     	*	@return	None
       
   699     	*/
       
   700     	void RemoveScheduledDataFromChannelL( const CIptvEpgChannel& aChannel );
       
   701 
       
   702 		/**
       
   703 		* Get program names and program ids using service id.		
       
   704 		* @param aServiceProviderId Service ID.
       
   705 		* @param aResultArray Array where results are put.
       
   706 		*/
       
   707 		void GetProgramNamesByServiceIdL( const TUint32 aServiceProviderId, 
       
   708 									  RPointerArray<CIptvEpgProgram>* 
       
   709 									    aResultArray );
       
   710         
       
   711 	private: 
       
   712 
       
   713         /**               
       
   714          * Initialise database   
       
   715          */     
       
   716         void InitDbL();
       
   717         
       
   718         /**
       
   719         * Construct SQL-query strings
       
   720         */
       
   721         void MakeSqlStrings();
       
   722         
       
   723         /**
       
   724         *	Method to check iStatus state to see if we are having backup
       
   725         *	in progress. If that's the case then we'll put CActiveSchedulerWait
       
   726         *	on and wait until backup has been finished. Otherwise this method
       
   727         *	does nothing.
       
   728         *	@param	None
       
   729         *	@return	None
       
   730         */
       
   731         void CheckBackupStatus();
       
   732         
       
   733     private:
       
   734 
       
   735 		/** File server session is connected in construction and closed in
       
   736 			destruction */
       
   737     	RFs              iFsSession;
       
   738     	
       
   739     	/** File name of the database which to handle */
       
   740 		TFileName        iDbFile;
       
   741 
       
   742         /** Multicast DB session */
       
   743         RDbs iMulticastDbSession;
       
   744         
       
   745         /** Multicast database */
       
   746         RDbNamedDatabase iMulticastDb;
       
   747 
       
   748         /** Channel SQL-query string */
       
   749         TBuf<KCustomSqlLength> iSqlChannel;
       
   750         
       
   751         /* Program SQL-query string */
       
   752         TBuf<KCustomSqlLength> iSqlProgram;
       
   753 
       
   754 		/* Backup session to observer starting/ending backup operation */
       
   755         CBaBackupSessionWrapper* iBackupWrapper;
       
   756         
       
   757         /* Current state of this object */
       
   758         TIptvEpgDatabaseInternalState iLocalState;
       
   759         
       
   760         CActiveSchedulerWait* iActiveWait;
       
   761     };
       
   762 
       
   763 #endif // __CIPTVEPGDATABASE_H__
       
   764             
       
   765 // End of File