1.   Overview

特定接入点的查找/创建应该是这样的一个过程。首先你从一个配置文件里面读出你要选择的AP的名字(一般情况下我们是知道要用那个接入点的,而且为了方便配置一般也把它写到配置文件中去)。在得到这个名字后,我们就遍历机器上所有的接入点,查找是否有我们需要的,如果有我们就返回那个接入点的索引,如果没有就要在设备上创建一个AP,创建这个AP的参数也存在配置文件中,成功创建后返回其索引以备后用。

2.   Code

// 从配置文件中读出接入点的名称

TBuf<64> apnConnName;

GetAPNnameFromConfig(apnConnName);

apnConnName.LowerCase();

// 遍历通信数据库,寻找对应的接入点的索引

TUint32 iapId(-1);

CCommsDatabase* commDb = CCommsDatabase::NewL();

CleanupStack::PushL(commDb);

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

TFileName iapName;

User::LeaveIfError(view->GotoFirstRecord());

do

{

    view->ReadTextL(TPtrC(COMMDB_NAME), iapName);

    iapName.LowerCase();

    if (!iapName.Compare(*apName))

    {

       view->ReadUintL(TPtrC(COMMDB_ID), iapId);

       break;

    }

}

While (KErrNone == view->GotoNextRecord());

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

CleanupStack::PopAndDestroy(apName);

// 找到就返回

if (iapId != -1)

    return iapId;

// 没有找到就创建一个,从配置文件中读出参数

TInt apnDataBearer;

TBuf<64> apnAccessPointName;

TBool apnAuthentication;

TBuf<64> apnProxyNameAddr;

TInt apnProxyPortNumber;

GetAPNBearerFromConf(apnDataBearer);

GetAPNnameFromConf(apnAccessPointName);

GetAPNAuthFromConf(apnAuthentication);

GetAPNProxyNameFromConf(apnProxyNameAddr);

GetAPNProxyPortFromConf(apnProxyPortNumber);

//创建一个接入点

CApAccessPointItem* apn = CApAccessPointItem::NewLC();

apn->SetNamesL( apnConnName );

apn->SetBearerTypeL( (TApBearerType)apnDataBearer );

apn->WriteLongTextL( EApGprsAccessPointName, apnAccessPointName );

if( apnAuthentication )

{

    apn->WriteBool( EApGprsDisablePlainTextAuth, ETrue );

    apn->WriteBool( EApGprsDisablePlainTextAuth, ETrue );

}

else

{

    apn->WriteBool( EApGprsDisablePlainTextAuth, EFalse );

}

if( apnProxyNameAddr.Length() )

{

    apn->WriteLongTextL( EApProxyServerAddress, apnProxyNameAddr );

    apn->WriteUint( EApProxyPortNumber, (TUint)apnProxyPortNumber );

}

CCommsDatabase* commDb = CCommsDatabase::NewL();

CleanupStack::PushL( commDb );

CApDataHandler* handler = CApDataHandler::NewLC( *commDb );

TInt commErr = commDb ->BeginTransaction();

newApId = (TInt32)handler->CreateFromDataL( *apn );

commErr = commDb->CommitTransaction();

CleanupStack::PopAndDestroy( handler );

CleanupStack::PopAndDestroy( commDb );

CleanupStack::PopAndDestroy( apn );

return newApId;

 

 

 


CTIC.川科创新
 3G嵌入式技术教育专家(3G送手机)

3G手机软件工程师培训 现热招中 报名即 送3G手机 一部

咨询电话:400-702-8828  www.ctic.cc 

posts - 41, comments - 14, trackbacks - 0, articles - 2

Copyright © Learn