|
1 /* |
|
2 * Copyright (c) 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 "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 * Implementation of CSsmActivityCmd class. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "ssmactivitycmd.h" |
|
20 #include "trace.h" |
|
21 |
|
22 #include <activitymanager.h> |
|
23 #include <barsread2.h> |
|
24 |
|
25 // ======== MEMBER FUNCTIONS ======== |
|
26 |
|
27 // --------------------------------------------------------------------------- |
|
28 // CSsmActivityCmd::NewL |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 CSsmActivityCmd* CSsmActivityCmd::NewL() |
|
32 { |
|
33 FUNC_LOG; |
|
34 return new ( ELeave ) CSsmActivityCmd(); |
|
35 } |
|
36 |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // CSsmActivityCmd::~CSsmActivityCmd |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 CSsmActivityCmd::~CSsmActivityCmd() |
|
43 { |
|
44 FUNC_LOG; |
|
45 } |
|
46 |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // CSsmActivityCmd::Initialize |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 TInt CSsmActivityCmd::Initialize( CSsmCustomCommandEnv* /*aCmdEnv*/ ) |
|
53 { |
|
54 FUNC_LOG; |
|
55 |
|
56 TInt err( KErrNone ); |
|
57 TRAP( err, iActivityMgr = CUserActivityManager::NewL( EPriorityNormal ) ); |
|
58 ERROR( err, "Failed to create activity manager." ); |
|
59 return err; |
|
60 } |
|
61 |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // CSsmActivityCmd::Execute |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 void CSsmActivityCmd::Execute( const TDesC8& aParams, |
|
68 TRequestStatus& aRequest ) |
|
69 { |
|
70 FUNC_LOG; |
|
71 |
|
72 aRequest = KRequestPending; |
|
73 iClientStatus = &aRequest; |
|
74 |
|
75 TInt err( KErrNone ); |
|
76 TInt timeout( 0 ); |
|
77 |
|
78 TRAP( err, timeout = ExtractParamsL( aParams ) ); |
|
79 |
|
80 ERROR( err, "Failed to parse parameters for execution" ); |
|
81 |
|
82 if ( KErrNone == err ) |
|
83 { |
|
84 TInt inactiveTime( User::InactivityTime().Int() ); |
|
85 |
|
86 INFO_2( "inactiveTime=%d, timeout=%d", inactiveTime, timeout ); |
|
87 // already inactive, complete immediately |
|
88 if ( inactiveTime >= timeout ) |
|
89 { |
|
90 INFO( "Already inactive" ); |
|
91 |
|
92 Complete( KErrNone ); |
|
93 } |
|
94 else |
|
95 { |
|
96 INFO( "Start waiting for inactivity" ); |
|
97 |
|
98 iActivityMgr->Start( TTimeIntervalSeconds( timeout ), |
|
99 TCallBack( InactiveCallback, this ), |
|
100 TCallBack( ActiveCallback, this ) ); |
|
101 } |
|
102 } |
|
103 else |
|
104 { |
|
105 Complete( KErrArgument ); |
|
106 } |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // CSsmActivityCmd::ExecuteCancel |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 void CSsmActivityCmd::ExecuteCancel() |
|
114 { |
|
115 FUNC_LOG; |
|
116 |
|
117 if ( iActivityMgr ) |
|
118 { |
|
119 iActivityMgr->Cancel(); |
|
120 } |
|
121 |
|
122 Complete( KErrCancel ); |
|
123 } |
|
124 |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // CSsmActivityCmd::Close |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 void CSsmActivityCmd::Close() |
|
131 { |
|
132 FUNC_LOG; |
|
133 |
|
134 if ( iActivityMgr ) |
|
135 { |
|
136 iActivityMgr->Cancel(); |
|
137 delete iActivityMgr; |
|
138 iActivityMgr = NULL; |
|
139 } |
|
140 } |
|
141 |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // CSsmActivityCmd::Release |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 void CSsmActivityCmd::Release() |
|
148 { |
|
149 FUNC_LOG; |
|
150 |
|
151 delete this; |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // CSsmActivityCmd::InactiveCallback |
|
156 // |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 TInt CSsmActivityCmd::InactiveCallback( TAny* aActivityMonitor ) |
|
160 { |
|
161 FUNC_LOG; |
|
162 |
|
163 CSsmActivityCmd* mon = static_cast<CSsmActivityCmd*>( aActivityMonitor ); |
|
164 |
|
165 // This would be a good place for cancelling CUserActivityManager |
|
166 // However, it reactivates its timer after client callback has been made, |
|
167 // so cancel won't have any effect |
|
168 // Just complete the request, Complete() checks whether there exists one |
|
169 mon->Complete( KErrNone ); // allow proceeding |
|
170 |
|
171 return KErrNone; |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------------------------- |
|
175 // CSsmActivityCmd::ActiveCallback |
|
176 // |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 TInt CSsmActivityCmd::ActiveCallback( TAny* /*aActivityMonitor*/ ) |
|
180 { |
|
181 FUNC_LOG; |
|
182 |
|
183 return KErrNone; |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // CSsmActivityCmd::Complete |
|
188 // |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 void CSsmActivityCmd::Complete( TInt aErrorCode ) |
|
192 { |
|
193 FUNC_LOG; |
|
194 |
|
195 INFO_2( "iClientStatus=0x%x, aErrorCode=%d", iClientStatus, aErrorCode ); |
|
196 |
|
197 if ( iClientStatus ) |
|
198 { |
|
199 INFO( "Allow startlist execution to continue" ); |
|
200 |
|
201 User::RequestComplete( iClientStatus, aErrorCode ); |
|
202 } |
|
203 } |
|
204 |
|
205 // --------------------------------------------------------------------------- |
|
206 // CSsmActivityCmd::Complete |
|
207 // |
|
208 // --------------------------------------------------------------------------- |
|
209 // |
|
210 TInt CSsmActivityCmd::ExtractParamsL( const TDesC8& aParams ) |
|
211 { |
|
212 FUNC_LOG; |
|
213 |
|
214 RResourceReader reader; |
|
215 reader.OpenLC( aParams ); |
|
216 TInt timeout = reader.ReadInt16L(); |
|
217 CleanupStack::PopAndDestroy(); // Reader |
|
218 return timeout; |
|
219 } |