|
1 // Copyright (c) 1998-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 // Implements the CSmsuActive class |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 */ |
|
21 |
|
22 #include "smsuact.h" |
|
23 #include "SmsuTimer.h" |
|
24 #include "smsstacklog.h" |
|
25 #include "smsumain.h" |
|
26 |
|
27 /** |
|
28 * Constructor. |
|
29 * |
|
30 * @param aPriority Active object priority |
|
31 * @capability None |
|
32 */ |
|
33 EXPORT_C CSmsuActiveBase::CSmsuActiveBase(TInt aPriority) |
|
34 : CActive(aPriority) |
|
35 { |
|
36 CActiveScheduler::Add(this); |
|
37 } // CSmsuActiveBase::CSmsuActiveBase |
|
38 |
|
39 |
|
40 /** |
|
41 * Destructor. |
|
42 * @capability None |
|
43 */ |
|
44 EXPORT_C CSmsuActiveBase::~CSmsuActiveBase() |
|
45 { |
|
46 Cancel(); |
|
47 delete iSmsuTimeout; |
|
48 } // CSmsuActiveBase::~CSmsuActiveBase |
|
49 |
|
50 |
|
51 /** |
|
52 * Constructs a timer. |
|
53 * |
|
54 * This is required before use of TimedSetActive(). |
|
55 * @capability None |
|
56 */ |
|
57 EXPORT_C void CSmsuActiveBase::ConstructTimeoutL() |
|
58 { |
|
59 LOGSMSU1("CSmsuActiveBase::ConstructTimeoutL()"); |
|
60 |
|
61 iSmsuTimeout = CSmsuTimeout::NewL(*this); |
|
62 } // CSmsuActiveBase::ConstructTimeoutL |
|
63 |
|
64 |
|
65 /** |
|
66 * Activates the object, and sets it to be completed after a specified time. |
|
67 * |
|
68 * @param aTimeIntervalMicroSeconds32 Time after which to complete the object |
|
69 * @capability None |
|
70 */ |
|
71 EXPORT_C void CSmsuActiveBase::TimedSetActive(const TTimeIntervalMicroSeconds32& aTimeIntervalMicroSeconds32) |
|
72 { |
|
73 LOGSMSU2("CSmsuActiveBase::TimedSetActive(): aTimeIntervalMicroSeconds32=%d", |
|
74 aTimeIntervalMicroSeconds32.Int()); |
|
75 |
|
76 __ASSERT_DEBUG(iSmsuTimeout != NULL, SmsuPanic(ESmsuTimeoutNull)); |
|
77 |
|
78 if (iSmsuTimeout != NULL) |
|
79 { |
|
80 iSmsuTimeout->Start(aTimeIntervalMicroSeconds32); |
|
81 } |
|
82 |
|
83 SetActive(); |
|
84 } // CSmsuActiveBase::TimedSetActive |
|
85 |
|
86 |
|
87 /** |
|
88 * Cancels a TimedSetActive() request. |
|
89 * |
|
90 * @see TimedSetActive |
|
91 */ |
|
92 EXPORT_C void CSmsuActiveBase::TimedSetActiveCancel() |
|
93 { |
|
94 LOGSMSU1("CSmsuActiveBase::TimedSetActiveCancel()"); |
|
95 |
|
96 if (iSmsuTimeout != NULL) |
|
97 { |
|
98 iSmsuTimeout->Cancel(); |
|
99 } |
|
100 } // CSmsuActiveBase::TimedSetActiveCancel |
|
101 |
|
102 |
|
103 /** |
|
104 * Determines if the object has timed out. |
|
105 * |
|
106 * @see TimedSetActive |
|
107 */ |
|
108 EXPORT_C TBool CSmsuActiveBase::TimedOut() const |
|
109 { |
|
110 LOGSMSU1("CSmsuActiveBase::TimedOut()"); |
|
111 |
|
112 if (iSmsuTimeout != NULL) |
|
113 { |
|
114 return iSmsuTimeout->TimedOut(); |
|
115 } |
|
116 |
|
117 return EFalse; |
|
118 } // CSmsuActiveBase::TimedOut |
|
119 |
|
120 |
|
121 /** |
|
122 * Sets an asynchronous observer to which to report completion of this object. |
|
123 * |
|
124 * @param aStatus Asynchronous status word of the observer |
|
125 * @capability None |
|
126 */ |
|
127 EXPORT_C void CSmsuActiveBase::Queue(TRequestStatus& aStatus) |
|
128 { |
|
129 LOGSMSU1("CSmsuActiveBase::Queue()"); |
|
130 |
|
131 __ASSERT_DEBUG(iReport==NULL, SmsuPanic(ESmsuAlreadyActive)); |
|
132 |
|
133 aStatus=KRequestPending; |
|
134 iReport=&aStatus; |
|
135 } // CSmsuActiveBase::Queue |
|
136 |
|
137 |
|
138 /** |
|
139 * Handles the object's request completion event. |
|
140 * |
|
141 * If a timer has been set with TimedSetActive(), this is cancelled. DoRunL() |
|
142 * is then called. If, after this, the object is not active, Complete() is called. |
|
143 * @capability None |
|
144 */ |
|
145 EXPORT_C void CSmsuActiveBase::RunL() |
|
146 { |
|
147 LOGSMSU1("CSmsuActiveBase::RunL()"); |
|
148 |
|
149 if (iSmsuTimeout != NULL) |
|
150 { |
|
151 iSmsuTimeout->Cancel(); |
|
152 } |
|
153 |
|
154 DoRunL(); |
|
155 |
|
156 if (!IsActive()) |
|
157 { |
|
158 Complete(iStatus.Int()); |
|
159 } |
|
160 } // CSmsuActiveBase::RunL |
|
161 |
|
162 |
|
163 /** |
|
164 * Object use complete. |
|
165 * |
|
166 * This is called at the end of the RunL(), if the RunL() has not reset the object |
|
167 * to be active. |
|
168 * |
|
169 * If an observer has been set (see Queue()), DoComplete() is called, and that |
|
170 * observer is signalled with the object status. |
|
171 * |
|
172 * @param aStatus Active object status word |
|
173 * @capability None |
|
174 */ |
|
175 EXPORT_C void CSmsuActiveBase::Complete(TInt aStatus) |
|
176 { |
|
177 LOGSMSU2("CSmsuActiveBase::Complete(): aStatus=%d", aStatus); |
|
178 |
|
179 if (iReport) |
|
180 { |
|
181 DoComplete(aStatus); |
|
182 User::RequestComplete(iReport, aStatus); |
|
183 iReport = NULL; |
|
184 } |
|
185 } // CSmsuActiveBase::Complete |
|
186 |
|
187 |
|
188 /** |
|
189 * Handles leaves occurring in the RunL() function. |
|
190 * |
|
191 * It calls Complete(). |
|
192 * |
|
193 * @param aError RunL() leave code |
|
194 * @return KErrNone |
|
195 * @capability None |
|
196 */ |
|
197 EXPORT_C TInt CSmsuActiveBase::RunError(TInt aError) |
|
198 { |
|
199 LOGSMSU2("CSmsuActiveBase::RunError(): aError=%d", aError); |
|
200 |
|
201 __ASSERT_DEBUG(!IsActive(), User::Invariant()); |
|
202 |
|
203 Complete(aError); |
|
204 |
|
205 return KErrNone; |
|
206 } // CSmsuActiveBase::RunError |
|
207 |
|
208 |
|
209 /** |
|
210 * Signals this object. |
|
211 * |
|
212 * @param aStatus Status code with which to signal the object |
|
213 * @param aSetActive True to set the object to be active |
|
214 * @capability None |
|
215 */ |
|
216 EXPORT_C void CSmsuActiveBase::CompleteMyself(TInt aStatus, TBool aSetActive /* = ETrue */) |
|
217 { |
|
218 // Ignore in code coverage - not used within the SMS stack. |
|
219 BULLSEYE_OFF |
|
220 LOGSMSU3("CSmsuActiveBase::CompleteMyself(): aStatus=%d, aSetActive=%d", |
|
221 aStatus, aSetActive); |
|
222 |
|
223 // Initialise iStatus with a pending request... |
|
224 iStatus = KRequestPending; |
|
225 |
|
226 // Set active if required... |
|
227 if (aSetActive) |
|
228 { |
|
229 SetActive(); |
|
230 } |
|
231 |
|
232 // Complete the request... |
|
233 TRequestStatus* status = &iStatus; |
|
234 |
|
235 User::RequestComplete(status, aStatus); |
|
236 BULLSEYE_RESTORE |
|
237 } |
|
238 |
|
239 /** |
|
240 * This function is used to request that the active object is completed |
|
241 * after the current timeout is handled. When a timeout occurs, the active |
|
242 * object is cancelled which requires DoCancel() to be called. However |
|
243 * the object is active until after the DoCancel() meaning it is not |
|
244 * possible to make a new request. This function requests a second |
|
245 * call to Complete() (via RunL etc.) which is done without the object |
|
246 * being active. |
|
247 * |
|
248 * This function can only be called when a timeout occurs, otherwise |
|
249 * it would not get actioned. |
|
250 * |
|
251 * @param aStatus Status code with which to signal the object |
|
252 * |
|
253 * @capability None |
|
254 */ |
|
255 EXPORT_C void CSmsuActiveBase::CompleteMyselfAfterTimeout(TInt aStatus) |
|
256 { |
|
257 LOGSMSU2("CSmsuActiveBase::CompleteMyselfAfterTimeout(): aStatus=%d", aStatus); |
|
258 |
|
259 __ASSERT_DEBUG(iSmsuTimeout != NULL, SmsuPanic(ESmsuTimeoutNull)); |
|
260 |
|
261 if (iSmsuTimeout != NULL && iSmsuTimeout->TimedOut()) |
|
262 { |
|
263 iSmsuTimeout->RequestCompleteMyselfAfterCancel(aStatus); |
|
264 } |
|
265 } // CSmsuActiveBase::CompleteMyselfAfterTimeout |