omadrm/drmengine/server/src/DRMReplayCache.cpp
branchRCL_3
changeset 12 8a03a285ab14
parent 0 95b198f216e5
--- a/omadrm/drmengine/server/src/DRMReplayCache.cpp	Fri Mar 12 15:43:46 2010 +0200
+++ b/omadrm/drmengine/server/src/DRMReplayCache.cpp	Mon Mar 15 12:41:43 2010 +0200
@@ -19,14 +19,14 @@
 // INCLUDE FILES
 
 #include <f32file.h>
-#include <S32FILE.H>
-#include <BAUTILS.H>
-#include "drmreplaycache.h"
+#include <s32file.h>
+#include <bautils.h>
+#include "DRMReplayCache.h"
 
 
 // EXTERNAL DATA STRUCTURES
 
-// EXTERNAL FUNCTION PROTOTYPES  
+// EXTERNAL FUNCTION PROTOTYPES
 
 // CONSTANTS
 
@@ -46,12 +46,12 @@
 LOCAL_C const TUint16 KDbMaxNumOfItems = 100;
 
 // MODULE DATA STRUCTURES
-NONSHARABLE_STRUCT( TDoDeleteFile ) 
+NONSHARABLE_STRUCT( TDoDeleteFile )
     {
     RFs* iFs;
     const TDesC* iFile;
     };
-    
+
 // LOCAL FUNCTION PROTOTYPES
 LOCAL_C void DoRollBack( TAny* aAny );
 LOCAL_C void DoDeleteFile( TAny* aAny );
@@ -63,7 +63,7 @@
 // -----------------------------------------------------------------------------
 // DoRollBack
 //
-// Do a rollback operation to the RDbDatabase* 
+// Do a rollback operation to the RDbDatabase*
 // -----------------------------------------------------------------------------
 //
 LOCAL_C void DoRollBack( TAny* aAny )
@@ -80,8 +80,8 @@
 LOCAL_C void DoDeleteFile( TAny* aAny )
     {
     TDoDeleteFile* s = reinterpret_cast< TDoDeleteFile* >( aAny );
-    
-    s->iFs->Delete( *( s->iFile ) );    
+
+    s->iFs->Delete( *( s->iFile ) );
     }
 
 // ============================ MEMBER FUNCTIONS ===============================
@@ -89,7 +89,7 @@
 // -----------------------------------------------------------------------------
 // RDRMReplayCache::RDRMReplayCache
 //
-// Default constructor 
+// Default constructor
 // -----------------------------------------------------------------------------
 //
 RDRMReplayCache::RDRMReplayCache():
@@ -97,13 +97,13 @@
 iTimeDb(),
 iPlainDb()
     {
-    // Nothing.    
+    // Nothing.
     }
 
 // -----------------------------------------------------------------------------
 // RDRMReplayCache::RDRMReplayCache
 //
-// Constructor 
+// Constructor
 // -----------------------------------------------------------------------------
 //
 RDRMReplayCache::RDRMReplayCache( RFs& aFs ) :
@@ -113,14 +113,14 @@
     {
     // Nothing.
     }
-    
+
 
 // -----------------------------------------------------------------------------
 // RDRMReplayCache::Set
 //
 // Set iFs to given aFs.
 // -----------------------------------------------------------------------------
-//    
+//
 void RDRMReplayCache::Set( RFs& aFs )
     {
     iFs = &aFs;
@@ -131,7 +131,7 @@
 //
 // Closes the databases.
 // -----------------------------------------------------------------------------
-//    
+//
 void RDRMReplayCache::Close()
     {
     // iView.Close();
@@ -144,7 +144,7 @@
 //
 // Initialize the databases.
 // -----------------------------------------------------------------------------
-//    
+//
 void RDRMReplayCache::InitL( const TDesC& aTimedDb,
                              const TDesC& aPlainDb )
     {
@@ -159,16 +159,16 @@
 // Check whether the given entry is in cache. Overloaded.
 // -----------------------------------------------------------------------------
 //
-TBool RDRMReplayCache::InCacheL( const TDesC8& aID, 
+TBool RDRMReplayCache::InCacheL( const TDesC8& aID,
                                  const TTime& aTime )
     {
     TBool res = EFalse;
-    
+
     RDbView view;
     InitViewLC( view, ETimeDb, EFalse );
-    
+
     view.FirstL();
-    
+
     while ( view.AtRow() && !res )
         {
         view.GetL();
@@ -180,9 +180,9 @@
             }
         view.NextL();
         }
-        
+
     CleanupStack::PopAndDestroy(); // view
-    
+
     return res;
     }
 
@@ -191,27 +191,27 @@
 //
 // Check whether the given entry is in cache. Overloaded.
 // -----------------------------------------------------------------------------
-//   
+//
 TBool RDRMReplayCache::InCacheL( const TDesC8& aID )
     {
     TBool res = EFalse;
-    
+
     RDbView view;
     InitViewLC( view, EPlainDb, EFalse );
-    
+
     view.FirstL();
-    
+
     while ( view.AtRow() && !res )
         {
         view.GetL();
-        
+
         res = CompareCIDL( view, aID );
-        
+
         view.NextL();
         }
-        
+
     CleanupStack::PopAndDestroy(); // view
-    
+
     return res;
     }
 
@@ -220,73 +220,73 @@
 //
 // Add an entry to the database. Overloaded.
 // -----------------------------------------------------------------------------
-//    
-void RDRMReplayCache::AddL( const TDesC8& aID, 
+//
+void RDRMReplayCache::AddL( const TDesC8& aID,
                             const TTime& aTime,
                             const TTime& aInsertionTime )
     {
     RDbColWriteStream stream;
     RDbView view;
-        
+
     PushL( iTimeDb );
-    
+
     InitViewLC( view, ETimeDb, ETrue );
     CompactViewL( view );
 
-    // Oldest ones are in the list earlier, and as long as clock works 
+    // Oldest ones are in the list earlier, and as long as clock works
     // correctly, insertiontime(n-1)<insertiontime(n).
     view.EndL();
-    
+
     User::LeaveIfError( iTimeDb.Begin() );
-    
-    view.InsertL(); 
-    
+
+    view.InsertL();
+
     InsertIdL( view, aID );
     view.SetColL( KDbViewInsertionTimeOrdinal, aInsertionTime.Int64() );
     view.SetColL( KDbViewTimeOrdinal, aTime.Int64() );
-    
+
     view.PutL();
-    
+
     CleanupStack::PopAndDestroy(); // view
-    
+
     User::LeaveIfError( iTimeDb.Commit() );
     User::LeaveIfError( iTimeDb.Compact() );
-    
+
     Pop(); // iTimeDb
     }
-    
+
 // -----------------------------------------------------------------------------
 // RDRMReplayCache::AddL
 //
 // Add an entry to the database. Overloaded.
 // -----------------------------------------------------------------------------
-//   
+//
 void RDRMReplayCache::AddL( const TDesC8& aID,
                             const TTime& aInsertionTime )
     {
-    
+
     RDbView view;
-    
+
     PushL( iPlainDb );
-    
+
     InitViewLC( view, EPlainDb, ETrue );
     CompactViewL( view );
-    
+
     view .EndL();
-    
+
     User::LeaveIfError( iPlainDb.Begin() );
-    
+
     view.InsertL();
     InsertIdL( view, aID );
     view.SetColL( KDbViewInsertionTimeOrdinal, aInsertionTime.Int64() );
-    
+
     view.PutL();
-    
+
     CleanupStack::PopAndDestroy(); // view
-    
+
     User::LeaveIfError( iPlainDb.Commit() );
     User::LeaveIfError( iPlainDb.Compact() );
-    
+
     Pop(); // iPlainDb
     }
 
@@ -295,14 +295,14 @@
 //
 // Initialize the databases.
 // -----------------------------------------------------------------------------
-//       
-void RDRMReplayCache::InitDbL( RDbNamedDatabase& aDb, 
+//
+void RDRMReplayCache::InitDbL( RDbNamedDatabase& aDb,
                                const TDesC& aFileName,
                                TDatabaseId aId )
     {
     TInt error = KErrNone;
     TBool exists = BaflUtils::FileExists( *iFs, aFileName );
-    
+
     if ( exists )
         {
         TRAP( error, OpenDbL( aDb, aFileName ) );
@@ -312,13 +312,13 @@
         ReplaceDbL( aDb, aFileName, aId );
         }
     }
-    
+
 // -----------------------------------------------------------------------------
 // RDRMReplayCache::~RDRMReplayCache
 //
 // Destructor.
 // -----------------------------------------------------------------------------
-//   
+//
 RDRMReplayCache::~RDRMReplayCache()
     {
     }
@@ -328,29 +328,29 @@
 //
 // Open the database.
 // -----------------------------------------------------------------------------
-//   
-void RDRMReplayCache::OpenDbL( RDbNamedDatabase& aDb, 
+//
+void RDRMReplayCache::OpenDbL( RDbNamedDatabase& aDb,
                                const TDesC& aFileName )
     {
     CDbTableNames* tables = NULL;
-    
+
     User::LeaveIfError( aDb.Open( *iFs, aFileName ) );
     CleanupClosePushL( aDb );
-    
+
     if ( aDb.IsDamaged() )
         {
         User::LeaveIfError( aDb.Recover() );
         }
-        
+
     // Sanity check.
     tables = aDb.TableNamesL();
     CleanupStack::PushL( tables );
-    
+
     if ( tables->Count() != 1 || ( *tables )[ 0 ].Compare( KReplayCacheTable ) )
         {
         User::Leave( KErrCorrupt );
         }
-    
+
     CleanupStack::PopAndDestroy(); // tables
     CleanupStack::Pop(); // aDb
     }
@@ -360,9 +360,9 @@
 //
 // Replace the database.
 // -----------------------------------------------------------------------------
-//       
-void RDRMReplayCache::ReplaceDbL( RDbNamedDatabase& aDb, 
-                                  const TDesC& aFileName, 
+//
+void RDRMReplayCache::ReplaceDbL( RDbNamedDatabase& aDb,
+                                  const TDesC& aFileName,
                                   TDatabaseId aId )
     {
     CDbColSet*  colSet = NULL;
@@ -370,92 +370,92 @@
     TDbCol cidCol( KCIDColName, EDbColLongText8 );
     TDbCol insertionTimeCol( KInsertionTimeColName, EDbColInt64 );
     TDbCol timeCol( KTimeColName, EDbColInt64 );
-    
+
     TDoDeleteFile deletefile = { iFs, &aFileName };
-    
+
     TCleanupItem item( DoDeleteFile, &deletefile );
     CleanupStack::PushL( item );
-    
+
     User::LeaveIfError( aDb.Replace( *iFs, aFileName ) );
     CleanupClosePushL( aDb );
-    
+
     // Add columns
     colSet = CDbColSet::NewLC();
     colSet->AddL( cidCol );
     colSet->AddL( insertionTimeCol );
-    
+
     if ( aId == ETimeDb )
         {
         colSet->AddL( timeCol );
         }
-    
+
     User::LeaveIfError( aDb.Begin() );
     User::LeaveIfError( aDb.CreateTable( KReplayCacheTable, *colSet ) );
     User::LeaveIfError( aDb.Commit() );
-    
+
     CleanupStack::PopAndDestroy(); // colSet
-    CleanupStack::Pop(); // aDb    
+    CleanupStack::Pop(); // aDb
     CleanupStack::Pop(); // item
     }
-    
+
 // -----------------------------------------------------------------------------
 // RDRMReplayCache::InitViewLC
 //
 // Initialize the view.
 // -----------------------------------------------------------------------------
-//   
-void RDRMReplayCache::InitViewLC( RDbView& aView, 
-                                  TDatabaseId aId, 
+//
+void RDRMReplayCache::InitViewLC( RDbView& aView,
+                                  TDatabaseId aId,
                                   TBool aUpdate )
     {
     RDbDatabase* db = ( aId ==  ETimeDb ? &iTimeDb : &iPlainDb );
-    
-    User::LeaveIfError( 
-        aView.Prepare( *db, 
-                       TDbQuery( KViewInitQuery, EDbCompareCollated ), 
+
+    User::LeaveIfError(
+        aView.Prepare( *db,
+                       TDbQuery( KViewInitQuery, EDbCompareCollated ),
                        aUpdate ? RDbRowSet::EUpdatable : RDbRowSet::EReadOnly ) );
-    
+
     CleanupClosePushL( aView );
-    
+
     User::LeaveIfError( aView.EvaluateAll() );
     }
-    
+
 // -----------------------------------------------------------------------------
 // RDRMReplayCache::CompareCIDL
 //
 // Compare whether the rowset's CID matches the given CID.
 // -----------------------------------------------------------------------------
-//       
-TBool RDRMReplayCache::CompareCIDL( RDbRowSet& aView, 
+//
+TBool RDRMReplayCache::CompareCIDL( RDbRowSet& aView,
                                     const TDesC8& aCID )
     {
     TBool res = EFalse;
-    
+
     TInt size = aView.ColLength( KDbViewIDOrdinal );
-    
+
     RDbColReadStream colData;
     colData.OpenLC( aView, KDbViewIDOrdinal );
-    
-    // The data contains also the cardinality of the CID data, but anyway... 
+
+    // The data contains also the cardinality of the CID data, but anyway...
     HBufC8* des = HBufC8::NewLC( colData, size );
 
     if ( aCID.CompareC( *des ) == 0 )
         {
         res = ETrue;
         }
-    
+
     CleanupStack::PopAndDestroy(); // des
     CleanupStack::PopAndDestroy(); // colData
-    
+
     return res;
     }
-    
+
 // -----------------------------------------------------------------------------
 // RDRMReplayCache::PushL
 //
 // Push a cleanup item to cleanup stack.
 // -----------------------------------------------------------------------------
-//   
+//
 void RDRMReplayCache::PushL( RDbDatabase& aDb )
     {
     TCleanupItem item( DoRollBack, &aDb );
@@ -467,7 +467,7 @@
 //
 // Pop a cleanup item pushed in by PushL.
 // -----------------------------------------------------------------------------
-//       
+//
 void RDRMReplayCache::Pop()
     {
     CleanupStack::Pop();
@@ -478,11 +478,11 @@
 //
 // Delete aHowMany entries from the view.
 // -----------------------------------------------------------------------------
-//       
+//
 void RDRMReplayCache::DeleteOldestsL( RDbRowSet& aView, TInt16 aHowMany )
     {
     aView.FirstL();
-    
+
     while ( aHowMany > 0 )
         {
         aView.DeleteL();
@@ -496,11 +496,11 @@
 //
 // Compact the view, deleting items if necessary.
 // -----------------------------------------------------------------------------
-//       
+//
 void RDRMReplayCache::CompactViewL( RDbRowSet& aView )
     {
     TInt count = aView.CountL();
-    
+
     if ( count >= KDbMaxNumOfItems )
         {
         // usually only one item is deleted, no need to use Begin/Commit.
@@ -513,17 +513,17 @@
 //
 // Insert content-ID to the view.
 // -----------------------------------------------------------------------------
-//       
-void RDRMReplayCache::InsertIdL( RDbRowSet& aView, 
+//
+void RDRMReplayCache::InsertIdL( RDbRowSet& aView,
                                  const TDesC8& aId )
     {
-    
+
     RDbColWriteStream stream;
     stream.OpenLC( aView, KDbViewIDOrdinal );
     stream << aId;
-    
+
     stream.CommitL();
     CleanupStack::PopAndDestroy(); // stream
     }
-    
+
 // End of File