|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "shutdowntimer.h" |
|
17 #include "savepriv.h" |
|
18 |
|
19 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
20 #include "shutdownsrv.h" |
|
21 #else //SYMBIAN_ENABLE_SPLIT_HEADERS |
|
22 #include "shutdownsess.h" |
|
23 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS |
|
24 #include "shutdownsrvpatchdata.h" |
|
25 |
|
26 /* |
|
27 Patchable data KShtdwnTimeoutBase can be configured as -1 not to apply the timer |
|
28 as backward compatibility. |
|
29 */ |
|
30 const TInt32 KShtdwnTimeoutNoApply = -1; |
|
31 |
|
32 /** |
|
33 Standard phase-one factory method for creating CShutdownTimer instances. |
|
34 It might return a NULL pointer if the patchable constant KShtdwnTimeoutBase has been configured |
|
35 as -1 which indicates no timer should be started. |
|
36 @param aShtdwnSrv The reference to CServShutdownServer. |
|
37 @return 0 if no timer should be started, otherwise a pointer to CShutdownTimer object. |
|
38 @leave Some system-wide error codes including KErrNoMemory. |
|
39 @panic KErrNotSupported Incorrect patchable variables configuration. |
|
40 */ |
|
41 CShutdownTimer* CShutdownTimer::NewL(CServShutdownServer& aShtdwnSrv) |
|
42 { |
|
43 __ASSERT_ALWAYS( (KShtdwnTimeoutBase >= KShtdwnTimeoutNoApply) && (KShtdwnTimeoutClient >= 0), \ |
|
44 User::Panic(__SHUTDOWN_SERVER_NAME, KErrNotSupported)); |
|
45 |
|
46 CShutdownTimer* self = 0; |
|
47 if(KShtdwnTimeoutBase > KShtdwnTimeoutNoApply) |
|
48 { |
|
49 self = new(ELeave) CShutdownTimer(aShtdwnSrv); |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL(); |
|
52 CleanupStack::Pop(self); |
|
53 } |
|
54 |
|
55 return self; |
|
56 } |
|
57 |
|
58 /** |
|
59 Constructor |
|
60 @param aShtdwnSrv The reference to CServShutdownServer |
|
61 */ |
|
62 CShutdownTimer::CShutdownTimer(CServShutdownServer& aShtdwnSrv): |
|
63 CTimer(CActive::EPriorityStandard), iShtdwnSrv(aShtdwnSrv) |
|
64 { |
|
65 CActiveScheduler::Add(this); |
|
66 } |
|
67 |
|
68 /** |
|
69 Removes the timer object from the active scheduler's list if it has been added. |
|
70 */ |
|
71 void CShutdownTimer::DoCancel() |
|
72 { |
|
73 // Do nothing |
|
74 } |
|
75 |
|
76 /** |
|
77 Calculates the timeout value by the number of the clients and starts the timer. |
|
78 @param aNumClients The number of the clients. |
|
79 */ |
|
80 void CShutdownTimer::Start(TInt aNumClients) |
|
81 { |
|
82 TInt32 timeout = KShtdwnTimeoutBase + KShtdwnTimeoutClient * aNumClients; |
|
83 After(timeout); |
|
84 } |
|
85 |
|
86 |
|
87 /** |
|
88 Gets called when the timeout expires. |
|
89 Calls CServShutdownServer::SwitchOff() to execute the switch off. |
|
90 */ |
|
91 void CShutdownTimer::RunL() |
|
92 { |
|
93 iShtdwnSrv.SwitchOff(); |
|
94 } |