upnpharvester/cdssync/cdssynclib/inc/cdssyncimplsql.h
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2008 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 "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:      Cds Sync Implementation Header
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 #ifndef __CDSSYNCIMPL_H__
       
    25 #define __CDSSYNCIMPL_H__
       
    26 
       
    27 #include <e32cons.h>
       
    28 #include <e32base.h> 
       
    29 #include <f32file.h>
       
    30 #include "cdssync.h"
       
    31 #include <xml/parser.h>
       
    32 #include <xml/contenthandler.h>
       
    33 
       
    34 // Forward declarations
       
    35 class CCdsSyncSqlAo;
       
    36 class MCmSqlMain;
       
    37 class CCmSqlPropertyItem;
       
    38 class CCmSqlGenericItem;
       
    39 class CCmSqlBaseItem;
       
    40 
       
    41 typedef RPointerArray<CCmSqlPropertyItem> CCmSqlPropertyItemArray;
       
    42 
       
    43 using namespace Xml;
       
    44 
       
    45 /**
       
    46  *  CItemResource class definition
       
    47  *
       
    48  *  @lib cdssync.lib
       
    49  *  @since S60 5.1
       
    50  */
       
    51 NONSHARABLE_CLASS( CItemResource ) : public CBase 
       
    52 {
       
    53 public:
       
    54     
       
    55     /**
       
    56      * Two-phased constructor.
       
    57      */
       
    58     static CItemResource* NewLC();
       
    59    
       
    60     /**
       
    61      * Two-phased constructor.
       
    62      */    
       
    63     static CItemResource* NewL();
       
    64     
       
    65     /**
       
    66      * Destructor
       
    67      */
       
    68     virtual ~CItemResource();
       
    69     
       
    70 private:
       
    71     /**
       
    72      * Performs the first phase of two phase construction.
       
    73      */
       
    74     CItemResource();
       
    75 
       
    76     /**
       
    77      * Performs the second phase construction.
       
    78      */    
       
    79     void ConstructL();
       
    80 
       
    81 public:
       
    82     /**
       
    83      * Track duration
       
    84      */
       
    85     HBufC8* iDuration;   // owned
       
    86     /**
       
    87      * Track bitrate
       
    88      */    
       
    89     HBufC8* iBitrate;    // owned
       
    90     /**
       
    91      * File size
       
    92      */
       
    93     HBufC8* iSize;       // owned
       
    94     /**
       
    95      * Item resolution
       
    96      */
       
    97     HBufC8* iResolution; // owned
       
    98     /**
       
    99      * Item uri
       
   100      */
       
   101     HBufC8* iUri;        // owned
       
   102     /**
       
   103      * Item protocol
       
   104      */
       
   105     HBufC8* iProtocol;   // owned
       
   106 };
       
   107 
       
   108 
       
   109 /**
       
   110  * CCdsSyncImpl class definition
       
   111  *
       
   112  * @lib cdssync.lib
       
   113  *
       
   114  * @since S60 5.1
       
   115  */    
       
   116 class CCdsSyncImpl : public CActive, 
       
   117                      public MContentHandler 
       
   118       {
       
   119 
       
   120 private:
       
   121 
       
   122     // Syncronization status
       
   123     enum TCdsSyncStatus
       
   124         {
       
   125         ECdsSyncIdle,
       
   126         ECdsSyncInitializing,
       
   127         ECdsSyncReadyToParse,
       
   128         ECdsSyncParsing,
       
   129         ECdsSyncFinalizing
       
   130         };
       
   131 
       
   132 public:
       
   133 
       
   134     /**
       
   135      * Two-phased constructor.
       
   136      */
       
   137     static CCdsSyncImpl* NewLC();
       
   138 
       
   139     /**
       
   140      * Two-phased constructor.
       
   141      */    
       
   142     static CCdsSyncImpl* NewL();
       
   143     
       
   144     /**
       
   145      * Destructor
       
   146      */    
       
   147     ~CCdsSyncImpl();
       
   148 
       
   149 public: // new functions    
       
   150 
       
   151     /**
       
   152      * Initializes data
       
   153      *
       
   154      * @Since S60 5.1
       
   155      * @param aSourceDataArray, source data
       
   156      * @param aDeviceId, device id where data is retrieved
       
   157      * @param aObserver, process observer
       
   158      * @param aAddGranularity, data granularity
       
   159      */    
       
   160     void InitL( RPointerArray<HBufC8>& aSourceDataArray,
       
   161                          const TInt& aDeviceId, 
       
   162                          MCdsSyncObserver& aObserver,
       
   163                          TInt aAddGranularity);
       
   164 
       
   165     /**
       
   166      * Notifies when data is added
       
   167      *
       
   168      * @Since S60 5.1
       
   169      * @param aSourceDataComplete, indicates if all source data is added
       
   170      */
       
   171     void NotifySourceDataAddedL( 
       
   172         TBool aSourceDataComplete = EFalse );
       
   173 
       
   174     /**
       
   175      * Cancels operation and cleans data
       
   176      *
       
   177      * @Since S60 5.1     
       
   178      */
       
   179     void ResetL();
       
   180     
       
   181     /**
       
   182      * Called when operation is completed
       
   183      *
       
   184      * @Since S60 5.1
       
   185      * @param aErrCode, error code
       
   186      */    
       
   187     void OperationsCompleteL( TInt aErrCode );
       
   188 
       
   189     /**
       
   190      * Notifies observer about progress
       
   191      *
       
   192      * @Since S60 5.1
       
   193      * @param aItemCount, processed items
       
   194      */
       
   195     void ProgressL( TInt aItemCount );
       
   196 
       
   197     /**
       
   198      * Returns the chunk count to be processed including current chunk
       
   199      *
       
   200      * @Since S60 5.1
       
   201      * @return TInt, chunk count
       
   202      */    
       
   203     TInt ChunkCount();
       
   204     
       
   205     /**
       
   206      * Returns successfully processed item count. 
       
   207      *
       
   208      * @since S60 5.1
       
   209      * @return TInt, count of items that has been processed successfully.
       
   210      */
       
   211     TInt ProcessedItemCount();
       
   212     
       
   213     /**
       
   214      * Sets search index to cds sync
       
   215      *
       
   216      * @since S60 5.1
       
   217      * @param aSearchIndex, search index
       
   218      */    
       
   219     void SetSearchIndex( const TInt aSearchIndex );    
       
   220     
       
   221     /**
       
   222      * Chunk complete callback
       
   223      *
       
   224      * @since S60 5.1
       
   225      */    
       
   226     void ChunkCompleteL();
       
   227 
       
   228 // From base class MContentHandler        
       
   229 
       
   230     /**
       
   231      * From MContentHandler
       
   232      * See base class definition
       
   233      */     
       
   234     void OnStartDocumentL( const RDocumentParameters& aDocParam, 
       
   235                            TInt aErrorCode );
       
   236     /**
       
   237      * From MContentHandler
       
   238      * See base class definition
       
   239      */
       
   240     void OnEndDocumentL( TInt aErrorCode );
       
   241     
       
   242     /**
       
   243      * From MContentHandler
       
   244      * See base class definition
       
   245      */
       
   246     void OnStartElementL( const RTagInfo& aElement, 
       
   247                           const RAttributeArray& aAttributes, 
       
   248                           TInt aErrorCode );
       
   249     
       
   250     /**
       
   251      * From MContentHandler
       
   252      * See base class definition
       
   253      */
       
   254     void OnEndElementL( const RTagInfo& aElement, TInt aErrorCode );
       
   255 
       
   256     /**
       
   257      * From MContentHandler
       
   258      * See base class definition
       
   259      */
       
   260     void OnContentL( const TDesC8& aBytes, TInt aErrorCode );
       
   261     
       
   262     /**
       
   263      * From MContentHandler
       
   264      * See base class definition
       
   265      */
       
   266     void OnStartPrefixMappingL( const RString& aPrefix, 
       
   267                                 const RString& aUri, 
       
   268                                 TInt aErrorCode);
       
   269     
       
   270     /**
       
   271      * From MContentHandler
       
   272      * See base class definition
       
   273      */
       
   274     void OnEndPrefixMappingL( const RString& aPrefix, TInt aErrorCode );
       
   275 
       
   276     /**
       
   277      * From MContentHandler
       
   278      * See base class definition
       
   279      */
       
   280     void OnIgnorableWhiteSpaceL( const TDesC8& aBytes, TInt aErrorCode );
       
   281 
       
   282     /**
       
   283      * From MContentHandler
       
   284      * See base class definition
       
   285      */
       
   286     void OnSkippedEntityL( const RString& aName, TInt aErrorCode );
       
   287 
       
   288     /**
       
   289      * From MContentHandler
       
   290      * See base class definition
       
   291      */
       
   292     void OnProcessingInstructionL( const TDesC8& aTarget, 
       
   293                                    const TDesC8& aData, 
       
   294                                    TInt aErrorCode);
       
   295     
       
   296     /**
       
   297      * From MContentHandler
       
   298      * See base class definition
       
   299      */
       
   300     void OnError( TInt aErrorCode );
       
   301 
       
   302     /**
       
   303      * From MContentHandler
       
   304      * See base class definition
       
   305      */
       
   306     TAny* GetExtendedInterface( const TInt32 aUid );
       
   307     
       
   308 // From base class CActive
       
   309 
       
   310     /**
       
   311      * From CActive
       
   312      * See base class definition
       
   313      */
       
   314     void RunL();
       
   315 
       
   316     /**
       
   317      * From CActive
       
   318      * See base class definition
       
   319      */    
       
   320     void DoCancel();
       
   321     
       
   322 private:
       
   323 
       
   324     /**
       
   325      * Performs the first phase of two phase construction.
       
   326      */    
       
   327     CCdsSyncImpl();
       
   328 
       
   329     /**
       
   330      * Performs the second phase construction.
       
   331      */        
       
   332     void ConstructL();
       
   333 
       
   334     /**
       
   335      * Parses profile id
       
   336      *
       
   337      * @since S60 5.1
       
   338      * @param aItem, item data
       
   339      * @param aRes, item resource
       
   340      */
       
   341     void ParseProfileIdL( CCmSqlGenericItem& aItem,
       
   342                           const CItemResource& aRes ) const;
       
   343         
       
   344     /**
       
   345      * Starts background parsing
       
   346      *
       
   347      * @since S60 5.1
       
   348      */
       
   349     TInt DoBackgroundParseL();
       
   350 
       
   351     /**
       
   352      * Background parsing callback
       
   353      *
       
   354      * @since S60 5.1
       
   355      * @param aCdsSync, observer
       
   356      */
       
   357     static TInt BackgroundParseL( TAny *aCdsSync );
       
   358 
       
   359     /**
       
   360      * Finds attributes
       
   361      *
       
   362      * @since S60 5.1
       
   363      * @param aName, local name
       
   364      * @param aPref, prefix
       
   365      * @param aAttributes, attribute array
       
   366      */
       
   367     TInt FindAttribute( const TDesC8& aName, 
       
   368                         const TDesC8& aPref, 
       
   369                         const RAttributeArray& aAttributes ) const;
       
   370     
       
   371     /**
       
   372      * Parses resolution information
       
   373      *
       
   374      * @since S60 5.1
       
   375      * @param aDes, buffer to be parsed
       
   376      * @param aWidth, image widht
       
   377      * @param aHeight, image height
       
   378      */
       
   379     void ParseResolution( const TDesC8& aDes,
       
   380                           TUint& aWidth,
       
   381                           TUint& aHeight ) const;
       
   382     
       
   383     /**
       
   384      * Parses value from descriptor
       
   385      *
       
   386      * @since S60 5.1
       
   387      * @param aDes, buffer to be parsed
       
   388      * @return TUInt, parsed value     
       
   389      */
       
   390     TUint ParseUint( const TDesC8& aDes ) const;
       
   391 
       
   392     /**
       
   393      * Parses value from descriptor
       
   394      *
       
   395      * @since S60 5.1
       
   396      * @param aDes, buffer to be parsed
       
   397      * @return TInt64, parsed value     
       
   398      */
       
   399     TInt64 ParseInt64( const TDesC8& aDes ) const;
       
   400 
       
   401     /**
       
   402      * Parses track duration
       
   403      *
       
   404      * @since S60 5.1
       
   405      * @param aDes, buffer to be parsed
       
   406      * @return TReal, duration
       
   407      */
       
   408     TReal ParseDuration( const TDesC8& aDes ) const;
       
   409 
       
   410     /**
       
   411      * Parses time
       
   412      *
       
   413      * @since S60 5.1
       
   414      * @param aDes, buffer to be parsed
       
   415      * @return TTime, parsed time
       
   416      */    
       
   417     TTime ParseTime( const TDesC8& aDes ) const;
       
   418 
       
   419     /**
       
   420      * Calculates hash value
       
   421      *
       
   422      * @since S60 5.1  
       
   423      * @return HBufC, hash value
       
   424      */
       
   425     HBufC8* CalculateHashL() const;
       
   426 
       
   427     /**
       
   428      * Append escpace characters to hash value
       
   429      *
       
   430      * @since S60 5.1
       
   431      * @param aHash, hash value
       
   432      * @return HBufC, hash value with escape charachters
       
   433      */
       
   434     HBufC* EscapeHashLC( const TDesC8& aHash ) const;
       
   435 
       
   436     /**
       
   437      * Gets property ID
       
   438      *
       
   439      * @since S60 5.1
       
   440      * @param aMetadataIndex, index for metadata type table
       
   441      * @param aValue, property name
       
   442      * @return TInt64, property id
       
   443      */
       
   444     TInt64 GetPropertyIdL( TInt aMetadataIndex, const TDesC8& aValue ) const;
       
   445 
       
   446     /**
       
   447      * Clears item data
       
   448      *
       
   449      * @since S60 5.1
       
   450      */
       
   451     void CleanItemData();
       
   452 
       
   453     /**
       
   454      * Removes unchanged items
       
   455      *
       
   456      * @since S60 5.1
       
   457      */
       
   458     void RemoveUnchangedItems();
       
   459 
       
   460     /**
       
   461      * Parses uri
       
   462      *
       
   463      * @since S60 5.1
       
   464      */
       
   465     void ParseUri();
       
   466      
       
   467 private:
       
   468 
       
   469     /**
       
   470      * Cds Sync observer
       
   471      */
       
   472     MCdsSyncObserver*   iObserver;                          // not owned
       
   473     /**
       
   474      * Parser
       
   475      */
       
   476     CParser*            iParser;                            // owned
       
   477     /**
       
   478      * Metadata database
       
   479      */
       
   480     MCmSqlMain*         iMetadataDb;                        // owned
       
   481     /**
       
   482      * Active object for low priority processing
       
   483      */
       
   484     CIdle*              iBackground;                        // owned
       
   485     /**
       
   486      * Cds Sync active object
       
   487      */
       
   488     CCdsSyncSqlAo*      iSqlAo;                             // owned
       
   489     /**
       
   490      * Data chuck
       
   491      */
       
   492     HBufC8* iCurrentDocument;                               // owned
       
   493     /**
       
   494      * Sync status
       
   495      */
       
   496     TCdsSyncStatus    iState;
       
   497     /**
       
   498      * Data buffer
       
   499      */
       
   500     HBufC8* iCurrentContent;                                // owned
       
   501     /**
       
   502      * Item id
       
   503      */    
       
   504     HBufC8* iItemId;                                        // owned
       
   505     /**
       
   506      * Artist name
       
   507      */
       
   508     HBufC8* iArtist;                                        // owned
       
   509     /**
       
   510      * Album name
       
   511      */
       
   512     HBufC8* iAlbum;                                         // owned
       
   513     /**
       
   514      * Title
       
   515      */
       
   516     HBufC8* iTitle;                                         // owned
       
   517     /**
       
   518      * Album class
       
   519      */
       
   520     HBufC8* iClass;                                         // owned
       
   521     /**
       
   522      * Music genre
       
   523      */    
       
   524     HBufC8* iGenre;                                         // owned
       
   525     /**
       
   526      * Album data
       
   527      */
       
   528     HBufC8* iDate;                                          // owned
       
   529     /**
       
   530      * Description field
       
   531      */
       
   532     HBufC8* iDescription;                                   // owned
       
   533     /**
       
   534      * Album art
       
   535      */
       
   536     HBufC8* iAlbumArtUri;                                   // owned
       
   537     /**
       
   538      * Item resource array
       
   539      */
       
   540     RPointerArray<CItemResource> iResources;                // items owned
       
   541     /**
       
   542      * Flag for indicating that source data is ready
       
   543      */
       
   544     TBool iSourceDataComplete;
       
   545     /**
       
   546      * Datachunk index
       
   547      */
       
   548     TInt iChunkIndex;
       
   549     /**
       
   550      * Amount of unchanged items
       
   551      */
       
   552     TInt iUnchangedItemCount;
       
   553     /**
       
   554      * Hash order
       
   555      */    
       
   556     TLinearOrder<CCmSqlBaseItem> iHashOrder;
       
   557     /**
       
   558      * Name order
       
   559      */
       
   560     TLinearOrder<CCmSqlPropertyItem> iNameOrder;
       
   561     /**
       
   562      * Source data array
       
   563      */
       
   564     RPointerArray<HBufC8>* iSourceDataArray;                // not owned
       
   565     /**
       
   566      * Name array
       
   567      */
       
   568     RPointerArray<CCmSqlPropertyItemArray> iNames;          // items owned
       
   569     /**
       
   570      * Array of items to add
       
   571      */
       
   572     RPointerArray<CCmSqlGenericItem> iItemsToAdd;           // items owned
       
   573     /**
       
   574      * Array of items in the database
       
   575      */
       
   576     RPointerArray<CCmSqlBaseItem> iItemsInDb;               // items owned
       
   577     /**
       
   578      * File server session
       
   579      */
       
   580     RFs iFs;
       
   581     /**
       
   582      * Search index
       
   583      */    
       
   584     TInt iSearchIndex;
       
   585     /**
       
   586      * Count of processed items
       
   587      */ 
       
   588     TInt iProcessedItems;
       
   589 #ifdef _DEBUG
       
   590     /**
       
   591      * Hash time
       
   592      */ 
       
   593     TInt64 iHashTime;
       
   594 #endif // _DEBUG
       
   595     };
       
   596 #endif // __CDSSYNCIMPL_H__