今天没事,所以就弄了一下创建cmnet接入点,以前看过Mark的创建cmwap接入点,但是一直没有看到完整版的创建cmnet,今天趁此整理一下,方便同行使用。感觉和网络上的类似都是对表的读和写的操作。上代码:
TUint32 CIAPConnectEngine::CreateNewIapL(const TDesC& aName, const TDesC& aApn)
{
CCommsDatabase* commsDb;
commsDb = CCommsDatabase::NewL();
CleanupStack::PushL(commsDb);
TInt ret = commsDb->BeginTransaction();
while (ret != KErrNone)
{
User::After(3*100*1000);
ret = commsDb->BeginTransaction();
}
/* Step 1 */
// creating a new network record
TUint32 network_id;
CCommsDbTableView* network = commsDb->OpenTableLC(TPtrC(NETWORK));
network->InsertRecord(network_id);
network->WriteTextL(TPtrC(COMMDB_NAME), aName);
network->PutRecordChanges();
CleanupStack::PopAndDestroy(network);
/* Step 2 */
// creating a new outgoing gprs record
TUint32 og_gprs_id;
// See implementations in the CreateNewOgGprsL function
CreateNewOgGprsL(*commsDb,aName,aApn,og_gprs_id);
/* Step 3 */
// find Mobile LOCATION id
TUint32 m_location_id = 2;
{
TUint32 location_id;
CCommsDbTableView* view = commsDb->OpenTableLC(TPtrC(LOCATION));
TInt result = view->GotoFirstRecord();
TBuf<128> locationName;
while ( result == KErrNone )
{
view->ReadTextL(TPtrC(COMMDB_NAME), locationName);
view->ReadUintL(TPtrC(LOCATION_MOBILE), location_id);
TBool isMobile = EFalse;
view->ReadBoolL(TPtrC(LOCATION_MOBILE), isMobile);
// ApnTools::ReadBool(view,TPtrC(LOCATION_MOBILE), isMobile);
if ( isMobile && location_id > 0 )
{
m_location_id = location_id;
break;
}
result = view->GotoNextRecord();
}
CleanupStack::PopAndDestroy(view);
}
/* Step 4 */
// creating a new IAP record
CCommsDbTableView* iap = commsDb->OpenTableLC(TPtrC(IAP));
TUint32 iap_id;
iap->InsertRecord(iap_id);
iap->WriteTextL(TPtrC(COMMDB_NAME), aName);
iap->WriteUintL(TPtrC(IAP_SERVICE), og_gprs_id);
iap->WriteTextL(TPtrC(IAP_SERVICE_TYPE), TPtrC(OUTGOING_GPRS));
iap->WriteTextL(TPtrC(IAP_BEARER_TYPE), TPtrC(MODEM_BEARER));
iap->WriteUintL(TPtrC(IAP_BEARER), 2);
iap->WriteUintL( TPtrC(IAP_NETWORK), network_id);
iap->WriteUintL( TPtrC(IAP_NETWORK_WEIGHTING), 0 );
iap->WriteUintL( TPtrC(IAP_LOCATION), m_location_id);
iap->PutRecordChanges();
CleanupStack::PopAndDestroy(iap);
/* Step 5 */
// creating a new wap accesspoint record
TUint32 ap_id;
// See implementations in the CreateNewAccessPointL function
CreateNewAccessPointL(*commsDb, aName, ap_id);
/* Step 6 */
// creating a new wap bearer
CCommsDbTableView* wap_bearer = commsDb->OpenTableLC(TPtrC(WAP_IP_BEARER));
TUint32 wb_id;
wap_bearer->InsertRecord(wb_id);
wap_bearer->WriteUintL(TPtrC(WAP_ACCESS_POINT_ID), ap_id);
_LIT(wap_gw_address, "0.0.0.0");
wap_bearer->WriteTextL(TPtrC(WAP_GATEWAY_ADDRESS), wap_gw_address);
wap_bearer->WriteUintL( TPtrC(WAP_IAP), iap_id);
wap_bearer->WriteUintL( TPtrC(WAP_WSP_OPTION),
EWapWspOptionConnectionOriented);
wap_bearer->WriteBoolL( TPtrC(WAP_SECURITY), EFalse);
wap_bearer->WriteUintL( TPtrC(WAP_PROXY_PORT), 0 );
wap_bearer->WriteTextL(TPtrC(WAP_PROXY_LOGIN_NAME), _L(""));
wap_bearer->WriteTextL(TPtrC(WAP_PROXY_LOGIN_PASS), _L(""));
wap_bearer->PutRecordChanges();
CleanupStack::PopAndDestroy(wap_bearer);
//the apn not need proxy but has proxy record, need delete
CCommsDbTableView* view = commsDb->OpenViewMatchingUintLC(TPtrC(PROXIES), TPtrC(PROXY_ISP), og_gprs_id);
TInt error = 0;
error = view->GotoFirstRecord();
while ( error == KErrNone )
{
TUint32 proxy_id;
view->ReadUintL(TPtrC(COMMDB_ID), proxy_id);
//ApnTools::ReadUint(view, , proxy_id);
view->DeleteRecord();
error = view->GotoNextRecord();
}
CleanupStack::PopAndDestroy(view);
User::LeaveIfError(commsDb->CommitTransaction());
CleanupStack::PopAndDestroy(commsDb);
return iap_id;
}
void CIAPConnectEngine::CreateNewOgGprsL(CCommsDatabase& aCommsDb,
const TDesC& aName, const TDesC& aApn, TUint32& aOgGprsId)
{
CCommsDbTableView* commsOgGprs =
aCommsDb.OpenTableLC(TPtrC(OUTGOING_GPRS));
commsOgGprs->InsertRecord(aOgGprsId);
commsOgGprs->WriteTextL(TPtrC(COMMDB_NAME),aName);
commsOgGprs->WriteBoolL(TPtrC(GPRS_IF_PROMPT_FOR_AUTH), ETrue);
commsOgGprs->WriteBoolL(TPtrC(GPRS_IP_ADDR_FROM_SERVER), ETrue);
commsOgGprs->WriteBoolL(TPtrC(GPRS_IP_DNS_ADDR_FROM_SERVER), ETrue);
commsOgGprs->WriteTextL(TPtrC(GPRS_IP_GATEWAY), _L("0.0.0.0"));
commsOgGprs->WriteTextL(TPtrC(GPRS_IF_AUTH_NAME), _L(""));
commsOgGprs->WriteTextL(TPtrC(GPRS_IF_AUTH_PASS),_L(""));
commsOgGprs->WriteBoolL(TPtrC(GPRS_IF_PROMPT_FOR_AUTH), EFalse);
commsOgGprs->WriteTextL(TPtrC(GPRS_IF_NETWORKS), _L("ip"));
commsOgGprs->WriteTextL(TPtrC(GPRS_APN), aApn);
commsOgGprs->WriteUintL(TPtrC(GPRS_PDP_TYPE), 0);
commsOgGprs->WriteBoolL(TPtrC(GPRS_HEADER_COMPRESSION), EFalse);
commsOgGprs->WriteBoolL(TPtrC(GPRS_DATA_COMPRESSION), EFalse);
commsOgGprs->WriteUintL(TPtrC(GPRS_REQ_PRECEDENCE), 0);
commsOgGprs->WriteUintL(TPtrC(GPRS_REQ_DELAY), 0);
commsOgGprs->WriteUintL(TPtrC(GPRS_REQ_RELIABILITY), 0);
commsOgGprs->WriteUintL(TPtrC(GPRS_REQ_PEAK_THROUGHPUT), 0);
commsOgGprs->WriteUintL(TPtrC(GPRS_REQ_MEAN_THROUGHPUT), 0);
commsOgGprs->WriteUintL(TPtrC(GPRS_MIN_PRECEDENCE), 0);
commsOgGprs->WriteUintL(TPtrC(GPRS_MIN_DELAY), 0);
commsOgGprs->WriteUintL(TPtrC(GPRS_MIN_RELIABILITY), 0);
commsOgGprs->WriteUintL(TPtrC(GPRS_MIN_PEAK_THROUGHPUT), 0);
commsOgGprs->WriteUintL(TPtrC(GPRS_MIN_MEAN_THROUGHPUT), 0);
commsOgGprs->WriteBoolL(TPtrC(GPRS_ANONYMOUS_ACCESS), EFalse);
commsOgGprs->WriteBoolL(TPtrC(GPRS_USE_EDGE), EFalse);
commsOgGprs->WriteBoolL(TPtrC(GPRS_ENABLE_LCP_EXTENSIONS), EFalse);
commsOgGprs->WriteBoolL(TPtrC(GPRS_DISABLE_PLAIN_TEXT_AUTH), EFalse);
commsOgGprs->WriteUintL(TPtrC(GPRS_AP_TYPE), 0);
commsOgGprs->WriteUintL(TPtrC(GPRS_QOS_WARNING_TIMEOUT), -1);
commsOgGprs->WriteUintL(TPtrC(GPRS_PDP_TYPE), 0);
commsOgGprs->WriteTextL(TPtrC(GPRS_PDP_ADDRESS), _L(""));
commsOgGprs->WriteTextL(TPtrC(GPRS_IF_PARAMS), _L(""));
commsOgGprs->WriteUintL(TPtrC(GPRS_IF_AUTH_RETRIES), 0);
commsOgGprs->WriteTextL(TPtrC(GPRS_IP_NETMASK), _L(""));
commsOgGprs->WriteTextL(TPtrC(GPRS_IP_ADDR),_L("0.0.0.0"));
commsOgGprs->WriteTextL(TPtrC(GPRS_IP_NAME_SERVER1),_L("0.0.0.0"));
commsOgGprs->WriteTextL(TPtrC(GPRS_IP_NAME_SERVER2),_L("0.0.0.0"));
commsOgGprs->PutRecordChanges();
CleanupStack::PopAndDestroy(commsOgGprs);
}
void CIAPConnectEngine::CreateNewAccessPointL(CCommsDatabase& aCommsDb,
const TDesC& aCommsdb_name_val, TUint32& aApId)
{
CCommsDbTableView* commsAp = aCommsDb.OpenTableLC(TPtrC(WAP_ACCESS_POINT));
commsAp->InsertRecord(aApId);
commsAp->WriteTextL(TPtrC(COMMDB_NAME), aCommsdb_name_val);
commsAp->WriteTextL(TPtrC(WAP_CURRENT_BEARER), TPtrC(WAP_IP_BEARER));
commsAp->PutRecordChanges();
CleanupStack::PopAndDestroy(commsAp);
}
经过对比发现 创建cmwap和cmnet的不同之处在于CreateNewOgGprsL。当然还少了设置代理的那段。。
呵呵此代码在N97上测试通过。
下面是cmwap创建
http://blog.sina.com.cn/s/blog_5ccfd2d50100gbte.html