|
1 /* |
|
2 * Copyright (c) 2007-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 * Implements the timer which stops the server after no sessions have been |
|
16 * open for a defined period. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 /** |
|
22 @file |
|
23 */ |
|
24 |
|
25 #include <scs/scsserver.h> |
|
26 |
|
27 |
|
28 CShutdownTimer* CShutdownTimer::NewL(TInt aDelayUs) |
|
29 /** |
|
30 Factory function allocates a new, initialized instance of CShutdownTimer. |
|
31 |
|
32 @param aDelayUs Delay in microseconds. |
|
33 @return New, initialized instance of CShutdownTimer. |
|
34 The newly-created object is owned by the caller. |
|
35 */ |
|
36 { |
|
37 CShutdownTimer* self = new(ELeave) CShutdownTimer(aDelayUs); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(); // CTimer implementation |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 CShutdownTimer::CShutdownTimer(TInt aDelayUs) |
|
45 /** |
|
46 Record the shutdown period and add this object to the active scheduler. |
|
47 |
|
48 @param aDelayUs Delay in microseconds. |
|
49 */ |
|
50 : CTimer(CActive::EPriorityStandard), |
|
51 iDelayUs(aDelayUs) |
|
52 { |
|
53 CActiveScheduler::Add(this); |
|
54 } |
|
55 |
|
56 void CShutdownTimer::Restart() |
|
57 /** |
|
58 Restart this timer. This timer should not be active when this |
|
59 function is called. |
|
60 |
|
61 Once started, the timer can be stopped with the base class' Cancel function. |
|
62 */ |
|
63 { |
|
64 if(iImmediateTimeoutNextRestart) |
|
65 { |
|
66 CActiveScheduler::Stop(); |
|
67 return; |
|
68 } |
|
69 |
|
70 // Start idle timeout |
|
71 After(iDelayUs); |
|
72 } |
|
73 |
|
74 void CShutdownTimer::ImmediateTimeoutNextRestart() |
|
75 /** |
|
76 Timer should immediately expire when Restart is next called. |
|
77 */ |
|
78 { |
|
79 iImmediateTimeoutNextRestart = ETrue; |
|
80 } |
|
81 |
|
82 |
|
83 void CShutdownTimer::RunL() |
|
84 /** |
|
85 Implement CActive by stopping the active scheduler, which |
|
86 has the effect of breaking out of the server loop. |
|
87 */ |
|
88 { |
|
89 CActiveScheduler::Stop(); |
|
90 } |
|
91 |