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