omadrm/drmengine/server/src/DRMActiveOperation.cpp
changeset 23 493788a4a8a4
parent 0 95b198f216e5
equal deleted inserted replaced
5:79d62d1d7957 23:493788a4a8a4
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 #include "drmactiveoperation.h"
    20 #include "DRMActiveOperation.h"
    21 #include "drmrightsdb.h"
    21 #include "drmrightsdb.h"
    22 #include "drmrightscleaner.h"
    22 #include "DRMRightsCleaner.h"
    23 #include "drmobsoletefinder.h"
    23 #include "DRMObsoleteFinder.h"
    24 #include "drmdbsession.h"
    24 #include "DRMDbSession.h"
    25 
    25 
    26 // EXTERNAL DATA STRUCTURES
    26 // EXTERNAL DATA STRUCTURES
    27 
    27 
    28 // EXTERNAL FUNCTION PROTOTYPES  
    28 // EXTERNAL FUNCTION PROTOTYPES
    29 
    29 
    30 // CONSTANTS
    30 // CONSTANTS
    31 
    31 
    32 // MACROS
    32 // MACROS
    33 
    33 
    40 // FORWARD DECLARATIONS
    40 // FORWARD DECLARATIONS
    41 
    41 
    42 
    42 
    43 // ============================= LOCAL FUNCTIONS ===============================
    43 // ============================= LOCAL FUNCTIONS ===============================
    44 
    44 
    45     
    45 
    46 // ============================ MEMBER FUNCTIONS ===============================
    46 // ============================ MEMBER FUNCTIONS ===============================
    47 
    47 
    48 // -----------------------------------------------------------------------------
    48 // -----------------------------------------------------------------------------
    49 // CDRMActiveOperation::NewLC
    49 // CDRMActiveOperation::NewLC
    50 //
    50 //
    57     {
    57     {
    58     CDRMActiveOperation* self = new( ELeave ) CDRMActiveOperation( aMessage,
    58     CDRMActiveOperation* self = new( ELeave ) CDRMActiveOperation( aMessage,
    59                                                                  aSession,
    59                                                                  aSession,
    60                                                                  aOperation );
    60                                                                  aOperation );
    61     CleanupStack::PushL( self );
    61     CleanupStack::PushL( self );
    62     
    62 
    63     return self;
    63     return self;
    64     }
    64     }
    65 
    65 
    66 // -----------------------------------------------------------------------------
    66 // -----------------------------------------------------------------------------
    67 // CDRMActiveOperation::~CDRMActiveOperation
    67 // CDRMActiveOperation::~CDRMActiveOperation
    71 //
    71 //
    72 CDRMActiveOperation::~CDRMActiveOperation()
    72 CDRMActiveOperation::~CDRMActiveOperation()
    73     {
    73     {
    74     // Close the stream
    74     // Close the stream
    75     iFileStream.Close();
    75     iFileStream.Close();
    76     
    76 
    77     if( iFileName )
    77     if( iFileName )
    78         {
    78         {
    79         if( iFileServer ) 
    79         if( iFileServer )
    80             {	
    80             {
    81             iFileServer->Delete( *iFileName );        
    81             iFileServer->Delete( *iFileName );
    82             }
    82             }
    83         delete iFileName;
    83         delete iFileName;
    84         iFileName = NULL;  
    84         iFileName = NULL;
    85         }
    85         }
    86         
    86 
    87     if ( iActiveOperation )
    87     if ( iActiveOperation )
    88         {
    88         {
    89         // Construction was successful, but 
    89         // Construction was successful, but
    90         // something has went wrong.
    90         // something has went wrong.
    91         
    91 
    92         iActiveOperation->Cancel();
    92         iActiveOperation->Cancel();
    93         if( !iMessage.IsNull() )
    93         if( !iMessage.IsNull() )
    94             {
    94             {
    95             iMessage.Complete( KErrCancel );           
    95             iMessage.Complete( KErrCancel );
    96             }
    96             }
    97         }
    97         }
    98     }
    98     }
    99     
    99 
   100 // -----------------------------------------------------------------------------
   100 // -----------------------------------------------------------------------------
   101 // CDRMActiveOperation::ActivateL
   101 // CDRMActiveOperation::ActivateL
   102 //
   102 //
   103 // Activate the thing by issuing a request to the DB and executing it also.
   103 // Activate the thing by issuing a request to the DB and executing it also.
   104 // -----------------------------------------------------------------------------
   104 // -----------------------------------------------------------------------------
   105 //
   105 //
   106 void CDRMActiveOperation::ActivateL( CDRMRightsDB& aDb,
   106 void CDRMActiveOperation::ActivateL( CDRMRightsDB& aDb,
   107                                      const TTime& aTime )
   107                                      const TTime& aTime )
   108     {
   108     {
   109     CActiveScheduler::Add( this );
   109     CActiveScheduler::Add( this );
   110     
   110 
   111 
   111 
   112     CDRMRightsCleaner* cleaner = 
   112     CDRMRightsCleaner* cleaner =
   113         aDb.DeleteExpiredPermissionsL( aTime, iStatus );
   113         aDb.DeleteExpiredPermissionsL( aTime, iStatus );
   114     CleanupStack::PushL( cleaner );
   114     CleanupStack::PushL( cleaner );
   115     cleaner->ExecuteCleanupLD();
   115     cleaner->ExecuteCleanupLD();
   116     CleanupStack::Pop();
   116     CleanupStack::Pop();
   117     SetActive();
   117     SetActive();
   118     iActiveOperation = cleaner;             
   118     iActiveOperation = cleaner;
   119     }
   119     }
   120 
   120 
   121 // -----------------------------------------------------------------------------
   121 // -----------------------------------------------------------------------------
   122 // CDRMActiveOperation::ActivateL
   122 // CDRMActiveOperation::ActivateL
   123 //
   123 //
   124 // Activate the thing by creating an object and executing it
   124 // Activate the thing by creating an object and executing it
   125 // -----------------------------------------------------------------------------
   125 // -----------------------------------------------------------------------------
   126 //
   126 //
   127 void CDRMActiveOperation::ActivateL( CDRMRightsDB& aDb,
   127 void CDRMActiveOperation::ActivateL( CDRMRightsDB& aDb,
   128                                      RFs& aFileServer,
   128                                      RFs& aFileServer,
   129                                      const TDesC& aTempPath, 
   129                                      const TDesC& aTempPath,
   130                                      const TBool aPerformScan )
   130                                      const TBool aPerformScan )
   131     {
   131     {
   132     CActiveScheduler::Add( this );
   132     CActiveScheduler::Add( this );
   133 
   133 
   134     iFileName = new (ELeave) TFileName;
   134     iFileName = new (ELeave) TFileName;
   135     iFileServer = &aFileServer;
   135     iFileServer = &aFileServer;
   136      
   136 
   137     User::LeaveIfError( 
   137     User::LeaveIfError(
   138         iFileStream.Temp( aFileServer, 
   138         iFileStream.Temp( aFileServer,
   139                          aTempPath, 
   139                          aTempPath,
   140                          *iFileName, 
   140                          *iFileName,
   141                          EFileWrite | EFileStream ) );
   141                          EFileWrite | EFileStream ) );
   142     
   142 
   143     CDRMObsoleteFinder* finder = CDRMObsoleteFinder::NewL(aFileServer,
   143     CDRMObsoleteFinder* finder = CDRMObsoleteFinder::NewL(aFileServer,
   144                                                           &aDb,
   144                                                           &aDb,
   145                                                           iStatus, 
   145                                                           iStatus,
   146                                                           iFileStream,
   146                                                           iFileStream,
   147                                                           aPerformScan );
   147                                                           aPerformScan );
   148     CleanupStack::PushL( finder );
   148     CleanupStack::PushL( finder );
   149     finder->ExecuteFinderLD();
   149     finder->ExecuteFinderLD();
   150     CleanupStack::Pop();
   150     CleanupStack::Pop();
   151     SetActive();
   151     SetActive();
   152     iActiveOperation = finder;              
   152     iActiveOperation = finder;
   153     }  
   153     }
   154 
   154 
   155 // -----------------------------------------------------------------------------
   155 // -----------------------------------------------------------------------------
   156 // CDRMActiveOperation::Remove
   156 // CDRMActiveOperation::Remove
   157 //
   157 //
   158 // Cancels the operation.
   158 // Cancels the operation.
   163     switch(iOperation)
   163     switch(iOperation)
   164         {
   164         {
   165         case EOperationExportObsolete:
   165         case EOperationExportObsolete:
   166             {
   166             {
   167             static_cast<CDRMObsoleteFinder*>(iActiveOperation)->DoCleanup();
   167             static_cast<CDRMObsoleteFinder*>(iActiveOperation)->DoCleanup();
   168             } 
   168             }
   169             break;            
   169             break;
   170         default: 
   170         default:
   171             {
   171             {
   172             static_cast<CDRMRightsCleaner*>(iActiveOperation)->DoCleanup();
   172             static_cast<CDRMRightsCleaner*>(iActiveOperation)->DoCleanup();
   173             } 
   173             }
   174             break;
   174             break;
   175         }
   175         }
   176     }
   176     }
   177 
   177 
   178 // -----------------------------------------------------------------------------
   178 // -----------------------------------------------------------------------------
   182 // -----------------------------------------------------------------------------
   182 // -----------------------------------------------------------------------------
   183 //
   183 //
   184 void CDRMActiveOperation::RunL()
   184 void CDRMActiveOperation::RunL()
   185     {
   185     {
   186     TFileName* fileName = NULL;
   186     TFileName* fileName = NULL;
   187     
   187 
   188     // All done.
   188     // All done.
   189     if( !iMessage.IsNull() )
   189     if( !iMessage.IsNull() )
   190         {
   190         {
   191         iMessage.Complete( iStatus.Int() );           
   191         iMessage.Complete( iStatus.Int() );
   192         }    
   192         }
   193     
   193 
   194     // iActiveOperation deletes itself.
   194     // iActiveOperation deletes itself.
   195     iActiveOperation = NULL;
   195     iActiveOperation = NULL;
   196     
   196 
   197     Deque();
   197     Deque();
   198     
   198 
   199     if( iOperation == EOperationExportObsolete )
   199     if( iOperation == EOperationExportObsolete )
   200         {
   200         {
   201         fileName = iFileName;
   201         fileName = iFileName;
   202         iFileName = NULL;
   202         iFileName = NULL;
   203         iSession.AsyncOperationDone(fileName);            
   203         iSession.AsyncOperationDone(fileName);
   204         }
   204         }
   205     else 
   205     else
   206         {
   206         {
   207         iSession.AsyncOperationDone();            
   207         iSession.AsyncOperationDone();
   208         }
   208         }
   209     }
   209     }
   210     
   210 
   211 // -----------------------------------------------------------------------------
   211 // -----------------------------------------------------------------------------
   212 // CDRMActiveOperation::DoCancel
   212 // CDRMActiveOperation::DoCancel
   213 //
   213 //
   214 // Cancels the operation.
   214 // Cancels the operation.
   215 // -----------------------------------------------------------------------------
   215 // -----------------------------------------------------------------------------
   216 //
   216 //
   217 void CDRMActiveOperation::DoCancel()
   217 void CDRMActiveOperation::DoCancel()
   218     {
   218     {
   219     }
   219     }
   220     
   220 
   221     
   221 
   222 
   222 
   223 // -----------------------------------------------------------------------------
   223 // -----------------------------------------------------------------------------
   224 // CDRMActiveOperation::CDRMActiveOperation
   224 // CDRMActiveOperation::CDRMActiveOperation
   225 //
   225 //
   226 // Constructor.
   226 // Constructor.
   235     iOperation( aOperation ),
   235     iOperation( aOperation ),
   236     iFileServer( NULL )
   236     iFileServer( NULL )
   237     {
   237     {
   238     // Nothing
   238     // Nothing
   239     }
   239     }
   240     
   240 
   241 // End of file
   241 // End of file