|
1 /* |
|
2 * Copyright (c) 2007-2008 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: Provides connection for emergency call when necessary |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <nifman.h> // For global variables |
|
21 |
|
22 #include "svpemergencyconnection.h" |
|
23 #include "svplogger.h" // For logging |
|
24 |
|
25 |
|
26 // ======== MEMBER FUNCTIONS ======== |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // CSVPEmergencyConnection |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 CSVPEmergencyConnection::CSVPEmergencyConnection( |
|
33 TPriority aPriority, MSVPEmergencyConnectionObserver& aObserver ) |
|
34 : CActive( aPriority ), |
|
35 iObserver( aObserver ) |
|
36 { |
|
37 CActiveScheduler::Add( this ); |
|
38 } |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // ConstructL |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 void CSVPEmergencyConnection::ConstructL() |
|
45 { |
|
46 SVPDEBUG1("CSVPEmergencyConnection::ConstructL()") |
|
47 |
|
48 User::LeaveIfError( iSocketServer.Connect() ); |
|
49 User::LeaveIfError( iConnection.Open( iSocketServer ) ); |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // NewL |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CSVPEmergencyConnection* CSVPEmergencyConnection::NewL( |
|
57 TPriority aPriority, MSVPEmergencyConnectionObserver& aObserver ) |
|
58 { |
|
59 CSVPEmergencyConnection* self = CSVPEmergencyConnection::NewLC( |
|
60 aPriority, aObserver ); |
|
61 CleanupStack::Pop( self ); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // NewLC |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 CSVPEmergencyConnection* CSVPEmergencyConnection::NewLC( |
|
70 TPriority aPriority, MSVPEmergencyConnectionObserver& aObserver ) |
|
71 { |
|
72 CSVPEmergencyConnection* self = |
|
73 new( ELeave ) CSVPEmergencyConnection( aPriority, aObserver ); |
|
74 CleanupStack::PushL( self ); |
|
75 self->ConstructL(); |
|
76 return self; |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // Destructor |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 CSVPEmergencyConnection::~CSVPEmergencyConnection() |
|
84 { |
|
85 SVPDEBUG1("CSVPEmergencyConnection::~CSVPEmergencyConnection()") |
|
86 |
|
87 Cancel(); |
|
88 |
|
89 iConnection.Close(); |
|
90 iSocketServer.Close(); |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // Connects asynchronically with SNAP ID |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 void CSVPEmergencyConnection::ConnectWithSnapIdL( TUint32 aSnapId ) |
|
98 { |
|
99 SVPDEBUG2("CSVPEmergencyConnection::ConnectWithSnapIdL, ID: %d", aSnapId) |
|
100 |
|
101 if ( IsActive() ) |
|
102 { |
|
103 User::Leave( KErrInUse ); |
|
104 } |
|
105 |
|
106 // Start connection |
|
107 iRequestType = ESVPSnapConnect; |
|
108 iSnapConnPref.SetSnap( aSnapId ); |
|
109 iConnection.Start( iSnapConnPref, iStatus ); |
|
110 SetActive(); |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // Returns the used IAP ID of SNAP connection |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 TInt CSVPEmergencyConnection::IapId( TUint32& aIapId ) |
|
118 { |
|
119 SVPDEBUG1("CSVPEmergencyConnection::IapIdL()") |
|
120 |
|
121 _LIT( KIapId, "IAP\\Id" ); |
|
122 TRAPD( error, iConnection.GetIntSetting( KIapId, aIapId ) ) |
|
123 return error; |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // Connects with IAP ID |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 void CSVPEmergencyConnection::ConnectL( TUint32 aIapId ) |
|
131 { |
|
132 SVPDEBUG2("CSVPEmergencyConnection::ConnectL(), IAP ID: %d", aIapId) |
|
133 |
|
134 if ( IsActive() ) |
|
135 { |
|
136 User::Leave( KErrInUse ); |
|
137 } |
|
138 |
|
139 // Start connection |
|
140 iRequestType = ESVPConnect; |
|
141 iConnPref.SetIapId( aIapId ); |
|
142 iConnPref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); |
|
143 iConnection.Start( iConnPref, iStatus ); |
|
144 SetActive(); |
|
145 } |
|
146 |
|
147 // --------------------------------------------------------------------------- |
|
148 // Requests for SIP proxy address |
|
149 // --------------------------------------------------------------------------- |
|
150 // |
|
151 #ifdef _DEBUG |
|
152 void CSVPEmergencyConnection::RequestSipProxyAddressL( TUint32 aIapId ) |
|
153 #else |
|
154 void CSVPEmergencyConnection::RequestSipProxyAddressL( TUint32 /*aIapId*/ ) |
|
155 #endif // __DEBUG |
|
156 { |
|
157 SVPDEBUG2("CSVPEmergencyConnection::RequestSipProxyAddressL(),\ |
|
158 IAP ID: %d", aIapId) |
|
159 |
|
160 if ( IsActive() ) |
|
161 { |
|
162 User::Leave( KErrInUse ); |
|
163 } |
|
164 |
|
165 // Request SIP proxy address |
|
166 iRequestType = ESVPSipProxyAddress; |
|
167 iSipServerAddrBuf().index = 0; |
|
168 iConnection.Ioctl( |
|
169 KCOLConfiguration, |
|
170 KConnGetSipServerAddr, // DHCP option 120 |
|
171 iStatus, |
|
172 &iSipServerAddrBuf ); |
|
173 SetActive(); |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // From class CSVPEmergencyConnection. |
|
178 // DoCancel |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 void CSVPEmergencyConnection::DoCancel() |
|
182 { |
|
183 SVPDEBUG1("CSVPEmergencyConnection::DoCancel()") |
|
184 |
|
185 iRequestType = ESVPNone; |
|
186 iConnection.CancelIoctl(); |
|
187 iConnection.Close(); |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // From class CActive. |
|
192 // RunL |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 void CSVPEmergencyConnection::RunL() |
|
196 { |
|
197 TInt error = iStatus.Int(); |
|
198 SVPDEBUG2("CSVPEmergencyConnection::RunL(), error: %d", error) |
|
199 |
|
200 if ( error ) |
|
201 { |
|
202 iRequestType = ESVPNone; |
|
203 iObserver.ConnectionError( error ); |
|
204 return; |
|
205 } |
|
206 |
|
207 switch ( iRequestType ) |
|
208 { |
|
209 case ESVPSnapConnect: |
|
210 iRequestType = ESVPNone; |
|
211 iObserver.SnapConnected(); |
|
212 break; |
|
213 |
|
214 case ESVPConnect: |
|
215 iRequestType = ESVPNone; |
|
216 iObserver.Connected(); |
|
217 break; |
|
218 |
|
219 case ESVPSipProxyAddress: |
|
220 { |
|
221 iRequestType = ESVPNone; |
|
222 |
|
223 // Copy SIP proxy address in dotted-decimal notation |
|
224 HBufC16* sipProxyAddrBuf = HBufC16::NewLC( 39 ); // CS:1 |
|
225 TPtr16 sipProxyAddrPtr = sipProxyAddrBuf->Des(); |
|
226 iSipServerAddrBuf().address.Output( sipProxyAddrPtr ); |
|
227 |
|
228 // Call observer |
|
229 iObserver.SipProxyAddressReady( *sipProxyAddrBuf ); |
|
230 CleanupStack::PopAndDestroy( sipProxyAddrBuf ); // CS:0 |
|
231 break; |
|
232 } |
|
233 |
|
234 default: |
|
235 iRequestType = ESVPNone; |
|
236 iObserver.ConnectionError( KErrGeneral ); |
|
237 break; |
|
238 } |
|
239 } |