javamanager/javainstaller/appinstuiplugin/src/asyncwaitcallback.cpp
changeset 21 2a9601315dfc
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2009 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:  This class implements general wait object for calling a desired
       
    15  *                callback function after asynchronous notification
       
    16  *
       
    17 */
       
    18 
       
    19 
       
    20 #include "asyncwaitcallback.h"
       
    21 #include "logger.h"
       
    22 
       
    23 using namespace Java::Installer;
       
    24 
       
    25 // ============================ MEMBER FUNCTIONS ===============================
       
    26 
       
    27 CAsyncWaitCallBack* CAsyncWaitCallBack::NewL(TCallBack aCallBack)
       
    28 {
       
    29     CAsyncWaitCallBack* self = new(ELeave) CAsyncWaitCallBack();
       
    30     CleanupStack::PushL(self);
       
    31     self->ConstructL(aCallBack);
       
    32     CleanupStack::Pop(self);
       
    33     return self;
       
    34 }
       
    35 
       
    36 
       
    37 CAsyncWaitCallBack::CAsyncWaitCallBack():
       
    38         CActive(CActive::EPriorityStandard), iActivatingReasonCode(0)
       
    39 {
       
    40 }
       
    41 
       
    42 
       
    43 CAsyncWaitCallBack::~CAsyncWaitCallBack()
       
    44 {
       
    45 }
       
    46 
       
    47 
       
    48 void CAsyncWaitCallBack::ConstructL(TCallBack aCallBack)
       
    49 {
       
    50     iCallBack = aCallBack;
       
    51     CActiveScheduler::Add(this);
       
    52 }
       
    53 
       
    54 
       
    55 void CAsyncWaitCallBack::RunL()
       
    56 {
       
    57     // Execute callback only if the request completed with correct
       
    58     // status code
       
    59     if (iStatus == iActivatingReasonCode)
       
    60     {
       
    61         iCallBack.CallBack();
       
    62     }
       
    63     else
       
    64     {
       
    65         WLOG1(EJavaInstaller,
       
    66               "CAsyncWaitCallBack was called with unexpected notif code %d, reactivate",
       
    67               iStatus.Int());
       
    68         // Reactivate wait
       
    69         iProcessToListen.Rendezvous(iStatus);
       
    70         SetActive();
       
    71     }
       
    72 }
       
    73 
       
    74 
       
    75 void CAsyncWaitCallBack::DoCancel()
       
    76 {
       
    77     iProcessToListen.RendezvousCancel(iStatus);
       
    78 }
       
    79 
       
    80 
       
    81 void CAsyncWaitCallBack::Wait(RProcess aProcessToListen, TInt aActivatingReasonCode)
       
    82 {
       
    83     iActivatingReasonCode = aActivatingReasonCode;
       
    84     iProcessToListen = aProcessToListen;
       
    85     iProcessToListen.Rendezvous(iStatus);
       
    86     SetActive();
       
    87 }
       
    88