mobilemessaging/mmsui/viewersrc/MmsViewerOperation.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2004-2006 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:  
       
    15 *       CMmsViewerOperation
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // ========== INCLUDE FILES ================================
       
    22 #include <e32std.h>
       
    23 
       
    24 #include "MmsMtmConst.h"	// For logging support
       
    25 
       
    26 #include "MmsViewerOperation.h"
       
    27 
       
    28 // ========== EXTERNAL DATA STRUCTURES =====================
       
    29 
       
    30 // ========== EXTERNAL FUNCTION PROTOTYPES =================
       
    31 
       
    32 // ========== CONSTANTS ====================================
       
    33 
       
    34 // ========== MACROS =======================================
       
    35 
       
    36 // ========== LOCAL CONSTANTS AND MACROS ===================
       
    37 
       
    38 // ========== MODULE DATA STRUCTURES =======================
       
    39 
       
    40 // ========== LOCAL FUNCTION PROTOTYPES ====================
       
    41 
       
    42 // ========== LOCAL FUNCTIONS ==============================
       
    43 #ifdef CANCEL_TEST_CODE
       
    44 // ---------------------------------------------------------
       
    45 // Testing code of Cancel
       
    46 // ---------------------------------------------------------
       
    47 //
       
    48 class CHighOperation : public CActive
       
    49     {
       
    50     public: 
       
    51         virtual ~CHighOperation()
       
    52             {
       
    53             Cancel();
       
    54             }
       
    55 
       
    56         CHighOperation( CMmsViewerOperation&    aObserver,
       
    57                         TInt                    aUseRandomCancel );
       
    58         void CompleteSelf();
       
    59 
       
    60         /**
       
    61         * From CActive
       
    62         */
       
    63         void RunL();
       
    64 
       
    65         /**
       
    66         * From CActive
       
    67         */
       
    68         void DoCancel();
       
    69             
       
    70     public:
       
    71         CMmsViewerOperation&    iObserver;
       
    72         TInt                    iUseRandomCancel;
       
    73     };
       
    74 
       
    75 CHighOperation::CHighOperation( CMmsViewerOperation&    aObserver,
       
    76                                 TInt                    aUseRandomCancel ): 
       
    77     CActive( EPriorityStandard ),
       
    78     iObserver( aObserver ),
       
    79     iUseRandomCancel( aUseRandomCancel )
       
    80     {
       
    81     CActiveScheduler::Add( this );
       
    82     if ( iUseRandomCancel > 100 )
       
    83         {
       
    84         SetPriority( EPriorityStandard + 1);
       
    85         }
       
    86     if ( iUseRandomCancel < 100 )
       
    87         {
       
    88         SetPriority( EPriorityStandard - 1);
       
    89         }
       
    90     }
       
    91 void CHighOperation::CompleteSelf()
       
    92     {
       
    93     iStatus = KRequestPending;
       
    94     TRequestStatus* pStatus = &iStatus;
       
    95     SetActive();
       
    96     User::RequestComplete( pStatus, KErrNone );
       
    97     }
       
    98 
       
    99 void CHighOperation::RunL()
       
   100     {
       
   101     if ( iUseRandomCancel > 100 )
       
   102         {
       
   103         iObserver.Cancel();
       
   104         }
       
   105     else
       
   106         {
       
   107         /*// probability determines frequency
       
   108         TTime myTime;
       
   109         myTime.HomeTime();
       
   110         TTimeIntervalMicroSeconds micros = myTime.MicroSecondsFrom( 0 ); 
       
   111         TInt fraction = (TInt)micros.Int64()%99;
       
   112         if ( fraction < 0 )
       
   113             fraction = 0 - fraction;
       
   114         if ( fraction < iUseRandomCancel )
       
   115             {
       
   116             iObserver.Cancel();
       
   117             }*/
       
   118         iObserver.Cancel();
       
   119         }
       
   120         
       
   121     /*if ( iUseRandomCancel <= 100 )
       
   122         {
       
   123         CompleteSelf();
       
   124         }*/
       
   125     }
       
   126             
       
   127         /**
       
   128         * From CActive
       
   129         */
       
   130 void CHighOperation::DoCancel()
       
   131     {
       
   132     }
       
   133 
       
   134 
       
   135 #endif
       
   136 
       
   137 // ========== MEMBER FUNCTIONS =============================
       
   138 
       
   139 // ---------------------------------------------------------
       
   140 // CMmsViewerOperation::CMmsViewerOperation
       
   141 //
       
   142 // Constructor.
       
   143 // ---------------------------------------------------------
       
   144 //
       
   145 CMmsViewerOperation::CMmsViewerOperation(
       
   146         MMmsViewerOperationObserver& aObserver,
       
   147         CMmsViewerDocument& aDocument,
       
   148         RFs& aFs ) :
       
   149     CActive( EPriorityStandard ),
       
   150     iObserver( aObserver ),
       
   151     iDocument( aDocument ),
       
   152     iFs( aFs )
       
   153     {
       
   154     CActiveScheduler::Add( this );
       
   155     }
       
   156 
       
   157 
       
   158 // ---------------------------------------------------------
       
   159 // CMmsViewerOperation::CMmsViewerOperation
       
   160 //
       
   161 // Destructor.
       
   162 // ---------------------------------------------------------
       
   163 //
       
   164 CMmsViewerOperation::~CMmsViewerOperation()
       
   165     {
       
   166 #ifdef CANCEL_TEST_CODE
       
   167     delete iHighOp;
       
   168 #endif
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------
       
   172 // CompleteSelf
       
   173 //
       
   174 // Sets current operation active and completes it
       
   175 // ---------------------------------------------------------
       
   176 //
       
   177 void CMmsViewerOperation::CompleteSelf( TInt aError )
       
   178     {
       
   179     iStatus = KRequestPending;
       
   180     SetActive();
       
   181     TRequestStatus* pStatus = &iStatus;
       
   182     User::RequestComplete( pStatus, aError );
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------
       
   186 // SetActiveNoCompleteSelf
       
   187 //
       
   188 // Sets active but does not complete
       
   189 // ---------------------------------------------------------
       
   190 //
       
   191 void CMmsViewerOperation::SetActiveNoCompleteSelf( )
       
   192     {
       
   193     iStatus = KRequestPending;
       
   194     SetActive();
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------
       
   198 // CompleteActiveSelf
       
   199 //
       
   200 // Completes already active operation
       
   201 // ---------------------------------------------------------
       
   202 //
       
   203 void CMmsViewerOperation::CompleteActiveSelf( TInt aError )
       
   204     {
       
   205     LOGTEXT(_L8("MMSE: CMmsViewerOperation::CompleteActiveSelf"));
       
   206     // When CActive based operation is completed, User::RequestComplete sets 
       
   207     // iStatus to KRequestPending. Then User::RequestComplete calls RThread::RequestComplete(),
       
   208     // which copies aReason to iStatus. 
       
   209     // Operation stays active just until RunL() is called. When RunL() is running,
       
   210     // operation is no more active.
       
   211     // When RunL() is not yet called and operation is still active, we know that 
       
   212     // operation is NOT completed, if iStatus == KRequestPending. 
       
   213     // Note also that if operation has been completed by CompleteSelf(),
       
   214     // and Cancel is called(), Cancel() 'eats' the active object. RunL() is not more called.
       
   215     if (    IsActive() 
       
   216         &&  iStatus == KRequestPending )
       
   217         {
       
   218         TRequestStatus* pStatus = &iStatus;
       
   219         User::RequestComplete( pStatus, aError );
       
   220         }
       
   221     }
       
   222 
       
   223 // ---------------------------------------------------------
       
   224 // IsCompleted
       
   225 // ---------------------------------------------------------
       
   226 //
       
   227 TBool CMmsViewerOperation::IsCompleted( )
       
   228     {
       
   229     return ( IsActive() &&  iStatus != KRequestPending );
       
   230     }
       
   231     
       
   232 // ---------------------------------------------------------
       
   233 // IsCompleted
       
   234 // ---------------------------------------------------------
       
   235 //
       
   236 #ifdef CANCEL_TEST_CODE
       
   237 void CMmsViewerOperation::LaunchCancelTestL( TInt aUseRandomCancel )
       
   238     {
       
   239     if ( !iHighOp )
       
   240         {
       
   241         iHighOp = new (ELeave) CHighOperation( *this, aUseRandomCancel );
       
   242         iHighOp->CompleteSelf();
       
   243         }
       
   244     }
       
   245 
       
   246 void CMmsViewerOperation::CancelCancelTest( )
       
   247     {
       
   248     if ( iHighOp )
       
   249         iHighOp->Cancel();
       
   250     delete iHighOp;
       
   251     iHighOp = NULL;
       
   252     }
       
   253 
       
   254 #endif    
       
   255 
       
   256 
       
   257 // EOF