|
1 // Copyright (c) 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 // CATGetModemStatus |
|
15 // Description: |
|
16 // CInitializePhone |
|
17 |
|
18 #include <ctsy/ltsy/cctsydispatchercallback.h> |
|
19 #include <ctsy/ltsy/mltsydispatchphoneinterface.h> |
|
20 #include "initializephone.h" |
|
21 #include "mslogger.h" |
|
22 #include "atgetmodemstatus.h" |
|
23 #include "atgetnetworkregistrationstatus.h" |
|
24 #include "atgetsimstatusready.h" |
|
25 #include "getcurrentnetworkinfo.h" |
|
26 #include "atgetnetworkinfo.h" |
|
27 #include "atgetsignalstrength.h" |
|
28 #include "atgetbatteryinfo.h" |
|
29 #include "athelpercommand.h" |
|
30 #include "notifybatteryandsignal.h" |
|
31 #include "commengine.h" |
|
32 #include "atnetworkregstatuschange.h" |
|
33 |
|
34 _LIT8(KATSMSSetting1, "AT+CMGF=0\r"); |
|
35 _LIT8(KATSMSSetting2, "AT+CNMI=2,2\r"); |
|
36 _LIT8(KATNwkRegistration, "AT+CREG=1\r"); |
|
37 _LIT8(KATGprsNwkRegistration, "AT+CGREG=1\r"); |
|
38 _LIT8(KATUnsolicitedWind, "AT+WIND=16383\r"); |
|
39 _LIT8(KATSetTDRSingal, "AT&D1\r"); |
|
40 // Class CInitializePhone |
|
41 // --------------------------------------------------------------------------- |
|
42 // CInitializePhone::NewL |
|
43 // other items were commented in a header |
|
44 // --------------------------------------------------------------------------- |
|
45 CInitializePhone* CInitializePhone::NewL(CGlobalPhonemanager& aGloblePhone, |
|
46 CCtsyDispatcherCallback& aCtsyDispatcherCallback, |
|
47 CATNetworkRegStatusChange& aNtwkRegStatusChange, |
|
48 CNotifyBatteryAndSignal& aNotifyBatteryAndSignal) |
|
49 { |
|
50 CInitializePhone* self = new(ELeave) CInitializePhone(aGloblePhone, |
|
51 aCtsyDispatcherCallback, |
|
52 aNtwkRegStatusChange, |
|
53 aNotifyBatteryAndSignal); |
|
54 CleanupStack::PushL(self ); |
|
55 self->ConstructL(); |
|
56 CleanupStack::Pop(self); |
|
57 return self ; |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // CInitializePhone::CInitializePhone |
|
62 // other items were commented in a header |
|
63 // --------------------------------------------------------------------------- |
|
64 CInitializePhone::CInitializePhone(CGlobalPhonemanager& aGloblePhone, |
|
65 CCtsyDispatcherCallback& aCtsyDispatcherCallback, |
|
66 CATNetworkRegStatusChange& aNtwkRegStatusChange, |
|
67 CNotifyBatteryAndSignal& aNotifyBatteryAndSignal) |
|
68 :CATCommandControlBase(aGloblePhone,aCtsyDispatcherCallback), |
|
69 iNtwkRegStatusChange(aNtwkRegStatusChange), |
|
70 iNotifyBatteryAndSignal(aNotifyBatteryAndSignal) |
|
71 { |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // CInitializePhone::ConstructL |
|
76 // other items were commented in a header |
|
77 // --------------------------------------------------------------------------- |
|
78 void CInitializePhone::ConstructL() |
|
79 { |
|
80 iATGetCurNetworkInfo = CGetCurrentNetworkInfo::NewL(iPhoneGlobals,iCtsyDispatcherCallback); |
|
81 iATGetCurNetworkInfo->SetIpcRequestCompleteObserver(this); |
|
82 |
|
83 iATHelperCommand = CATHelperCommand::NewL(iPhoneGlobals,iCtsyDispatcherCallback); |
|
84 |
|
85 iATGetModemStatus = CATGetModemStatus::NewL(iPhoneGlobals,iCtsyDispatcherCallback); |
|
86 |
|
87 iATSIMCard = CATSIMCard::NewL(iPhoneGlobals,iCtsyDispatcherCallback); |
|
88 |
|
89 iNetworkRegStatus = CATNetworkRegistration::NewL(iPhoneGlobals,iCtsyDispatcherCallback); |
|
90 iNetworkRegStatus->SetIpcRequestCompleteObserver(this); |
|
91 iNetworkRegStatus->SetIpcId(MLtsyDispatchPhoneGetNetworkRegistrationStatus::KLtsyDispatchPhoneGetNetworkRegistrationStatusApiId); |
|
92 |
|
93 iATGetSignal = CATGetSignal::NewL(iPhoneGlobals,iCtsyDispatcherCallback); |
|
94 |
|
95 iATGetBattery = CATGetBattery::NewL(iPhoneGlobals,iCtsyDispatcherCallback); |
|
96 |
|
97 iPendingRequestList.Reset(); |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CInitializePhone::~CInitializePhone |
|
102 // other items were commented in a header |
|
103 // --------------------------------------------------------------------------- |
|
104 CInitializePhone::~CInitializePhone() |
|
105 { |
|
106 delete iATGetModemStatus; |
|
107 iATGetModemStatus = NULL; |
|
108 |
|
109 delete iNetworkRegStatus; |
|
110 iNetworkRegStatus = NULL; |
|
111 |
|
112 delete iATSIMCard; |
|
113 iATSIMCard = NULL; |
|
114 |
|
115 delete iATGetCurNetworkInfo; |
|
116 |
|
117 delete iATGetSignal; |
|
118 iATGetSignal = NULL; |
|
119 |
|
120 delete iATGetBattery; |
|
121 iATGetBattery = NULL; |
|
122 |
|
123 delete iATHelperCommand; |
|
124 iATHelperCommand = NULL; |
|
125 |
|
126 iPendingRequestList.Close(); |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // CInitializePhone::AtCommandExecuteComplete |
|
131 // other items were commented in a header |
|
132 // --------------------------------------------------------------------------- |
|
133 void CInitializePhone::AtCommandExecuteComplete(TAtEventSource aEventSource, TInt aStatus) |
|
134 { |
|
135 // we are not going to handle the event of EWriteCompletion if no error was returned |
|
136 if((aEventSource == EWriteCompletion)&&(KErrNone == aStatus)) |
|
137 { |
|
138 return; |
|
139 } |
|
140 |
|
141 TInt err = aStatus; |
|
142 switch(iATType) |
|
143 { |
|
144 case ELtsyAT_Phone_ModemStatus: |
|
145 if(aStatus == KErrNone) |
|
146 { |
|
147 err = iATGetModemStatus->GetErrorValue(); |
|
148 } |
|
149 |
|
150 ModemStatusComplete(err); |
|
151 CompleteATCommand(iATGetModemStatus); |
|
152 break; |
|
153 |
|
154 case ELtsyAT_Phone_NwkRegStatus: |
|
155 if(KErrNone == aStatus) |
|
156 { |
|
157 err = iNetworkRegStatus->GetErrorValue(); |
|
158 } |
|
159 iCtsyDispatcherCallback.CallbackPhoneGetNetworkRegistrationStatusComp(err, |
|
160 iPhoneGlobals.iPhoneStatus.iRegistrationStatus); |
|
161 CompleteATCommand(iNetworkRegStatus); |
|
162 break; |
|
163 |
|
164 case ELtsyAT_Phone_SimCardStatus: |
|
165 if(KErrNone == aStatus) |
|
166 { |
|
167 err = iATSIMCard->GetErrorValue(); |
|
168 } |
|
169 iCtsyDispatcherCallback.CallbackPhoneBootNotifySimStatusReadyComp(err); |
|
170 CompleteATCommand(iATSIMCard); |
|
171 break; |
|
172 |
|
173 case ELtsyAT_Phone_GetSignal: |
|
174 if(KErrNone == aStatus) |
|
175 { |
|
176 err = iATGetSignal->GetErrorValue(); |
|
177 } |
|
178 GetSignalComplete(err); |
|
179 CompleteATCommand(iATGetSignal); |
|
180 break; |
|
181 |
|
182 case ELtsyAT_Phone_GetBattery: |
|
183 if(KErrNone == aStatus) |
|
184 { |
|
185 err = iATGetBattery->GetErrorValue(); |
|
186 } |
|
187 GetBatteryComplete(err); |
|
188 CompleteATCommand(iATGetBattery); |
|
189 break; |
|
190 |
|
191 case ELtsyAT_Phone_SMSSetting1: |
|
192 ExecuteNextATHelpCommand(KATSMSSetting2,ELtsyAT_Phone_SMSSetting2); |
|
193 break; |
|
194 |
|
195 case ELtsyAT_Phone_SMSSetting2: |
|
196 ExecuteNextATHelpCommand(KATNwkRegistration,ELtsyAT_Phone_RegistNwk); |
|
197 break; |
|
198 case ELtsyAT_Phone_RegistNwk: |
|
199 ExecuteNextATHelpCommand(KATGprsNwkRegistration,ELtsyAT_Phone_GPRSRegNwk); |
|
200 break; |
|
201 |
|
202 case ELtsyAT_Phone_GPRSRegNwk: |
|
203 ExecuteNextATHelpCommand(KATSetTDRSingal,ELtsyAT_Phone_SetTDRSingal); |
|
204 break; |
|
205 |
|
206 case ELtsyAT_Phone_SetTDRSingal: |
|
207 ExecuteNextATHelpCommand(KATUnsolicitedWind,ELtsyAT_Phone_SetWind); |
|
208 break; |
|
209 |
|
210 case ELtsyAT_Phone_SetWind: |
|
211 iPhoneGlobals.iEventSignalActive = EFalse; |
|
212 if(iPhoneGlobals.iPhoneStatus.iInitStatus == EPhoneInitialising) |
|
213 { |
|
214 iPhoneGlobals.iPhoneStatus.iInitStatus = EPhoneInitialised; |
|
215 } |
|
216 CompleteATCommand(iATHelperCommand); |
|
217 break; |
|
218 |
|
219 default: |
|
220 break; |
|
221 } |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // CInitializePhone::StartRequestL |
|
226 // other items were commented in a header |
|
227 // --------------------------------------------------------------------------- |
|
228 void CInitializePhone::StartRequest() |
|
229 { |
|
230 StartATCommand(iATGetModemStatus); |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 // CInitializePhone::ExecuteNextRequestL |
|
235 // other items were commented in a header |
|
236 // --------------------------------------------------------------------------- |
|
237 void CInitializePhone::ExecutePendingRequest() |
|
238 { |
|
239 if(iPendingRequestList.Count() > 0 && !iIsPendingRequestStillRunning) |
|
240 { |
|
241 // Mark if the next pending request should be run immediately. |
|
242 // There is a case: If we have alreay known the passed-back results for a certain API, so when such API passed by, |
|
243 // what is going to to is to complete this IPC request immediately synchronously. |
|
244 TBool nextPendingReqShouldBeExecutedImmediatley = EFalse; |
|
245 |
|
246 // get the IPC number |
|
247 TInt ipc = iPendingRequestList[0]; |
|
248 |
|
249 // remove this request from the pending request list |
|
250 iPendingRequestList.Remove(0); |
|
251 |
|
252 switch(ipc) |
|
253 { |
|
254 case MLtsyDispatchPhoneBootNotifySimStatusReady::KLtsyDispatchPhoneBootNotifySimStatusReadyApiId: |
|
255 StartATCommand(iATSIMCard); |
|
256 break; |
|
257 |
|
258 case MLtsyDispatchPhoneGetNetworkRegistrationStatus::KLtsyDispatchPhoneGetNetworkRegistrationStatusApiId: |
|
259 iNtwkRegStatusChange.Disable(); |
|
260 StartATCommand(iNetworkRegStatus); |
|
261 break; |
|
262 |
|
263 case MLtsyDispatchPhoneGetCurrentNetworkInfo::KLtsyDispatchPhoneGetCurrentNetworkInfoApiId: |
|
264 iATGetCurNetworkInfo->StartRequest(); |
|
265 break; |
|
266 |
|
267 case MLtsyDispatchPhoneGetNetworkMode::KLtsyDispatchPhoneGetNetworkModeApiId: |
|
268 iCtsyDispatcherCallback.CallbackPhoneGetNetworkModeComp(0,RMobilePhone::ENetworkModeGsm); |
|
269 nextPendingReqShouldBeExecutedImmediatley = ETrue; |
|
270 break; |
|
271 |
|
272 case MLtsyDispatchPhoneGetNitzInfo::KLtsyDispatchPhoneGetNitzInfoApiId: |
|
273 iCtsyDispatcherCallback.CallbackPhoneGetNitzInfoComp(0,iPhoneGlobals.iPhoneStatus.iMobilePhoneNITZ); |
|
274 nextPendingReqShouldBeExecutedImmediatley = ETrue; |
|
275 break; |
|
276 |
|
277 case MLtsyDispatchPhoneGetSignalStrength::KLtsyDispatchPhoneGetSignalStrengthApiId: |
|
278 StartATCommand(iATGetSignal); |
|
279 break; |
|
280 |
|
281 case MLtsyDispatchPhoneGetBatteryInfo::KLtsyDispatchPhoneGetBatteryInfoApiId: |
|
282 StartATCommand(iATGetBattery); |
|
283 break; |
|
284 |
|
285 case MLtsyDispatchPhoneGetHomeNetwork::KLtsyDispatchPhoneGetHomeNetworkApiId: |
|
286 iCtsyDispatcherCallback.CallbackPhoneGetHomeNetworkComp(0,iNetworkInfo); |
|
287 nextPendingReqShouldBeExecutedImmediatley = ETrue; |
|
288 break; |
|
289 |
|
290 case MLtsyDispatchPhoneSimRefreshRegister::KLtsyDispatchPhoneSimRefreshRegisterApiId: |
|
291 iCtsyDispatcherCallback.CallbackPhoneSimRefreshRegisterComp(0); |
|
292 iATHelperCommand->SetAtCommandObserver(this); |
|
293 ExecuteNextATHelpCommand(KATSMSSetting1,ELtsyAT_Phone_SMSSetting1); |
|
294 break; |
|
295 |
|
296 default: |
|
297 break; |
|
298 } |
|
299 |
|
300 // if the request was complete, we need to call ExecutePendingRequest() to execute next pending request again |
|
301 if(nextPendingReqShouldBeExecutedImmediatley) |
|
302 { |
|
303 ExecutePendingRequest(); |
|
304 } |
|
305 } |
|
306 } |
|
307 |
|
308 // --------------------------------------------------------------------------- |
|
309 // CInitializePhone::NotifyIpcRequestComplete |
|
310 // other items were commented in a header |
|
311 // --------------------------------------------------------------------------- |
|
312 void CInitializePhone::NotifyIpcRequestComplete(TInt aIpcId) |
|
313 { |
|
314 if(aIpcId == MLtsyDispatchPhoneGetCurrentNetworkInfo::KLtsyDispatchPhoneGetCurrentNetworkInfoApiId) |
|
315 { |
|
316 NetworkInfoComplete(); |
|
317 } |
|
318 else if(aIpcId == MLtsyDispatchPhoneGetNetworkRegistrationStatus::KLtsyDispatchPhoneGetNetworkRegistrationStatusApiId) |
|
319 { |
|
320 iNtwkRegStatusChange.Enable(); |
|
321 } |
|
322 } |
|
323 |
|
324 // --------------------------------------------------------------------------- |
|
325 // CInitializePhone::ExecuteNextATHelpCommand |
|
326 // other items were commented in a header |
|
327 // --------------------------------------------------------------------------- |
|
328 void CInitializePhone::ExecuteNextATHelpCommand(const TDesC8& aATString,TLtsyATCommandType aATType) |
|
329 { |
|
330 iATHelperCommand->Complete(); |
|
331 iATHelperCommand->SetAtCommandString(aATString); |
|
332 iATType = aATType; |
|
333 iATHelperCommand->StartRequest(); |
|
334 } |
|
335 |
|
336 // --------------------------------------------------------------------------- |
|
337 // CInitializePhone::StartATCommand |
|
338 // other items were commented in a header |
|
339 // --------------------------------------------------------------------------- |
|
340 void CInitializePhone::StartATCommand(CAtCommandBase* aAtCommand) |
|
341 { |
|
342 iIsPendingRequestStillRunning = ETrue; |
|
343 aAtCommand->SetAtCommandObserver(this); |
|
344 iATType = aAtCommand->AtType(); |
|
345 aAtCommand->StartRequest(); |
|
346 } |
|
347 |
|
348 // --------------------------------------------------------------------------- |
|
349 // CInitializePhone::CompleteATCommand |
|
350 // other items were commented in a header |
|
351 // --------------------------------------------------------------------------- |
|
352 void CInitializePhone::CompleteATCommand(CAtCommandBase* aAtCommand) |
|
353 { |
|
354 iIsPendingRequestStillRunning = EFalse; |
|
355 aAtCommand->RemoveAtCommandObserver(); |
|
356 aAtCommand->Complete(); |
|
357 ExecutePendingRequest(); |
|
358 } |
|
359 |
|
360 // --------------------------------------------------------------------------- |
|
361 // CInitializePhone::ModemStatusComplete |
|
362 // other items were commented in a header |
|
363 // --------------------------------------------------------------------------- |
|
364 void CInitializePhone::ModemStatusComplete(TInt aError) |
|
365 { |
|
366 if(KErrNone == aError) |
|
367 { |
|
368 iCtsyDispatcherCallback.CallbackPhoneBootNotifyModemStatusReadyComp(aError, |
|
369 ERfsStateInfoNormal); |
|
370 } |
|
371 else |
|
372 { |
|
373 User::After(5000000); |
|
374 iCtsyDispatcherCallback.CallbackPhoneBootNotifyModemStatusReadyComp(aError, |
|
375 ERfsStateInfoNormal); |
|
376 } |
|
377 } |
|
378 |
|
379 // --------------------------------------------------------------------------- |
|
380 // CInitializePhone::NetworkInfoComplete |
|
381 // other items were commented in a header |
|
382 // --------------------------------------------------------------------------- |
|
383 void CInitializePhone::NetworkInfoComplete() |
|
384 { |
|
385 ExecutePendingRequest(); |
|
386 } |
|
387 |
|
388 // --------------------------------------------------------------------------- |
|
389 // CInitializePhone::GetSignalComplete |
|
390 // other items were commented in a header |
|
391 // --------------------------------------------------------------------------- |
|
392 void CInitializePhone::GetSignalComplete(TInt aError) |
|
393 { |
|
394 if(KErrNone == aError) |
|
395 { |
|
396 iSignalInfo = iATGetSignal->getSignalInfo(); |
|
397 iPhoneGlobals.iPhoneStatus.iSignalInfo = iSignalInfo; |
|
398 } |
|
399 iCtsyDispatcherCallback.CallbackPhoneGetSignalStrengthComp(aError, |
|
400 iSignalInfo.iSignalStrength, |
|
401 iSignalInfo.iBar); |
|
402 } |
|
403 // --------------------------------------------------------------------------- |
|
404 // CInitializePhone::GetBatteryComplete |
|
405 // other items were commented in a header |
|
406 // --------------------------------------------------------------------------- |
|
407 void CInitializePhone::GetBatteryComplete(TInt aError) |
|
408 { |
|
409 if(KErrNone == aError) |
|
410 { |
|
411 iBatteryInfo = iATGetBattery->GetBatteryinfo(); |
|
412 iPhoneGlobals.iPhoneStatus.iBatteryInfo = iBatteryInfo; |
|
413 iPhoneGlobals.iPhoneStatus.iRfStateInfo = iATGetBattery->GetRfStateInfo(); |
|
414 } |
|
415 iCtsyDispatcherCallback.CallbackPhoneGetBatteryInfoComp(aError,iBatteryInfo); |
|
416 } |
|
417 |
|
418 // --------------------------------------------------------------------------- |
|
419 // CInitializePhone::GetBatteryComplete |
|
420 // other items were commented in a header |
|
421 // --------------------------------------------------------------------------- |
|
422 void CInitializePhone::AppendIpcRequestToPendingListL(TInt aIpc) |
|
423 { |
|
424 iPendingRequestList.AppendL(aIpc); |
|
425 } |
|
426 // |
|
427 // End of file |