ipsservices/ipssosplugin/src/ipsplgsingleopwatcher.cpp
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2002 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 *     Messaging progress watching classes
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 
       
    24 #include "emailtrace.h"
       
    25 #include "ipsplgheaders.h"
       
    26 
       
    27 // CONSTANTS
       
    28 const TInt KSingleOpWatcherPriority = KMaxTInt;
       
    29 #ifdef _DEBUG
       
    30 _LIT( KPanicIpsPlgSingleOpWatcher, "CIpsPlgSingleOpWatcher");
       
    31 #endif
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // ---------------------------------------------------------
       
    36 // CIpsPlgSingleOpWatcher::NewLC
       
    37 //
       
    38 // ---------------------------------------------------------
       
    39 //
       
    40 EXPORT_C CIpsPlgSingleOpWatcher* CIpsPlgSingleOpWatcher::NewLC( 
       
    41     MIpsPlgSingleOpWatcher& aObserver )
       
    42     {
       
    43     FUNC_LOG;
       
    44     CIpsPlgSingleOpWatcher* self = new( ELeave ) CIpsPlgSingleOpWatcher( aObserver );
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL();
       
    47     return self;
       
    48     }
       
    49 
       
    50 
       
    51 // ---------------------------------------------------------
       
    52 // CIpsPlgSingleOpWatcher::NewL
       
    53 //
       
    54 // ---------------------------------------------------------
       
    55 //
       
    56 EXPORT_C CIpsPlgSingleOpWatcher* CIpsPlgSingleOpWatcher::NewL( 
       
    57     MIpsPlgSingleOpWatcher& aObserver )
       
    58     {
       
    59     FUNC_LOG;
       
    60     CIpsPlgSingleOpWatcher* self = CIpsPlgSingleOpWatcher::NewLC( aObserver );
       
    61     CleanupStack::Pop( self ); // self
       
    62     return self;
       
    63     }
       
    64 
       
    65 
       
    66 // ---------------------------------------------------------
       
    67 // CIpsPlgSingleOpWatcher::CIpsPlgSingleOpWatcher
       
    68 //
       
    69 // ---------------------------------------------------------
       
    70 //
       
    71 CIpsPlgSingleOpWatcher::CIpsPlgSingleOpWatcher( 
       
    72     MIpsPlgSingleOpWatcher& aObserver )
       
    73     : CActive( KSingleOpWatcherPriority ), iObserver( aObserver )
       
    74     {
       
    75     FUNC_LOG;
       
    76     CActiveScheduler::Add( this );
       
    77     }
       
    78 
       
    79 
       
    80 // ---------------------------------------------------------
       
    81 // CIpsPlgSingleOpWatcher::ConstructL
       
    82 //
       
    83 // ---------------------------------------------------------
       
    84 //
       
    85 void CIpsPlgSingleOpWatcher::ConstructL()
       
    86     {
       
    87     FUNC_LOG;
       
    88     // Nothing to do, reserved for future use...
       
    89     }
       
    90 
       
    91 
       
    92 // ---------------------------------------------------------
       
    93 // CIpsPlgSingleOpWatcher::~CIpsPlgSingleOpWatcher
       
    94 //
       
    95 // ---------------------------------------------------------
       
    96 //
       
    97 EXPORT_C CIpsPlgSingleOpWatcher::~CIpsPlgSingleOpWatcher()
       
    98     {
       
    99     FUNC_LOG;
       
   100     Cancel();
       
   101     delete iOperation;
       
   102     delete iBaseOperation;
       
   103     delete iRequestObserver;
       
   104     }
       
   105 
       
   106 
       
   107 // ---------------------------------------------------------
       
   108 // CIpsPlgSingleOpWatcher::SetOperation
       
   109 // --- Setter ---
       
   110 // Must only be called once during the lifetime 
       
   111 //of a CIpsPlgSingleOpWatcher object.
       
   112 // ---------------------------------------------------------
       
   113 //
       
   114 EXPORT_C void CIpsPlgSingleOpWatcher::SetOperation(CMsvOperation* aOperation)
       
   115     {
       
   116     FUNC_LOG;
       
   117     __ASSERT_DEBUG( !IsActive(), 
       
   118         User::Panic( KPanicIpsPlgSingleOpWatcher, KErrInUse ) );
       
   119     __ASSERT_DEBUG( !iOperation, 
       
   120         User::Panic( KPanicIpsPlgSingleOpWatcher, KErrAlreadyExists ) );
       
   121     __ASSERT_DEBUG( aOperation, 
       
   122         User::Panic( KPanicIpsPlgSingleOpWatcher, KErrNotFound ) );
       
   123     __ASSERT_DEBUG( !iBaseOperation, 
       
   124         User::Panic( KPanicIpsPlgSingleOpWatcher, KErrAlreadyExists ) );
       
   125     //
       
   126     // Take ownership of operation and set our active status so we're handled 
       
   127     // by the active scheduler.
       
   128     iOperation = aOperation;
       
   129     iStatus = KRequestPending;
       
   130     SetActive();
       
   131     }
       
   132 
       
   133 void CIpsPlgSingleOpWatcher::SetOperation( CIpsPlgBaseOperation* aBaseOperation )
       
   134     {
       
   135     FUNC_LOG;
       
   136     __ASSERT_DEBUG( !IsActive(), 
       
   137         User::Panic( KPanicIpsPlgSingleOpWatcher, KErrInUse ) );
       
   138     __ASSERT_DEBUG( !iOperation, 
       
   139         User::Panic( KPanicIpsPlgSingleOpWatcher, KErrAlreadyExists ) );
       
   140     __ASSERT_DEBUG( aBaseOperation, 
       
   141         User::Panic( KPanicIpsPlgSingleOpWatcher, KErrNotFound ) );
       
   142     __ASSERT_DEBUG( !iBaseOperation, 
       
   143         User::Panic( KPanicIpsPlgSingleOpWatcher, KErrAlreadyExists ) );
       
   144     
       
   145     iBaseOperation = aBaseOperation;
       
   146     iStatus = KRequestPending;
       
   147     SetActive();
       
   148     }
       
   149 
       
   150 const CIpsPlgBaseOperation* CIpsPlgSingleOpWatcher::BaseOperation( ) const
       
   151     {
       
   152     FUNC_LOG;
       
   153     CIpsPlgBaseOperation* op = NULL;
       
   154     
       
   155     if ( !iOperation )
       
   156         {
       
   157         __ASSERT_DEBUG( iBaseOperation, 
       
   158             User::Panic( KPanicIpsPlgSingleOpWatcher, KErrNotFound  )  );
       
   159         op =  iBaseOperation;
       
   160         }
       
   161     
       
   162     return op;
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------
       
   166 // CIpsPlgSingleOpWatcher::Operation
       
   167 // --- Accessor ---
       
   168 // ---------------------------------------------------------
       
   169 //
       
   170 EXPORT_C CMsvOperation& CIpsPlgSingleOpWatcher::Operation() const
       
   171     {
       
   172     FUNC_LOG;
       
   173     CMsvOperation* op = NULL;
       
   174     if ( !iOperation )
       
   175         {
       
   176         __ASSERT_DEBUG( iBaseOperation, 
       
   177             User::Panic( KPanicIpsPlgSingleOpWatcher, KErrNotFound  )  );
       
   178         op = static_cast<CMsvOperation*>( iBaseOperation );
       
   179         }
       
   180     else if ( !iBaseOperation )
       
   181         {
       
   182         __ASSERT_DEBUG( iOperation, 
       
   183             User::Panic( KPanicIpsPlgSingleOpWatcher, KErrNotFound  )  );
       
   184         op = iOperation;
       
   185         }
       
   186         
       
   187     return *op;
       
   188     }
       
   189 
       
   190 
       
   191 
       
   192 
       
   193 // ---------------------------------------------------------
       
   194 // CIpsPlgSingleOpWatcher::DoCancel
       
   195 // --- From CActive ---
       
   196 // ---------------------------------------------------------
       
   197 //
       
   198 void CIpsPlgSingleOpWatcher::DoCancel()        
       
   199     {
       
   200     FUNC_LOG;
       
   201 
       
   202     // Pass on cancel
       
   203     if ( iOperation && iOperation->IsActive() )
       
   204         {
       
   205         iOperation->Cancel();
       
   206         }
       
   207     else if ( iBaseOperation && iBaseOperation->IsActive() )
       
   208         {
       
   209         iBaseOperation->Cancel();
       
   210         }
       
   211     else
       
   212         {
       
   213         TRequestStatus* status = &iStatus;
       
   214         User::RequestComplete(status, KErrNone);
       
   215         }
       
   216     }
       
   217 
       
   218 
       
   219 //------------------------------------
       
   220 // CIpsPlgSingleOpWatcher::RunL
       
   221 // --- From CActive ---
       
   222 // ---------------------------------------------------------
       
   223 //
       
   224 void CIpsPlgSingleOpWatcher::RunL()
       
   225     {
       
   226     FUNC_LOG;
       
   227     //
       
   228     // Inform client of watcher that the operation has completed
       
   229     iObserver.OpCompleted( *this, iStatus.Int() );
       
   230     }
       
   231 
       
   232 
       
   233 void CIpsPlgSingleOpWatcher::SetRequestObserver(
       
   234     CIpsPlgImap4MoveRemoteOpObserver* aObserver )
       
   235     {
       
   236     delete iRequestObserver;
       
   237     iRequestObserver = aObserver;
       
   238     }
       
   239 
       
   240 // End of file
       
   241