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