videofeeds/server/IptvEpgDb/inc/CIptvEpgDb.h
branchRCL_3
changeset 23 befca0ec475f
parent 0 96612d01cf9f
equal deleted inserted replaced
22:839377eedc2b 23:befca0ec475f
       
     1 /*
       
     2 * Copyright (c) 2002-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 CIptvEpgDb class. Engine version 1.1.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CIPTVEPGDB_H
       
    21 #define CIPTVEPGDB_H
       
    22 
       
    23 #include <e32std.h>
       
    24 #include <badesca.h>    // CDesCArrayFlat (cannot be forward declarated)
       
    25 #include <d32dbms.h>    // RDbStoreDatabase
       
    26 #include <f32file.h>    // RFs
       
    27 #include "CIptvUtil.h"
       
    28 #include "MIptvEpgVodCallback.h"
       
    29 #include <cenrepnotifyhandler.h>
       
    30 
       
    31 const int KCustomSqlMaxLength( 256 );
       
    32 const TInt KIptvDbNameMaxLength( 50 );
       
    33 
       
    34 // Category table
       
    35 _LIT( KIptvEpgCategoryTable, "Cat" );
       
    36 _LIT( KIptvEpgCategoryDbKeyCol, "Key" );
       
    37 _LIT( KIptvEpgCategoryDbParentKeyCol, "PKey" );
       
    38 _LIT( KIptvEpgCategoryDbIdCol, "Id" );
       
    39 _LIT( KIptvEpgCategoryDbNameCol, "Name" );
       
    40 _LIT( KIptvEpgCategoryDbIconFileIdCol, "IconId" ); // Obsolete field
       
    41 _LIT( KIptvEpgCategoryDbIsIconFilePathUrlCol, "IsIconPathUrl" ); // Obsolete
       
    42 _LIT( KIptvEpgCategoryDbIconFilePathCol, "IconPath" );
       
    43 _LIT( KIptvEpgCategoryDbDescriptionCol, "Desc" );
       
    44 _LIT( KIptvEpgCategoryDbPubDateCol, "PD" ); // Obsolete field
       
    45 _LIT( KIptvEpgCategoryDbContentCountCol, "ContentCount" );
       
    46 
       
    47 // Content table
       
    48 _LIT( KIptvEpgContentTable, "Con" );
       
    49 _LIT( KIptvEpgContentDbKeyCol, "Key" );
       
    50 _LIT( KIptvEpgContentDbIdCol, "Id" );
       
    51 _LIT( KIptvEpgContentDbNameCol, "Name" );
       
    52 _LIT( KIptvEpgContentDbFileIdCol, "FID" );
       
    53 _LIT( KIptvEpgContentDbDriveIdCol, "Dr" );
       
    54 _LIT( KIptvEpgContentDbPreviewFileIdCol, "PFID" );
       
    55 _LIT( KIptvEpgContentDbPreviewDriveIdCol, "PDr" );
       
    56 _LIT( KIptvEpgContentDbContentProtectionCol, "CP" );
       
    57 _LIT( KIptvEpgContentDbIconFileIdCol, "IconId" );
       
    58 _LIT( KIptvEpgContentDbIsIconFilePathUrlCol, "IsIconPathUrl" );
       
    59 _LIT( KIptvEpgContentDbIconFilePathCol, "IconPath" );
       
    60 _LIT( KIptvEpgContentDbContentFileIdCol, "ConId" );
       
    61 _LIT( KIptvEpgContentDbDescriptionCol, "Desc" );
       
    62 _LIT( KIptvEpgContentDbPubDateCol, "PD" );
       
    63 _LIT( KIptvEpgContentDbBrowserUrlCol, "BU" );
       
    64 _LIT( KIptvEpgContentDbOrderCol, "Ord" );
       
    65 _LIT( KIptvEpgContentDbAuthorCol, "Aut" );
       
    66 _LIT( KIptvEpgContentDbCopyrightCol, "Cop" );
       
    67 _LIT( KIptvEpgContentDbSizeCol, "Siz" );
       
    68 _LIT( KIptvEpgContentDbDurationCol, "Dur" );
       
    69 _LIT( KIptvEpgContentDbLanguageCol, "Lan" );
       
    70 _LIT( KIptvEpgContentDbRatingAgeCol, "RatingAge" );
       
    71 
       
    72 // Category_Content table
       
    73 _LIT( KIptvEpgCategoryContentTable, "CategoryContent" );
       
    74 _LIT( KIptvEpgCategoryContentCategoryKeyCol, "CategoryKey" );
       
    75 _LIT( KIptvEpgCategoryContentContentKeyCol, "ContentKey" );
       
    76 
       
    77 // Service table
       
    78 _LIT( KIptvEpgServiceTable, "Service" );
       
    79 _LIT( KIptvEpgServiceLastUpdate, "LastUpdate" );
       
    80 _LIT( KIptvEpgServiceNextUpdate, "NextUpdate" );
       
    81 _LIT( KIptvEpgServiceETag, "ETag" );
       
    82 _LIT( KIptvEpgServiceLastModifiedSince, "LastModifiedSince" );
       
    83 _LIT( KIptvEpgServiceXmlFileHash, "EXmlFileHash" );
       
    84 _LIT( KIptvEpgServiceVersion, "Version" );
       
    85 
       
    86 // ContentAccess
       
    87 _LIT( KIptvCATable, "ContentAccess" );
       
    88 _LIT( KIptvCAContentKey, "ContentKey" );
       
    89 _LIT( KIptvCAContentUrl, "ContentUrl" );
       
    90 _LIT( KIptvCADlType, "DlType" );
       
    91 _LIT( KIptvCALanguage, "Language" );
       
    92 _LIT( KIptvCAPrice, "Price" );
       
    93 _LIT( KIptvCAPurchaseType, "PurchaseType" );
       
    94 _LIT( KIptvCAPurchaseUrl, "PurchaseUrl" );
       
    95 _LIT( KIptvCALastPlayPosition, "LastPlayPosition" );
       
    96 _LIT( KIptvCAMimeType, "MimeType" );
       
    97 _LIT( KIptvCAFileSize, "FileSize" );
       
    98 _LIT( KIptvCADuration, "Duration" );
       
    99 _LIT( KIptvCAFileId, "FileId" );
       
   100 _LIT( KIptvCADriveId, "DriveId" );
       
   101 _LIT( KIptvCAIndex, "Index" );
       
   102 _LIT( KIptvCAExpression, "Expression" );
       
   103 
       
   104 // Name of the category Key index
       
   105 _LIT( KIptvEpgCategoryDbIndexName, "CategoryIndex" );
       
   106 
       
   107 // Name of the content Key index
       
   108 _LIT( KIptvEpgContentDbIndexName, "ContentIndex" );
       
   109 
       
   110 // Name of the CategoryContent Key index
       
   111 _LIT( KIptvEpgCategoryContentDbIndexName, "CatConIndex" );
       
   112 
       
   113 class CIptvEpgCategory;
       
   114 class CIptvEpgContent;
       
   115 class CIptvVodContentCategoryBriefDetails;
       
   116 class CIptvVodContentContentBriefDetails;
       
   117 class CIptvVodContentContentFullDetails;
       
   118 class CIptvMyVideosGlobalFileId;
       
   119 class CIptvServer;
       
   120 class CIptvEpgSession;
       
   121 
       
   122 /**
       
   123  *
       
   124  * An instance of class CIptvEpgDb provides Epg database access creating and
       
   125  * manipulating Epg database files and database entries (categories and
       
   126  * contents.
       
   127  *
       
   128  * Database definition:
       
   129  *
       
   130  *   The Epg database contains one table as follows:
       
   131  *
       
   132  *   Table name: Category
       
   133  *     Column:            Type:          Length (bytes):
       
   134  *     ------             -----          ---------------
       
   135  *     Key                EDbColUint32   4
       
   136  *     ParentKey          EDbColUint32   4
       
   137  *     Id                 EDbColText     KIptvIdMaxLength * 2
       
   138  *     Name               EDbColText     KIptvEpgCategoryNameMaxLength * 2
       
   139  *     IconFileId         EDbColUint32   4
       
   140  *     IsIconFilePathUrl  EDbColUint32   4
       
   141  *     IconFilePath       EDbColText     KIptvEpgCategoryIconFilePathMaxLength * 2
       
   142  *     PubDate            EDbColDateTime 8
       
   143  *     Description        EDbColText     KIptvEpgCategoryDescriptionMaxLength * 2
       
   144  *     contentCount       EDbColUint32   4
       
   145  *
       
   146  *   There is also index for Category table with name "CategoryIndex". It
       
   147  *   consists of Key column.
       
   148  *
       
   149  *   Index provides quick find.
       
   150  *
       
   151  *
       
   152  * Database definition:
       
   153  *
       
   154  *   The Epg database contains one table as follows:
       
   155  *
       
   156  *   Table name: Content
       
   157  *     Column:              Type:          Length (bytes):
       
   158  *     ------               -----          ---------------
       
   159  *     Key                  EDbColUint32   4
       
   160  *     Id                   EDbColText     KIptvIdMaxLength * 2
       
   161  *     Name                 EDbColText     KIptvEpgContentNameMaxLength * 2
       
   162  *     FileId               EDbColUint32   4
       
   163  *     Drive                EDbColUint32   4
       
   164  *     PFileId              EDbColUint32   4
       
   165  *     PDrive               EDbColUint32   4
       
   166  *     ContentProtection    EDbColUint32   4 (NOT USED)
       
   167  *     IconFileId           EDbColUint32   4
       
   168  *     IsIconFilePathUrl    EDbColUint32   4
       
   169  *     IconFilePath         EDbColText     KIptvEpgContentIconFilePathMaxLength * 2
       
   170  *     ContentFileId        EDbColUint32   4
       
   171  *     Description          EDbColText     KIptvEpgContentDescriptionMaxLength * 2
       
   172  *     PubDate              EDbColDateTime 8
       
   173  *     BrowserUrl           EDbColText     KIptvEpgContentBrowserUrlMaxLength * 2
       
   174  *     Order                EDbColUint32   4
       
   175  *     Author               EDbColText     KIptvEpgContentAuthorLength * 2
       
   176  *     Copyright            EDbColText     KIptvEpgContentCopyrightLength * 2
       
   177  *     Size                 EDbColUint32   4
       
   178  *     Duration             EDbColUint32   4
       
   179  *     Language             EDbColText     KIptvCALanguageLength * 2
       
   180  *     RatingAge            EDbColUint16   2
       
   181  *
       
   182  *   Missing from content table, not implemented in increment 1:
       
   183  *
       
   184  *   - Next postponed download time
       
   185  *   - Next scheduled download time
       
   186  *
       
   187  *   There is also index for Content table with name "ContentIndex". It
       
   188  *   consists of Key column.
       
   189  *
       
   190  *   Index provides quick find.
       
   191  *
       
   192  * Database definition:
       
   193  *
       
   194  *   The Epg database contains one table as follows:
       
   195  *
       
   196  *   Table name: CategoryContent
       
   197  *     Column:              Type:          Length (bytes):
       
   198  *     ------               -----          --------------
       
   199  *     CategoryKey          EDbColUint32   4
       
   200  *     ContentKey           EDbColUint32   4
       
   201  *
       
   202  *
       
   203  *
       
   204  * Database definition:
       
   205  *
       
   206  *   The Epg database contains one table as follows:
       
   207  *
       
   208  *   Table name: Service
       
   209  *     Column:              Type:          Length (bytes):
       
   210  *     ------               -----          ---------------
       
   211  *     LastUpdate           EDbColDateTime   8
       
   212  *     NextUpdate           EDbColDateTime   8
       
   213  *     ETag                 EDbColText       64
       
   214  *     LastModifiedSince    EDbColText       64
       
   215  *     EXmlFileHash         EDbColText       20
       
   216  *     Version              EDbColUint32     4
       
   217  *
       
   218  * Database definition:
       
   219  *
       
   220  *   The Epg database contains one table as follows:
       
   221  *
       
   222  *   Table name: ContentAccess
       
   223  *     Column:              Type:          Length (bytes):
       
   224  *     ------               -----          ---------------
       
   225  *     ContentKey           EDbColUint32     4
       
   226  *     ContentUrl           EDbColLongText   KIptvCAContentUrlLength * 2
       
   227  *     DlType               EDbColUint32     4
       
   228  *     Language             EDbColText       KIptvCALanguageLength * 2
       
   229  *     Price                EDbColText       KIptvCAPriceLength * 2
       
   230  *     PurchaseType         EDbColUint32     4
       
   231  *     PurchaseURL          EDbColLongText   KIptvCAPurchaseUrlLength * 2
       
   232  *     LastPlayPosition     EDbColUint32     4
       
   233  *     MimeType             EDbColText       KIptvCAMimeTypeLength * 2
       
   234  *     FileSize             EDbColUint32     4
       
   235  *     Duration             EDbColUint32     4
       
   236  *     FileId               EDbColUint32     4
       
   237  *     DriveId              EDbColUint32     4
       
   238  *     Index                EDbColUint32     4
       
   239  *     Expression           EDbColUint32     4
       
   240  *
       
   241  *  @lib IptvServer.exe
       
   242  *  @since Engine 1.0
       
   243  */
       
   244 class CIptvEpgDb : public CBase,
       
   245                    public MCenRepNotifyHandlerCallback
       
   246     {
       
   247 
       
   248 public:
       
   249 
       
   250     /**
       
   251      * Two-phased constructor.
       
   252      *
       
   253      * @param aEpgFile Database file name.
       
   254      * @param aServiceId Service id.
       
   255      * @param aServer Server.
       
   256      */
       
   257     static CIptvEpgDb* NewL(
       
   258         const TFileName& aEpgFile,
       
   259         const TUint32& aServiceId,
       
   260         CIptvServer& aServer );
       
   261 
       
   262     /**
       
   263      * Destructor.
       
   264      */
       
   265     ~CIptvEpgDb();
       
   266 
       
   267     // Query methods for EpgMsgHandler from VodContentClient interface
       
   268 
       
   269     /**
       
   270      * Get list of ECG categories.
       
   271      * The ownership of the returned list is transferred to caller.
       
   272      * The order of categories is defined by database originated from
       
   273      * service provider.
       
   274      *
       
   275      * @param aParentCategoryId Points to category ID which sub-categories
       
   276      *                          should be listed. If NULL, the root is
       
   277      *                          referenced.
       
   278      * @param aCategoryList Reference to a storage where pointer to
       
   279      *                      created category list is returned.
       
   280      * @return Error code, KErrNone if no errors,
       
   281      *                     KErrCouldNotConnect if server is needs
       
   282      *                       permission for connection,
       
   283      *                     otherwise one of the system wide error codes.
       
   284      */
       
   285     TInt GetEcgCategoryListL(
       
   286         TIptvCategoryId aParentCategoryId,
       
   287         RPointerArray<CIptvVodContentCategoryBriefDetails>& aCategoryList );
       
   288 
       
   289     /**
       
   290      * Get detais of one category item.
       
   291      *
       
   292      * @since                Engine 1.1
       
   293      * @param aCategoryId    Selected category ID identifier.
       
   294      * @param aCategory      Reference to a full details data returned.
       
   295      * @return               Error code, KErrNone if no errors.
       
   296      */
       
   297     TInt GetCategoryDetailsL(
       
   298         TIptvCategoryId aCategoryId,
       
   299         CIptvVodContentCategoryBriefDetails& aCategory );
       
   300 
       
   301     /**
       
   302      * Get parent category ID identifier.
       
   303      * This method allows application to browse toward root category,
       
   304      * then two consecutive calls are needed.
       
   305      *
       
   306      * @param aCategoryId Points to category ID which parent category is
       
   307      *                    requested.
       
   308      * @param aParentId Reference to a storage where parent ID is returned.
       
   309      * @return Error code, KErrNone if no errors,
       
   310      *                     KErrCouldNotConnect if server is needs permission
       
   311      *                                         for connection,
       
   312      *                     otherwise one of the system wide error codes.
       
   313      */
       
   314     TInt GetParentCategoryL(
       
   315         TIptvCategoryId aCategoryId,
       
   316         TIptvCategoryId& aParentId );
       
   317 
       
   318     /**
       
   319      * Get list of ECG contents in the specified category in order defined
       
   320      * by database originated from service provider.
       
   321      * The ownership of the returned list is transferred to caller.
       
   322      *
       
   323      * @param aCategoryId Selected category ID identifier
       
   324      * @param aSearchString A search string used to filter contents search.
       
   325      *                      If NULL, no filtering issued.
       
   326      * @param aFrom The start index for listed contents. If NULL, start from
       
   327      *              the first one.
       
   328      * @param aAmount Amount of content elementes to be listes. If NULL,
       
   329      *                all starting from aFrom.
       
   330      * @param aTotalAmount Pointer to a variable where total amount of
       
   331      *                     content is returned.
       
   332      * @param aEcgList Reference to returned ECG list items.
       
   333      * @return Error code, KErrNone if no errors,
       
   334      *                     KErrCouldNotConnect if server is needs permission
       
   335      *                                         for connection,
       
   336      *                     otherwise one of the system wide error codes.
       
   337      */
       
   338     TInt GetEcgListL(
       
   339         TIptvCategoryId aCategoryId,
       
   340         const TDesC& aSearchString,
       
   341         TUint32 aFrom,
       
   342         TUint32 aAmount,
       
   343         TUint32& aTotalAmount,
       
   344         RPointerArray<CIptvVodContentContentBriefDetails>& aEcgList );
       
   345 
       
   346     /**
       
   347      * Get list of all ECG contents in alphabetical order.
       
   348      * The ownership of the returned list is transferred to caller.
       
   349      *
       
   350      * @param aSearchString A search string used to filter contents search.
       
   351      *                      If NULL, no filtering issued.
       
   352      * @param aFrom The start index for listed contents.
       
   353      *              If NULL, start from the first one.
       
   354      * @param aAmount Amount of content elementes to be listes.
       
   355      *                If NULL, all starting from aFrom.
       
   356      * @param aTotalAmount Pointer to a variable where total amount of
       
   357      *                     content is returned.
       
   358      * @param aEcgList Reference to returned ECG list items.
       
   359      * @return Error code, KErrNone if no errors,
       
   360      *                     KErrCouldNotConnect if server is needs permission
       
   361      *                                         for connection,
       
   362      *                     otherwise one of the system wide error codes.
       
   363      */
       
   364     TInt GetEcgAllListL(
       
   365         const TDesC& aSearchString,
       
   366         TUint32 aFrom,
       
   367         TUint32 aAmount,
       
   368         TUint32& aTotalAmount,
       
   369         RPointerArray<CIptvVodContentContentBriefDetails>& aEcgList );
       
   370 
       
   371     /**
       
   372      * Get full detais of one content item.
       
   373      * The ownership of the returned data is transferred to caller.
       
   374      *
       
   375      * @param aContentId Selected content ID identifier.
       
   376      * @param aContentFullDetails Reference to returned full details data.
       
   377      * @return Error code, KErrNone if no errors,
       
   378      *                     KErrCouldNotConnect if server is needs permission
       
   379      *                                         for connection,
       
   380      *                     otherwise one of the system wide error codes.
       
   381      */
       
   382     TInt GetContentDetailsL(
       
   383         TIptvContentId aContentId,
       
   384         CIptvVodContentContentFullDetails& aContentFullDetails );
       
   385     
       
   386     /**
       
   387      * Marks the database files to be deleted after database has been closed.
       
   388      * @param aDelete ETrue to delete the files (default value), EFalse to clear this flag.
       
   389      */
       
   390     void DeleteDatabaseFiles( TBool aDelete = ETrue );
       
   391 
       
   392 // from MIptvEpgPluginManager interface
       
   393 
       
   394     /**
       
   395      * Add new category to database.
       
   396      *
       
   397      * @param aCategory     Reference to CIptvEpgCategory object.
       
   398      * @param aCategoryKey  New category key value is inserted to
       
   399      *                      aCategoryKey
       
   400      * @return              KErrNone if successful, otherwise another of the
       
   401      *                      system-wide error codes.
       
   402      */
       
   403     TInt AddCategoryL(
       
   404         CIptvEpgCategory& aCategory,
       
   405         TUint32& aCategoryKey );
       
   406 
       
   407     /**
       
   408      * Add relation between category and content.
       
   409      *
       
   410      * @param aCategoryKey  Category key.
       
   411      * @param aContentKey   Content key.
       
   412      */
       
   413     TInt AddRelationL( TUint32& aCategoryKey, TUint32& aContentKey );
       
   414 
       
   415     /**
       
   416      * Add new content to given category.
       
   417      *
       
   418      * @param aContent        Reference to CIptvEpgContent object.
       
   419      * @param aMediaContents  Pointer array containing media content objects.
       
   420      *                        There can be n media content's for one content.
       
   421      * @param aContentKey     New content key value is inserted to
       
   422      *                        aContentKey
       
   423      * @return                KErrNone if successful, otherwise another of
       
   424      *                        the system-wide error codes.
       
   425      */
       
   426     TInt AddContentL(
       
   427         CIptvEpgContent& aContent,
       
   428         RPointerArray<CIptvMediaContent> aMediaContents,
       
   429         TUint32& aContentKey );
       
   430 
       
   431     /**
       
   432      * Update category icon.
       
   433      *
       
   434      * @param aCategoryKey      Category key.
       
   435      * @param aIconFileId       Icon file id to search from the database.
       
   436      * @param aIconFilePath     Full path to icon file or URL + filename.
       
   437      * @param aIsUrl            If aIconFilePath is URL aIsUrl == ETrue,
       
   438      *                          if aIconFilePath is path
       
   439      *                          to local filesystem aIsUrl == EFalse.
       
   440      * @return                  KErrNone if successful, otherwise another of
       
   441      *                          the system-wide error codes.
       
   442      */
       
   443     TInt UpdateCategoryIconL(
       
   444         TUint32& aCategoryKey,
       
   445         TUint32& aIconFileId,
       
   446         const TDesC& aIconFilePath,
       
   447         TBool aIsUrl );
       
   448 
       
   449     /**
       
   450      * Update content icon.
       
   451      *
       
   452      * @param aCategoryKey      Content key.
       
   453      * @param aIconFileId       Icon file id to search from the database.
       
   454      * @param aIconFilePath     Full path to icon file or URL + filename.
       
   455      * @param aIsUrl            If aIconFilePath is URL aIsUrl == ETrue,
       
   456      *                          if aIconFilePath is path
       
   457      *                          to local filesystem aIsUrl == EFalse.
       
   458      * @return                  KErrNone if successful, otherwise another of
       
   459      *                          the system-wide error codes.
       
   460      */
       
   461     TInt UpdateContentIconL(
       
   462         TUint32& aContentKey,
       
   463         TUint32& aIconFileId,
       
   464         const TDesC& aIconFilePath,
       
   465         TBool aIsUrl );
       
   466 
       
   467     /**
       
   468      * Get service update information.
       
   469      *
       
   470      * @param aLastUpdate   Last update time.
       
   471      * @param aInterval     Update interval.
       
   472      */
       
   473     TInt GetServiceInformationL(
       
   474         TTime& aLastUpdate,
       
   475         TTime& aInterval);
       
   476 
       
   477     /**
       
   478      * Update service update information.
       
   479      *
       
   480      * @param aLastUpdate   Last update time.
       
   481      * @param aInterval     Update interval.
       
   482      */
       
   483     TInt UpdateServiceInformationL(
       
   484         const TTime& aLastUpdate,
       
   485         const TTime& aInterval );
       
   486 
       
   487     /**
       
   488      * Get service update information for HTTP headers.
       
   489      *
       
   490      * @param aETag                 ETag
       
   491      * @param aLastModifiedSince    LastModifiedSince
       
   492      */
       
   493     TInt GetServiceETagAndLastmodifiedSinceL(
       
   494         TDes& aETag,
       
   495         TDes& aLastModifiedSince );
       
   496 
       
   497     /**
       
   498      * Update service update information for HTTP headers.
       
   499      *
       
   500      * @param aETag                 ETag
       
   501      * @param aLastModifiedSince    LastModifiedSince
       
   502      */
       
   503     TInt UpdateServiceETagAndLastModifiedSinceL(
       
   504         const TDesC& aETag,
       
   505         const TDesC& aLastModifiedSince );
       
   506 
       
   507     /**
       
   508      * Get hash for service XML file.
       
   509      *
       
   510      * @param aHash    Hash string
       
   511      */
       
   512     TInt GetServiceXmlFileHashL(
       
   513         TDes& aHash);
       
   514 
       
   515     /**
       
   516      * Update hash for service XML file.
       
   517      *
       
   518      * @param aHash    Hash string
       
   519      */
       
   520     TInt UpdateServiceXmlFileHashL(
       
   521         const TDesC& aHash);
       
   522 
       
   523     /**
       
   524      * Reset global Id.
       
   525      *
       
   526      * @param aId           Global file id to be reset.
       
   527      */
       
   528     TInt ResetGlobalId( CIptvMyVideosGlobalFileId& aId );
       
   529 
       
   530     /**
       
   531      * Set global Id.
       
   532      *
       
   533      * @param aContentKey   Key of content to be updated.
       
   534      * @param aId           Global file id to be set.
       
   535      * @param aIndex        Index of content to be updated.
       
   536      * @return KErrNone if successful, otherwise another of the system-wide
       
   537      *         error codes.
       
   538      */
       
   539     TInt SetGlobalId(
       
   540         TUint32 aContentKey,
       
   541         CIptvMyVideosGlobalFileId& aId,
       
   542         TUint32 aIndex );
       
   543 
       
   544 // Engine 1.1
       
   545 
       
   546     /**
       
   547      * Start to update database, firstly to a temporaty work version.
       
   548      */
       
   549     void StartUpdateL();
       
   550 
       
   551     /**
       
   552      * Replace the database in use with the newly updated one.
       
   553      *
       
   554      * @param aSession Related EPG session.
       
   555      */
       
   556     void EndUpdateL( CIptvEpgSession& aSession );
       
   557 
       
   558     /**
       
   559      * Finish database update and delete work database if still exists.
       
   560      */
       
   561     void FinishUpdateL();
       
   562 
       
   563     /**
       
   564      * Fetch content access list from database.
       
   565      *
       
   566      * @param aContentId    Id of required content access list.
       
   567      * @param aContents     Required content access list.
       
   568      * @return              Completion status.
       
   569      */
       
   570     TInt GetContentAccessListL(
       
   571         TUint32 aContentId,
       
   572         RPointerArray<CIptvMediaContent>& aContents );
       
   573 
       
   574     /**
       
   575      * Fetch content access from database.
       
   576      *
       
   577      * @param aContentId    Id of required content access.
       
   578      * @param aIndex        Index of required content access.
       
   579      * @return              Required content access.
       
   580      */
       
   581     CIptvMediaContent* GetContentAccessL(
       
   582         TUint32 aContentId,
       
   583         TUint32 aIndex );
       
   584 
       
   585     /**
       
   586      * Set last play position of the video.
       
   587      *
       
   588      * @param aContentId    Id of position to be set.
       
   589      * @param aIndex        Index of position to be set.
       
   590      * @param aPosition     New position.
       
   591      * @return              Completion status.
       
   592      */
       
   593     TInt SetLastPositionL(
       
   594         TUint32 aContentId,
       
   595         TUint32 aIndex,
       
   596         TUint32 aPosition );
       
   597     
       
   598     /**
       
   599      * Set mpx id for content.
       
   600      *
       
   601      * @param aContentId    Id of position to be set.
       
   602      * @param aCaIndex      Index of position to be set.
       
   603      * @param aMpxId        Mpx Id.
       
   604      * @return              Completion status.
       
   605      */
       
   606     TInt SetMpxIdL( TUint32 aContentId, TUint32 aCaIndex, TUint32 aMpxId );
       
   607 
       
   608     /**
       
   609      * Set update time to service manager.
       
   610      *
       
   611      * @param aTime         New update time.
       
   612      */
       
   613     void SetUpdateTimeToServiceManagerL( const TTime& aTime );
       
   614 
       
   615 // From MCenRepNotifyHandlerCallback
       
   616 
       
   617     /**
       
   618      * CenRep callback.
       
   619      *
       
   620      * @param aId           CenRep key id.
       
   621      * @param aNewValue     CenRep key new value.
       
   622      */
       
   623     void HandleNotifyInt( TUint32 aId, TInt aNewValue );
       
   624 
       
   625     /**
       
   626      * CenRep callback.
       
   627      *
       
   628      * @param aId           CenRep key id.
       
   629      * @param error         CenRep failure code.
       
   630      * @param aHandler      Handler.
       
   631      */
       
   632     void HandleNotifyError(
       
   633         TUint32 aId,
       
   634         TInt error,
       
   635         CCenRepNotifyHandler* aHandler );
       
   636 
       
   637     /**
       
   638      * CenRep callback.
       
   639      *
       
   640      * @param aId CenRep key id.
       
   641      */
       
   642     void HandleNotifyGeneric( TUint32 aId ) ;
       
   643 
       
   644 private:
       
   645 
       
   646     /**
       
   647      * Default constructor.
       
   648      *
       
   649      * @param aServiceId    Service id.
       
   650      * @param aServer       Server.
       
   651      */
       
   652     CIptvEpgDb(
       
   653         const TUint32& aServiceId,
       
   654         CIptvServer& aServer );
       
   655 
       
   656     /**
       
   657      * ConstructL
       
   658      * @param aEpgFile      Full path to DB file.
       
   659      * @param aDbCreated    Database was created.
       
   660      */
       
   661     void ConstructL( const TFileName& aEpgFile );
       
   662 
       
   663     /**
       
   664      * Initialize DB.
       
   665      */
       
   666     void InitDbL();
       
   667 
       
   668     /**
       
   669      *
       
   670      * Create new Epg database if DB file is not found.
       
   671      *
       
   672      * @param aFile         Database file name.
       
   673      * @param aCreated      Database was really created.
       
   674      */
       
   675     void CreateDbL( const TDesC& aFile, TBool& aCreated );
       
   676 
       
   677     /**
       
   678      * Create category table to DB.
       
   679      *
       
   680      * @param aDatabase     Handle to database.
       
   681      * @return              Completion status.
       
   682      */
       
   683     TInt CreateCategoryTableL( RDbNamedDatabase& aDatabase ) const;
       
   684 
       
   685     /**
       
   686      * Create index for category table.
       
   687      *
       
   688      * @param aDatabase     Handle to database.
       
   689      */
       
   690     void CreateCategoryIndexL( RDbNamedDatabase& aDatabase ) const;
       
   691 
       
   692     /**
       
   693      * Create content table to DB.
       
   694      *
       
   695      * @param aDatabase     Handle to database.
       
   696      * @return              Completion status.
       
   697      */
       
   698     TInt CreateContentTableL( RDbNamedDatabase& aDatabase ) const;
       
   699 
       
   700     /**
       
   701      * Create index for content table.
       
   702      *
       
   703      * @param aDatabase     Handle to database.
       
   704      */
       
   705     void CreateContentIndexL( RDbNamedDatabase& aDatabase ) const;
       
   706 
       
   707     /**
       
   708      * Create CategoryContent table to DB.
       
   709      *
       
   710      * @param aDatabase     Handle to database.
       
   711      */
       
   712     void CreateCategoryContentTableL( RDbNamedDatabase& aDatabase ) const;
       
   713 
       
   714     /**
       
   715      * Create index for CategoryContent table.
       
   716      *
       
   717      * @param aDatabase     Handle to database.
       
   718      */
       
   719     void CreateCategoryContentIndexL( RDbNamedDatabase& aDatabase ) const;
       
   720 
       
   721     /**
       
   722      * Create Service table to DB.
       
   723      *
       
   724      * @param aDatabase     Handle to database.
       
   725      * @return              Completion status.
       
   726      */
       
   727     TInt CreateServiceTableL( RDbNamedDatabase& aDatabase ) const;
       
   728 
       
   729     /**
       
   730      * Create ContentAccess table to DB.
       
   731      *
       
   732      * @param aDatabase     Handle to database.
       
   733      * @return              Completion status.
       
   734      */
       
   735     TInt CreateContentAccessTableL( RDbNamedDatabase& aDatabase ) const;
       
   736 
       
   737     /**
       
   738      * This method combines two GetCategoryKeyL methods to one method
       
   739      * (with parameters TDesC& aValue and TUint32& aValue).
       
   740      *
       
   741      * Get category key for given category defined by aField, aDesValue or
       
   742      * aIntValue. Key is databases internal autoincrement which is unique
       
   743      * for every category. If category is already in the database key value
       
   744      * is inserted to aKey parameter and aUpdateCategory is set to ETrue.
       
   745      *
       
   746      * If category is not in the database, aUpdateCategory parameter is
       
   747      * EFalse.
       
   748      *
       
   749      * @param aField        TCategorySearchField enumeration defines the
       
   750      *                      search field.
       
   751      * @param aDesValue     Value which is usedas a "search key" if it is
       
   752      *                      type TDesC.
       
   753      * @param aIntValue     Value which is usedas a "search key" if it is
       
   754      *                      type TUint32.
       
   755      * @param aKey          Category key if given category found from the
       
   756      *                      database.
       
   757      * @param aUpdateCategory  ETrue if category can be updated, EFalse if
       
   758      *                      new category must be created to database.
       
   759      * @return              KErrNone if successful, otherwise another of the
       
   760      *                      system-wide error codes.
       
   761      */
       
   762     TInt GetCategoryKeyL(
       
   763         TCategorySearchField aField,
       
   764         TDesC& aDesValue,
       
   765         TUint32& aIntValue,
       
   766         TUint32& aKey,
       
   767         TBool& aUpdateCategory );
       
   768 
       
   769     /**
       
   770      * Set service update information.
       
   771      *
       
   772      * @param aLastUpdate   Last update time.
       
   773      * @param aInterval     Update interval.
       
   774      * @param aUpdateSet    Update set.
       
   775      * @return              Completion status.
       
   776      */
       
   777     TInt SetServiceInformationL(
       
   778         RDbNamedDatabase& aDb,
       
   779         const TTime& aLastUpdate,
       
   780         const TTime& aInterval) const;
       
   781 
       
   782     /**
       
   783      * Initialize common SQL command strings.
       
   784      */
       
   785     void MakeSqlStrings();
       
   786 
       
   787     /**
       
   788      * Store category to database..
       
   789      *
       
   790      * @param aView         Predefined database view.
       
   791      * @param aCategory     Category descriptor.
       
   792      */
       
   793     void WriteCategoryToDbL(
       
   794         RDbView& aView,
       
   795         CIptvEpgCategory& aCategory ) const;
       
   796 
       
   797     /**
       
   798      * Store video content to database.
       
   799      *
       
   800      * @param aView         Predefined database view.
       
   801      * @param aContent      Content descriptor.
       
   802      * @param aLeave        Disables global file id store.
       
   803      */
       
   804     void WriteContentToDbL(
       
   805         RDbView& aView,
       
   806         CIptvEpgContent& aContent,
       
   807         TBool aLeave ) const;
       
   808 
       
   809     /**
       
   810      * Read category from database.
       
   811      *
       
   812      * @param aView         Predefined database view.
       
   813      * @param aCategory     Category descriptor.
       
   814      */
       
   815     void ReadCategoryFromDbL(
       
   816         const RDbView& aView,
       
   817         CIptvVodContentCategoryBriefDetails& aCategory ) const;
       
   818 
       
   819     /**
       
   820      * Read videos short details from database.
       
   821      *
       
   822      * @param aView         Predefined database view.
       
   823      * @param aBriefDetails Content short descriptor
       
   824      */
       
   825     void ReadContentBriefDetailsFromDbL(
       
   826         const RDbView& aView,
       
   827         CIptvVodContentContentBriefDetails& aBriefDetails ) const;
       
   828 
       
   829     /**
       
   830      * Read videos full details from database.
       
   831      *
       
   832      * @param aView         Predefined database view.
       
   833      * @param aContentFullDetails Content full descriptor.
       
   834      */
       
   835     void ReadContentFullDetailsFromDbL(
       
   836         const RDbView& aView,
       
   837         CIptvVodContentContentFullDetails& aContentFullDetails ) const;
       
   838 
       
   839     /**
       
   840      * Fetch content access from database.
       
   841      *
       
   842      * @param aView         Predefined database view.
       
   843      * @return              Required content access.
       
   844      */
       
   845     CIptvMediaContent* ReadContentAccessFromDbL(
       
   846         const RDbView& aView ) const;
       
   847 
       
   848     /**
       
   849      * Create root category to database.
       
   850      *
       
   851      * @param aDb           Handle to database.
       
   852      */
       
   853     void CreateRootCategoryL( RDbNamedDatabase& aDb ) const;
       
   854 
       
   855     /**
       
   856      * Check whether selected content has been downloaded.
       
   857      *
       
   858      * @param aView         Predefined database view.
       
   859      * @return True indicates download.
       
   860      */
       
   861     TBool IsDownloadedL( const RDbView& aView ) const;
       
   862 
       
   863     /**
       
   864      * Open existing database.
       
   865      *
       
   866      * @param aDb           Handle to database.
       
   867      * @param aFile         database file.
       
   868      */
       
   869     void OpenDatabaseL( RDbNamedDatabase& aDb, const TDesC& aFile );
       
   870 
       
   871     /**
       
   872      * Get database version.
       
   873      *
       
   874      * @return              Required version.
       
   875      */
       
   876     TInt GetVersionL();
       
   877 
       
   878     /**
       
   879      * Write content access to database.
       
   880      *
       
   881      * @param aView         Predefined database view.
       
   882      * @param aMediaContent Content descriptor.
       
   883      * @param aContentKey   Content key.
       
   884      * @param aIndex        Content index.
       
   885      */
       
   886     void WriteContentAccessToDbL(
       
   887         RDbView& aView,
       
   888         const CIptvMediaContent* aMediaContent,
       
   889         TUint32 aContentKey,
       
   890         TUint32 aIndex ) const;
       
   891 
       
   892     /**
       
   893      * Add category to database.
       
   894      *
       
   895      * @param aDb           Handle to database.
       
   896      * @param aCategory     Category descriptor.
       
   897      * @param aCategoryKey  Category key.
       
   898      * @return              Completion status.
       
   899      */
       
   900     TInt AddCategoryL(
       
   901         RDbNamedDatabase& aDb,
       
   902         CIptvEpgCategory& aCategory,
       
   903         TUint32& aCategoryKey ) const;
       
   904 
       
   905     /**
       
   906      * Get list of contents associated with global file id.
       
   907      *
       
   908      * @param aContents     .Contents list.
       
   909      */
       
   910     void GetGlobalFileIdsL( RPointerArray<CIptvMediaContent>& aContents );
       
   911 
       
   912     /**
       
   913      * Copy content associated with global file Id. Also gathers a list of changed
       
   914      * Content IDs so that clients having old information can be notified.
       
   915      *
       
   916      * @param aContent Content descriptor.
       
   917      * @param aOldContentIds Array for old Content IDs.
       
   918      * @param aNewContentIds Array for new Content IDs.
       
   919      */
       
   920     void CopyGlobalFileIdToNewDbL( CIptvMediaContent* aContent,
       
   921                                    RArray<TUint32>& aOldContentIds,
       
   922                                    RArray<TUint32>& aNewContentIds );
       
   923 
       
   924     /**
       
   925      * Reads CenRep data to internal variables.
       
   926      */
       
   927     void ReadCenRepData();
       
   928 
       
   929     /**
       
   930      * Reset global Id.
       
   931      *
       
   932      * @param aId           Global file id to be reset.
       
   933      * @param aError        Completion status.
       
   934      */
       
   935     void ResetGlobalIdL(
       
   936         CIptvMyVideosGlobalFileId& aId,
       
   937         TInt& aError );
       
   938 
       
   939     /**
       
   940      * Set global Id.
       
   941      *
       
   942      * @param aContentKey   Key of content to be updated.
       
   943      * @param aId           Global file id to be set.
       
   944      * @param aIndex        Index of content to be updated.
       
   945      * @param aError        Completion status.
       
   946      * @return KErrNone if successful, otherwise another of the system-wide
       
   947      *         error codes.
       
   948      */
       
   949     void SetGlobalIdL(
       
   950         TUint32 aContentKey,
       
   951         CIptvMyVideosGlobalFileId& aId,
       
   952         TUint32 aIndex,
       
   953         TInt& aError );
       
   954 
       
   955     /**
       
   956      * Deletes EPG-database from file system.
       
   957      */
       
   958     void DeleteDatabaseL();
       
   959 
       
   960 private: // Data
       
   961 
       
   962     /**
       
   963      * File system session.
       
   964      */
       
   965     RFs iFsSession;
       
   966 
       
   967     /**
       
   968      * Database file.
       
   969      */
       
   970     TFileName iEpgFile;
       
   971 
       
   972     /**
       
   973      * Database session.
       
   974      */
       
   975     RDbNamedDatabase iEpgDb;
       
   976 
       
   977     /**
       
   978      * Temporary database for update.
       
   979      */
       
   980     RDbNamedDatabase iTmpDb;
       
   981 
       
   982     /**
       
   983      * Temp database is open.
       
   984      */
       
   985     TBool iTmpDbOpen;
       
   986 
       
   987     /**
       
   988      * Category SQL-query.
       
   989      */
       
   990     TBuf<KCustomSqlMaxLength> iSqlCategory;
       
   991 
       
   992     /**
       
   993      * Content SQL-query.
       
   994      */
       
   995     TBuf<KCustomSqlMaxLength> iSqlContent;
       
   996 
       
   997     /**
       
   998      * Service id.
       
   999      */
       
  1000     TUint32 iServiceId;
       
  1001 
       
  1002     /**
       
  1003      * Temporary database name.
       
  1004      */
       
  1005     TBuf<KIptvDbNameMaxLength> iTmpDbName;
       
  1006 
       
  1007     /**
       
  1008      * Server.
       
  1009      */
       
  1010     CIptvServer& iServer;
       
  1011 
       
  1012     /**
       
  1013      * User age to check rating age limit limit.
       
  1014      */
       
  1015     TUint16 iParentalControl;
       
  1016 
       
  1017     /**
       
  1018      * Central Repository session.
       
  1019      */
       
  1020     CRepository* iCenRepSession;
       
  1021 
       
  1022     /**
       
  1023      * Central Repository handler.
       
  1024      */
       
  1025     CCenRepNotifyHandler* iCenRepNotifyHandler;
       
  1026 
       
  1027     /**
       
  1028      * Flag that tells if database is to be deleted from file system after close.
       
  1029      */
       
  1030     TBool iDeleteDatabaseFiles;
       
  1031 
       
  1032     };
       
  1033 
       
  1034 #endif // CIPTVEPGDB_H