os/security/authorisation/userpromptservice/database/test/dumpupsdb/source/activewaiter.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 the License "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 *
    16 */
    17 
    18 
    19 #include "activewaiter.h"
    20 
    21 CActiveWaiter::CActiveWaiter()
    22 	: CActive(CActive::EPriorityStandard)
    23 	{
    24 	CActiveScheduler::Add(this);
    25 	}
    26 	
    27 CActiveWaiter::~CActiveWaiter()
    28 	{ Cancel(); }
    29 
    30 
    31 void CActiveWaiter::WaitActiveL(TInt aExpectedStatus /*=KErrNone*/)
    32 	{ 
    33 	ASSERT(!iScheduler.IsStarted());
    34 	SetActive();
    35 	
    36 	iScheduler.Start();
    37 	
    38 	if(iStatus.Int() != aExpectedStatus)
    39 		{
    40 		User::Leave(iStatus.Int());
    41 		}
    42 	}
    43 
    44 /**
    45 Sets the active scheduler active and immidiately Cancels, calling the 
    46 supplied cancel observer during DoCancel();
    47 @param aCancelObserver performs and DoCancel() operations on behalf of this object
    48 */
    49 void CActiveWaiter::SetActiveAndCancel(MActiveWaiterObserver& aCancelObserver)
    50 	{
    51 	ASSERT(!iScheduler.IsStarted());
    52 	ASSERT(iCancelObserver == NULL);
    53 	SetActive();
    54 	
    55 	iCancelObserver = &aCancelObserver;
    56 	
    57 	Cancel();
    58 	}
    59 
    60 /**
    61 Cancels the current operation, and stops the active scheduler loop,
    62 allowing a previous call to WaitActiveL() to return.
    63 @param aCancelObserver performs and DoCancel() operations on behalf of this object
    64 */
    65 void CActiveWaiter::CancelWaitActive(MActiveWaiterObserver& aCancelObserver)
    66 	{ 
    67 	ASSERT(iScheduler.IsStarted());
    68 	ASSERT(iCancelObserver == NULL);
    69 		
    70 	iCancelObserver = &aCancelObserver;
    71 	
    72 	Cancel();
    73 	
    74 	ASSERT(iScheduler.CanStopNow());
    75 	iScheduler.AsyncStop();
    76 	}
    77 
    78 void CActiveWaiter::RunL()
    79 	{
    80 	if (iScheduler.IsStarted())
    81 		{
    82 		ASSERT(iScheduler.CanStopNow());
    83 		iScheduler.AsyncStop();
    84 		}
    85 	}
    86 
    87 void CActiveWaiter::DoCancel()
    88 	{
    89 	ASSERT(iCancelObserver != NULL);
    90 	
    91 	iCancelObserver->DoCancel();
    92 	iCancelObserver = NULL;
    93 	}