|
1 // Copyright (c) 1997-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 /** |
|
17 @file |
|
18 */ |
|
19 |
|
20 #include <commsdattypesv1_1.h> |
|
21 #include <cdbcols.h> |
|
22 #include "smspmain.h" |
|
23 #include "smsuset.h" |
|
24 #include "smspcdb.h" |
|
25 #include "SmsuTimer.h" |
|
26 |
|
27 using namespace CommsDat; |
|
28 |
|
29 |
|
30 /** |
|
31 * 2 phase constructor. |
|
32 * |
|
33 * @param aSmsSettings a reference to the global SMS settings. |
|
34 * @param aSmsMessaging a reference to the ETEL SMS messaging subsession. |
|
35 * @param aPriority of the request. |
|
36 * @leave Leaves if ContructL() leaves, or not enough memory is available. |
|
37 * @return a new CSmspSetBearer object |
|
38 */ |
|
39 CSmspSetBearer* CSmspSetBearer::NewL(const TSmsSettings& aSmsSettings,RMobileSmsMessaging& aSmsMessaging, TInt aPriority) |
|
40 { |
|
41 LOGSMSPROT2("CSmspSetBearer::NewL aPriority = %d", aPriority); |
|
42 |
|
43 CSmspSetBearer* smsSetBearer=new(ELeave) CSmspSetBearer(aSmsSettings,aSmsMessaging, aPriority); |
|
44 CleanupStack::PushL(smsSetBearer); |
|
45 smsSetBearer->ConstructL(); |
|
46 CleanupStack::Pop(); |
|
47 |
|
48 return smsSetBearer; |
|
49 } // CSmspSetBearer::NewL |
|
50 |
|
51 |
|
52 /** |
|
53 * 2-phase constructor, perform construction that can leave |
|
54 */ |
|
55 void CSmspSetBearer::ConstructL() |
|
56 { |
|
57 LOGSMSPROT1("CSmspSetBearer::ConstructL()"); |
|
58 |
|
59 CSmspCommDbEvent::ConstructL(); |
|
60 |
|
61 User::LeaveIfError(iProperty.Attach(KUidSystemCategory, KUidCommDbSMSBearerChange.iUid)); |
|
62 } // CSmspSetBearer::ConstructL |
|
63 |
|
64 |
|
65 /** |
|
66 * Private constructor used in the first phase of construction. |
|
67 * |
|
68 * @param aSmsSettings a reference to the global SMS settings. |
|
69 * @param aSmsMessaging a reference to the ETEL SMS messaging subsession. |
|
70 * @param aPriority of the request. |
|
71 * |
|
72 */ |
|
73 CSmspSetBearer::CSmspSetBearer(const TSmsSettings& aSmsSettings, RMobileSmsMessaging& aSmsMessaging, TInt aPriority) |
|
74 :CSmspCommDbEvent(aSmsSettings, aSmsMessaging, aPriority) |
|
75 ,iState(ESmsSetBearerStateInit) |
|
76 { |
|
77 } // CSmspSetBearer::CSmspSetBearer |
|
78 |
|
79 |
|
80 /** |
|
81 * CSmspSetBearer destructor |
|
82 */ |
|
83 CSmspSetBearer::~CSmspSetBearer() |
|
84 { |
|
85 Cancel(); |
|
86 } // CSmspSetBearer::~CSmspSetBearer |
|
87 |
|
88 |
|
89 /** |
|
90 * Notifies if SMS bearer is set to the TSY. Start setting bearer |
|
91 * process if bearer is not set. |
|
92 */ |
|
93 void CSmspSetBearer::NotifyBearerSet(TRequestStatus& aStatus) |
|
94 { |
|
95 LOGSMSPROT2("CSmspSetBearer::NotifyBearerSet, aStatus = %d", aStatus.Int()); |
|
96 if (!iBearerSet && IsActive()) |
|
97 { |
|
98 Cancel(); |
|
99 } |
|
100 |
|
101 Queue(aStatus); |
|
102 |
|
103 if (iBearerSet) |
|
104 { |
|
105 LOGSMSPROT1("CSmspSetBearer::NotifyBearerSet RequestComplete called"); |
|
106 CSmsuActiveBase::Complete(KErrNone); |
|
107 } |
|
108 else |
|
109 { |
|
110 LOGSMSPROT1("CSmspSetBearer::NotifyBearerSet started"); |
|
111 Start(); |
|
112 } |
|
113 } // CSmspSetBearer::NotifyBearerSet |
|
114 |
|
115 |
|
116 /** |
|
117 * Starts the sequence for configuring the current SMS bearer on the phone/TSY. |
|
118 */ |
|
119 void CSmspSetBearer::Start() |
|
120 { |
|
121 LOGSMSPROT1("CSmspSetBearer::Start"); |
|
122 // Cancel any outstanding request |
|
123 TRAPD(err, GetSmsBearerL(iBearer)); |
|
124 |
|
125 iBearerSet = EFalse; |
|
126 |
|
127 if (err == KErrNone) |
|
128 { |
|
129 LOGSMSPROT2("CSmspSetBearer::GetSmsBearerL() left with %d", err); |
|
130 |
|
131 // Set the previous bearer to the one that has been read |
|
132 // from CommDB so that iPreviousBearer has an initial value |
|
133 // when the smsstack is first started. |
|
134 iPreviousBearer = iBearer; |
|
135 SetSmsBearer(); |
|
136 } |
|
137 else |
|
138 { |
|
139 LOGSMSPROT2("CSmspSetBearer::Start failed to get SMS bearer, error = %d", err); |
|
140 Complete(err); |
|
141 } |
|
142 } // CSmspSetBearer::Start |
|
143 |
|
144 |
|
145 /** |
|
146 * Handles a completed request. |
|
147 * |
|
148 * Makes a state transition based on the result of the request and current state. |
|
149 * |
|
150 * @leave Panic if RunL is called while object is in idle state. |
|
151 */ |
|
152 void CSmspSetBearer::DoRunL() |
|
153 { |
|
154 LOGSMSPROT3("CSmspSetBearer::DoRunL(): iState=%d iStatus=%d", iState, iStatus.Int()); |
|
155 |
|
156 switch (iState) |
|
157 { |
|
158 case ESmsSetBearerNotifyOnEvent: |
|
159 { |
|
160 if (iStatus.Int() == KErrNone) |
|
161 { |
|
162 TInt tempBearer; |
|
163 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY |
|
164 CMDBSession *dbSession = CMDBSession::NewL(KCDVersion1_2); |
|
165 #else |
|
166 CMDBSession *dbSession = CMDBSession::NewL(KCDVersion1_1); |
|
167 #endif |
|
168 CleanupStack::PushL(dbSession); |
|
169 CMDBRecordSet<CCDGlobalSettingsRecord> globalSettingsRecord(KCDTIdGlobalSettingsRecord); |
|
170 TRAPD(err, globalSettingsRecord.LoadL(*dbSession)); |
|
171 if (err != KErrNone) |
|
172 { |
|
173 LOGSMSPROT2("CSmspSetBearer::DoRunL, could not load global settings, leave error code = %d", err); |
|
174 User::Leave(err); |
|
175 } |
|
176 |
|
177 iPreviousBearer = iBearer; |
|
178 |
|
179 LOGSMSPROT2("CSmspSetBearer::DoRunL Storing previous bearer setting. Previous bearer now = %d", iBearer); |
|
180 |
|
181 tempBearer = ((CCDGlobalSettingsRecord*)globalSettingsRecord.iRecords[0])->iSMSBearer; |
|
182 iBearer = static_cast<RMobileSmsMessaging::TMobileSmsBearer>(tempBearer); |
|
183 |
|
184 CleanupStack::PopAndDestroy(dbSession); |
|
185 |
|
186 SetSmsBearer(); |
|
187 } |
|
188 else |
|
189 { |
|
190 NotifyOnEvent(); |
|
191 } |
|
192 } |
|
193 break; |
|
194 |
|
195 case ESmsSetBearerStateSettingBearer: |
|
196 { |
|
197 if (iStatus.Int() == KErrNone) |
|
198 { |
|
199 iBearerSet = ETrue; |
|
200 } |
|
201 else |
|
202 { |
|
203 // Set bearer to previous value, if status!=KErrNone |
|
204 // (e.g. KErrNotSupported) |
|
205 // Set global setting to previous value, |
|
206 // then complete. |
|
207 LOGSMSPROT3("CSmspSetBearer::DoRunL TSY failed to set MO SMS bearer. status = %d. Bearer = %d", iStatus.Int(), iBearer); |
|
208 |
|
209 iBearer = iPreviousBearer; |
|
210 LOGSMSPROT2("CSmspSetBearer::DoRunL Setting bearer back to previous setting. Bearer = %d", iBearer); |
|
211 |
|
212 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY |
|
213 CMDBSession *dbSession = CMDBSession::NewL(KCDVersion1_2); |
|
214 #else |
|
215 CMDBSession *dbSession = CMDBSession::NewL(KCDVersion1_1); |
|
216 #endif |
|
217 CleanupStack::PushL(dbSession); |
|
218 CMDBRecordSet<CCDGlobalSettingsRecord> globalSettingsRecord(KCDTIdGlobalSettingsRecord); |
|
219 TRAPD(err, globalSettingsRecord.LoadL(*dbSession)); |
|
220 if (err != KErrNone) |
|
221 { |
|
222 LOGSMSPROT2("CSmspSetBearer::DoRunL could not load global settings, error = %d", err); |
|
223 User::Leave(err); |
|
224 } |
|
225 |
|
226 ((CCDGlobalSettingsRecord*)globalSettingsRecord.iRecords[0])->iSMSBearer = iPreviousBearer; |
|
227 TRAP(err, globalSettingsRecord.ModifyL(*dbSession)); |
|
228 if (err != KErrNone) |
|
229 { |
|
230 LOGSMSPROT2("CSmspSetBearer::DoRunL could not modify global settings, error = %d", err); |
|
231 User::Leave(err); |
|
232 } |
|
233 |
|
234 CleanupStack::PopAndDestroy(dbSession); |
|
235 } |
|
236 } |
|
237 break; |
|
238 |
|
239 default: |
|
240 { |
|
241 SmspPanic(KSmspPanicUnexpectedState); |
|
242 } |
|
243 break; |
|
244 } |
|
245 |
|
246 // |
|
247 // DoRunL() will now return to CSmsuActiveBase which if the object |
|
248 // is not active, will call Complete(). |
|
249 // |
|
250 } // CSmspSetBearer::DoRunL |
|
251 |
|
252 |
|
253 /** |
|
254 * Handles a request to cancel the state machine. |
|
255 * Cancels any outstanding request and calls Complete(). |
|
256 */ |
|
257 void CSmspSetBearer::DoCancel() |
|
258 { |
|
259 LOGSMSPROT1("CSmspSetBearer::DoCancel"); |
|
260 |
|
261 TimedSetActiveCancel(); |
|
262 |
|
263 // Explicitly set iBearerSet to false to ensure new bearer is set on each execution |
|
264 iBearerSet = EFalse; |
|
265 |
|
266 switch (iState) |
|
267 { |
|
268 case ESmsSetBearerStateInit: |
|
269 { |
|
270 // NOP |
|
271 } |
|
272 break; |
|
273 |
|
274 case ESmsSetBearerStateSettingBearer: |
|
275 { |
|
276 iSmsMessaging.CancelAsyncRequest(EMobileSmsMessagingSetMoSmsBearer); |
|
277 } |
|
278 break; |
|
279 |
|
280 case ESmsSetBearerNotifyOnEvent: |
|
281 { |
|
282 iProperty.Cancel(); |
|
283 } |
|
284 break; |
|
285 |
|
286 default: |
|
287 { |
|
288 SmspPanic(KSmspPanicUnexpectedState); |
|
289 } |
|
290 break; |
|
291 } |
|
292 |
|
293 // |
|
294 // Handle completion of this Active Object. Note that the object |
|
295 // may well still be active at this point... |
|
296 // |
|
297 if (TimedOut()) |
|
298 { |
|
299 Complete(KErrTimedOut); |
|
300 } |
|
301 else |
|
302 { |
|
303 Complete(KErrCancel); |
|
304 } |
|
305 } // CSmspSetBearer::DoCancel |
|
306 |
|
307 |
|
308 /** |
|
309 * Performs the state transition to CSmspSetBearer::ESmsSetBearerStateQueryingCommDb by |
|
310 * querying CommDB for the current value. |
|
311 * |
|
312 * @param aBearer a reference to the TMobileSmsBearer. |
|
313 */ |
|
314 void CSmspSetBearer::GetSmsBearerL(RMobileSmsMessaging::TMobileSmsBearer& aBearer) |
|
315 { |
|
316 LOGSMSPROT1("CSmspSetBearer::GetSmsBearerL()"); |
|
317 |
|
318 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY |
|
319 CMDBSession* sess = CMDBSession::NewL(KCDVersion1_2); |
|
320 #else |
|
321 CMDBSession* sess = CMDBSession::NewL(KCDVersion1_1); |
|
322 #endif |
|
323 CleanupStack::PushL(sess); |
|
324 |
|
325 CMDBField<TUint32>* smsBearerField = NULL; |
|
326 |
|
327 smsBearerField = new(ELeave) CMDBField<TUint32>(KCDTIdSMSBearer); |
|
328 CleanupStack::PushL(smsBearerField); |
|
329 |
|
330 smsBearerField->SetRecordId(1); |
|
331 smsBearerField->LoadL(*sess); |
|
332 |
|
333 aBearer = static_cast<RMobileSmsMessaging::TMobileSmsBearer>(static_cast<TUint32>(*smsBearerField)); |
|
334 LOGSMSPROT2("CSmspSetBearer::GetSmsBearerL(): aBearer=%d", aBearer); |
|
335 |
|
336 CleanupStack::PopAndDestroy(smsBearerField); |
|
337 CleanupStack::PopAndDestroy(sess); |
|
338 } // CSmspSetBearer::GetSmsBearerL |
|
339 |
|
340 |
|
341 /** |
|
342 * Performs the state transition to CSmspSetBearer::ESmsSetBearerStateSettingBearer |
|
343 * by trying to set the sms bearer on the phone/TSY. |
|
344 */ |
|
345 void CSmspSetBearer::SetSmsBearer() |
|
346 { |
|
347 LOGSMSPROT2("CSmspSetBearer::SetSmsBearer, iBearer = %d", iBearer); |
|
348 |
|
349 iBearerSet = EFalse; |
|
350 iState = ESmsSetBearerStateSettingBearer; |
|
351 |
|
352 iSmsMessaging.SetMoSmsBearer(iStatus, iBearer); |
|
353 TimedSetActive(iSmsSettings.Timeout()); |
|
354 } // CSmspSetBearer::SetSmsBearer |
|
355 |
|
356 |
|
357 /** |
|
358 * Wait for notification from property for when the CommDB global setting SMS_BEARER changes |
|
359 */ |
|
360 void CSmspSetBearer::NotifyOnEvent() |
|
361 { |
|
362 LOGSMSPROT1("CSmspSetBearer::NotifyOnEvent"); |
|
363 |
|
364 iState = ESmsSetBearerNotifyOnEvent; |
|
365 CSmspCommDbEvent::NotifyOnEvent(); |
|
366 } // CSmspSetBearer::NotifyOnEvent |