omadrm/drmengine/server/src/DRMReplayCache.cpp
changeset 23 493788a4a8a4
parent 0 95b198f216e5
equal deleted inserted replaced
5:79d62d1d7957 23:493788a4a8a4
    17 
    17 
    18 
    18 
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 
    20 
    21 #include <f32file.h>
    21 #include <f32file.h>
    22 #include <S32FILE.H>
    22 #include <s32file.h>
    23 #include <BAUTILS.H>
    23 #include <bautils.h>
    24 #include "drmreplaycache.h"
    24 #include "DRMReplayCache.h"
    25 
    25 
    26 
    26 
    27 // EXTERNAL DATA STRUCTURES
    27 // EXTERNAL DATA STRUCTURES
    28 
    28 
    29 // EXTERNAL FUNCTION PROTOTYPES  
    29 // EXTERNAL FUNCTION PROTOTYPES
    30 
    30 
    31 // CONSTANTS
    31 // CONSTANTS
    32 
    32 
    33 // MACROS
    33 // MACROS
    34 
    34 
    44 LOCAL_C const TUint8 KDbViewTimeOrdinal = 3;
    44 LOCAL_C const TUint8 KDbViewTimeOrdinal = 3;
    45 LOCAL_C const TUint8 KDbViewIDOrdinal = 1;
    45 LOCAL_C const TUint8 KDbViewIDOrdinal = 1;
    46 LOCAL_C const TUint16 KDbMaxNumOfItems = 100;
    46 LOCAL_C const TUint16 KDbMaxNumOfItems = 100;
    47 
    47 
    48 // MODULE DATA STRUCTURES
    48 // MODULE DATA STRUCTURES
    49 NONSHARABLE_STRUCT( TDoDeleteFile ) 
    49 NONSHARABLE_STRUCT( TDoDeleteFile )
    50     {
    50     {
    51     RFs* iFs;
    51     RFs* iFs;
    52     const TDesC* iFile;
    52     const TDesC* iFile;
    53     };
    53     };
    54     
    54 
    55 // LOCAL FUNCTION PROTOTYPES
    55 // LOCAL FUNCTION PROTOTYPES
    56 LOCAL_C void DoRollBack( TAny* aAny );
    56 LOCAL_C void DoRollBack( TAny* aAny );
    57 LOCAL_C void DoDeleteFile( TAny* aAny );
    57 LOCAL_C void DoDeleteFile( TAny* aAny );
    58 
    58 
    59 // FORWARD DECLARATIONS
    59 // FORWARD DECLARATIONS
    61 
    61 
    62 // ============================= LOCAL FUNCTIONS ===============================
    62 // ============================= LOCAL FUNCTIONS ===============================
    63 // -----------------------------------------------------------------------------
    63 // -----------------------------------------------------------------------------
    64 // DoRollBack
    64 // DoRollBack
    65 //
    65 //
    66 // Do a rollback operation to the RDbDatabase* 
    66 // Do a rollback operation to the RDbDatabase*
    67 // -----------------------------------------------------------------------------
    67 // -----------------------------------------------------------------------------
    68 //
    68 //
    69 LOCAL_C void DoRollBack( TAny* aAny )
    69 LOCAL_C void DoRollBack( TAny* aAny )
    70     {
    70     {
    71     reinterpret_cast< RDbDatabase* >( aAny )->Rollback();
    71     reinterpret_cast< RDbDatabase* >( aAny )->Rollback();
    78 // -----------------------------------------------------------------------------
    78 // -----------------------------------------------------------------------------
    79 //
    79 //
    80 LOCAL_C void DoDeleteFile( TAny* aAny )
    80 LOCAL_C void DoDeleteFile( TAny* aAny )
    81     {
    81     {
    82     TDoDeleteFile* s = reinterpret_cast< TDoDeleteFile* >( aAny );
    82     TDoDeleteFile* s = reinterpret_cast< TDoDeleteFile* >( aAny );
    83     
    83 
    84     s->iFs->Delete( *( s->iFile ) );    
    84     s->iFs->Delete( *( s->iFile ) );
    85     }
    85     }
    86 
    86 
    87 // ============================ MEMBER FUNCTIONS ===============================
    87 // ============================ MEMBER FUNCTIONS ===============================
    88 
    88 
    89 // -----------------------------------------------------------------------------
    89 // -----------------------------------------------------------------------------
    90 // RDRMReplayCache::RDRMReplayCache
    90 // RDRMReplayCache::RDRMReplayCache
    91 //
    91 //
    92 // Default constructor 
    92 // Default constructor
    93 // -----------------------------------------------------------------------------
    93 // -----------------------------------------------------------------------------
    94 //
    94 //
    95 RDRMReplayCache::RDRMReplayCache():
    95 RDRMReplayCache::RDRMReplayCache():
    96 iFs( NULL ),
    96 iFs( NULL ),
    97 iTimeDb(),
    97 iTimeDb(),
    98 iPlainDb()
    98 iPlainDb()
    99     {
    99     {
   100     // Nothing.    
   100     // Nothing.
   101     }
   101     }
   102 
   102 
   103 // -----------------------------------------------------------------------------
   103 // -----------------------------------------------------------------------------
   104 // RDRMReplayCache::RDRMReplayCache
   104 // RDRMReplayCache::RDRMReplayCache
   105 //
   105 //
   106 // Constructor 
   106 // Constructor
   107 // -----------------------------------------------------------------------------
   107 // -----------------------------------------------------------------------------
   108 //
   108 //
   109 RDRMReplayCache::RDRMReplayCache( RFs& aFs ) :
   109 RDRMReplayCache::RDRMReplayCache( RFs& aFs ) :
   110 iFs( &aFs ),
   110 iFs( &aFs ),
   111 iTimeDb(),
   111 iTimeDb(),
   112 iPlainDb()
   112 iPlainDb()
   113     {
   113     {
   114     // Nothing.
   114     // Nothing.
   115     }
   115     }
   116     
   116 
   117 
   117 
   118 // -----------------------------------------------------------------------------
   118 // -----------------------------------------------------------------------------
   119 // RDRMReplayCache::Set
   119 // RDRMReplayCache::Set
   120 //
   120 //
   121 // Set iFs to given aFs.
   121 // Set iFs to given aFs.
   122 // -----------------------------------------------------------------------------
   122 // -----------------------------------------------------------------------------
   123 //    
   123 //
   124 void RDRMReplayCache::Set( RFs& aFs )
   124 void RDRMReplayCache::Set( RFs& aFs )
   125     {
   125     {
   126     iFs = &aFs;
   126     iFs = &aFs;
   127     }
   127     }
   128 
   128 
   129 // -----------------------------------------------------------------------------
   129 // -----------------------------------------------------------------------------
   130 // RDRMReplayCache::Close
   130 // RDRMReplayCache::Close
   131 //
   131 //
   132 // Closes the databases.
   132 // Closes the databases.
   133 // -----------------------------------------------------------------------------
   133 // -----------------------------------------------------------------------------
   134 //    
   134 //
   135 void RDRMReplayCache::Close()
   135 void RDRMReplayCache::Close()
   136     {
   136     {
   137     // iView.Close();
   137     // iView.Close();
   138     iTimeDb.Close();
   138     iTimeDb.Close();
   139     iPlainDb.Close();
   139     iPlainDb.Close();
   142 // -----------------------------------------------------------------------------
   142 // -----------------------------------------------------------------------------
   143 // RDRMReplayCache::InitL
   143 // RDRMReplayCache::InitL
   144 //
   144 //
   145 // Initialize the databases.
   145 // Initialize the databases.
   146 // -----------------------------------------------------------------------------
   146 // -----------------------------------------------------------------------------
   147 //    
   147 //
   148 void RDRMReplayCache::InitL( const TDesC& aTimedDb,
   148 void RDRMReplayCache::InitL( const TDesC& aTimedDb,
   149                              const TDesC& aPlainDb )
   149                              const TDesC& aPlainDb )
   150     {
   150     {
   151     InitDbL( iTimeDb, aTimedDb, ETimeDb );
   151     InitDbL( iTimeDb, aTimedDb, ETimeDb );
   152     InitDbL( iPlainDb, aPlainDb, EPlainDb );
   152     InitDbL( iPlainDb, aPlainDb, EPlainDb );
   157 // RDRMReplayCache::InCacheL
   157 // RDRMReplayCache::InCacheL
   158 //
   158 //
   159 // Check whether the given entry is in cache. Overloaded.
   159 // Check whether the given entry is in cache. Overloaded.
   160 // -----------------------------------------------------------------------------
   160 // -----------------------------------------------------------------------------
   161 //
   161 //
   162 TBool RDRMReplayCache::InCacheL( const TDesC8& aID, 
   162 TBool RDRMReplayCache::InCacheL( const TDesC8& aID,
   163                                  const TTime& aTime )
   163                                  const TTime& aTime )
   164     {
   164     {
   165     TBool res = EFalse;
   165     TBool res = EFalse;
   166     
   166 
   167     RDbView view;
   167     RDbView view;
   168     InitViewLC( view, ETimeDb, EFalse );
   168     InitViewLC( view, ETimeDb, EFalse );
   169     
   169 
   170     view.FirstL();
   170     view.FirstL();
   171     
   171 
   172     while ( view.AtRow() && !res )
   172     while ( view.AtRow() && !res )
   173         {
   173         {
   174         view.GetL();
   174         view.GetL();
   175         TTime time = view.ColInt64( KDbViewTimeOrdinal );
   175         TTime time = view.ColInt64( KDbViewTimeOrdinal );
   176 
   176 
   178             {
   178             {
   179             res = CompareCIDL( view, aID );
   179             res = CompareCIDL( view, aID );
   180             }
   180             }
   181         view.NextL();
   181         view.NextL();
   182         }
   182         }
   183         
   183 
   184     CleanupStack::PopAndDestroy(); // view
   184     CleanupStack::PopAndDestroy(); // view
   185     
   185 
   186     return res;
   186     return res;
   187     }
   187     }
   188 
   188 
   189 // -----------------------------------------------------------------------------
   189 // -----------------------------------------------------------------------------
   190 // RDRMReplayCache::InCacheL
   190 // RDRMReplayCache::InCacheL
   191 //
   191 //
   192 // Check whether the given entry is in cache. Overloaded.
   192 // Check whether the given entry is in cache. Overloaded.
   193 // -----------------------------------------------------------------------------
   193 // -----------------------------------------------------------------------------
   194 //   
   194 //
   195 TBool RDRMReplayCache::InCacheL( const TDesC8& aID )
   195 TBool RDRMReplayCache::InCacheL( const TDesC8& aID )
   196     {
   196     {
   197     TBool res = EFalse;
   197     TBool res = EFalse;
   198     
   198 
   199     RDbView view;
   199     RDbView view;
   200     InitViewLC( view, EPlainDb, EFalse );
   200     InitViewLC( view, EPlainDb, EFalse );
   201     
   201 
   202     view.FirstL();
   202     view.FirstL();
   203     
   203 
   204     while ( view.AtRow() && !res )
   204     while ( view.AtRow() && !res )
   205         {
   205         {
   206         view.GetL();
   206         view.GetL();
   207         
   207 
   208         res = CompareCIDL( view, aID );
   208         res = CompareCIDL( view, aID );
   209         
   209 
   210         view.NextL();
   210         view.NextL();
   211         }
   211         }
   212         
   212 
   213     CleanupStack::PopAndDestroy(); // view
   213     CleanupStack::PopAndDestroy(); // view
   214     
   214 
   215     return res;
   215     return res;
   216     }
   216     }
   217 
   217 
   218 // -----------------------------------------------------------------------------
   218 // -----------------------------------------------------------------------------
   219 // RDRMReplayCache::AddL
   219 // RDRMReplayCache::AddL
   220 //
   220 //
   221 // Add an entry to the database. Overloaded.
   221 // Add an entry to the database. Overloaded.
   222 // -----------------------------------------------------------------------------
   222 // -----------------------------------------------------------------------------
   223 //    
   223 //
   224 void RDRMReplayCache::AddL( const TDesC8& aID, 
   224 void RDRMReplayCache::AddL( const TDesC8& aID,
   225                             const TTime& aTime,
   225                             const TTime& aTime,
   226                             const TTime& aInsertionTime )
   226                             const TTime& aInsertionTime )
   227     {
   227     {
   228     RDbColWriteStream stream;
   228     RDbColWriteStream stream;
   229     RDbView view;
   229     RDbView view;
   230         
   230 
   231     PushL( iTimeDb );
   231     PushL( iTimeDb );
   232     
   232 
   233     InitViewLC( view, ETimeDb, ETrue );
   233     InitViewLC( view, ETimeDb, ETrue );
   234     CompactViewL( view );
   234     CompactViewL( view );
   235 
   235 
   236     // Oldest ones are in the list earlier, and as long as clock works 
   236     // Oldest ones are in the list earlier, and as long as clock works
   237     // correctly, insertiontime(n-1)<insertiontime(n).
   237     // correctly, insertiontime(n-1)<insertiontime(n).
   238     view.EndL();
   238     view.EndL();
   239     
   239 
   240     User::LeaveIfError( iTimeDb.Begin() );
   240     User::LeaveIfError( iTimeDb.Begin() );
   241     
   241 
   242     view.InsertL(); 
   242     view.InsertL();
   243     
   243 
   244     InsertIdL( view, aID );
   244     InsertIdL( view, aID );
   245     view.SetColL( KDbViewInsertionTimeOrdinal, aInsertionTime.Int64() );
   245     view.SetColL( KDbViewInsertionTimeOrdinal, aInsertionTime.Int64() );
   246     view.SetColL( KDbViewTimeOrdinal, aTime.Int64() );
   246     view.SetColL( KDbViewTimeOrdinal, aTime.Int64() );
   247     
   247 
   248     view.PutL();
   248     view.PutL();
   249     
   249 
   250     CleanupStack::PopAndDestroy(); // view
   250     CleanupStack::PopAndDestroy(); // view
   251     
   251 
   252     User::LeaveIfError( iTimeDb.Commit() );
   252     User::LeaveIfError( iTimeDb.Commit() );
   253     User::LeaveIfError( iTimeDb.Compact() );
   253     User::LeaveIfError( iTimeDb.Compact() );
   254     
   254 
   255     Pop(); // iTimeDb
   255     Pop(); // iTimeDb
   256     }
   256     }
   257     
   257 
   258 // -----------------------------------------------------------------------------
   258 // -----------------------------------------------------------------------------
   259 // RDRMReplayCache::AddL
   259 // RDRMReplayCache::AddL
   260 //
   260 //
   261 // Add an entry to the database. Overloaded.
   261 // Add an entry to the database. Overloaded.
   262 // -----------------------------------------------------------------------------
   262 // -----------------------------------------------------------------------------
   263 //   
   263 //
   264 void RDRMReplayCache::AddL( const TDesC8& aID,
   264 void RDRMReplayCache::AddL( const TDesC8& aID,
   265                             const TTime& aInsertionTime )
   265                             const TTime& aInsertionTime )
   266     {
   266     {
   267     
   267 
   268     RDbView view;
   268     RDbView view;
   269     
   269 
   270     PushL( iPlainDb );
   270     PushL( iPlainDb );
   271     
   271 
   272     InitViewLC( view, EPlainDb, ETrue );
   272     InitViewLC( view, EPlainDb, ETrue );
   273     CompactViewL( view );
   273     CompactViewL( view );
   274     
   274 
   275     view .EndL();
   275     view .EndL();
   276     
   276 
   277     User::LeaveIfError( iPlainDb.Begin() );
   277     User::LeaveIfError( iPlainDb.Begin() );
   278     
   278 
   279     view.InsertL();
   279     view.InsertL();
   280     InsertIdL( view, aID );
   280     InsertIdL( view, aID );
   281     view.SetColL( KDbViewInsertionTimeOrdinal, aInsertionTime.Int64() );
   281     view.SetColL( KDbViewInsertionTimeOrdinal, aInsertionTime.Int64() );
   282     
   282 
   283     view.PutL();
   283     view.PutL();
   284     
   284 
   285     CleanupStack::PopAndDestroy(); // view
   285     CleanupStack::PopAndDestroy(); // view
   286     
   286 
   287     User::LeaveIfError( iPlainDb.Commit() );
   287     User::LeaveIfError( iPlainDb.Commit() );
   288     User::LeaveIfError( iPlainDb.Compact() );
   288     User::LeaveIfError( iPlainDb.Compact() );
   289     
   289 
   290     Pop(); // iPlainDb
   290     Pop(); // iPlainDb
   291     }
   291     }
   292 
   292 
   293 // -----------------------------------------------------------------------------
   293 // -----------------------------------------------------------------------------
   294 // RDRMReplayCache::InitDbL
   294 // RDRMReplayCache::InitDbL
   295 //
   295 //
   296 // Initialize the databases.
   296 // Initialize the databases.
   297 // -----------------------------------------------------------------------------
   297 // -----------------------------------------------------------------------------
   298 //       
   298 //
   299 void RDRMReplayCache::InitDbL( RDbNamedDatabase& aDb, 
   299 void RDRMReplayCache::InitDbL( RDbNamedDatabase& aDb,
   300                                const TDesC& aFileName,
   300                                const TDesC& aFileName,
   301                                TDatabaseId aId )
   301                                TDatabaseId aId )
   302     {
   302     {
   303     TInt error = KErrNone;
   303     TInt error = KErrNone;
   304     TBool exists = BaflUtils::FileExists( *iFs, aFileName );
   304     TBool exists = BaflUtils::FileExists( *iFs, aFileName );
   305     
   305 
   306     if ( exists )
   306     if ( exists )
   307         {
   307         {
   308         TRAP( error, OpenDbL( aDb, aFileName ) );
   308         TRAP( error, OpenDbL( aDb, aFileName ) );
   309         }
   309         }
   310     if ( error || !exists )
   310     if ( error || !exists )
   311         {
   311         {
   312         ReplaceDbL( aDb, aFileName, aId );
   312         ReplaceDbL( aDb, aFileName, aId );
   313         }
   313         }
   314     }
   314     }
   315     
   315 
   316 // -----------------------------------------------------------------------------
   316 // -----------------------------------------------------------------------------
   317 // RDRMReplayCache::~RDRMReplayCache
   317 // RDRMReplayCache::~RDRMReplayCache
   318 //
   318 //
   319 // Destructor.
   319 // Destructor.
   320 // -----------------------------------------------------------------------------
   320 // -----------------------------------------------------------------------------
   321 //   
   321 //
   322 RDRMReplayCache::~RDRMReplayCache()
   322 RDRMReplayCache::~RDRMReplayCache()
   323     {
   323     {
   324     }
   324     }
   325 
   325 
   326 // -----------------------------------------------------------------------------
   326 // -----------------------------------------------------------------------------
   327 // RDRMReplayCache::OpenDbL
   327 // RDRMReplayCache::OpenDbL
   328 //
   328 //
   329 // Open the database.
   329 // Open the database.
   330 // -----------------------------------------------------------------------------
   330 // -----------------------------------------------------------------------------
   331 //   
   331 //
   332 void RDRMReplayCache::OpenDbL( RDbNamedDatabase& aDb, 
   332 void RDRMReplayCache::OpenDbL( RDbNamedDatabase& aDb,
   333                                const TDesC& aFileName )
   333                                const TDesC& aFileName )
   334     {
   334     {
   335     CDbTableNames* tables = NULL;
   335     CDbTableNames* tables = NULL;
   336     
   336 
   337     User::LeaveIfError( aDb.Open( *iFs, aFileName ) );
   337     User::LeaveIfError( aDb.Open( *iFs, aFileName ) );
   338     CleanupClosePushL( aDb );
   338     CleanupClosePushL( aDb );
   339     
   339 
   340     if ( aDb.IsDamaged() )
   340     if ( aDb.IsDamaged() )
   341         {
   341         {
   342         User::LeaveIfError( aDb.Recover() );
   342         User::LeaveIfError( aDb.Recover() );
   343         }
   343         }
   344         
   344 
   345     // Sanity check.
   345     // Sanity check.
   346     tables = aDb.TableNamesL();
   346     tables = aDb.TableNamesL();
   347     CleanupStack::PushL( tables );
   347     CleanupStack::PushL( tables );
   348     
   348 
   349     if ( tables->Count() != 1 || ( *tables )[ 0 ].Compare( KReplayCacheTable ) )
   349     if ( tables->Count() != 1 || ( *tables )[ 0 ].Compare( KReplayCacheTable ) )
   350         {
   350         {
   351         User::Leave( KErrCorrupt );
   351         User::Leave( KErrCorrupt );
   352         }
   352         }
   353     
   353 
   354     CleanupStack::PopAndDestroy(); // tables
   354     CleanupStack::PopAndDestroy(); // tables
   355     CleanupStack::Pop(); // aDb
   355     CleanupStack::Pop(); // aDb
   356     }
   356     }
   357 
   357 
   358 // -----------------------------------------------------------------------------
   358 // -----------------------------------------------------------------------------
   359 // RDRMReplayCache::ReplaceDbL
   359 // RDRMReplayCache::ReplaceDbL
   360 //
   360 //
   361 // Replace the database.
   361 // Replace the database.
   362 // -----------------------------------------------------------------------------
   362 // -----------------------------------------------------------------------------
   363 //       
   363 //
   364 void RDRMReplayCache::ReplaceDbL( RDbNamedDatabase& aDb, 
   364 void RDRMReplayCache::ReplaceDbL( RDbNamedDatabase& aDb,
   365                                   const TDesC& aFileName, 
   365                                   const TDesC& aFileName,
   366                                   TDatabaseId aId )
   366                                   TDatabaseId aId )
   367     {
   367     {
   368     CDbColSet*  colSet = NULL;
   368     CDbColSet*  colSet = NULL;
   369 //    CDbKey* key = NULL;
   369 //    CDbKey* key = NULL;
   370     TDbCol cidCol( KCIDColName, EDbColLongText8 );
   370     TDbCol cidCol( KCIDColName, EDbColLongText8 );
   371     TDbCol insertionTimeCol( KInsertionTimeColName, EDbColInt64 );
   371     TDbCol insertionTimeCol( KInsertionTimeColName, EDbColInt64 );
   372     TDbCol timeCol( KTimeColName, EDbColInt64 );
   372     TDbCol timeCol( KTimeColName, EDbColInt64 );
   373     
   373 
   374     TDoDeleteFile deletefile = { iFs, &aFileName };
   374     TDoDeleteFile deletefile = { iFs, &aFileName };
   375     
   375 
   376     TCleanupItem item( DoDeleteFile, &deletefile );
   376     TCleanupItem item( DoDeleteFile, &deletefile );
   377     CleanupStack::PushL( item );
   377     CleanupStack::PushL( item );
   378     
   378 
   379     User::LeaveIfError( aDb.Replace( *iFs, aFileName ) );
   379     User::LeaveIfError( aDb.Replace( *iFs, aFileName ) );
   380     CleanupClosePushL( aDb );
   380     CleanupClosePushL( aDb );
   381     
   381 
   382     // Add columns
   382     // Add columns
   383     colSet = CDbColSet::NewLC();
   383     colSet = CDbColSet::NewLC();
   384     colSet->AddL( cidCol );
   384     colSet->AddL( cidCol );
   385     colSet->AddL( insertionTimeCol );
   385     colSet->AddL( insertionTimeCol );
   386     
   386 
   387     if ( aId == ETimeDb )
   387     if ( aId == ETimeDb )
   388         {
   388         {
   389         colSet->AddL( timeCol );
   389         colSet->AddL( timeCol );
   390         }
   390         }
   391     
   391 
   392     User::LeaveIfError( aDb.Begin() );
   392     User::LeaveIfError( aDb.Begin() );
   393     User::LeaveIfError( aDb.CreateTable( KReplayCacheTable, *colSet ) );
   393     User::LeaveIfError( aDb.CreateTable( KReplayCacheTable, *colSet ) );
   394     User::LeaveIfError( aDb.Commit() );
   394     User::LeaveIfError( aDb.Commit() );
   395     
   395 
   396     CleanupStack::PopAndDestroy(); // colSet
   396     CleanupStack::PopAndDestroy(); // colSet
   397     CleanupStack::Pop(); // aDb    
   397     CleanupStack::Pop(); // aDb
   398     CleanupStack::Pop(); // item
   398     CleanupStack::Pop(); // item
   399     }
   399     }
   400     
   400 
   401 // -----------------------------------------------------------------------------
   401 // -----------------------------------------------------------------------------
   402 // RDRMReplayCache::InitViewLC
   402 // RDRMReplayCache::InitViewLC
   403 //
   403 //
   404 // Initialize the view.
   404 // Initialize the view.
   405 // -----------------------------------------------------------------------------
   405 // -----------------------------------------------------------------------------
   406 //   
   406 //
   407 void RDRMReplayCache::InitViewLC( RDbView& aView, 
   407 void RDRMReplayCache::InitViewLC( RDbView& aView,
   408                                   TDatabaseId aId, 
   408                                   TDatabaseId aId,
   409                                   TBool aUpdate )
   409                                   TBool aUpdate )
   410     {
   410     {
   411     RDbDatabase* db = ( aId ==  ETimeDb ? &iTimeDb : &iPlainDb );
   411     RDbDatabase* db = ( aId ==  ETimeDb ? &iTimeDb : &iPlainDb );
   412     
   412 
   413     User::LeaveIfError( 
   413     User::LeaveIfError(
   414         aView.Prepare( *db, 
   414         aView.Prepare( *db,
   415                        TDbQuery( KViewInitQuery, EDbCompareCollated ), 
   415                        TDbQuery( KViewInitQuery, EDbCompareCollated ),
   416                        aUpdate ? RDbRowSet::EUpdatable : RDbRowSet::EReadOnly ) );
   416                        aUpdate ? RDbRowSet::EUpdatable : RDbRowSet::EReadOnly ) );
   417     
   417 
   418     CleanupClosePushL( aView );
   418     CleanupClosePushL( aView );
   419     
   419 
   420     User::LeaveIfError( aView.EvaluateAll() );
   420     User::LeaveIfError( aView.EvaluateAll() );
   421     }
   421     }
   422     
   422 
   423 // -----------------------------------------------------------------------------
   423 // -----------------------------------------------------------------------------
   424 // RDRMReplayCache::CompareCIDL
   424 // RDRMReplayCache::CompareCIDL
   425 //
   425 //
   426 // Compare whether the rowset's CID matches the given CID.
   426 // Compare whether the rowset's CID matches the given CID.
   427 // -----------------------------------------------------------------------------
   427 // -----------------------------------------------------------------------------
   428 //       
   428 //
   429 TBool RDRMReplayCache::CompareCIDL( RDbRowSet& aView, 
   429 TBool RDRMReplayCache::CompareCIDL( RDbRowSet& aView,
   430                                     const TDesC8& aCID )
   430                                     const TDesC8& aCID )
   431     {
   431     {
   432     TBool res = EFalse;
   432     TBool res = EFalse;
   433     
   433 
   434     TInt size = aView.ColLength( KDbViewIDOrdinal );
   434     TInt size = aView.ColLength( KDbViewIDOrdinal );
   435     
   435 
   436     RDbColReadStream colData;
   436     RDbColReadStream colData;
   437     colData.OpenLC( aView, KDbViewIDOrdinal );
   437     colData.OpenLC( aView, KDbViewIDOrdinal );
   438     
   438 
   439     // The data contains also the cardinality of the CID data, but anyway... 
   439     // The data contains also the cardinality of the CID data, but anyway...
   440     HBufC8* des = HBufC8::NewLC( colData, size );
   440     HBufC8* des = HBufC8::NewLC( colData, size );
   441 
   441 
   442     if ( aCID.CompareC( *des ) == 0 )
   442     if ( aCID.CompareC( *des ) == 0 )
   443         {
   443         {
   444         res = ETrue;
   444         res = ETrue;
   445         }
   445         }
   446     
   446 
   447     CleanupStack::PopAndDestroy(); // des
   447     CleanupStack::PopAndDestroy(); // des
   448     CleanupStack::PopAndDestroy(); // colData
   448     CleanupStack::PopAndDestroy(); // colData
   449     
   449 
   450     return res;
   450     return res;
   451     }
   451     }
   452     
   452 
   453 // -----------------------------------------------------------------------------
   453 // -----------------------------------------------------------------------------
   454 // RDRMReplayCache::PushL
   454 // RDRMReplayCache::PushL
   455 //
   455 //
   456 // Push a cleanup item to cleanup stack.
   456 // Push a cleanup item to cleanup stack.
   457 // -----------------------------------------------------------------------------
   457 // -----------------------------------------------------------------------------
   458 //   
   458 //
   459 void RDRMReplayCache::PushL( RDbDatabase& aDb )
   459 void RDRMReplayCache::PushL( RDbDatabase& aDb )
   460     {
   460     {
   461     TCleanupItem item( DoRollBack, &aDb );
   461     TCleanupItem item( DoRollBack, &aDb );
   462     CleanupStack::PushL( item );
   462     CleanupStack::PushL( item );
   463     }
   463     }
   465 // -----------------------------------------------------------------------------
   465 // -----------------------------------------------------------------------------
   466 // RDRMReplayCache::Pop
   466 // RDRMReplayCache::Pop
   467 //
   467 //
   468 // Pop a cleanup item pushed in by PushL.
   468 // Pop a cleanup item pushed in by PushL.
   469 // -----------------------------------------------------------------------------
   469 // -----------------------------------------------------------------------------
   470 //       
   470 //
   471 void RDRMReplayCache::Pop()
   471 void RDRMReplayCache::Pop()
   472     {
   472     {
   473     CleanupStack::Pop();
   473     CleanupStack::Pop();
   474     }
   474     }
   475 
   475 
   476 // -----------------------------------------------------------------------------
   476 // -----------------------------------------------------------------------------
   477 // RDRMReplayCache::DeleteOldestL
   477 // RDRMReplayCache::DeleteOldestL
   478 //
   478 //
   479 // Delete aHowMany entries from the view.
   479 // Delete aHowMany entries from the view.
   480 // -----------------------------------------------------------------------------
   480 // -----------------------------------------------------------------------------
   481 //       
   481 //
   482 void RDRMReplayCache::DeleteOldestsL( RDbRowSet& aView, TInt16 aHowMany )
   482 void RDRMReplayCache::DeleteOldestsL( RDbRowSet& aView, TInt16 aHowMany )
   483     {
   483     {
   484     aView.FirstL();
   484     aView.FirstL();
   485     
   485 
   486     while ( aHowMany > 0 )
   486     while ( aHowMany > 0 )
   487         {
   487         {
   488         aView.DeleteL();
   488         aView.DeleteL();
   489         aView.NextL();
   489         aView.NextL();
   490         --aHowMany;
   490         --aHowMany;
   494 // -----------------------------------------------------------------------------
   494 // -----------------------------------------------------------------------------
   495 // RDRMReplayCache::CompactViewL
   495 // RDRMReplayCache::CompactViewL
   496 //
   496 //
   497 // Compact the view, deleting items if necessary.
   497 // Compact the view, deleting items if necessary.
   498 // -----------------------------------------------------------------------------
   498 // -----------------------------------------------------------------------------
   499 //       
   499 //
   500 void RDRMReplayCache::CompactViewL( RDbRowSet& aView )
   500 void RDRMReplayCache::CompactViewL( RDbRowSet& aView )
   501     {
   501     {
   502     TInt count = aView.CountL();
   502     TInt count = aView.CountL();
   503     
   503 
   504     if ( count >= KDbMaxNumOfItems )
   504     if ( count >= KDbMaxNumOfItems )
   505         {
   505         {
   506         // usually only one item is deleted, no need to use Begin/Commit.
   506         // usually only one item is deleted, no need to use Begin/Commit.
   507         DeleteOldestsL( aView, static_cast< TInt >( KDbMaxNumOfItems ) - count + 1 );
   507         DeleteOldestsL( aView, static_cast< TInt >( KDbMaxNumOfItems ) - count + 1 );
   508         }
   508         }
   511 // -----------------------------------------------------------------------------
   511 // -----------------------------------------------------------------------------
   512 // RDRMReplayCache::InsertIdL
   512 // RDRMReplayCache::InsertIdL
   513 //
   513 //
   514 // Insert content-ID to the view.
   514 // Insert content-ID to the view.
   515 // -----------------------------------------------------------------------------
   515 // -----------------------------------------------------------------------------
   516 //       
   516 //
   517 void RDRMReplayCache::InsertIdL( RDbRowSet& aView, 
   517 void RDRMReplayCache::InsertIdL( RDbRowSet& aView,
   518                                  const TDesC8& aId )
   518                                  const TDesC8& aId )
   519     {
   519     {
   520     
   520 
   521     RDbColWriteStream stream;
   521     RDbColWriteStream stream;
   522     stream.OpenLC( aView, KDbViewIDOrdinal );
   522     stream.OpenLC( aView, KDbViewIDOrdinal );
   523     stream << aId;
   523     stream << aId;
   524     
   524 
   525     stream.CommitL();
   525     stream.CommitL();
   526     CleanupStack::PopAndDestroy(); // stream
   526     CleanupStack::PopAndDestroy(); // stream
   527     }
   527     }
   528     
   528 
   529 // End of File
   529 // End of File