|
1 /* |
|
2 * Copyright (c) 2006-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: Utils implements general tools for bandwidth and |
|
15 * packet loss calculation and IAP selection etc |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <commdb.h> |
|
21 #include <aknlistquerydialog.h> |
|
22 #include <ConnTest.rsg> |
|
23 |
|
24 #include <aknselectionlist.h> |
|
25 #include <aknPopup.h> |
|
26 #include <aknlists.h> |
|
27 #include <txtetext.h> |
|
28 |
|
29 #include "Utils.h" |
|
30 #include "conntest.hrh" |
|
31 |
|
32 ////////////////////////////////////////////////////////////////////// |
|
33 // Construction/Destruction |
|
34 ////////////////////////////////////////////////////////////////////// |
|
35 |
|
36 |
|
37 // ---------------------------------------------------------------------------- |
|
38 // Utils::Utils() |
|
39 // Constructor |
|
40 // ---------------------------------------------------------------------------- |
|
41 // |
|
42 Utils::Utils() |
|
43 { |
|
44 } |
|
45 |
|
46 // ---------------------------------------------------------------------------- |
|
47 // Utils::~Utils() |
|
48 // Destructor |
|
49 // ---------------------------------------------------------------------------- |
|
50 // |
|
51 Utils::~Utils() |
|
52 { |
|
53 } |
|
54 |
|
55 // ---------------------------------------------------------------------------- |
|
56 // Utils::CalculateThroughput |
|
57 // Calculate throughput |
|
58 // ---------------------------------------------------------------------------- |
|
59 // |
|
60 void Utils::CalculateThroughput( TDes8& aBuffer, TTime aStartTime, TInt aSize ) |
|
61 { |
|
62 TTime now; |
|
63 now.UniversalTime(); |
|
64 TTimeIntervalMicroSeconds interval; |
|
65 interval = now.MicroSecondsFrom( aStartTime ); |
|
66 TInt num = I64INT(interval.Int64()); |
|
67 |
|
68 if (num != 0) |
|
69 { |
|
70 aBuffer.AppendFormat( _L8("Size: %d\n"), aSize ); |
|
71 aBuffer.AppendFormat( _L8("Time: %4.1f s\n"), (TReal)num / 1000000 ); |
|
72 aBuffer.AppendFormat( _L8(" - %4.1f kB/s\n"), (TReal)((TReal)aSize / (1024.0 |
|
73 * (TReal)num)) * 1000000 ); |
|
74 aBuffer.AppendFormat( _L8(" - %4.1f kbit/s\n"), (TReal)8 * ((TReal)aSize / (1024.0 |
|
75 * (TReal)num)) * 1000000 ); |
|
76 } |
|
77 else |
|
78 { |
|
79 aBuffer.AppendFormat( _L8("Size: %d\n"), aSize ); |
|
80 aBuffer.AppendFormat( _L8("Time zero\n") ); |
|
81 } |
|
82 |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // Utils::SetTimeoutsL(const TInt aTimeout) |
|
87 // Adjust given Nifman's idle timeout for every bearer. |
|
88 // ---------------------------------------------------------------------------- |
|
89 // |
|
90 void Utils::SetTimeoutsL( const TInt aTimeout ) |
|
91 { |
|
92 // GPRS and CSD bearer |
|
93 Utils::SetTableTimeoutL( aTimeout, TPtrC( MODEM_BEARER ) ); |
|
94 |
|
95 // LAN bearer |
|
96 Utils::SetTableTimeoutL( aTimeout, TPtrC( LAN_BEARER ) ); |
|
97 } |
|
98 |
|
99 // ---------------------------------------------------------------------------- |
|
100 // Utils::SetTableTimeoutL() |
|
101 // Set Nifman's idle times for each record in given table. |
|
102 // ---------------------------------------------------------------------------- |
|
103 // |
|
104 void Utils::SetTableTimeoutL( const TInt aTimeout, const TDesC& aTableName ) |
|
105 { |
|
106 TInt result; |
|
107 TUint32 value; |
|
108 TBuf<64> title; |
|
109 |
|
110 CCommsDatabase* TheDb; |
|
111 |
|
112 TheDb = CCommsDatabase::NewL(); |
|
113 CleanupStack::PushL( TheDb ); |
|
114 |
|
115 CCommsDbTableView* view2 = TheDb->OpenTableLC( aTableName ); |
|
116 |
|
117 result = view2->GotoFirstRecord(); |
|
118 User::LeaveIfError( result ); |
|
119 |
|
120 while (result == KErrNone) |
|
121 { |
|
122 view2->ReadTextL( TPtrC( COMMDB_NAME ), title ); |
|
123 |
|
124 switch (aTimeout) |
|
125 { |
|
126 case EConnTestCmdTimeoutLastSocketActivity: |
|
127 title.Append( _L("\nLastSocketActivity") ); |
|
128 view2->ReadUintL( TPtrC( LAST_SOCKET_ACTIVITY_TIMEOUT ), value ); |
|
129 break; |
|
130 |
|
131 case EConnTestCmdTimeoutLastSocketClosed: |
|
132 title.Append( _L("\nLastSocketClosed") ); |
|
133 view2->ReadUintL( TPtrC( LAST_SOCKET_CLOSED_TIMEOUT ), value ); |
|
134 break; |
|
135 |
|
136 case EConnTestCmdTimeoutLastSessionClosed: |
|
137 title.Append( _L("\nLastSessionClosed") ); |
|
138 view2->ReadUintL( TPtrC( LAST_SESSION_CLOSED_TIMEOUT ), value ); |
|
139 break; |
|
140 |
|
141 default: |
|
142 value = 0; // To get rid of compiler warning |
|
143 break; |
|
144 } |
|
145 |
|
146 TInt val2( value ); |
|
147 CAknNumberQueryDialog* dlg; |
|
148 |
|
149 dlg = CAknNumberQueryDialog::NewL( val2, CAknQueryDialog::ENoTone ); |
|
150 CleanupStack::PushL( dlg ); |
|
151 dlg->SetPromptL( title ); |
|
152 TInt changed = dlg->ExecuteLD( R_CONNTEST_NUMBER_LAYOUT ); |
|
153 CleanupStack::Pop( dlg ); |
|
154 |
|
155 if (changed) |
|
156 { |
|
157 result = view2->UpdateRecord(); |
|
158 User::LeaveIfError( result ); |
|
159 |
|
160 if (val2 == -1) |
|
161 { |
|
162 val2 = KMaxTInt; |
|
163 } |
|
164 |
|
165 switch (aTimeout) |
|
166 { |
|
167 case EConnTestCmdTimeoutLastSocketActivity: |
|
168 view2->WriteUintL( TPtrC( LAST_SOCKET_ACTIVITY_TIMEOUT ), |
|
169 val2 ); |
|
170 break; |
|
171 |
|
172 case EConnTestCmdTimeoutLastSocketClosed: |
|
173 view2->WriteUintL( TPtrC( LAST_SOCKET_CLOSED_TIMEOUT ), |
|
174 val2 ); |
|
175 break; |
|
176 |
|
177 case EConnTestCmdTimeoutLastSessionClosed: |
|
178 view2->WriteUintL( TPtrC( LAST_SESSION_CLOSED_TIMEOUT ), |
|
179 val2 ); |
|
180 break; |
|
181 |
|
182 default: |
|
183 break; |
|
184 } |
|
185 |
|
186 result = view2->PutRecordChanges(); |
|
187 User::LeaveIfError( result ); |
|
188 } |
|
189 result = view2->GotoNextRecord(); |
|
190 } |
|
191 |
|
192 CleanupStack::PopAndDestroy( view2 ); // view2 |
|
193 CleanupStack::PopAndDestroy( TheDb ); // TheDb |
|
194 } |
|
195 |
|
196 // ---------------------------------------------------------------------------- |
|
197 // Utils::SetConnectionPrefsIap() |
|
198 // Set IapId value into connection preferences table |
|
199 // ---------------------------------------------------------------------------- |
|
200 // |
|
201 void Utils::SetConnectionPrefsIapL() |
|
202 { |
|
203 |
|
204 CCommsDatabase* TheDb; |
|
205 |
|
206 TheDb = CCommsDatabase::NewL(); |
|
207 CleanupStack::PushL( TheDb ); |
|
208 |
|
209 CCommsDbConnectionPrefTableView* view = TheDb->OpenConnectionPrefTableLC(); |
|
210 |
|
211 TInt ret = view->GotoFirstRecord(); |
|
212 |
|
213 CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref tablePref; |
|
214 |
|
215 if (ret == KErrNone) |
|
216 { |
|
217 view->ReadConnectionPreferenceL( tablePref ); |
|
218 } |
|
219 |
|
220 User::LeaveIfError( ret ); |
|
221 |
|
222 TInt value( tablePref.iBearer.iIapId ); |
|
223 CAknNumberQueryDialog* dlg; |
|
224 |
|
225 dlg = CAknNumberQueryDialog::NewL( value, CAknQueryDialog::ENoTone ); |
|
226 CleanupStack::PushL( dlg ); |
|
227 dlg->SetPromptL( _L("Iap Id:") ); |
|
228 TInt changed = dlg->ExecuteLD( R_CONNTEST_NUMBER_LAYOUT ); |
|
229 CleanupStack::Pop( dlg ); |
|
230 |
|
231 if (changed) |
|
232 { |
|
233 tablePref.iBearer.iIapId = value; |
|
234 view->UpdateBearerL( tablePref.iBearer ); |
|
235 } |
|
236 |
|
237 CleanupStack::PopAndDestroy( view ); // view |
|
238 CleanupStack::PopAndDestroy( TheDb ); // TheDb |
|
239 } |
|
240 |
|
241 // ---------------------------------------------------------------------------- |
|
242 // Utils::AskIapIdL(TUint32& aId) |
|
243 // Ask IAP id from the user |
|
244 // ---------------------------------------------------------------------------- |
|
245 // |
|
246 TInt Utils::AskIapIdL( TUint32& aId ) |
|
247 { |
|
248 return Utils::SelectIdFromTableL( aId, TPtrC( IAP ) ); |
|
249 } |
|
250 |
|
251 // ---------------------------------------------------------------------------- |
|
252 // Utils::AskNetworkIdL(TUint32& aId) |
|
253 // Ask Network id from the user |
|
254 // ---------------------------------------------------------------------------- |
|
255 // |
|
256 TInt Utils::AskNetworkIdL( TUint32& aId ) |
|
257 { |
|
258 return Utils::SelectIdFromTableL( aId, TPtrC( NETWORK ) ); |
|
259 } |
|
260 |
|
261 // ---------------------------------------------------------------------------- |
|
262 // Utils::SelectIdFromTableL() |
|
263 // Does the real work for selecting IAP or Network id |
|
264 // ---------------------------------------------------------------------------- |
|
265 // |
|
266 TInt Utils::SelectIdFromTableL( TUint32& aId, const TDesC& aTableName ) |
|
267 { |
|
268 CCommsDatabase* TheDb; |
|
269 TInt res; |
|
270 TBuf<40> name; |
|
271 TBuf<20> title; |
|
272 TUint32 id; |
|
273 RArray<TUint32> idArray; |
|
274 CDesCArrayFlat* items = new (ELeave) CDesCArrayFlat( 16 ); |
|
275 |
|
276 // Get IAP names and ids from the database |
|
277 TheDb = CCommsDatabase::NewL( EDatabaseTypeIAP ); |
|
278 CleanupStack::PushL( TheDb ); |
|
279 |
|
280 TheDb->ShowHiddenRecords(); |
|
281 |
|
282 CCommsDbTableView* view; |
|
283 |
|
284 view = TheDb->OpenTableLC( aTableName ); |
|
285 title.Format( _L("Select %S:"), &aTableName ); |
|
286 |
|
287 res = view->GotoFirstRecord(); |
|
288 |
|
289 while (res == KErrNone) |
|
290 { |
|
291 view->ReadTextL( TPtrC( COMMDB_NAME ), name ); |
|
292 view->ReadUintL( TPtrC( COMMDB_ID ), id ); |
|
293 |
|
294 idArray.Insert( id, 0 ); |
|
295 items->InsertL( 0, name ); |
|
296 |
|
297 res = view->GotoNextRecord(); |
|
298 RDebug::Print( _L("ConnTest: IAP name, id: %S, %d"), &name, id ); |
|
299 } |
|
300 |
|
301 CleanupStack::PopAndDestroy( view ); // view |
|
302 CleanupStack::PopAndDestroy( TheDb ); // TheDb |
|
303 |
|
304 // Create listbox and PUSH it. |
|
305 CEikTextListBox* list = new (ELeave) CAknSinglePopupMenuStyleListBox; |
|
306 CleanupStack::PushL( list ); |
|
307 |
|
308 // Create popup list and PUSH it. |
|
309 CAknPopupList* popupList = CAknPopupList::NewL( list, |
|
310 R_AVKON_SOFTKEYS_OK_CANCEL, AknPopupLayouts::EMenuWindow ); |
|
311 CleanupStack::PushL( popupList ); |
|
312 |
|
313 // initialize listbox. |
|
314 list->ConstructL( popupList, CEikListBox::ELeftDownInViewRect ); |
|
315 list->CreateScrollBarFrameL( ETrue ); |
|
316 list->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, |
|
317 CEikScrollBarFrame::EAuto ); |
|
318 |
|
319 // Set listitems. |
|
320 CTextListBoxModel* model = list->Model(); |
|
321 model->SetItemTextArray( items ); |
|
322 model->SetOwnershipType( ELbmOwnsItemArray ); |
|
323 |
|
324 // Set title |
|
325 popupList->SetTitleL( title ); |
|
326 |
|
327 // Show popup list. |
|
328 TInt popupOk = popupList->ExecuteLD(); |
|
329 CleanupStack::Pop( popupList ); // popuplist |
|
330 if (popupOk) |
|
331 { |
|
332 TInt index = list->CurrentItemIndex(); |
|
333 aId = idArray[index]; |
|
334 } |
|
335 |
|
336 CleanupStack::PopAndDestroy( list ); // list |
|
337 |
|
338 idArray.Close(); |
|
339 // delete items; (list deletes) |
|
340 items = NULL; |
|
341 return popupOk; |
|
342 } |
|
343 |
|
344 // ---------------------------------------------------------------------------- |
|
345 // Utils::CreateDataChunk() |
|
346 // Create data chunk for POST performance tests |
|
347 // ---------------------------------------------------------------------------- |
|
348 // |
|
349 void Utils::CreateDataChunk( TDes8& aBuffer, TInt aLength ) |
|
350 { |
|
351 for (TInt i = 0; i < aLength && i < aBuffer.MaxLength(); i++) |
|
352 { |
|
353 if (i == 0) |
|
354 { |
|
355 aBuffer.Copy( _L8("a") ); |
|
356 } |
|
357 else |
|
358 { |
|
359 aBuffer.Append( _L8("a") ); |
|
360 } |
|
361 } |
|
362 } |
|
363 |