1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/boardsupport/haitest/bspsvs/suite/common/src/ActiveCallbackBase.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,101 @@
1.4 +/*
1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +#include "ActiveCallbackBase.h"
1.22 +
1.23 +CActiveCallbackBase::CActiveCallbackTimer* CActiveCallbackBase::CActiveCallbackTimer::NewL(CActive& aActive, TInt aPriority)
1.24 + {
1.25 + CActiveCallbackTimer* self=new (ELeave) CActiveCallbackTimer(aActive, aPriority);
1.26 + CleanupStack::PushL(self);
1.27 + self->ConstructL();
1.28 + CActiveScheduler::Add(self);
1.29 + CleanupStack::Pop(self);
1.30 + return self;
1.31 + }
1.32 +
1.33 +CActiveCallbackBase::CActiveCallbackTimer::CActiveCallbackTimer(CActive& aActive, TInt aPriority)
1.34 +: CTimer(aPriority)
1.35 +, iActive(aActive)
1.36 + {
1.37 + }
1.38 +
1.39 +void CActiveCallbackBase::CActiveCallbackTimer::RunL()
1.40 + {
1.41 + if ( iStatus.Int()==KErrNone )
1.42 + {
1.43 + // Timer termiated without error
1.44 + if ( iActive.IsActive() )
1.45 + {
1.46 + iActive.Cancel();
1.47 + }
1.48 + }
1.49 + }
1.50 +
1.51 +CActiveCallbackBase* CActiveCallbackBase::NewLC(CDataWrapperBase& aDataWrapperBase, TInt aPriority)
1.52 + {
1.53 + CActiveCallbackBase* self=new(ELeave) CActiveCallbackBase(aDataWrapperBase, aPriority);
1.54 + CleanupStack::PushL(self);
1.55 + self->ConstructL();
1.56 + return self;
1.57 + }
1.58 +
1.59 +CActiveCallbackBase* CActiveCallbackBase::NewL(CDataWrapperBase& aDataWrapperBase, TInt aPriority)
1.60 + {
1.61 + CActiveCallbackBase* self=CActiveCallbackBase::NewLC(aDataWrapperBase, aPriority);
1.62 + CleanupStack::Pop();
1.63 + return self;
1.64 + }
1.65 +
1.66 +CActiveCallbackBase::CActiveCallbackBase(CDataWrapperBase& aDataWrapperBase, TInt aPriority)
1.67 +: CActiveCallback(aDataWrapperBase, aPriority)
1.68 +, iDataWrapperBase(aDataWrapperBase)
1.69 +, iTimer(NULL)
1.70 + {
1.71 + }
1.72 +
1.73 +void CActiveCallbackBase::ConstructL()
1.74 + {
1.75 + CActiveCallback::ConstructL();
1.76 + iTimer=CActiveCallbackTimer::NewL(*this);
1.77 + }
1.78 +
1.79 +CActiveCallbackBase::~CActiveCallbackBase()
1.80 +/**
1.81 + * Public destructor
1.82 + */
1.83 + {
1.84 + delete iTimer;
1.85 + iTimer=NULL;
1.86 + }
1.87 +
1.88 +void CActiveCallbackBase::Activate(TInt aIndex, TInt aTimeout)
1.89 + {
1.90 + CActiveCallback::Activate(aIndex);
1.91 + if ( aTimeout!=0 )
1.92 + {
1.93 + iTimer->After(aTimeout);
1.94 + }
1.95 + }
1.96 +
1.97 +void CActiveCallbackBase::KillTimer()
1.98 + {
1.99 + if ( iTimer->IsActive() )
1.100 + {
1.101 + iDataWrapperBase.INFO_PRINTF1(_L("CActiveCallbackBase::KillTimer"));
1.102 + iTimer->Cancel();
1.103 + }
1.104 + }