os/security/cryptomgmtlibs/securitycommonutils/source/scsserver/shutdowntimer.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptomgmtlibs/securitycommonutils/source/scsserver/shutdowntimer.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,91 @@
1.4 +/*
1.5 +* Copyright (c) 2007-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 the License "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 +* Implements the timer which stops the server after no sessions have been
1.19 +* open for a defined period.
1.20 +*
1.21 +*/
1.22 +
1.23 +
1.24 +/**
1.25 + @file
1.26 +*/
1.27 +
1.28 +#include <scs/scsserver.h>
1.29 +
1.30 +
1.31 +CShutdownTimer* CShutdownTimer::NewL(TInt aDelayUs)
1.32 +/**
1.33 + Factory function allocates a new, initialized instance of CShutdownTimer.
1.34 +
1.35 + @param aDelayUs Delay in microseconds.
1.36 + @return New, initialized instance of CShutdownTimer.
1.37 + The newly-created object is owned by the caller.
1.38 + */
1.39 + {
1.40 + CShutdownTimer* self = new(ELeave) CShutdownTimer(aDelayUs);
1.41 + CleanupStack::PushL(self);
1.42 + self->ConstructL(); // CTimer implementation
1.43 + CleanupStack::Pop(self);
1.44 + return self;
1.45 + }
1.46 +
1.47 +CShutdownTimer::CShutdownTimer(TInt aDelayUs)
1.48 +/**
1.49 + Record the shutdown period and add this object to the active scheduler.
1.50 +
1.51 + @param aDelayUs Delay in microseconds.
1.52 + */
1.53 + : CTimer(CActive::EPriorityStandard),
1.54 + iDelayUs(aDelayUs)
1.55 + {
1.56 + CActiveScheduler::Add(this);
1.57 + }
1.58 +
1.59 +void CShutdownTimer::Restart()
1.60 +/**
1.61 + Restart this timer. This timer should not be active when this
1.62 + function is called.
1.63 +
1.64 + Once started, the timer can be stopped with the base class' Cancel function.
1.65 + */
1.66 + {
1.67 + if(iImmediateTimeoutNextRestart)
1.68 + {
1.69 + CActiveScheduler::Stop();
1.70 + return;
1.71 + }
1.72 +
1.73 + // Start idle timeout
1.74 + After(iDelayUs);
1.75 + }
1.76 +
1.77 +void CShutdownTimer::ImmediateTimeoutNextRestart()
1.78 +/**
1.79 + Timer should immediately expire when Restart is next called.
1.80 + */
1.81 + {
1.82 + iImmediateTimeoutNextRestart = ETrue;
1.83 + }
1.84 +
1.85 +
1.86 +void CShutdownTimer::RunL()
1.87 +/**
1.88 + Implement CActive by stopping the active scheduler, which
1.89 + has the effect of breaking out of the server loop.
1.90 + */
1.91 + {
1.92 + CActiveScheduler::Stop();
1.93 + }
1.94 +