24
|
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 |
// Implements CSmsPhoneInitialization and CSmsModemNotification
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
/**
|
|
19 |
@file
|
|
20 |
*/
|
|
21 |
|
|
22 |
#include "smspmodm.h"
|
|
23 |
#include "smsuset.h"
|
|
24 |
#include "smspmain.h"
|
|
25 |
#include "SmsuTimer.h"
|
|
26 |
#include "smspread.h"
|
|
27 |
|
|
28 |
|
|
29 |
//
|
|
30 |
// implementation of CSmsPhoneInitialization
|
|
31 |
//
|
|
32 |
|
|
33 |
|
|
34 |
/**
|
|
35 |
* D'tor
|
|
36 |
*/
|
|
37 |
CSmsPhoneInitialization::~CSmsPhoneInitialization()
|
|
38 |
{
|
|
39 |
Cancel();
|
|
40 |
} // CSmsPhoneInitialization::~CSmsPhoneInitialization
|
|
41 |
|
|
42 |
|
|
43 |
/**
|
|
44 |
* start initializing the phone
|
|
45 |
*/
|
|
46 |
void CSmsPhoneInitialization::Start()
|
|
47 |
{
|
|
48 |
LOGSMSPROT1("CSmsPhoneInitialization::Start Start initializing the phone");
|
|
49 |
|
|
50 |
Cancel();
|
|
51 |
|
|
52 |
iInitialized = KErrNotReady;
|
|
53 |
iNetworkInfoAvailable =EFalse;
|
|
54 |
|
|
55 |
iState=ESmsPhoneInitializationPhoneInit;
|
|
56 |
iGsmPhone.Initialise(iStatus);
|
|
57 |
SetActive();
|
|
58 |
} // CSmsPhoneInitialization::Start
|
|
59 |
|
|
60 |
|
|
61 |
void CSmsPhoneInitialization::DoRunL()
|
|
62 |
{
|
|
63 |
LOGSMSPROT3("CSmsPhoneInitialization::DoRunL [iStatus=%d, iState=%d]", iStatus.Int(), iState);
|
|
64 |
|
|
65 |
switch (iState)
|
|
66 |
{
|
|
67 |
case ESmsPhoneInitializationPhoneInit:
|
|
68 |
{
|
|
69 |
AfterPhoneInitialize(iStatus.Int());
|
|
70 |
}
|
|
71 |
break;
|
|
72 |
|
|
73 |
case ESmsPhoneInitializationSettingMoBearer:
|
|
74 |
{
|
|
75 |
if (iStatus.Int() != KErrNone)
|
|
76 |
{
|
|
77 |
LOGSMSPROT1("ERROR - TSY failed to set bearer but initialisation will continue; bearer setting may be successful during send");
|
|
78 |
}
|
|
79 |
|
|
80 |
iState=ESmsPhoneInitializationGettingRegistrationStatus;
|
|
81 |
iGsmPhone.GetNetworkRegistrationStatus(iStatus, iRegistrationStatus);
|
|
82 |
SetActive();
|
|
83 |
}
|
|
84 |
break;
|
|
85 |
|
|
86 |
case ESmsPhoneInitializationGettingRegistrationStatus:
|
|
87 |
{
|
|
88 |
if(iStatus == KErrNone)
|
|
89 |
{
|
|
90 |
LOGSMSPROT2("CSmsPhoneInitialization::DoRunL registration status : >%d<",iRegistrationStatus);
|
|
91 |
if (iRegistrationStatus==RMobilePhone::ERegisteredOnHomeNetwork ||
|
|
92 |
iRegistrationStatus == RMobilePhone::ERegisteredRoaming)
|
|
93 |
{
|
|
94 |
iState=ESmsPhoneInitializationGettingCurrentNetworkInfo;
|
|
95 |
iGsmPhone.GetCurrentNetwork(iStatus, iNetworkInfoPckg);
|
|
96 |
SetActive();
|
|
97 |
}
|
|
98 |
else
|
|
99 |
{
|
|
100 |
iState=ESmsPhoneInitializationWaitingForCurrentNetwork;
|
|
101 |
iGsmPhone.NotifyCurrentNetworkChange(iStatus,iNetworkInfoPckg);
|
|
102 |
SetActive();
|
|
103 |
}
|
|
104 |
}
|
|
105 |
else
|
|
106 |
{
|
|
107 |
iState=ESmsPhoneInitializationCompleted;
|
|
108 |
iNetworkInfoAvailable =EFalse;
|
|
109 |
LOGSMSPROT2("CSmsPhoneInitialization::DoRunL NETWORK INFO NOT available due %d",iStatus.Int());
|
|
110 |
iSmsPDURead.Start();
|
|
111 |
}
|
|
112 |
}
|
|
113 |
break;
|
|
114 |
|
|
115 |
case ESmsPhoneInitializationWaitingForCurrentNetwork:
|
|
116 |
{
|
|
117 |
if(iStatus == KErrNone)
|
|
118 |
{
|
|
119 |
iState=ESmsPhoneInitializationGettingCurrentNetworkInfo;
|
|
120 |
iGsmPhone.GetCurrentNetwork(iStatus, iNetworkInfoPckg);
|
|
121 |
SetActive();
|
|
122 |
}
|
|
123 |
else
|
|
124 |
{
|
|
125 |
iState=ESmsPhoneInitializationCompleted;
|
|
126 |
iNetworkInfoAvailable =EFalse;
|
|
127 |
LOGSMSPROT2("CSmsPhoneInitialization::DoRunL NETWORK INFO NOT available due %d",iStatus.Int());
|
|
128 |
iSmsPDURead.Start();
|
|
129 |
}
|
|
130 |
}
|
|
131 |
break;
|
|
132 |
|
|
133 |
case ESmsPhoneInitializationGettingCurrentNetworkInfo:
|
|
134 |
{
|
|
135 |
iState=ESmsPhoneInitializationCompleted;
|
|
136 |
if(iStatus == KErrNone)
|
|
137 |
{
|
|
138 |
iNetworkInfoAvailable =ETrue;
|
|
139 |
LOGSMSPROT2("CSmsPhoneInitialization::DoRunL network longname : >%S<",&iNetworkInfo.iLongName);
|
|
140 |
LOGSMSPROT2("CSmsPhoneInitialization::DoRunL network shortname : >%S<",&iNetworkInfo.iShortName);
|
|
141 |
LOGSMSPROT2("CSmsPhoneInitialization::DoRunL network shortname : >%S<",&iNetworkInfo.iDisplayTag);
|
|
142 |
}
|
|
143 |
else
|
|
144 |
{
|
|
145 |
iNetworkInfoAvailable =EFalse;
|
|
146 |
LOGSMSPROT2("CSmsPhoneInitialization::DoRunL NETWORK INFO NOT available due %d",iStatus.Int());
|
|
147 |
}
|
|
148 |
iSmsPDURead.Start();
|
|
149 |
}
|
|
150 |
break;
|
|
151 |
|
|
152 |
default:
|
|
153 |
{
|
|
154 |
SmspPanic(KSmspPanicUnexpectedState);
|
|
155 |
}
|
|
156 |
break;
|
|
157 |
}
|
|
158 |
|
|
159 |
//
|
|
160 |
// DoRunL() will now return to CSmsuActiveBase which if the object
|
|
161 |
// is not active, will call Complete().
|
|
162 |
//
|
|
163 |
} // CSmsPhoneInitialization::DoRunL
|
|
164 |
|
|
165 |
|
|
166 |
/**
|
|
167 |
* cancel the initialization
|
|
168 |
*/
|
|
169 |
void CSmsPhoneInitialization::DoCancel()
|
|
170 |
{
|
|
171 |
LOGSMSPROT1("CSmsPhoneInitialization::DoCancel()");
|
|
172 |
|
|
173 |
switch (iState)
|
|
174 |
{
|
|
175 |
case ESmsPhoneInitializationPhoneInit:
|
|
176 |
{
|
|
177 |
iGsmPhone.InitialiseCancel();
|
|
178 |
}
|
|
179 |
break;
|
|
180 |
|
|
181 |
case ESmsPhoneInitializationSettingMoBearer:
|
|
182 |
{
|
|
183 |
iInitialisationSetBearer->Cancel();
|
|
184 |
}
|
|
185 |
break;
|
|
186 |
|
|
187 |
case ESmsPhoneInitializationGettingRegistrationStatus:
|
|
188 |
{
|
|
189 |
iGsmPhone.CancelAsyncRequest(EMobilePhoneGetNetworkRegistrationStatus);
|
|
190 |
}
|
|
191 |
break;
|
|
192 |
|
|
193 |
case ESmsPhoneInitializationWaitingForCurrentNetwork:
|
|
194 |
{
|
|
195 |
iGsmPhone.CancelAsyncRequest(EMobilePhoneNotifyCurrentNetworkNoLocationChange);
|
|
196 |
}
|
|
197 |
break;
|
|
198 |
|
|
199 |
case ESmsPhoneInitializationGettingCurrentNetworkInfo:
|
|
200 |
{
|
|
201 |
iGsmPhone.CancelAsyncRequest(EMobilePhoneGetCurrentNetwork);
|
|
202 |
}
|
|
203 |
break;
|
|
204 |
|
|
205 |
case ESmsPhoneInitializationCompleted:
|
|
206 |
case ESmsPhoneInitializationIdle:
|
|
207 |
{
|
|
208 |
// NOP
|
|
209 |
}
|
|
210 |
break;
|
|
211 |
|
|
212 |
default:
|
|
213 |
{
|
|
214 |
SmspPanic(KSmspPanicUnexpectedState);
|
|
215 |
}
|
|
216 |
break;
|
|
217 |
}
|
|
218 |
|
|
219 |
iInitialized = KErrNotReady;
|
|
220 |
} // CSmsPhoneInitialization::DoCancel
|
|
221 |
|
|
222 |
|
|
223 |
/**
|
|
224 |
* Completes the phone initialization request
|
|
225 |
*
|
|
226 |
* @param aStatus a status value
|
|
227 |
*/
|
|
228 |
void CSmsPhoneInitialization::Complete(TInt aStatus)
|
|
229 |
{
|
|
230 |
LOGSMSPROT1("CSmsPhoneInitialization::Complete()");
|
|
231 |
|
|
232 |
//
|
|
233 |
// Call the base function to perform the actual complete...
|
|
234 |
//
|
|
235 |
CSmsuActiveBase::Complete(aStatus);
|
|
236 |
} // CSmsPhoneInitialization::Complete
|
|
237 |
|
|
238 |
|
|
239 |
/**
|
|
240 |
* Read the TSY caps and start CSmsPDURead if aStatus == KErrNone
|
|
241 |
* Otherwise, issue another asynchronous Initialize request.
|
|
242 |
*
|
|
243 |
* @param aStatus An error code indicating the status returned on the
|
|
244 |
* previous call to RPhone::Initialise().
|
|
245 |
*/
|
|
246 |
void CSmsPhoneInitialization::AfterPhoneInitialize(TInt aStatus)
|
|
247 |
{
|
|
248 |
LOGSMSPROT2("CSmsPhoneInitialization::AfterPhoneIntialize [status=%d]", aStatus);
|
|
249 |
|
|
250 |
if (aStatus == KErrNone)
|
|
251 |
{
|
|
252 |
RMobileSmsMessaging::TMobileSmsCapsV1Pckg smsCapsPckg(iMobileSmsCaps);
|
|
253 |
aStatus = iSmsMessaging.GetCaps(smsCapsPckg);
|
|
254 |
}
|
|
255 |
|
|
256 |
if (aStatus == KErrNone)
|
|
257 |
{
|
|
258 |
if (iMobileSmsCaps.iSmsMode != RMobileSmsMessaging::KCapsGsmSms)
|
|
259 |
{
|
|
260 |
LOGSMSPROT1("TSY does not support GsmSms");
|
|
261 |
aStatus = KErrNotSupported;
|
|
262 |
}
|
|
263 |
else
|
|
264 |
{
|
|
265 |
// Initialisation of phone is complete and phone supports GSM SMS.
|
|
266 |
// Therefore, set the MO SMS bearer.
|
|
267 |
iState=ESmsPhoneInitializationSettingMoBearer;
|
|
268 |
iInitialisationSetBearer->NotifyBearerSet(iStatus);
|
|
269 |
SetActive();
|
|
270 |
}
|
|
271 |
}
|
|
272 |
else
|
|
273 |
{
|
|
274 |
if (++iNumberOfAttempts < iMaxNumberOfAttempts)
|
|
275 |
{
|
|
276 |
LOGSMSPROT2("CSmsPhoneInitialization Restarting [aStatus=%d]", aStatus);
|
|
277 |
iGsmPhone.Initialise(iStatus);
|
|
278 |
SetActive();
|
|
279 |
}
|
|
280 |
else
|
|
281 |
{
|
|
282 |
LOGSMSPROT3("CSmsPhoneInitialization Failed after %d attempts [aStatus=%d]", iNumberOfAttempts, aStatus);
|
|
283 |
}
|
|
284 |
}
|
|
285 |
|
|
286 |
iInitialized = aStatus;
|
|
287 |
} // CSmsPhoneInitialization::AfterPhoneInitialize
|
|
288 |
|
|
289 |
|
|
290 |
/**
|
|
291 |
* Default constructor.
|
|
292 |
*/
|
|
293 |
CSmsPhoneInitialization::CSmsPhoneInitialization(RMobileSmsMessaging& aSmsMessaging, RMobilePhone& aGsmPhone, CSmsPDURead& aSmsPDURead,
|
|
294 |
RMobileSmsMessaging::TMobileSmsCapsV1& aMobileSmsCaps, TInt aPriority, CSmspSetBearer* aInitialisationSetBearer)
|
|
295 |
:CSmsuActiveBase(aPriority)
|
|
296 |
,iState(ESmsPhoneInitializationPhoneInit)
|
|
297 |
,iSmsMessaging(aSmsMessaging)
|
|
298 |
,iGsmPhone(aGsmPhone)
|
|
299 |
,iSmsPDURead(aSmsPDURead)
|
|
300 |
,iMobileSmsCaps(aMobileSmsCaps)
|
|
301 |
,iMaxNumberOfAttempts(KMaxNumberOfInitiaisationAttempts)
|
|
302 |
,iNetworkInfoPckg(iNetworkInfo)
|
|
303 |
,iInitialisationSetBearer(aInitialisationSetBearer)
|
|
304 |
{
|
|
305 |
} // RMobileSmsMessaging::TMobileSmsCapsV1
|
|
306 |
|
|
307 |
//
|
|
308 |
// implementation of CSmsModemNotification
|
|
309 |
//
|
|
310 |
|
|
311 |
|
|
312 |
/**
|
|
313 |
* 2 phase constructor - safely create a CSmsModemNotification object
|
|
314 |
*/
|
|
315 |
CSmsModemNotification* CSmsModemNotification::NewL(MSmsComm& aSmsComm)
|
|
316 |
{
|
|
317 |
LOGSMSPROT1("CSmsModemNotification::NewL");
|
|
318 |
|
|
319 |
CSmsModemNotification* self=new(ELeave) CSmsModemNotification(aSmsComm);
|
|
320 |
CleanupStack::PushL(self);
|
|
321 |
self->ConstructL();
|
|
322 |
CleanupStack::Pop(self);
|
|
323 |
|
|
324 |
return self;
|
|
325 |
} // CSmsModemNotification::NewL
|
|
326 |
|
|
327 |
|
|
328 |
void CSmsModemNotification::ConstructL()
|
|
329 |
{
|
|
330 |
LOGSMSPROT1("CSmsModemNotification::ConstructL()");
|
|
331 |
|
|
332 |
User::LeaveIfError(iPhonePowerProperty.Attach(KUidSystemCategory, KUidPhonePwr.iUid));
|
|
333 |
|
|
334 |
ConstructTimeoutL();
|
|
335 |
} // CSmsModemNotification::ConstructL
|
|
336 |
|
|
337 |
|
|
338 |
/**
|
|
339 |
* D'tor
|
|
340 |
*/
|
|
341 |
CSmsModemNotification::~CSmsModemNotification()
|
|
342 |
{
|
|
343 |
Cancel();
|
|
344 |
iPhonePowerProperty.Close();
|
|
345 |
} // CSmsModemNotification::~CSmsModemNotification
|
|
346 |
|
|
347 |
|
|
348 |
RPhone::TModemDetection CSmsModemNotification::ModemState()
|
|
349 |
{
|
|
350 |
LOGSMSPROT1("CSmsModemNotification::ModemState()");
|
|
351 |
|
|
352 |
//
|
|
353 |
// Get the phone power state.
|
|
354 |
//
|
|
355 |
TInt phonePowerState;
|
|
356 |
|
|
357 |
if (iPhonePowerProperty.Get(phonePowerState) != KErrNone)
|
|
358 |
{
|
|
359 |
phonePowerState = ESAPhoneOff;
|
|
360 |
}
|
|
361 |
|
|
362 |
if (phonePowerState == ESAPhoneOn)
|
|
363 |
{
|
|
364 |
return RPhone::EDetectedPresent;
|
|
365 |
}
|
|
366 |
else
|
|
367 |
{
|
|
368 |
return RPhone::EDetectedNotPresent;
|
|
369 |
}
|
|
370 |
} // CSmsModemNotification::ModemState
|
|
371 |
|
|
372 |
|
|
373 |
/**
|
|
374 |
* start the modem notification
|
|
375 |
*/
|
|
376 |
void CSmsModemNotification::Start()
|
|
377 |
{
|
|
378 |
LOGSMSPROT1("CSmsModemNotification::Start");
|
|
379 |
|
|
380 |
__ASSERT_DEBUG(iState==ESmsModemNotificationIdle,SmspPanic(KSmspPanicUnexpectedState));
|
|
381 |
|
|
382 |
//
|
|
383 |
// Subscribe to the power property...
|
|
384 |
//
|
|
385 |
iState = ESmsModemNotificationWaitingForNotification;
|
|
386 |
iPhonePowerProperty.Subscribe(iStatus);
|
|
387 |
|
|
388 |
SetActive();
|
|
389 |
} // CSmsModemNotification::Start
|
|
390 |
|
|
391 |
|
|
392 |
/**
|
|
393 |
* asyncronous completion - called by ActiveScheduler when modem notification completed
|
|
394 |
*/
|
|
395 |
void CSmsModemNotification::DoRunL()
|
|
396 |
{
|
|
397 |
LOGSMSPROT2("CSmsModemNotification::RunL [iStatus=%d]", iStatus.Int() );
|
|
398 |
|
|
399 |
__ASSERT_DEBUG(iState==ESmsModemNotificationWaitingForNotification,SmspPanic(KSmspPanicUnexpectedState));
|
|
400 |
|
|
401 |
//
|
|
402 |
// DoRunL() will now return to CSmsuActiveBase which if the object
|
|
403 |
// is not active, will call Complete().
|
|
404 |
//
|
|
405 |
} // CSmsModemNotification::DoRunL
|
|
406 |
|
|
407 |
|
|
408 |
/**
|
|
409 |
* cancel the modem notification
|
|
410 |
*/
|
|
411 |
void CSmsModemNotification::DoCancel()
|
|
412 |
{
|
|
413 |
LOGSMSPROT1("CSmsModemNotification::DoCancel()");
|
|
414 |
|
|
415 |
__ASSERT_DEBUG(iState==ESmsModemNotificationWaitingForNotification,SmspPanic(KSmspPanicUnexpectedState));
|
|
416 |
|
|
417 |
//
|
|
418 |
// Cancel the request...
|
|
419 |
//
|
|
420 |
iPhonePowerProperty.Cancel();
|
|
421 |
|
|
422 |
//
|
|
423 |
// Handle completion of this Active Object. Note that the object
|
|
424 |
// may well still be active at this point...
|
|
425 |
//
|
|
426 |
if (TimedOut())
|
|
427 |
{
|
|
428 |
Complete(KErrTimedOut);
|
|
429 |
}
|
|
430 |
else
|
|
431 |
{
|
|
432 |
Complete(KErrCancel);
|
|
433 |
}
|
|
434 |
} // CSmsModemNotification::DoCancel
|
|
435 |
|
|
436 |
|
|
437 |
/**
|
|
438 |
* C'tor
|
|
439 |
*/
|
|
440 |
CSmsModemNotification::CSmsModemNotification(MSmsComm& aSmsComm)
|
|
441 |
: CSmsuActiveBase(KSmsSessionPriority),
|
|
442 |
iState(ESmsModemNotificationIdle),
|
|
443 |
iSmsComm(aSmsComm)
|
|
444 |
{
|
|
445 |
} // CSmsModemNotification::CSmsModemNotification
|
|
446 |
|
|
447 |
|
|
448 |
/**
|
|
449 |
* complete the modem notification - inform the observer
|
|
450 |
*/
|
|
451 |
void CSmsModemNotification::Complete(TInt aStatus)
|
|
452 |
{
|
|
453 |
LOGSMSPROT1("CSmsModemNotification::Complete()");
|
|
454 |
|
|
455 |
//
|
|
456 |
// Call the base function to perform the actual complete...
|
|
457 |
//
|
|
458 |
CSmsuActiveBase::Complete(aStatus);
|
|
459 |
|
|
460 |
iState = ESmsModemNotificationIdle;
|
|
461 |
|
|
462 |
//
|
|
463 |
// If the request was not cancelled, then restart ourselves ready
|
|
464 |
// for the next event...
|
|
465 |
//
|
|
466 |
if (aStatus != KErrCancel && aStatus != KErrTimedOut)
|
|
467 |
{
|
|
468 |
Start(); // starting here to ensure no states are missed
|
|
469 |
}
|
|
470 |
|
|
471 |
//
|
|
472 |
// Notify our client that the event occured...
|
|
473 |
//
|
|
474 |
RPhone::TModemDetection modemDetection = ModemState();
|
|
475 |
|
|
476 |
iSmsComm.ModemNotificationCompleted(aStatus, modemDetection);
|
|
477 |
} // CSmsModemNotification::Complete
|