|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef QSYM_IAP_UTIL_H |
|
19 #define QSYM_IAP_UTIL_H |
|
20 |
|
21 #include <es_sock.h> |
|
22 #include <sys/socket.h> |
|
23 #include <net/if.h> |
|
24 #include <rconnmon.h> |
|
25 |
|
26 QString qt_TDesC2QStringL(const TDesC& aDescriptor) |
|
27 { |
|
28 #ifdef QT_NO_UNICODE |
|
29 return QString::fromLocal8Bit(aDescriptor.Ptr(), aDescriptor.Length()); |
|
30 #else |
|
31 return QString::fromUtf16(aDescriptor.Ptr(), aDescriptor.Length()); |
|
32 #endif |
|
33 } |
|
34 |
|
35 static void qt_SetDefaultIapL() |
|
36 { |
|
37 TUint count; |
|
38 TRequestStatus status; |
|
39 TUint ids[15]; |
|
40 |
|
41 RSocketServ serv; |
|
42 CleanupClosePushL(serv); |
|
43 |
|
44 RConnection conn; |
|
45 CleanupClosePushL(conn); |
|
46 |
|
47 RConnectionMonitor monitor; |
|
48 CleanupClosePushL(monitor); |
|
49 |
|
50 monitor.ConnectL(); |
|
51 monitor.GetConnectionCount(count, status); |
|
52 User::WaitForRequest(status); |
|
53 if(status.Int() != KErrNone) { |
|
54 User::Leave(status.Int()); |
|
55 } |
|
56 |
|
57 TUint numSubConnections; |
|
58 |
|
59 if(count > 0) { |
|
60 for (TInt i = 1; i <= count; i++) { |
|
61 User::LeaveIfError(monitor.GetConnectionInfo(i, ids[i-1], numSubConnections)); |
|
62 } |
|
63 /* |
|
64 * get IAP value for first active connection |
|
65 */ |
|
66 TBuf< 50 > iapName; |
|
67 monitor.GetStringAttribute(ids[0], 0, KIAPName, iapName, status); |
|
68 User::WaitForRequest(status); |
|
69 if (status.Int() != KErrNone) { |
|
70 User::Leave(status.Int()); |
|
71 } else { |
|
72 QString strIapName = qt_TDesC2QStringL(iapName); |
|
73 struct ifreq ifReq; |
|
74 strcpy(ifReq.ifr_name, strIapName.toLatin1().data()); |
|
75 User::LeaveIfError(setdefaultif(&ifReq)); |
|
76 } |
|
77 } else { |
|
78 /* |
|
79 * no active connections yet |
|
80 * use IAP dialog to select one |
|
81 */ |
|
82 User::LeaveIfError(serv.Connect()); |
|
83 User::LeaveIfError(conn.Open(serv)); |
|
84 User::LeaveIfError(conn.Start()); |
|
85 |
|
86 _LIT(KIapNameSetting, "IAP\\Name"); |
|
87 TBuf8<50> iap8Name; |
|
88 User::LeaveIfError(conn.GetDesSetting(TPtrC(KIapNameSetting), iap8Name)); |
|
89 iap8Name.ZeroTerminate(); |
|
90 |
|
91 conn.Stop(); |
|
92 |
|
93 struct ifreq ifReq; |
|
94 strcpy(ifReq.ifr_name, (char*)iap8Name.Ptr()); |
|
95 User::LeaveIfError(setdefaultif(&ifReq)); |
|
96 } |
|
97 CleanupStack::PopAndDestroy(&monitor); |
|
98 CleanupStack::PopAndDestroy(&conn); |
|
99 CleanupStack::PopAndDestroy(&serv); |
|
100 } |
|
101 |
|
102 static int qt_SetDefaultIap() |
|
103 { |
|
104 TRAPD(err, qt_SetDefaultIapL()); |
|
105 return err; |
|
106 } |
|
107 |
|
108 #endif // QSYM_IAP_UTIL_H |