iaupdate/IAD/engine/controller/src/iaupdaterendezvous.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2007-2007 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:   CIAUpdateRendezvous
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "iaupdaterendezvous.h"
       
    22 #include "iaupdaterendezvousobserver.h"
       
    23 #include "iaupdatedebug.h"
       
    24 
       
    25 
       
    26 CIAUpdateRendezvous* CIAUpdateRendezvous::NewL( MIAUpdateRendezvousObserver& aObserver )
       
    27     {
       
    28     CIAUpdateRendezvous* self = 
       
    29         CIAUpdateRendezvous::NewLC( aObserver ); 
       
    30     CleanupStack::Pop( self );
       
    31     return self;
       
    32     }
       
    33 
       
    34 
       
    35 CIAUpdateRendezvous* CIAUpdateRendezvous::NewLC( MIAUpdateRendezvousObserver& aObserver )
       
    36     {
       
    37     CIAUpdateRendezvous* self = 
       
    38         new( ELeave ) CIAUpdateRendezvous( aObserver );
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL();
       
    41     return self;    
       
    42     }
       
    43 
       
    44 
       
    45 CIAUpdateRendezvous::CIAUpdateRendezvous( MIAUpdateRendezvousObserver& aObserver )
       
    46 : CActive( CActive::EPriorityStandard ), 
       
    47   iObserver( aObserver )
       
    48     {
       
    49     
       
    50     }
       
    51 
       
    52 
       
    53 void CIAUpdateRendezvous::ConstructL()
       
    54     {
       
    55     CActiveScheduler::Add( this );
       
    56     }
       
    57 
       
    58 
       
    59 CIAUpdateRendezvous::~CIAUpdateRendezvous()
       
    60     {
       
    61     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateRendezvous::~CIAUpdateRendezvous() begin");
       
    62     
       
    63     // It is always good and safe to do cancel in CActive objects.
       
    64     Cancel();
       
    65 
       
    66     // No need to close the rendezvous process here anymore.
       
    67     // It is closed in cancel above if this object was active.
       
    68     // Or, if the object was not active, then the process has already 
       
    69     // been closed before in RunL or it has not been even opened.
       
    70 
       
    71     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateRendezvous::~CIAUpdateRendezvous() end");
       
    72     }
       
    73 
       
    74 
       
    75 void CIAUpdateRendezvous::DoCancel()
       
    76     {
       
    77     IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateRendezvous::DoCancel() begin: %d", iStatus.Int());
       
    78     
       
    79     // Notice, that the active observer Cancel-function waits for the
       
    80     // silent launcher to send request complete before cancel of this
       
    81     // active object can finish. This is normal active object cancel operation behaviour.
       
    82     // Notice, that we do not call the callback functions of the observer here
       
    83     // because we suppose that the observer has started the cancel operation itself
       
    84     // or the caller will inform the observer itself.
       
    85 
       
    86     // Cancel the previously requested rendezvous with the process.
       
    87     // This will make the request complete with KErrCancel value.    
       
    88     TInt cancelError( RendezvousProcess().RendezvousCancel( iStatus ) );
       
    89     IAUPDATE_TRACE_1("[IAUPDATE] Rendezvous cancel error code: %d", cancelError);
       
    90     IAUPDATE_TRACE_1("[IAUPDATE] Rendezvous cancelled. Current iStatus: %d", iStatus.Int());
       
    91         
       
    92     // Because process is not needed anymore, close it.
       
    93     RendezvousProcess().Close();
       
    94 
       
    95     // If cancel error is KErrNone, then the rendezvous cancel above has 
       
    96     // completed the request with KErrCancel.
       
    97     if ( cancelError != KErrNone )
       
    98         {
       
    99         // We should never come here, because DoCancel is called only if this
       
   100         // active object is active. And then, rendezvous should be also active and
       
   101         // cancel above should finish correctly.
       
   102         IAUPDATE_TRACE("[IAUPDATE] WARNING: Rendezvous could not be cancelled.");
       
   103         TRequestStatus* ptrStatus = &iStatus;
       
   104         User::RequestComplete( ptrStatus, KErrCancel );        
       
   105         }
       
   106 
       
   107     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateRendezvous::DoCancel() end");
       
   108     }
       
   109 
       
   110 
       
   111 void CIAUpdateRendezvous::StartL( const TProcessId& aProcessId )
       
   112     {
       
   113     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateRendezvous::StartL() begin");
       
   114     
       
   115     if ( IsActive() )
       
   116         {
       
   117         IAUPDATE_TRACE("[IAUPDATE] StartL already in use");
       
   118         User::Leave( KErrInUse );
       
   119         }
       
   120     
       
   121     TInt error( RendezvousProcess().Open( aProcessId ) );
       
   122     if ( error != KErrNone )
       
   123         {
       
   124         IAUPDATE_TRACE_1("[IAUPDATE] Rendezvous open error: %d", error);
       
   125         RendezvousProcess().Close();
       
   126         User::Leave( error );        
       
   127         }
       
   128 
       
   129     RendezvousProcess().Rendezvous( iStatus );
       
   130     if ( iStatus != KRequestPending )
       
   131         {
       
   132         // Rendezvous operation could not be completed.
       
   133         IAUPDATE_TRACE_1("[IAUPDATE] Rendezvous error: %d", iStatus.Int());
       
   134         RendezvousProcess().Close();
       
   135         User::Leave( iStatus.Int() );
       
   136         }
       
   137 
       
   138     SetActive();
       
   139 
       
   140     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateRendezvous::StartL() end");
       
   141     }
       
   142 
       
   143 
       
   144 void CIAUpdateRendezvous::RunL()
       
   145     {
       
   146     // This is called when Rendezvous is finished in the iProcess.
       
   147     RendezvousProcess().Close();
       
   148     Observer().RendezvousComplete( iStatus.Int() );
       
   149     }
       
   150 
       
   151 
       
   152 MIAUpdateRendezvousObserver& CIAUpdateRendezvous::Observer()
       
   153     {
       
   154     return iObserver;
       
   155     }
       
   156 
       
   157 
       
   158 RProcess& CIAUpdateRendezvous::RendezvousProcess()
       
   159     {
       
   160     return iProcess;
       
   161     }