Symbian 得到接入点ID-网络编程简单示例

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;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值