|
1 /* |
|
2 * Copyright (c) 2008 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 "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: Shutdown watcher implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ShutdownWatcher.h" |
|
20 #include <startupdomainpskeys.h> |
|
21 |
|
22 |
|
23 // ======== MEMBER FUNCTIONS ======== |
|
24 |
|
25 // --------------------------------------------------------------------------- |
|
26 // CShutdownWatcher::NewL |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 CShutdownWatcher* CShutdownWatcher::NewL( MShutdownObserver& aObserver ) |
|
30 { |
|
31 CShutdownWatcher* self = new(ELeave) CShutdownWatcher( aObserver ); |
|
32 CleanupStack::PushL( self ); |
|
33 self->ConstructL(); |
|
34 CleanupStack::Pop( self ); |
|
35 return self; |
|
36 } |
|
37 |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // CShutdownWatcher::~CShutdownWatcher |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CShutdownWatcher::~CShutdownWatcher() |
|
44 { |
|
45 Cancel(); |
|
46 iProperty.Close(); |
|
47 } |
|
48 |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CShutdownWatcher::Start |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 void CShutdownWatcher::Start() |
|
55 { |
|
56 TInt status( 0 ); |
|
57 TInt err = iProperty.Get( KPSUidStartup, KPSGlobalSystemState, status ); |
|
58 if( err == KErrNone ) |
|
59 { |
|
60 if( status == ESwStateShuttingDown ) |
|
61 { |
|
62 iObserver.NotifyShuttingDown(); |
|
63 return; // that was all, system is already going down |
|
64 } |
|
65 } |
|
66 IssueRequest(); |
|
67 } |
|
68 |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // CShutdownWatcher::IssueRequest |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 void CShutdownWatcher::IssueRequest() |
|
75 { |
|
76 if( !IsActive() ) |
|
77 { |
|
78 iProperty.Subscribe( iStatus ); |
|
79 SetActive(); |
|
80 } |
|
81 } |
|
82 |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // CShutdownWatcher::DoCancel |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 void CShutdownWatcher::DoCancel() |
|
89 { |
|
90 iProperty.Cancel(); |
|
91 } |
|
92 |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CShutdownWatcher::RunL() |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void CShutdownWatcher::RunL() |
|
99 { |
|
100 IssueRequest(); |
|
101 |
|
102 TInt status( 0 ); |
|
103 iProperty.Get( status ); |
|
104 |
|
105 if( status == ESwStateShuttingDown ) |
|
106 { |
|
107 iObserver.NotifyShuttingDown(); |
|
108 Cancel(); // that was all, no other notifications needed |
|
109 } |
|
110 } |
|
111 |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // CShutdownWatcher::CShutdownWatcher |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 CShutdownWatcher::CShutdownWatcher( MShutdownObserver& aObserver ) |
|
118 : CActive( EPriorityStandard ), iObserver( aObserver ) |
|
119 { |
|
120 } |
|
121 |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // CShutdownWatcher::ConstructL() |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 void CShutdownWatcher::ConstructL() |
|
128 { |
|
129 TInt err = iProperty.Attach( KPSUidStartup, KPSGlobalSystemState ); |
|
130 User::LeaveIfError( err ); |
|
131 |
|
132 CActiveScheduler::Add( this ); |
|
133 } |
|
134 |
|
135 |
|
136 // End of file |