sym_iap_util.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
  4. ** Contact: Qt Software Information (qt-info@nokia.com)
  5. **
  6. ** This file is part of the examples of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** No Commercial Usage
  10. ** This file contains pre-release code and may not be distributed.
  11. ** You may use this file in accordance with the terms and conditions
  12. ** contained in the either Technology Preview License Agreement or the
  13. ** Beta Release License Agreement.
  14. **
  15. ** GNU Lesser General Public License Usage
  16. ** Alternatively, this file may be used under the terms of the GNU Lesser
  17. ** General Public License version 2.1 as published by the Free Software
  18. ** Foundation and appearing in the file LICENSE.LGPL included in the
  19. ** packaging of this file. Please review the following information to
  20. ** ensure the GNU Lesser General Public License version 2.1 requirements
  21. ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  22. **
  23. ** In addition, as a special exception, Nokia gives you certain
  24. ** additional rights. These rights are described in the Nokia Qt LGPL
  25. ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
  26. ** package.
  27. **
  28. ** GNU General Public License Usage
  29. ** Alternatively, this file may be used under the terms of the GNU
  30. ** General Public License version 3.0 as published by the Free Software
  31. ** Foundation and appearing in the file LICENSE.GPL included in the
  32. ** packaging of this file. Please review the following information to
  33. ** ensure the GNU General Public License version 3.0 requirements will be
  34. ** met: http://www.gnu.org/copyleft/gpl.html.
  35. **
  36. ** If you are unsure which license is appropriate for your use, please
  37. ** contact the sales department at qt-sales@nokia.com.
  38. ** $QT_END_LICENSE$
  39. **
  40. ****************************************************************************/
  41. #ifndef QSYM_IAP_UTIL_H
  42. #define QSYM_IAP_UTIL_H
  43. #include <es_sock.h>
  44. #include <sys/socket.h>
  45. #include <net/if.h>
  46. #include <rconnmon.h>
  47. QString qt_TDesC2QStringL(const TDesC& aDescriptor)
  48. {
  49. #ifdef QT_NO_UNICODE
  50. return QString::fromLocal8Bit(aDescriptor.Ptr(), aDescriptor.Length());
  51. #else
  52. return QString::fromUtf16(aDescriptor.Ptr(), aDescriptor.Length());
  53. #endif
  54. }
  55. static void qt_SetDefaultIapL()
  56. {
  57. TUint count;
  58. TRequestStatus status;
  59. TUint ids[15];
  60. RSocketServ serv;
  61. CleanupClosePushL(serv);
  62. RConnection conn;
  63. CleanupClosePushL(conn);
  64. RConnectionMonitor monitor;
  65. CleanupClosePushL(monitor);
  66. monitor.ConnectL();
  67. monitor.GetConnectionCount(count, status);
  68. User::WaitForRequest(status);
  69. if(status.Int() != KErrNone) {
  70. User::Leave(status.Int());
  71. }
  72. TUint numSubConnections;
  73. if(count > 0) {
  74. for (TInt i = 1; i <= count; i++) {
  75. User::LeaveIfError(monitor.GetConnectionInfo(i, ids[i-1], numSubConnections));
  76. }
  77. /*
  78. * get IAP value for first active connection
  79. */
  80. TBuf< 50 > iapName;
  81. monitor.GetStringAttribute(ids[0], 0, KIAPName, iapName, status);
  82. User::WaitForRequest(status);
  83. if (status.Int() != KErrNone) {
  84. User::Leave(status.Int());
  85. } else {
  86. QString strIapName = qt_TDesC2QStringL(iapName);
  87. struct ifreq ifReq;
  88. strcpy(ifReq.ifr_name, strIapName.toLatin1().data());
  89. User::LeaveIfError(setdefaultif(&ifReq));
  90. }
  91. } else {
  92. /*
  93. * no active connections yet
  94. * use IAP dialog to select one
  95. */
  96. User::LeaveIfError(serv.Connect());
  97. User::LeaveIfError(conn.Open(serv));
  98. User::LeaveIfError(conn.Start());
  99. _LIT(KIapNameSetting, "IAP\\Name");
  100. TBuf8<50> iap8Name;
  101. User::LeaveIfError(conn.GetDesSetting(TPtrC(KIapNameSetting), iap8Name));
  102. iap8Name.ZeroTerminate();
  103. conn.Stop();
  104. struct ifreq ifReq;
  105. strcpy(ifReq.ifr_name, (char*)iap8Name.Ptr());
  106. User::LeaveIfError(setdefaultif(&ifReq));
  107. }
  108. CleanupStack::PopAndDestroy(&monitor);
  109. CleanupStack::PopAndDestroy(&conn);
  110. CleanupStack::PopAndDestroy(&serv);
  111. }
  112. static int qt_SetDefaultIap()
  113. {
  114. TRAPD(err, qt_SetDefaultIapL());
  115. return err;
  116. }
  117. #endif // QSYM_IAP_UTIL_H