|
1 /* |
|
2 * Copyright (c) 2009 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: Utility class for Voip-states. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <cphcltemergencycall.h> |
|
19 #include <mpeengineinfo.h> |
|
20 #include <cconvergedserviceselector.h> |
|
21 #include "cphonestateutilsvoip.h" |
|
22 #include "cphonelogger.h" |
|
23 #include "phoneconstants.h" |
|
24 #include "mphonestatemachine.h" |
|
25 #include "mphoneviewcommandhandle.h" |
|
26 #include "phoneui.pan" |
|
27 #include "tphonecmdparamstring.h" |
|
28 #include "cphonekeys.h" |
|
29 #include "tphonecmdparamselector.h" |
|
30 #include "phonestatedefinitionsvoip.h" |
|
31 |
|
32 const TInt KServiceId1 = 1; |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // CPhoneStateUtilsVoip::CPhoneStateUtilsVoip |
|
38 // C++ constructor. |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CPhoneStateUtilsVoip::CPhoneStateUtilsVoip( MPhoneStateMachine& aStateMachine, |
|
42 MPhoneViewCommandHandle& aViewCommandHandle ) |
|
43 : |
|
44 iStateMachine( aStateMachine ), |
|
45 iViewCommandHandle( aViewCommandHandle ) |
|
46 { |
|
47 |
|
48 } |
|
49 |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CPhoneStateUtilsVoip::ConstructL |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 void CPhoneStateUtilsVoip::ConstructL() |
|
56 { |
|
57 iBuffer = HBufC::NewL( KPhoneNumberEntryBufferSize ); |
|
58 iEmergencyCall = CPhCltEmergencyCall::NewL( NULL ); |
|
59 iServiceSelector = CConvergedServiceSelector::NewL(); |
|
60 } |
|
61 |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // CPhoneStateUtilsVoip::NewL |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 CPhoneStateUtilsVoip* CPhoneStateUtilsVoip::NewL( |
|
68 MPhoneStateMachine& aStateMachine, |
|
69 MPhoneViewCommandHandle& aViewCommandHandle ) |
|
70 { |
|
71 CPhoneStateUtilsVoip* self = CPhoneStateUtilsVoip::NewLC( |
|
72 aStateMachine, aViewCommandHandle ); |
|
73 CleanupStack::Pop( self ); |
|
74 return self; |
|
75 } |
|
76 |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // CPhoneStateUtilsVoip::NewLC |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 CPhoneStateUtilsVoip* CPhoneStateUtilsVoip::NewLC( |
|
83 MPhoneStateMachine& aStateMachine, |
|
84 MPhoneViewCommandHandle& aViewCommandHandle ) |
|
85 { |
|
86 CPhoneStateUtilsVoip* self = new( ELeave ) CPhoneStateUtilsVoip( |
|
87 aStateMachine, aViewCommandHandle ); |
|
88 CleanupStack::PushL( self ); |
|
89 self->ConstructL(); |
|
90 return self; |
|
91 } |
|
92 |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CPhoneStateUtilsVoip::~CPhoneStateUtilsVoip |
|
96 // Destructor. |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 CPhoneStateUtilsVoip::~CPhoneStateUtilsVoip() |
|
100 { |
|
101 delete iBuffer; |
|
102 delete iEmergencyCall; |
|
103 delete iServiceSelector; |
|
104 } |
|
105 |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // CPhoneStateUtilsVoip::DialVoIPL |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 void CPhoneStateUtilsVoip::DialVoIPL( const TDesC& aNumber, TUint aServiceId ) |
|
112 { |
|
113 __LOGMETHODSTARTEND( PhoneUIVoIPExtension, |
|
114 "CPhoneStateUtilsVoip::DialVoIPL" ); |
|
115 |
|
116 __ASSERT_DEBUG( |
|
117 iStateMachine.PhoneEngineInfo(), Panic( EPhoneCtrlInvariant ) ); |
|
118 |
|
119 if ( 0 == aNumber.Compare( KNullDesC ) ) |
|
120 { |
|
121 // Get the number entry contents |
|
122 HBufC *phoneNumber = HBufC::NewLC( KPhoneNumberEntryBufferSize ); |
|
123 TPtr ptr( phoneNumber->Des() ); |
|
124 TPhoneCmdParamString stringParam; |
|
125 stringParam.SetString( &ptr ); |
|
126 iViewCommandHandle.ExecuteCommand( |
|
127 EPhoneViewGetNumberFromEntry, |
|
128 &stringParam ); |
|
129 |
|
130 // Set the phone number |
|
131 iStateMachine.PhoneEngineInfo()->SetPhoneNumber( ptr ); |
|
132 |
|
133 CleanupStack::PopAndDestroy( phoneNumber ); |
|
134 } |
|
135 else |
|
136 { |
|
137 iStateMachine.PhoneEngineInfo()->SetPhoneNumber( aNumber ); |
|
138 } |
|
139 |
|
140 // Make a call |
|
141 iStateMachine.PhoneEngineInfo()->SetServiceIdCommand( aServiceId ); |
|
142 iStateMachine.PhoneEngineInfo()->SetCallTypeCommand( EPECallTypeVoIP ); |
|
143 iStateMachine.SendPhoneEngineMessage( MPEPhoneModel::EPEMessageDial ); |
|
144 } |
|
145 |
|
146 |
|
147 // --------------------------------------------------------------------------- |
|
148 // CPhoneStateUtilsVoip::IsVoipPreferredCall |
|
149 // --------------------------------------------------------------------------- |
|
150 // |
|
151 TBool CPhoneStateUtilsVoip::IsVoipPreferredCall( TUint& aServiceId ) |
|
152 { |
|
153 __LOGMETHODSTARTEND( PhoneUIVoIPExtension, |
|
154 "CPhoneStateUtilsVoip::IsVoipPreferredCall" ); |
|
155 |
|
156 TBool isVoipPrefered( EFalse ); |
|
157 |
|
158 CConvergedServiceSelector::TSsResult results; |
|
159 TInt result = iServiceSelector->GetCallingServiceByCallType( results, |
|
160 CConvergedServiceSelector::ESsVoiceCall, 0, ETrue ); |
|
161 |
|
162 if ( KErrNone == result && |
|
163 CConvergedServiceSelector::ESsVoipCall == results.iCallType ) |
|
164 { |
|
165 __LOGMETHODSTARTEND( PhoneUIVoIPExtension, |
|
166 "CPhoneStateUtilsVoip::IsVoipPreferred ETrue" ); |
|
167 aServiceId = results.iServiceId; |
|
168 isVoipPrefered = ETrue; |
|
169 } |
|
170 |
|
171 return isVoipPrefered; |
|
172 } |
|
173 |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // CPhoneStateUtilsVoip::IsVoipNumberL |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 TBool CPhoneStateUtilsVoip::IsVoipNumber() |
|
180 { |
|
181 __LOGMETHODSTARTEND( PhoneUIVoIPExtension, |
|
182 "CPhoneStateUtilsVoip::IsVoipNumberL" ); |
|
183 |
|
184 TBool isVoipNumber = EFalse; |
|
185 |
|
186 TPtr ptr( iBuffer->Des() ); |
|
187 TPhoneCmdParamString stringParam; |
|
188 stringParam.SetString( &ptr ); |
|
189 iViewCommandHandle.ExecuteCommand( |
|
190 EPhoneViewGetNumberFromEntry, &stringParam ); |
|
191 |
|
192 isVoipNumber = !CPhoneKeys::Validate( ptr ); |
|
193 |
|
194 return isVoipNumber; |
|
195 } |
|
196 |
|
197 |
|
198 // --------------------------------------------------------------------------- |
|
199 // CPhoneStateUtilsVoip::SelectServiceAndDialL |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 void CPhoneStateUtilsVoip::SelectServiceAndDialL( |
|
203 const TDesC& aNumber, |
|
204 TUint aServiceId ) |
|
205 { |
|
206 __LOGMETHODSTARTEND( PhoneUIVoIPExtension, |
|
207 "CPhoneStateIdleVoIP::SelectServiceAndDialL" ); |
|
208 |
|
209 TPhoneCmdParamSelector params; |
|
210 |
|
211 // Get the number entry contents |
|
212 TPtr ptr( iBuffer->Des() ); |
|
213 TPhoneCmdParamString stringParam; |
|
214 stringParam.SetString( &ptr ); |
|
215 iViewCommandHandle.ExecuteCommand( |
|
216 EPhoneViewGetNumberFromEntry, |
|
217 &stringParam ); |
|
218 |
|
219 // Check the string |
|
220 TBool emergencyNumber = ( 0 == aNumber.Compare( KNullDesC ) ? |
|
221 IsEmergencyNumber( ptr ) : |
|
222 IsEmergencyNumber( aNumber ) ); |
|
223 |
|
224 if ( emergencyNumber ) |
|
225 { |
|
226 if ( 0 == aNumber.Compare( KNullDesC ) ) |
|
227 { |
|
228 // Set the phone number from number entry |
|
229 iStateMachine.PhoneEngineInfo()->SetPhoneNumber( ptr ); |
|
230 } |
|
231 else |
|
232 { |
|
233 iStateMachine.PhoneEngineInfo()->SetPhoneNumber( aNumber ); |
|
234 } |
|
235 |
|
236 // Make a emergency call |
|
237 iStateMachine.PhoneEngineInfo()->SetServiceIdCommand( KServiceId1 ); |
|
238 iStateMachine.PhoneEngineInfo()->SetCallTypeCommand( |
|
239 EPECallTypeCSVoice ); |
|
240 iStateMachine.SendPhoneEngineMessage( MPEPhoneModel::EPEMessageDial ); |
|
241 } |
|
242 else if ( 0 != aServiceId ) |
|
243 { |
|
244 // Service id is known |
|
245 DialVoIPL( aNumber, aServiceId ); |
|
246 } |
|
247 else if ( EPhoneViewResponseSuccess == iViewCommandHandle.HandleCommandL( |
|
248 EPhoneViewServiceSelection, ¶ms ) ) |
|
249 { |
|
250 DialVoIPL( aNumber, params.ServiceId() ); |
|
251 } |
|
252 } |
|
253 |
|
254 |
|
255 // --------------------------------------------------------------------------- |
|
256 // CPhoneStateUtilsVoip::IsEmergencyNumber |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 TBool CPhoneStateUtilsVoip::IsEmergencyNumber( const TDesC& aNumber ) const |
|
260 { |
|
261 __LOGMETHODSTARTEND( PhoneUIVoIPExtension, |
|
262 "CPhoneStateUtilsVoip::IsEmergencyNumber" ); |
|
263 |
|
264 TBool emergencyNumber( EFalse ); |
|
265 TInt error = iEmergencyCall->IsEmergencyPhoneNumber( aNumber, emergencyNumber ); |
|
266 |
|
267 return ( KErrNone == error && emergencyNumber ); |
|
268 } |