omadrm/drmengine/server/src/DRMRightsCleaner.cpp
branchRCL_3
changeset 12 8a03a285ab14
parent 0 95b198f216e5
equal deleted inserted replaced
11:e16d72588c28 12:8a03a285ab14
    17 
    17 
    18 
    18 
    19 
    19 
    20 // INCLUDE FILES
    20 // INCLUDE FILES
    21 
    21 
    22 #include <e32std.h>		// RPointerArray
    22 #include <e32std.h>     // RPointerArray
    23 #include <e32def.h>		// Type definitions
    23 #include <e32def.h>     // Type definitions
    24 
    24 
    25 #include <caf/caf.h>
    25 #include <caf/caf.h>
    26 #include "DRMCommon.h"	// DRM Error messages
    26 #include "DRMCommon.h"  // DRM Error messages
    27 #include "DRMRightsCleaner.h"
    27 #include "DRMRightsCleaner.h"
    28 #include "DRMRightsDB.h"
    28 #include "drmrightsdb.h"
    29 #include "drmlog.h"
    29 #include "drmlog.h"
    30 
    30 
    31 
    31 
    32 // EXTERNAL DATA STRUCTURES
    32 // EXTERNAL DATA STRUCTURES
    33 
    33 
    34 // EXTERNAL FUNCTION PROTOTYPES  
    34 // EXTERNAL FUNCTION PROTOTYPES
    35 
    35 
    36 // CONSTANTS
    36 // CONSTANTS
    37 
    37 
    38 // MACROS
    38 // MACROS
    39 
    39 
    48 // FORWARD DECLARATIONS
    48 // FORWARD DECLARATIONS
    49 
    49 
    50 // ============================= LOCAL FUNCTIONS ===============================
    50 // ============================= LOCAL FUNCTIONS ===============================
    51 // ============================ MEMBER FUNCTIONS ===============================
    51 // ============================ MEMBER FUNCTIONS ===============================
    52 
    52 
    53         
    53 
    54 // -----------------------------------------------------------------------------
    54 // -----------------------------------------------------------------------------
    55 // CDRMRightsCleaner::NewL
    55 // CDRMRightsCleaner::NewL
    56 // Two-phased constructor.
    56 // Two-phased constructor.
    57 // -----------------------------------------------------------------------------
    57 // -----------------------------------------------------------------------------
    58 //
    58 //
    60                                             CDRMRightsDB* aDatabase,
    60                                             CDRMRightsDB* aDatabase,
    61                                             TRequestStatus& aStatus,
    61                                             TRequestStatus& aStatus,
    62                                             const TDesC& aDatabasePath,
    62                                             const TDesC& aDatabasePath,
    63                                             const TTime& aTime )
    63                                             const TTime& aTime )
    64     {
    64     {
    65     CDRMRightsCleaner* self = new( ELeave ) CDRMRightsCleaner( aFs, 
    65     CDRMRightsCleaner* self = new( ELeave ) CDRMRightsCleaner( aFs,
    66                                                         aDatabase, aStatus, 
    66                                                         aDatabase, aStatus,
    67                                                         aDatabasePath, aTime );
    67                                                         aDatabasePath, aTime );
    68     CleanupStack::PushL( self );
    68     CleanupStack::PushL( self );
    69     self->ConstructL();
    69     self->ConstructL();
    70     CleanupStack::Pop();
    70     CleanupStack::Pop();
    71     
    71 
    72     return self;
    72     return self;
    73     }
    73     }
    74   
    74 
    75         
    75 
    76 // -----------------------------------------------------------------------------
    76 // -----------------------------------------------------------------------------
    77 // Destructor        
    77 // Destructor
    78 // -----------------------------------------------------------------------------
    78 // -----------------------------------------------------------------------------
    79 //
    79 //
    80 CDRMRightsCleaner::~CDRMRightsCleaner()
    80 CDRMRightsCleaner::~CDRMRightsCleaner()
    81     {
    81     {
    82     // just in case
    82     // just in case
    83     Deque();
    83     Deque();
    84     
    84 
    85     if( iCurrentDirectory )
    85     if( iCurrentDirectory )
    86         {
    86         {
    87         delete iCurrentDirectory;
    87         delete iCurrentDirectory;
    88         iCurrentDirectory = NULL;    
    88         iCurrentDirectory = NULL;
    89         }
    89         }
    90     };
    90     };
    91 
    91 
    92 // -----------------------------------------------------------------------------
    92 // -----------------------------------------------------------------------------
    93 // CDRMRightsCleaner::ExecuteCleanupLD        
    93 // CDRMRightsCleaner::ExecuteCleanupLD
    94 // -----------------------------------------------------------------------------
    94 // -----------------------------------------------------------------------------
    95 //    
    95 //
    96 void CDRMRightsCleaner::ExecuteCleanupLD()
    96 void CDRMRightsCleaner::ExecuteCleanupLD()
    97     {
    97     {
    98     TRequestStatus* status = 0;
    98     TRequestStatus* status = 0;
    99     
    99 
   100     if( !IsAdded() ) 
   100     if( !IsAdded() )
   101         {
   101         {
   102         CActiveScheduler::Add(this);        
   102         CActiveScheduler::Add(this);
   103         }
   103         }
   104     if ( !IsActive() ) 
   104     if ( !IsActive() )
   105         {
   105         {
   106         SetActive();        
   106         SetActive();
   107         }
   107         }
   108     
   108 
   109     iOperationStatus = KRequestPending;
   109     iOperationStatus = KRequestPending;
   110     status = &iStatus;
   110     status = &iStatus;
   111     User::RequestComplete(status,KErrNone);        
   111     User::RequestComplete(status,KErrNone);
   112     };
   112     };
   113 
   113 
   114 // -----------------------------------------------------------------------------                        
   114 // -----------------------------------------------------------------------------
   115 // Default Constructor - First phase.
   115 // Default Constructor - First phase.
   116 // -----------------------------------------------------------------------------
   116 // -----------------------------------------------------------------------------
   117 //
   117 //
   118 CDRMRightsCleaner::CDRMRightsCleaner( RFs& aFs,
   118 CDRMRightsCleaner::CDRMRightsCleaner( RFs& aFs,
   119                                       CDRMRightsDB* aDatabase,
   119                                       CDRMRightsDB* aDatabase,
   126     iOperationStatus( aStatus ),
   126     iOperationStatus( aStatus ),
   127     iDatabasePath( aDatabasePath ),
   127     iDatabasePath( aDatabasePath ),
   128     iExpirationTime( aTime ),
   128     iExpirationTime( aTime ),
   129     iCurrentDirectory( NULL ),
   129     iCurrentDirectory( NULL ),
   130     iDirIndex( 0 ),
   130     iDirIndex( 0 ),
   131     iCurrentFile( 0 )                                  
   131     iCurrentFile( 0 )
   132     {
   132     {
   133         
   133 
   134     }; 
   134     };
   135         
   135 
   136 
   136 
   137 // -----------------------------------------------------------------------------                        
   137 // -----------------------------------------------------------------------------
   138 // CDRMRightsCleaner::ConstructL
   138 // CDRMRightsCleaner::ConstructL
   139 // -----------------------------------------------------------------------------
   139 // -----------------------------------------------------------------------------
   140 // 
   140 //
   141 void CDRMRightsCleaner::ConstructL()
   141 void CDRMRightsCleaner::ConstructL()
   142     {   
   142     {
   143     };  
   143     };
   144 
   144 
   145 // -----------------------------------------------------------------------------                        
   145 // -----------------------------------------------------------------------------
   146 // CDRMRightsCleaner::RunError
   146 // CDRMRightsCleaner::RunError
   147 // More or less just ignore all errors and call RunL again
   147 // More or less just ignore all errors and call RunL again
   148 // -----------------------------------------------------------------------------
   148 // -----------------------------------------------------------------------------
   149 //  
   149 //
   150 TInt CDRMRightsCleaner::RunError(TInt aError)
   150 TInt CDRMRightsCleaner::RunError(TInt aError)
   151     {
   151     {
   152     TRequestStatus* status = 0;  
   152     TRequestStatus* status = 0;
   153     
   153 
   154     if( aError == KErrCancel )
   154     if( aError == KErrCancel )
   155         {
   155         {
   156         // we are complete:
   156         // we are complete:
   157         status = &iOperationStatus;
   157         status = &iOperationStatus;
   158         User::RequestComplete( status, KErrNone );                
   158         User::RequestComplete( status, KErrNone );
   159         delete this;           
   159         delete this;
   160         return KErrNone;
   160         return KErrNone;
   161         }
   161         }
   162       
   162 
   163     SetActive();
   163     SetActive();
   164     status = &iStatus;
   164     status = &iStatus;
   165     User::RequestComplete(status,KErrNone);      
   165     User::RequestComplete(status,KErrNone);
   166     
   166 
   167     return KErrNone;
   167     return KErrNone;
   168     };
   168     };
   169 
   169 
   170 // -----------------------------------------------------------------------------                        
   170 // -----------------------------------------------------------------------------
   171 // CDRMRightsCleaner::RunL
   171 // CDRMRightsCleaner::RunL
   172 // -----------------------------------------------------------------------------
   172 // -----------------------------------------------------------------------------
   173 //      
   173 //
   174 void CDRMRightsCleaner::RunL()
   174 void CDRMRightsCleaner::RunL()
   175     {
   175     {
   176     TRequestStatus* status = 0;    
   176     TRequestStatus* status = 0;
   177     TInt error = KErrNone;
   177     TInt error = KErrNone;
   178     TFileName path;
   178     TFileName path;
   179     TInt modIndex = 0;
   179     TInt modIndex = 0;
   180     TInt removeFile = EFalse;
   180     TInt removeFile = EFalse;
   181 
   181 
   182     // If the status of the cleaning is other than KErrNone
   182     // If the status of the cleaning is other than KErrNone
   183     User::LeaveIfError( iStatus.Int() );
   183     User::LeaveIfError( iStatus.Int() );
   184     
   184 
   185     if( !iCurrentDirectory ||
   185     if( !iCurrentDirectory ||
   186         iCurrentFile >= iCurrentDirectory->Count() )
   186         iCurrentFile >= iCurrentDirectory->Count() )
   187         {
   187         {
   188 
   188 
   189         if( iDirIndex >= KMaxDirs )
   189         if( iDirIndex >= KMaxDirs )
   190             {
   190             {
   191             // we are complete:
   191             // we are complete:
   192             status = &iOperationStatus;
   192             status = &iOperationStatus;
   193             User::RequestComplete( status, KErrNone );                
   193             User::RequestComplete( status, KErrNone );
   194             delete this; 
   194             delete this;
   195             return;    
   195             return;
   196             }
   196             }
   197         
   197 
   198         // if it exists, delete it
   198         // if it exists, delete it
   199         if( iCurrentDirectory )
   199         if( iCurrentDirectory )
   200             {
   200             {
   201             delete iCurrentDirectory;
   201             delete iCurrentDirectory;
   202             iCurrentDirectory = 0;
   202             iCurrentDirectory = 0;
   203             }
   203             }
   204         
   204 
   205         TFileName path = iDatabasePath;
   205         TFileName path = iDatabasePath;
   206     
   206 
   207     
   207 
   208         path.Append(iDirIndex < 10 ? iDirIndex + '0' : iDirIndex + 'a' - 10);
   208         path.Append(iDirIndex < 10 ? iDirIndex + '0' : iDirIndex + 'a' - 10);
   209         path.Append('\\');
   209         path.Append('\\');
   210 
   210 
   211        
   211 
   212         error =  iFileServer.GetDir(path, KEntryAttDir, ESortNone, iCurrentDirectory);
   212         error =  iFileServer.GetDir(path, KEntryAttDir, ESortNone, iCurrentDirectory);
   213 
   213 
   214         DRMLOG(_L("Entering directory:"));
   214         DRMLOG(_L("Entering directory:"));
   215         DRMLOG( path );
   215         DRMLOG( path );
   216 
   216 
   217         // increase the dir counter    
   217         // increase the dir counter
   218         iDirIndex++;
   218         iDirIndex++;
   219         iCurrentFile = 0;                
   219         iCurrentFile = 0;
   220         }
   220         }
   221 
   221 
   222     if( !error && iCurrentDirectory->Count() )
   222     if( !error && iCurrentDirectory->Count() )
   223         {
   223         {
   224         modIndex = iDirIndex-1;
   224         modIndex = iDirIndex-1;
   225         
   225 
   226         path = iDatabasePath;
   226         path = iDatabasePath;
   227         path.Append(modIndex < 10 ? modIndex + '0' : modIndex + 'a' - 10);
   227         path.Append(modIndex < 10 ? modIndex + '0' : modIndex + 'a' - 10);
   228         path.Append('\\');        
   228         path.Append('\\');
   229                                 
   229 
   230         path.Append((*iCurrentDirectory)[iCurrentFile].iName);
   230         path.Append((*iCurrentDirectory)[iCurrentFile].iName);
   231     
   231 
   232         DRMLOG(_L("Checking file:"));
   232         DRMLOG(_L("Checking file:"));
   233         DRMLOG( path );
   233         DRMLOG( path );
   234     
   234 
   235         // increase the file counter
   235         // increase the file counter
   236         iCurrentFile++;
   236         iCurrentFile++;
   237                                 
   237 
   238         TRAP( error, removeFile = iRightsDb->DeleteExpiredL( path, iExpirationTime ) );
   238         TRAP( error, removeFile = iRightsDb->DeleteExpiredL( path, iExpirationTime ) );
   239         if( error != KErrNone )
   239         if( error != KErrNone )
   240             {
   240             {
   241             DRMLOG2( _L( "CDRMRightsCleaner: error %d cleaning:" ), error );
   241             DRMLOG2( _L( "CDRMRightsCleaner: error %d cleaning:" ), error );
   242             DRMLOG( path );
   242             DRMLOG( path );
   243             }
   243             }
   244         else 
   244         else
   245             {
   245             {
   246             if ( removeFile )
   246             if ( removeFile )
   247                 {
   247                 {
   248                 DRMLOG(_L("Deleting file:"));
   248                 DRMLOG(_L("Deleting file:"));
   249                 DRMLOG( path );
   249                 DRMLOG( path );
   250                 iFileServer.Delete( path );
   250                 iFileServer.Delete( path );
   251                 }
   251                 }
   252             }    
   252             }
   253         }
   253         }
   254     
   254 
   255     SetActive();
   255     SetActive();
   256     status = &iStatus;
   256     status = &iStatus;
   257     User::RequestComplete(status, KErrNone);                
   257     User::RequestComplete(status, KErrNone);
   258     };    
   258     };
   259 
   259 
   260 // -----------------------------------------------------------------------------                        
   260 // -----------------------------------------------------------------------------
   261 // CDRMRightsCleaner::DoCancel
   261 // CDRMRightsCleaner::DoCancel
   262 // -----------------------------------------------------------------------------
   262 // -----------------------------------------------------------------------------
   263 //      
   263 //
   264 void CDRMRightsCleaner::DoCancel()
   264 void CDRMRightsCleaner::DoCancel()
   265     {     
   265     {
   266     }; 
   266     };
   267 
   267 
   268 
   268 
   269 // -----------------------------------------------------------------------------                        
   269 // -----------------------------------------------------------------------------
   270 // CDRMRightsCleaner::DoCleanup
   270 // CDRMRightsCleaner::DoCleanup
   271 // -----------------------------------------------------------------------------
   271 // -----------------------------------------------------------------------------
   272 //      
   272 //
   273 void CDRMRightsCleaner::DoCleanup()
   273 void CDRMRightsCleaner::DoCleanup()
   274     {
   274     {
   275     TRequestStatus* status = 0;      
   275     TRequestStatus* status = 0;
   276     if( iCancel <= 0 )
   276     if( iCancel <= 0 )
   277         {
   277         {
   278         Cancel();
   278         Cancel();
   279         iCancel = 1;
   279         iCancel = 1;
   280         SetActive();
   280         SetActive();
   281         status = &iStatus;
   281         status = &iStatus;
   282         User::RequestComplete(status, KErrCancel);
   282         User::RequestComplete(status, KErrCancel);
   283         }       
   283         }
   284     }; 
   284     };
   285 
   285 
   286 
   286 
   287 
   287 
   288 
   288 
   289 
   289 
   290 
   290 
   291 
   291 
   292 
   292 
   293 
   293