Symbian 得到存取點ID-網路編程簡單樣本

來源:互聯網
上載者:User

 1. 得到存取點ID(IAP ID)
在用如下代碼建立串連時:
RSocketServ   socketServ;
RConnection   connection;
TCommDbConnPref pref;
TRequestStatus rsConn, rsTimeout;
Timer Timer;
User::LeaveIfError(socketServ.Connect());
User::LeaveIfError(connect.Open(socketServ));
pref.SetDialogPreference(ECommDbDialogPrefPrompt);
pref.SetDirection(ECommDbConnectionDirectionOutoing);
pref.SetBearerSet(ECommDbBearerUnknown);
if(Timer.CreateLocal() == KErrNone)
{
    Timer::After(rsTimeout, 30 * 1000 * 1000)
    connection.Start(pref, rsConn);
    User::WaitForRequest(rsConn, rsTimeout);

    switch(rsConn.Int())
    {
       case KErrNone:
       case KErrInUse;
       case KErrAlreadyExists:
       dafault:
    }

    if(rsConn == KRequestPending)
    {
       connection.Stop();
       User::WaitForRequest(rsCconn);
    }

    if(rsTimeout == KRequestPending)
    {
       Timer::Calcel();
       User::WaitForRequest(rsTimeout);
    }

    Timer::Close();
}

connection.Close();
socketServ.Close();
會有提示選擇存取點的對話方塊出現. 在選擇了存取點之後, 可以用:
TUint32   iap(0);
_LIT(KCommdbIapSetting,   "IAP//Id");
User::LeaveIfError(connection.GetIntSetting(KCommdbIapSetting,   iap));
得到存取點的ID, 這裡iap就是存取點的ID.

2, 獲得活躍的存取點
TUint32 iap = 0;    
RSocketServ socketServ;   
User::LeaveIfError(socketServ.Connect());   
CleanupClosePushL(socketServ);   

RConnection conn;   
User::LeaveIfError(conn.Open(socketServ));   
CleanupClosePushL(conn); 
 
TUint count = 0;   
User::LeaveIfError(conn.EnumerateConnections(count)); 
 
TConnectionInfoBuf connectionInfo;   

TUint i;
for(; count > 0; count--)
{
    User::LeaveIfError(conn.GetConnectionInfo(count,connectionInfo));   
    iap = connectionInfo().iIapId;  
}

CleanupStack::PopAndDestroy(2, &socketServ);   

3, 輪詢可用的存取點:
3.1
(from: http://www.ok371.cn/html/13/0/999/1.htm)

How do I get a list of Internet Access Point (IAP) names and the corresponding ID values?

Answer:

An Internet Access Point (IAP) is a table in Symbian's Communication database (CommDB) which provides an entry point for making a connection over a given bearer type e.g. GPRS, WCDMA, GSM Data Call etc. There can be several IAP records in the IAP table within CommDB each pointing to a different connection type.

Note : The example code below uses Symbian OS APIs directly. Some SDKs might include UI Platform specific APIs to achieve the same thing. You can use
the Symbian APIs to allow your solution to work over different platforms - though any future changes made to CommDB API/functionality will affect your
implementation.

How do I get a list of IAP's names?

The below code snippet below showshow to get the IAP names for GPRS (and also WCDMA).

TUint32 CCommsDBAccessor::GetGPRSIAPsFromIAPTableL(CDesCArrayFlat* aList)
{
TBuf<52> iapfromtable;
TInt err = KErrNone;

// Open IAP table using the GPRS as the bearer.

    CCommsDbTableView* gprsTable = iCommsDB->OpenIAPTableViewMatchingBearerSetLC(ECommDbBearerGPRS,
    ECommDbConnectionDirectionOutgoing);

// Point to the first entry
User::LeaveIfError(gprsTable->GotoFirstRecord());
gprsTable->ReadTextL(TPtrC(COMMDB_NAME), iapfromtable);
aList->AppendL(iapfromtable);

while (err = gprsTable->GotoNextRecord(), err == KErrNone)
{
gprsTable->ReadTextL(TPtrC(COMMDB_NAME), iapfromtable);
aList->AppendL(iapfromtable);
}

CleanupStack::PopAndDestroy(); // gprsTable
}

How do I get the IAP ID values?
You can extend the second example above to get the IAP value. Include the line below
to read the IAP value for each record.

TUint32 id=0;
gprsTable->ReadUintL(TPtrC(COMMDB_ID), id);

The IAP value can be used in the override settings when making a connection. See FAQ 1064 for more details.

3.2

CCommsDatabase* commDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
CleanupStack::PushL(commDb);
//commDb->ShowHiddenRecords(); //如果調用了這個函數,而程式又沒有相應都許可權, 那麼在調用commDb->OpenTableLC(時會有異常拋出,該異常無法被抓住。

CCommsDbTableView* view = commDb->OpenTableLC(TPtrC(IAP));

for (TInt i = view->GotoFirstRecord(); i != KErrNotFound; i = view->GotoNextRecord())
{
TUint32 iapId;
TBuf<512> iapName;
view->ReadUintL(TPtrC(COMMDB_ID), iapId);
view->ReadTextL(TPtrC(COMMDB_NAME), iapName);

}

CleanupStack::PopAndDestroy(2, commDb); // view, commDb

iapTable->ReadUintL(TPtrC(COMMDB_ID), id);
iapTable->ReadTextL(TPtrC(COMMDB_NAME), iapfromtable);

if (iapfromtable == findString)
return id;

while (err = iapTable->GotoNextRecord(), err == KErrNone)
{
iapTable->ReadUintL(TPtrC(COMMDB_ID), id);
iapTable->ReadTextL(TPtrC(COMMDB_NAME), iapfromtable);
if (iapfromtable == findString)
return id;
}
return KErrNotFound;
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.