1 /* |
|
2 * Copyright (c) 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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "TestUtilConnection.h" |
|
22 |
|
23 #include "VCXTestLog.h" |
|
24 #include "MTestUtilConnectionObserver.h" |
|
25 #include <es_enum.h> |
|
26 |
|
27 // ========================== MEMBER FUNCTIONS =============================== |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // CTestUtilConnection::NewL() |
|
31 // |
|
32 // Constructs CTestUtilConnection object |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 EXPORT_C CTestUtilConnection* CTestUtilConnection::NewL(MTestUtilConnectionObserver* aObserver) |
|
36 { |
|
37 VCXLOGLO1(">>>CIptvTestUtilConnection::NewL"); |
|
38 CTestUtilConnection* self = NewLC(aObserver); |
|
39 CleanupStack::Pop(self); |
|
40 VCXLOGLO1("<<<CIptvTestUtilConnection::NewL"); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // CTestUtilConnection::NewLC() |
|
46 // |
|
47 // Constructs CTestUtilConnection object |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 EXPORT_C CTestUtilConnection* CTestUtilConnection::NewLC(MTestUtilConnectionObserver* aObserver) |
|
51 { |
|
52 VCXLOGLO1(">>>CIptvTestUtilConnection::NewLC"); |
|
53 CTestUtilConnection* self = new (ELeave) CTestUtilConnection(aObserver); |
|
54 CleanupStack::PushL(self); |
|
55 self->ConstructL(); |
|
56 VCXLOGLO1("<<<CIptvTestUtilConnection::NewLC"); |
|
57 return self; |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // CTestUtilConnection::CTestUtilConnection() |
|
62 // |
|
63 // Constructor |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 CTestUtilConnection::CTestUtilConnection(MTestUtilConnectionObserver* aObserver) |
|
67 : CActive(CActive::EPriorityHigh), iConnectionState(EIdle), iObserver(aObserver) |
|
68 { |
|
69 VCXLOGLO1(">>>CIptvTestUtilConnection::CIptvTestUtilConnection"); |
|
70 SetConnectionPreferences(ECommDbBearerUnknown, 0); |
|
71 VCXLOGLO1("<<<CIptvTestUtilConnection::CIptvTestUtilConnection"); |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // CTestUtilConnection::~CTestUtilConnection() |
|
76 // |
|
77 // Destructor |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 EXPORT_C CTestUtilConnection::~CTestUtilConnection() |
|
81 { |
|
82 VCXLOGLO1(">>>CIptvTestUtilConnection::~CIptvTestUtilConnection"); |
|
83 Cancel(); |
|
84 |
|
85 iConnect.Close(); |
|
86 iSocketServ.Close(); |
|
87 |
|
88 // iTimer.Cancel(); |
|
89 // iTimer.Close(); |
|
90 |
|
91 if( IsAdded() ) |
|
92 { |
|
93 Deque(); // calls also Cancel() |
|
94 } |
|
95 |
|
96 VCXLOGLO1("<<<CIptvTestUtilConnection::~CIptvTestUtilConnection"); |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // CTestUtilConnection::ConstructL() |
|
101 // |
|
102 // Second phase constructor |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 void CTestUtilConnection::ConstructL() |
|
106 { |
|
107 VCXLOGLO1(">>>CIptvTestUtilConnection::ConstructL"); |
|
108 |
|
109 iSocketServ.Connect(); |
|
110 iConnect.Open(iSocketServ); |
|
111 |
|
112 // User::LeaveIfError(iTimer.CreateLocal()); |
|
113 |
|
114 CActiveScheduler::Add(this); |
|
115 |
|
116 VCXLOGLO1("<<<CIptvTestUtilConnection::ConstructL"); |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // CTestUtilConnection::ConnectL() |
|
121 // |
|
122 // Start connecting to IAP. |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 EXPORT_C void CTestUtilConnection::ConnectL() |
|
126 { |
|
127 VCXLOGLO1(">>>CIptvTestUtilConnection::ConnectL"); |
|
128 |
|
129 if(iConnectionState == CTestUtilConnection::EConnected) |
|
130 { |
|
131 VCXLOGLO1(">>>CIptvTestUtilConnection:: Already connected"); |
|
132 return; |
|
133 } |
|
134 |
|
135 if (!IsActive()) |
|
136 { |
|
137 iConnect.Start(iPref, iStatus); |
|
138 iConnectionState = CTestUtilConnection::EConnecting; |
|
139 |
|
140 //if the line below panics it's either because you made a request but you haven't |
|
141 //SetActive the object (pR->iStatus.iFlags&TRequestStatus::EActive==0) or you didn't set the iStatus |
|
142 //to KRequestPending (pR->iStatus.iFlags&TRequestStatus::ERequestPending==0) |
|
143 // iTimerStatus = KRequestPending; |
|
144 // iTimer.After(iTimerStatus, KTimeout); |
|
145 |
|
146 SetActive(); |
|
147 VCXLOGLO1(">>>CIptvTestUtilConnection:: Connecting"); |
|
148 } |
|
149 else |
|
150 { |
|
151 //globalNote->ShowNoteL(EAknGlobalInformationNote, KTextNotReady); |
|
152 } |
|
153 VCXLOGLO1("<<<CIptvTestUtilConnection::ConnectL"); |
|
154 } |
|
155 |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // CTestUtilConnection::AttachL() |
|
159 // |
|
160 // Attach to open IAP. |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 EXPORT_C void CTestUtilConnection::AttachL() |
|
164 { |
|
165 VCXLOGLO1(">>>CIptvTestUtilConnection::AttachL"); |
|
166 |
|
167 if(iConnectionState == CTestUtilConnection::EConnected) |
|
168 { |
|
169 VCXLOGLO1(">>>CIptvTestUtilConnection:: Already connected"); |
|
170 VCXLOGLO1("<<<CIptvTestUtilConnection::AttachL"); |
|
171 User::Leave(KErrAlreadyExists); |
|
172 } |
|
173 |
|
174 if (!IsActive()) |
|
175 { |
|
176 TUint activeConnections = 0; |
|
177 User::LeaveIfError(iConnect.EnumerateConnections(activeConnections)); |
|
178 |
|
179 TConnectionInfo info; |
|
180 TPckg<TConnectionInfo> infoPckg(info); |
|
181 |
|
182 TInt found = EFalse; |
|
183 for(TInt i=1;i<=activeConnections;i++) |
|
184 { |
|
185 |
|
186 User::LeaveIfError(iConnect.GetConnectionInfo(i, infoPckg)); |
|
187 |
|
188 VCXLOGLO3("CIptvTestUtilConnection:: %d vs %d.", iPref.IapId(), info.iIapId); |
|
189 |
|
190 if(info.iIapId == iPref.IapId()) |
|
191 { |
|
192 found = ETrue; |
|
193 break; |
|
194 } |
|
195 |
|
196 } |
|
197 if(!found) |
|
198 { |
|
199 VCXLOGLO1(">>>CIptvTestUtilConnection:: No connection found to that AP."); |
|
200 VCXLOGLO1("<<<CIptvTestUtilConnection::AttachL"); |
|
201 User::Leave(KErrNotFound); |
|
202 } |
|
203 |
|
204 User::LeaveIfError(iConnect.Attach(infoPckg, RConnection::EAttachTypeNormal)); |
|
205 iConnectionState = CTestUtilConnection::EConnected; |
|
206 } |
|
207 |
|
208 VCXLOGLO1("<<<CIptvTestUtilConnection::AttachL"); |
|
209 return; |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // CTestUtilConnection::RunL() |
|
214 // |
|
215 // Handle request completion events |
|
216 // --------------------------------------------------------------------------- |
|
217 // |
|
218 void CTestUtilConnection::RunL() |
|
219 { |
|
220 VCXLOGLO1(">>>CIptvTestUtilConnection::RunL"); |
|
221 |
|
222 /*if(iTimerStatus.Int() == KErrNone) |
|
223 { |
|
224 VCXLOGLO1("CTestUtilConnection:: Connection timeout."); |
|
225 iObserver->ConnectionTimeout(); |
|
226 iTimer.Cancel(); |
|
227 } |
|
228 */ |
|
229 TInt statusCode = iStatus.Int(); |
|
230 |
|
231 switch (statusCode) |
|
232 { |
|
233 case KErrNone: // Connection created succesfully |
|
234 { |
|
235 //PrintNoteL(KTextConnectionCreated); |
|
236 VCXLOGLO1("CTestUtilConnection:: Connection created."); |
|
237 iConnectionState = CTestUtilConnection::EConnected; |
|
238 // iTimer.Cancel(); |
|
239 iObserver->ConnectionCreated(); |
|
240 break; |
|
241 } |
|
242 |
|
243 case KErrNotFound: // Connection failed |
|
244 { |
|
245 //PrintNoteL(KTextGeneralError); |
|
246 VCXLOGLO1("CTestUtilConnection:: Connection failed."); |
|
247 iConnectionState = CTestUtilConnection::EFailed; |
|
248 //iTimer.Cancel(); |
|
249 iObserver->ConnectionFailed(); |
|
250 break; |
|
251 } |
|
252 |
|
253 case KErrCancel: // Connection attempt cancelled |
|
254 { |
|
255 //PrintNoteL(KTextConnectionCancelled); |
|
256 VCXLOGLO1("CTestUtilConnection:: Connection attemption canceled."); |
|
257 iConnectionState = CTestUtilConnection::EFailed; |
|
258 // iTimer.Cancel(); |
|
259 iObserver->ConnectionFailed(); |
|
260 break; |
|
261 } |
|
262 |
|
263 case KErrAlreadyExists: // Connection already exists |
|
264 { |
|
265 //PrintNoteL(KTextConnectionExists); |
|
266 VCXLOGLO1("CTestUtilConnection:: Connection already exists."); |
|
267 iConnectionState = CTestUtilConnection::EFailed; |
|
268 // iTimer.Cancel(); |
|
269 iObserver->ConnectionAlreadyExists(); |
|
270 break; |
|
271 } |
|
272 |
|
273 default: |
|
274 { |
|
275 //TBuf<KErrorResolverMaxTextLength> errorText; |
|
276 // Use text resolver to resolve error text |
|
277 //errorText = iTextResolver->ResolveError(statusCode); |
|
278 //PrintErrorL(errorText, statusCode); |
|
279 VCXLOGLO2("CTestUtilConnection:: Unknown error: %d", statusCode); |
|
280 iConnectionState = CTestUtilConnection::EFailed; |
|
281 // iTimer.Cancel(); |
|
282 iObserver->ConnectionFailed(); |
|
283 break; |
|
284 } |
|
285 } |
|
286 |
|
287 VCXLOGLO1("<<<CIptvTestUtilConnection::RunL"); |
|
288 } |
|
289 |
|
290 // --------------------------------------------------------------------------- |
|
291 // CTestUtilConnection::DoCancel() |
|
292 // |
|
293 // Cancels ongoing requests |
|
294 // --------------------------------------------------------------------------- |
|
295 // |
|
296 void CTestUtilConnection::DoCancel() |
|
297 { |
|
298 VCXLOGLO1(">>>CIptvTestUtilConnection::DoCancel"); |
|
299 VCXLOGLO1("<<<CIptvTestUtilConnection::DoCancel"); |
|
300 // Nothing to do here |
|
301 } |
|
302 |
|
303 |
|
304 // --------------------------------------------------------------------------- |
|
305 // CTestUtilConnection::TerminateConnectionL() |
|
306 // |
|
307 // This function should not be used in normal situation, since it terminates |
|
308 // the active connection, even if there are other application using |
|
309 // the connection. Calling the RConnection::Close() closes the connection. |
|
310 // --------------------------------------------------------------------------- |
|
311 // |
|
312 EXPORT_C void CTestUtilConnection::TerminateConnectionL() |
|
313 { |
|
314 VCXLOGLO1(">>>CIptvTestUtilConnection::TermínateConnectionL"); |
|
315 |
|
316 /* |
|
317 if (iProgressNotifier->GetState() == EIAPConnectStateConnected) |
|
318 { |
|
319 // Show confirmation dialog first |
|
320 if (ShowQueryDialogL()) |
|
321 { |
|
322 // RConnection::Stop() terminates connection by stopping whole |
|
323 // network interface even if there are other clients using |
|
324 // the connection. It is not recommended to use it unless it is |
|
325 // really meaningful. |
|
326 User::LeaveIfError(iConnect.Stop()); |
|
327 |
|
328 } |
|
329 } |
|
330 else |
|
331 { |
|
332 PrintNoteL(KTextNotConnected); |
|
333 } |
|
334 */ |
|
335 User::LeaveIfError(iConnect.Stop()); |
|
336 VCXLOGLO1("<<<CIptvTestUtilConnection::TermínateConnectionL"); |
|
337 } |
|
338 |
|
339 CTestUtilConnection::TConnectionState CTestUtilConnection::GetState() |
|
340 { |
|
341 return iConnectionState; |
|
342 } |
|
343 |
|
344 // --------------------------------------------------------------------------- |
|
345 // CTestUtilConnection::SetConnectionPreferences(TUint aBearer, |
|
346 // TBool aDialog, |
|
347 // TUint32 aIapId) |
|
348 // |
|
349 // This function sets connection preferences. |
|
350 // --------------------------------------------------------------------------- |
|
351 // |
|
352 EXPORT_C void CTestUtilConnection::SetConnectionPreferences( |
|
353 TUint aBearer, |
|
354 TUint32 aIapId) |
|
355 { |
|
356 VCXLOGLO1(">>>CIptvTestUtilConnection::SetConnectionPreferences"); |
|
357 iPref.SetDirection(ECommDbConnectionDirectionOutgoing); |
|
358 iPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); |
|
359 iPref.SetIapId(aIapId); |
|
360 iPref.SetBearerSet(aBearer); |
|
361 iPref.SetDirection(ECommDbConnectionDirectionOutgoing); |
|
362 VCXLOGLO1("<<<CIptvTestUtilConnection::SetConnectionPreferences"); |
|
363 } |
|
364 |
|
365 // End of file |
|