1 /* |
|
2 * Copyright (c) 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: Class definition of CDiagEngineCallHandler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // CLASS DECLARATION |
|
20 #include "diagenginecallhandler.h" |
|
21 |
|
22 // SYSTEM INCLUDE FILES |
|
23 #include <DiagFrameworkDebug.h> // LOGSTRING |
|
24 #include <badesca.h> // CDesCArrayFlat |
|
25 |
|
26 // USER INCLUDE FILES |
|
27 #include "diagenginecallhandlerobserver.h" // MDiagEngineCallHandlerObserver |
|
28 |
|
29 |
|
30 // CONSTANTS |
|
31 |
|
32 // ======== LOCAL FUNCTIONS ======== |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // CDiagEngineCallHandler::NewL |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 CDiagEngineCallHandler* CDiagEngineCallHandler::NewL( |
|
41 MDiagEngineCallHandlerObserver& aObserver ) |
|
42 { |
|
43 CDiagEngineCallHandler* self = new( ELeave )CDiagEngineCallHandler( aObserver ); |
|
44 CleanupStack::PushL( self ); |
|
45 self->ConstructL(); |
|
46 CleanupStack::Pop( self ); |
|
47 return self; |
|
48 } |
|
49 |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CDiagEngineCallHandler::CDiagEngineCallHandler |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CDiagEngineCallHandler::CDiagEngineCallHandler( |
|
56 MDiagEngineCallHandlerObserver& aObserver ) |
|
57 : CActive( EPriorityStandard ), |
|
58 iObserver( aObserver ), |
|
59 iCallStatus(), |
|
60 iCallStatusPckg( iCallStatus ) |
|
61 { |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // CDiagEngineCallHandler::ConstructL |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 void CDiagEngineCallHandler::ConstructL() |
|
69 { |
|
70 CActiveScheduler::Add( this ); |
|
71 |
|
72 iCallIgnoreList = new( ELeave )CDesCArrayFlat( 1 ); |
|
73 |
|
74 iTelephony = CTelephony::NewL(); |
|
75 |
|
76 // Get call initial status. |
|
77 TInt err = iTelephony->GetLineStatus( CTelephony::EVoiceLine, iCallStatusPckg ); |
|
78 |
|
79 if ( err != KErrNone ) |
|
80 { |
|
81 // This can happen even if hw failure does not occur. E.g. |
|
82 // user puts the phone in offline mode, or sim card is missing. |
|
83 // In this situation, assume that phone is offline and continue |
|
84 // since it does not actually affect engine execution. |
|
85 LOGSTRING2( "CDiagEngineCallHandler::ConstructL() " |
|
86 L"Unable to get voice line status. Err = %d", err ) |
|
87 iState = EDiagEngineCallHandlerStateIdle; |
|
88 } |
|
89 else |
|
90 { |
|
91 LOGSTRING2( "CDiagEngineCallHandler::ConstructL() Call status = %d", |
|
92 iCallStatus.iStatus ) |
|
93 if ( iCallStatus.iStatus != CTelephony::EStatusIdle ) |
|
94 { |
|
95 iState = EDiagEngineCallHandlerStateBusy; |
|
96 } |
|
97 } |
|
98 |
|
99 RequestNotify(); |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // CDiagEngineCallHandler::~CDiagEngineCallHandler |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 CDiagEngineCallHandler::~CDiagEngineCallHandler() |
|
107 { |
|
108 Cancel(); |
|
109 |
|
110 delete iTelephony; |
|
111 iTelephony = NULL; |
|
112 |
|
113 delete iCallIgnoreList; |
|
114 iCallIgnoreList = NULL; |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // CDiagEngineCallHandler::AddIgnoreNumberL |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 void CDiagEngineCallHandler::AddIgnoreNumberL( const TDesC& aNumber ) |
|
122 { |
|
123 LOGSTRING( "CDiagEngineCallHandler::AddIgnoreNumberL: Number = " ) |
|
124 LOGTEXT( aNumber ) |
|
125 |
|
126 iCallIgnoreList->AppendL( aNumber ); |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // CDiagEngineCallHandler::RemoveIgnoreNumberL |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 void CDiagEngineCallHandler::RemoveIgnoreNumberL( const TDesC& aNumber ) |
|
134 { |
|
135 LOGSTRING( "CDiagEngineCallHandler::RemoveIgnoreNumberL: Number = " ) |
|
136 LOGTEXT( aNumber ) |
|
137 |
|
138 TInt position = 0; |
|
139 |
|
140 TInt err = iCallIgnoreList->Find( aNumber, position ); |
|
141 |
|
142 if ( err == KErrNone ) |
|
143 { |
|
144 // element found. Remove. |
|
145 iCallIgnoreList->Delete( position ); |
|
146 } |
|
147 else |
|
148 { |
|
149 LOGSTRING2( "CDiagEngineCallHandler::RemoveIgnoreNumberL:" |
|
150 L"Not found. Err = %d", err ) |
|
151 User::Leave( err ); |
|
152 } |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // CDiagEngineCallHandler::CurrentState |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 TDiagEngineCallHandlerState CDiagEngineCallHandler::CurrentState() const |
|
160 { |
|
161 return iState; |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // CDiagEngineCallHandler::RequestNotify |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 void CDiagEngineCallHandler::RequestNotify() |
|
169 { |
|
170 Cancel(); |
|
171 iTelephony->NotifyChange( |
|
172 iStatus, CTelephony::EVoiceLineStatusChange, iCallStatusPckg ); |
|
173 SetActive(); |
|
174 } |
|
175 |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // from CActive |
|
179 // CDiagEngineCallHandler::RunL() |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 void CDiagEngineCallHandler::RunL() |
|
183 { |
|
184 TBool notifyObserver = EFalse; |
|
185 |
|
186 LogCallStatus(); |
|
187 |
|
188 switch ( iCallStatus.iStatus ) |
|
189 { |
|
190 case CTelephony::EStatusIdle: |
|
191 notifyObserver = HandleIdle(); |
|
192 break; |
|
193 |
|
194 case CTelephony::EStatusDialling: // fall through |
|
195 case CTelephony::EStatusRinging: |
|
196 notifyObserver = HandleCall(); |
|
197 break; |
|
198 |
|
199 default: |
|
200 // Ignore. |
|
201 break; |
|
202 } |
|
203 |
|
204 if ( iStatus != KErrCancel ) |
|
205 { |
|
206 RequestNotify(); |
|
207 } |
|
208 |
|
209 if ( notifyObserver ) |
|
210 { |
|
211 iObserver.CallHandlerStateChangedL( iState ); |
|
212 } |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------------------------- |
|
216 // from CActive |
|
217 // CDiagEngineCallHandler::DoCancel() |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 void CDiagEngineCallHandler::DoCancel() |
|
221 { |
|
222 if ( iTelephony ) |
|
223 { |
|
224 iTelephony->CancelAsync( CTelephony::EVoiceLineStatusChangeCancel ); |
|
225 } |
|
226 } |
|
227 |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // CDiagEngineCallHandler::HandleIdle |
|
231 // --------------------------------------------------------------------------- |
|
232 // |
|
233 TBool CDiagEngineCallHandler::HandleIdle() |
|
234 { |
|
235 LOGSTRING( "CDiagEngineCallHandler::HandleIdle()" ) |
|
236 |
|
237 TBool notifyObserver = EFalse; |
|
238 if ( iState != EDiagEngineCallHandlerStateIdle ) |
|
239 { |
|
240 LOGSTRING( "CDiagEngineCallHandler::HandleIdle() Changing to IDLE" ) |
|
241 iState = EDiagEngineCallHandlerStateIdle; |
|
242 notifyObserver = ETrue; |
|
243 } |
|
244 |
|
245 return notifyObserver; |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // CDiagEngineCallHandler::HandleCall |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 TBool CDiagEngineCallHandler::HandleCall() |
|
253 { |
|
254 LOGSTRING( "CDiagEngineCallHandler::HandleCall()" ) |
|
255 |
|
256 TBool notifyObserver = EFalse; |
|
257 |
|
258 if ( iState == EDiagEngineCallHandlerStateIdle ) |
|
259 { |
|
260 LOGSTRING( "CDiagEngineCallHandler::HandleCall() was in Idle" ) |
|
261 |
|
262 // Get phone number |
|
263 TBuf<CTelephony::KMaxTelNumberSize> number; |
|
264 |
|
265 CTelephony::TRemotePartyInfoV1 remInfoUse; |
|
266 CTelephony::TCallInfoV1 callInfoUse; |
|
267 CTelephony::TCallSelectionV1 callSelectionUse; |
|
268 |
|
269 callSelectionUse.iLine = CTelephony::EVoiceLine; |
|
270 callSelectionUse.iSelect = CTelephony::EInProgressCall; |
|
271 |
|
272 CTelephony::TRemotePartyInfoV1Pckg remParty( remInfoUse ); |
|
273 CTelephony::TCallInfoV1Pckg callInfo( callInfoUse ); |
|
274 CTelephony::TCallSelectionV1Pckg callSelection( callSelectionUse ); |
|
275 |
|
276 iTelephony->GetCallInfo( callSelection, callInfo, remParty ); |
|
277 |
|
278 LOGSTRING( "CDiagEngineCallHandler::HandleCall() Remote Number = " ) |
|
279 LOGTEXT( remInfoUse.iRemoteNumber.iTelNumber ) |
|
280 |
|
281 LOGSTRING( "CDiagEngineCallHandler::HandleCall() Dialed Number = " ) |
|
282 LOGTEXT( callInfoUse.iDialledParty.iTelNumber ) |
|
283 |
|
284 if ( iCallStatus.iStatus == CTelephony::EStatusRinging ) |
|
285 { |
|
286 number.Copy( remInfoUse.iRemoteNumber.iTelNumber ); |
|
287 } |
|
288 else if ( iCallStatus.iStatus == CTelephony::EStatusDialling ) |
|
289 { |
|
290 number.Copy( callInfoUse.iDialledParty.iTelNumber ); |
|
291 } |
|
292 else |
|
293 { |
|
294 // number not valid. |
|
295 } |
|
296 |
|
297 // check if the number is in ignore list |
|
298 TInt position = 0; |
|
299 TInt err = iCallIgnoreList->Find( number, position ); |
|
300 |
|
301 if ( err == KErrNone ) |
|
302 { |
|
303 // number found. |
|
304 LOGSTRING( "CDiagEngineCallHandler::HandleCall() Ignore: Number =" ) |
|
305 LOGTEXT( number ) |
|
306 } |
|
307 else |
|
308 { |
|
309 // number found. |
|
310 LOGSTRING( "CDiagEngineCallHandler::HandleCall() Going to Busy State. Number = " ) |
|
311 LOGTEXT( number ) |
|
312 |
|
313 iState = EDiagEngineCallHandlerStateBusy; |
|
314 |
|
315 notifyObserver = ETrue; |
|
316 } |
|
317 } |
|
318 |
|
319 return notifyObserver; |
|
320 } |
|
321 |
|
322 // --------------------------------------------------------------------------- |
|
323 // CDiagEngineCallHandler::LogCallStatus |
|
324 // --------------------------------------------------------------------------- |
|
325 // |
|
326 void CDiagEngineCallHandler::LogCallStatus() const |
|
327 { |
|
328 #ifdef _DEBUG |
|
329 |
|
330 switch ( iCallStatus.iStatus ) |
|
331 { |
|
332 case CTelephony::EStatusUnknown: |
|
333 LOGSTRING( "CDiagEngineCallHandler::LogCallStatus():" |
|
334 L" Call Status = EStatusUnknown" ) |
|
335 break; |
|
336 |
|
337 case CTelephony::EStatusIdle: |
|
338 LOGSTRING( "CDiagEngineCallHandler::LogCallStatus():" |
|
339 L" Call Status = EStatusIdle" ) |
|
340 break; |
|
341 |
|
342 case CTelephony::EStatusDialling: |
|
343 LOGSTRING( "CDiagEngineCallHandler::LogCallStatus():" |
|
344 L" Call Status = EStatusDialling" ) |
|
345 break; |
|
346 |
|
347 case CTelephony::EStatusRinging: |
|
348 LOGSTRING( "CDiagEngineCallHandler::LogCallStatus():" |
|
349 L" Call Status = EStatusRinging" ) |
|
350 break; |
|
351 |
|
352 case CTelephony::EStatusAnswering: |
|
353 LOGSTRING( "CDiagEngineCallHandler::LogCallStatus():" |
|
354 L" Call Status = EStatusAnswering" ) |
|
355 break; |
|
356 |
|
357 case CTelephony::EStatusConnecting: |
|
358 LOGSTRING( "CDiagEngineCallHandler::LogCallStatus():" |
|
359 L" Call Status = EStatusConnecting" ) |
|
360 break; |
|
361 |
|
362 case CTelephony::EStatusConnected: |
|
363 LOGSTRING( "CDiagEngineCallHandler::LogCallStatus():" |
|
364 L" Call Status = EStatusConnected" ) |
|
365 break; |
|
366 |
|
367 case CTelephony::EStatusReconnectPending: |
|
368 LOGSTRING( "CDiagEngineCallHandler::LogCallStatus():" |
|
369 L" Call Status = EStatusReconnectPending" ) |
|
370 break; |
|
371 |
|
372 case CTelephony::EStatusDisconnecting: |
|
373 LOGSTRING( "CDiagEngineCallHandler::LogCallStatus():" |
|
374 L" Call Status = EStatusDisconnecting" ) |
|
375 break; |
|
376 |
|
377 case CTelephony::EStatusHold: |
|
378 LOGSTRING( "CDiagEngineCallHandler::LogCallStatus():" |
|
379 L" Call Status = EStatusHold" ) |
|
380 break; |
|
381 |
|
382 case CTelephony::EStatusTransferring: |
|
383 LOGSTRING( "CDiagEngineCallHandler::LogCallStatus():" |
|
384 L"Call Status = EStatusTransferring" ) |
|
385 break; |
|
386 |
|
387 case CTelephony::EStatusTransferAlerting: |
|
388 LOGSTRING( "CDiagEngineCallHandler::LogCallStatus():" |
|
389 L"Call Status = EStatusTransferAlerting" ) |
|
390 break; |
|
391 |
|
392 default: |
|
393 LOGSTRING2( "CDiagEngineCallHandler::LogCallStatus():" |
|
394 L"Unknown Call Status = %d", iCallStatus.iStatus ) |
|
395 break; |
|
396 } |
|
397 |
|
398 #endif // _DEBUG |
|
399 } |
|
400 |
|
401 // End of File |
|
402 |
|