创建接入点(IAP)用到的是通信数据库(CCommsDatabase). 下面的代码只是将模拟器的"Winsock" 接入点“复制”了一份。其中,CreateNewIAP()是主函数。
#include <commdbconnpref.h> #include <commdb.h> #include <cdbpreftable.h> TUint32 CreateWapApL(CCommsDatabase* db) { _LIT(KWapApName, "MyAP WAP"); TUint32 WapId; CCommsDbTableView* view = db->OpenTableLC(TPtrC(WAP_ACCESS_POINT)); User::LeaveIfError(view->InsertRecord(WapId)); view->WriteTextL(TPtrC(COMMDB_NAME), KWapApName); view->WriteTextL(TPtrC(WAP_CURRENT_BEARER), TPtrC(WAP_IP_BEARER)); User::LeaveIfError(view->PutRecordChanges()); delete view; return WapId; } TUint32 CreateGprsServiceL(CCommsDatabase* db) { _LIT(KGprsName, "MyAP Gprs"); _LIT(KSettingAPN, "Winsock"); TUint32 gprsId; CCommsDbTableView* view = db->OpenTableLC(TPtrC(OUTGOING_GPRS)); User::LeaveIfError(view->InsertRecord(gprsId)); view->WriteTextL(TPtrC(COMMDB_NAME), KGprsName); view->WriteTextL(TPtrC(GPRS_APN), KSettingAPN); view->WriteUintL(TPtrC(GPRS_PDP_TYPE), 0); view->WriteBoolL(TPtrC(GPRS_IP_ADDR_FROM_SERVER), EFalse); view->WriteBoolL(TPtrC(GPRS_IP_DNS_ADDR_FROM_SERVER), EFalse); view->WriteBoolL(TPtrC(GPRS_IP6_DNS_ADDR_FROM_SERVER), EFalse); view->WriteTextL(TPtrC(GPRS_IF_AUTH_NAME), _L("")); view->WriteTextL(TPtrC(GPRS_IF_AUTH_PASS), _L("")); view->WriteBoolL(TPtrC(GPRS_IF_PROMPT_FOR_AUTH), EFalse); view->WriteUintL(TPtrC(SERVICE_IF_AUTH_RETRIES), 0); view->WriteTextL(TPtrC(GPRS_IF_NETWORKS), _L("tcp,udp,icmp,icmp6")); view->WriteBoolL(TPtrC(GPRS_HEADER_COMPRESSION), EFalse); view->WriteBoolL(TPtrC(GPRS_DATA_COMPRESSION), EFalse); view->WriteUintL(TPtrC(GPRS_REQ_PRECEDENCE), 0); view->WriteUintL(TPtrC(GPRS_REQ_DELAY), 0); view->WriteUintL(TPtrC(GPRS_REQ_RELIABILITY), 0); view->WriteUintL(TPtrC(GPRS_REQ_PEAK_THROUGHPUT), 0); view->WriteUintL(TPtrC(GPRS_REQ_MEAN_THROUGHPUT), 0); view->WriteUintL(TPtrC(GPRS_MIN_PRECEDENCE), 0); view->WriteUintL(TPtrC(GPRS_MIN_DELAY), 0); view->WriteUintL(TPtrC(GPRS_MIN_RELIABILITY), 0); view->WriteUintL(TPtrC(GPRS_MIN_PEAK_THROUGHPUT), 0); view->WriteUintL(TPtrC(GPRS_MIN_MEAN_THROUGHPUT), 0); view->WriteBoolL(TPtrC(GPRS_ANONYMOUS_ACCESS), EFalse); view->WriteBoolL(TPtrC(GPRS_ENABLE_LCP_EXTENSIONS), EFalse); view->WriteBoolL(TPtrC(GPRS_DISABLE_PLAIN_TEXT_AUTH), EFalse); view->WriteUintL(TPtrC(GPRS_AP_TYPE), 2); view->WriteUintL(TPtrC(GPRS_QOS_WARNING_TIMEOUT), -1); User::LeaveIfError(view->PutRecordChanges()); delete view; return gprsId; } TUint32 CreateLocationL(CCommsDatabase* db) { _LIT(KLocName, "MyAP Location"); TUint32 LocId; CCommsDbTableView* view = db->OpenTableLC(TPtrC(LOCATION)); User::LeaveIfError(view->InsertRecord(LocId)); view->WriteTextL(TPtrC(COMMDB_NAME), KLocName); view->WriteTextL(TPtrC(LOCATION_INTL_PREFIX_CODE),_L("+")); view->WriteTextL(TPtrC(LOCATION_NAT_PREFIX_CODE),_L("0")); view->WriteTextL(TPtrC(LOCATION_NAT_CODE),_L("44")); view->WriteUintL(TPtrC(LOCATION_PAUSE_AFTER_DIAL_OUT), 0); view->WriteBoolL(TPtrC(LOCATION_MOBILE), ETrue); view->WriteBoolL(TPtrC(LOCATION_USE_PULSE_DIAL), EFalse); view->WriteBoolL(TPtrC(LOCATION_WAIT_FOR_DIAL_TONE), EFalse); User::LeaveIfError(view->PutRecordChanges()); delete view; return LocId; } TUint32 CreateBearerL(CCommsDatabase* db) { _LIT(KAgentName, "wsocka.agt"); _LIT(KIfName, "wsocki"); _LIT(KLddName, "foo"); _LIT(KBearerName, "MyAP Bearer"); TUint32 BearerId; CCommsDbTableView* view = db->OpenTableLC(TPtrC(LAN_BEARER)); User::LeaveIfError(view->InsertRecord(BearerId)); view->WriteTextL(TPtrC(COMMDB_NAME), KBearerName); view->WriteTextL(TPtrC(IF_NAME), KIfName); view->WriteTextL(TPtrC(LAN_BEARER_LDD_NAME), KIfName); view->WriteTextL(TPtrC(LAN_BEARER_PDD_NAME), KIfName); view->WriteTextL(TPtrC(AGENT_NAME), KAgentName); view->WriteUintL(TPtrC(LAST_SOCKET_ACTIVITY_TIMEOUT), -1); view->WriteUintL(TPtrC(LAST_SESSION_CLOSED_TIMEOUT), -1); view->WriteUintL(TPtrC(LAST_SOCKET_CLOSED_TIMEOUT), -1); User::LeaveIfError(view->PutRecordChanges()); delete view; return BearerId; } TUint32 CreateNetworkL(CCommsDatabase* db) { _LIT(KNetName, "MyAP Network"); TUint32 NetId; CCommsDbTableView* view = db->OpenTableLC(TPtrC(NETWORK)); User::LeaveIfError(view->InsertRecord(NetId)); view->WriteTextL(TPtrC(COMMDB_NAME), KNetName); User::LeaveIfError(view->PutRecordChanges()); delete view; return NetId; } void CreateConnectionPreferencesL(CCommsDatabase* db, TUint32 Iap) { CCommsDbConnectionPrefTableView * view = db->OpenConnectionPrefTableLC(ECommDbConnectionDirectionOutgoing); CCommsDbConnectionPrefTableView::TCommDbIapBearer bearerinfo; bearerinfo.iBearerSet=-1; bearerinfo.iIapId=Iap; CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref; pref.iRanking=0; pref.iDirection=ECommDbConnectionDirectionOutgoing; pref.iDialogPref =ECommDbDialogPrefDoNotPrompt; pref.iBearer=bearerinfo; view->InsertConnectionPreferenceL(pref); delete view; } TUint32 CreateIAPL(CCommsDatabase* db, TUint32 Bearer, TUint32 Network, TUint32 Service, TUint32 Location) { _LIT(KIAPName, "MyAP"); TUint32 IapId; CCommsDbTableView* view = db->OpenTableLC(TPtrC(IAP)); User::LeaveIfError(view->InsertRecord(IapId)); view->WriteTextL(TPtrC(COMMDB_NAME), KIAPName); view->WriteTextL(TPtrC(IAP_SERVICE_TYPE), TPtrC(OUTGOING_GPRS)); view->WriteTextL(TPtrC(IAP_BEARER_TYPE), TPtrC(LAN_BEARER)); view->WriteUintL(TPtrC(IAP_BEARER), Bearer); view->WriteUintL(TPtrC(IAP_NETWORK), Network); view->WriteUintL(TPtrC(IAP_SERVICE), Service); view->WriteUintL(TPtrC(LOCATION), Location); view->WriteUintL(TPtrC(IAP_NETWORK_WEIGHTING), 0); User::LeaveIfError(view->PutRecordChanges()); delete view; return IapId; } void CreateWapIPBearerL(CCommsDatabase* db, TUint32 Iap, TUint32 WapIap) { _LIT(KWapBearer, "MyAP Wap Bearer"); TUint32 Id; CCommsDbTableView* view = db->OpenTableLC(TPtrC(WAP_IP_BEARER)); User::LeaveIfError(view->InsertRecord(Id)); view->WriteTextL(TPtrC(COMMDB_NAME), KWapBearer); view->WriteUintL(TPtrC(IAP), Iap); view->WriteUintL(TPtrC(WAP_ACCESS_POINT_ID), WapIap); view->WriteUintL(TPtrC(WAP_WSP_OPTION), EWapWspOptionConnectionless); view->WriteBoolL(TPtrC(WAP_SECURITY), EFalse); / view->WriteTextL(TPtrC(WAP_GATEWAY_ADDRESS), _L("0.0.0.0")); view->WriteUintL(TPtrC(WAP_PROXY_PORT), 0); User::LeaveIfError(view->PutRecordChanges()); delete view; } void CreateNewIAP() { CCommsDatabase* db=CCommsDatabase::NewL(); TUint32 Bearer=CreateBearerL(db); TUint32 Network=CreateNetworkL(db); TUint32 Service=CreateGprsServiceL(db); TUint32 Location=CreateLocationL(db); TUint32 Iap=CreateIAPL(db, Bearer, Network, Service, Location); CreateConnectionPreferencesL(db, Iap); TUint32 WapAp=CreateWapApL(db); CreateWapIPBearerL(db,Iap,WapAp); delete db; }
需要在mmp中加入commdb.lib
LIBRARY commdb.lib
在三版本的(V9.X及以后)手机上运行时需要 WriteDeviceData 能力。
注:当没有在mmp中写该能力时,在插入数据的时候(write的时候),也会有CommsDbServer 12 的异常,这个要注意,而不仅仅是sdk里面讲的原因。
sdk里面对于使用到的能力也说的不是很清楚,sdk写得是Capability: Dependent on table - deferred to RDBMS.