|
1 /* |
|
2 * Copyright (c) 2002-2007 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: Monitor for user activity |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CSatUserActivityMonitor.h" |
|
21 #include "SatLog.h" |
|
22 |
|
23 // ============================ MEMBER FUNCTIONS =============================== |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // CSatUserActivityMonitor::CSatUserActivityMonitor |
|
27 // C++ default constructor can NOT contain any code, that |
|
28 // might leave. |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 CSatUserActivityMonitor::CSatUserActivityMonitor( |
|
32 MSatEventMonitorUtils& aUtils ) : |
|
33 CSatEventMonitorHandler( aUtils ) |
|
34 { |
|
35 LOG( SIMPLE, "SATEVENTMONITORS: CSatUserActivityMonitor::\ |
|
36 CSatUserActivityMonitor calling" ) |
|
37 |
|
38 iActivityManager = NULL; |
|
39 |
|
40 LOG( SIMPLE, "SATEVENTMONITORS: CSatUserActivityMonitor::\ |
|
41 CSatUserActivityMonitor exiting" ) |
|
42 } |
|
43 |
|
44 // Destructor |
|
45 CSatUserActivityMonitor::~CSatUserActivityMonitor() |
|
46 { |
|
47 LOG( SIMPLE, "SATEVENTMONITORS: CSatUserActivityMonitor::\ |
|
48 ~CSatUserActivityMonitor calling" ) |
|
49 |
|
50 Cancel(); |
|
51 |
|
52 if ( iActivityManager ) |
|
53 { |
|
54 delete iActivityManager; |
|
55 iActivityManager = NULL; |
|
56 } |
|
57 |
|
58 LOG( SIMPLE, "SATEVENTMONITORS: CSatUserActivityMonitor::\ |
|
59 ~CSatUserActivityMonitor exiting" ) |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CSatUserActivityMonitor::NewL |
|
64 // Two-phased constructor. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 CSatUserActivityMonitor* CSatUserActivityMonitor::NewL( |
|
68 MSatEventMonitorUtils& aUtils ) |
|
69 { |
|
70 LOG( SIMPLE, "SATEVENTMONITORS: CSatUserActivityMonitor::NewL calling" ) |
|
71 |
|
72 CSatUserActivityMonitor* self = |
|
73 new( ELeave ) CSatUserActivityMonitor( aUtils ); |
|
74 CleanupStack::PushL( self ); |
|
75 self->ConstructL(); |
|
76 CleanupStack::Pop( self ); |
|
77 |
|
78 LOG( SIMPLE, "SATEVENTMONITORS: CSatUserActivityMonitor::NewL exiting" ) |
|
79 return self; |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CSatUserActivityMonitor::ConstructL |
|
84 // Symbian 2nd phase constructor can leave. |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 void CSatUserActivityMonitor::ConstructL() |
|
88 { |
|
89 LOG( SIMPLE, "SATEVENTMONITORS: CSatUserActivityMonitor::\ |
|
90 ConstructL calling" ) |
|
91 |
|
92 // Create base class and give this monitors event as a parameter |
|
93 BaseConstructL( MSatEventMonitor::EUserActivity ); |
|
94 iMonitoring = EFalse; |
|
95 |
|
96 LOG( SIMPLE, "SATEVENTMONITORS: CSatUserActivityMonitor::\ |
|
97 ConstructL exiting" ) |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CSatUserActivityMonitor::StartActivityManagerL |
|
102 // Called when user has been inactive for a pre-defined time period |
|
103 // (other items were commented in a header). |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void CSatUserActivityMonitor::StartActivityManagerL() |
|
107 { |
|
108 LOG( SIMPLE,"SATEVENTMONITORS: \ |
|
109 CSatUserActivityMonitor::StartActivityManag calling" ) |
|
110 |
|
111 // Delete activity manager if it exists |
|
112 if ( iActivityManager ) |
|
113 { |
|
114 LOG( SIMPLE,"SATEVENTMONITORS: \ |
|
115 CSatUserActivityMonitor::StartActivityManag iActivityManager true" ) |
|
116 iActivityManager->Cancel(); |
|
117 delete iActivityManager; |
|
118 iActivityManager = NULL; |
|
119 } |
|
120 |
|
121 iMonitoring = ETrue; |
|
122 |
|
123 iActivityManager = CUserActivityManager::NewL( EPriorityNormal ); |
|
124 iActivityManager->Start( |
|
125 TTimeIntervalSeconds( 1 ), |
|
126 TCallBack( DispatchUserInactive, this ), |
|
127 TCallBack( DispatchUserActive, this ) ); |
|
128 |
|
129 // Changes checking immediatelly activity, |
|
130 // activity before exceeding one second. |
|
131 iActivityManager->SetInactivityTimeout( TTimeIntervalSeconds( 0 ) ); |
|
132 |
|
133 LOG( SIMPLE, "SATEVENTMONITORS: \ |
|
134 CSatUserActivityMonitor::StartActivityManagerL exiting" ) |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CSatUserActivityMonitor::DispatchUserInactive |
|
139 // Called when user has been inactive for a pre-defined time period |
|
140 // (other items were commented in a header). |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 TInt CSatUserActivityMonitor::DispatchUserInactive( TAny* /* aPtr */ ) |
|
144 { |
|
145 LOG( SIMPLE, "SATEVENTMONITORS: \ |
|
146 CSatUserActivityMonitor::DispatchUserInactive calling/exiting" ) |
|
147 return KErrNone; |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CSatUserActivityMonitor::DispatchUserActive |
|
152 // Called when user does something |
|
153 // (other items were commented in a header). |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 TInt CSatUserActivityMonitor::DispatchUserActive( TAny* aPtr ) |
|
157 { |
|
158 LOG( SIMPLE, "SATEVENTMONITORS: \ |
|
159 CSatUserActivityMonitor::DispatchUserActive calling" ) |
|
160 |
|
161 TInt retVal( KErrNone ); |
|
162 |
|
163 if ( aPtr ) |
|
164 { |
|
165 LOG( SIMPLE, "SATEVENTMONITORS: \ |
|
166 CSatUserActivityMonitor::DispatchUserActive aPtr true" ) |
|
167 CSatUserActivityMonitor* ptrThis = |
|
168 static_cast<CSatUserActivityMonitor*>( aPtr ); |
|
169 if ( ptrThis->iMonitoring ) |
|
170 { |
|
171 LOG( SIMPLE, "SATEVENTMONITORS: \ |
|
172 CSatUserActivityMonitor::DispatchUserActive ptrThis->iMonitoring" ) |
|
173 // Notify observer and set flag off, no more monitoring. |
|
174 ptrThis->EventOccured(); |
|
175 ptrThis->iMonitoring = EFalse; |
|
176 } |
|
177 else |
|
178 { |
|
179 retVal = KErrCancel; |
|
180 } |
|
181 } |
|
182 LOG2( SIMPLE, "SATEVENTMONITORS: CSatUserActivityMonitor::\ |
|
183 DispatchUserActive exiting, retVal: %d", retVal ) |
|
184 return retVal; |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // CSatUserActivityMonitor::DoCancelMonitor |
|
189 // Symbian 2nd phase constructor can leave. |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 void CSatUserActivityMonitor::DoCancelMonitor() |
|
193 { |
|
194 LOG( SIMPLE, |
|
195 "SATEVENTMONITORS: CSatUserActivityMonitor::DoCancelMonitor calling" ) |
|
196 |
|
197 Cancel(); |
|
198 |
|
199 LOG( SIMPLE, |
|
200 "SATEVENTMONITORS: CSatUserActivityMonitor::DoCancelMonitor exiting" ) |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CSatUserActivityMonitor::StartMonitor |
|
205 // Starts monitoring the user activity. The real start of user actitivity |
|
206 // monitoring starts in RunL, after call of Inactivity( 0 ), which causes run of |
|
207 // RunL immediatly. The inacativity call is needed to reset the user activity |
|
208 // timers in User class. |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 TInt CSatUserActivityMonitor::StartMonitor() |
|
212 { |
|
213 LOG( SIMPLE, |
|
214 "SATEVENTMONITORS: CSatUserActivityMonitor::StartMonitor calling" ) |
|
215 |
|
216 // Starts activity manager. |
|
217 TRAPD( err, StartActivityManagerL() ); |
|
218 |
|
219 LOG2( SIMPLE, |
|
220 "SATEVENTMONITORS: CSatUserActivityMonitor::StartMonitor exiting,\ |
|
221 err: %d", err ) |
|
222 return err; |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CSatUserActivityMonitor::Cancel |
|
227 // Cancels user activity monitor. |
|
228 // If activity manager is active, cancels request |
|
229 // and deletes activity manager. |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 void CSatUserActivityMonitor::Cancel() |
|
233 { |
|
234 LOG( SIMPLE, "SATEVENTMONITORS: CSatUserActivityMonitor::Cancel calling" ) |
|
235 |
|
236 if ( iActivityManager ) |
|
237 { |
|
238 LOG( DETAILED, |
|
239 "SATEVENTMONITORS: CSatUAMon::Cancel AM Cancel call" ) |
|
240 iActivityManager->Cancel(); |
|
241 |
|
242 delete iActivityManager; |
|
243 iActivityManager = NULL; |
|
244 } |
|
245 |
|
246 LOG( SIMPLE, "SATEVENTMONITORS: CSatUserActivityMonitor::Cancel exiting" ) |
|
247 } |
|
248 |
|
249 // End of file |