得到接入點ID(IAP ID)

1. 得到接入點ID(IAP ID)
在用如下代碼創建連接時: 
 RSocketServ  socketServ;
 RConnection  connect;
 TCommDbConnPref pref;
 TRequestStatus rsConn, rsTimeout;
 RTimer timer;
 User::LeaveIfError(socketServ.Connect());
 User::LeaveIfError(connect.Open(socketServ));
 pref.SetDialogPreference(ECommDbDialogPrefPrompt);
 pref.SetDirection(ECommDbConnectionDirectionOutgoing);
 pref.SetBearerSet(ECommDbBearerUnknown);
if(timer.CreateLocal() == KErrNone) //注意,如果不創建一個本地時間,彈不出來接入點*********///
{
    timer.After(rsTimeout, 30 * 1000 * 1000);
    connect.Start(pref, rsConn);
    User::WaitForRequest(rsConn, rsTimeout);
 
 /*
    switch(rsConn.Int())
    {
       case KErrNone:
       case KErrInUse;
       case KErrAlreadyExists:
       dafault:
    }
*/
    if(rsConn == KRequestPending)
    {
       connect.Stop();
       User::WaitForRequest(rsConn);
    }

    if(rsTimeout == KRequestPending)
    {
       timer.Cancel();
       User::WaitForRequest(rsTimeout);
    }

    timer.Close();
}

connect.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.

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;
}

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 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章