Symbian 创建APN

需要插入6个表各一条新纪录, 并且要去另一张表查一个字段. 说明一下, http://www.forum.nokia.com/info/sw.nokia.com/id/5a2147f6-15b7-46e4-8bf4-aaca7c7fc675/S60_Platform_Internet_Access_Points_Example_v2_0_en.zip.html 里面创建iap的代码有错误, 设置 GPRS_IP_DNS_ADDR_FROM_SERVER 的值因为 ETrue, 而原文是EFalse, 所以该新iap的代码无法进行dns.

以下是我的代码:
TInt CWolfEggReadDeviceInfo::CreateAPNL(CCommsDatabase* aCommsDb, const TDesC& aApnName, TBool aUseProxy, TUint8& aCause)
    {     
    /* Step 1 */ // creating a new network record
    TUint32 network_id;
    {
    //_S("Network"), Database table names. The name (a string) of each table is defined by a macro.
    CCommsDbTableView* network = aCommsDb->OpenTableLC(TPtrC(NETWORK));
    network->InsertRecord(network_id); //network_id was past to InsertRecord as a reference
    network->WriteTextL(TPtrC(COMMDB_NAME), aApnName);
    network->PutRecordChanges();
    CleanupStack::PopAndDestroy(network);
    }
      
    /* Step 2 */ // creating a new outgoing gprs record
    TUint32 og_gprs_id;
    // See implementations in the CreateNewOgGprsL function      
    CreateNewOgGprsL(aCommsDb, aApnName, og_gprs_id);
      
    /* Step 3 */ // search for mobile location id
    TUint32 location_id = 2;
    {          
    TUint32 locationId;          
    CCommsDbTableView* view = aCommsDb->OpenTableLC(TPtrC(LOCATION));
    TInt result = view->GotoFirstRecord();
          
    TBuf<128> locationName;
    while ( result == KErrNone )       
        {
        view->ReadTextL(TPtrC(COMMDB_NAME), locationName);          
        if ( locationName.Match(_L("Mobile")) != KErrNotFound )
            {
            view->ReadUintL(TPtrC(LOCATION_MOBILE), locationId);
            location_id = locationId; // Get location_id for step 4
            break;
            }
        result = view->GotoNextRecord();
        }
    CleanupStack::PopAndDestroy(view);
    }
      
    /* Step 4 */ // creating a new IAP record
    TUint32 iap_id;
    {
    //create new record            
    CCommsDbTableView* iap = aCommsDb->OpenTableLC(TPtrC(IAP));
    iap->InsertRecord(iap_id);   
    iap->WriteTextL(TPtrC(COMMDB_NAME), aApnName);
    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), location_id);
    iap->PutRecordChanges();
    CleanupStack::PopAndDestroy(iap);
    }
         
    /* Step 5 */ // creating a new wap access point record
    TUint32 wap_id;
    // See implementations in the CreateNewAccessPointL function
    CreateNewAccessPointL(aCommsDb, aApnName, wap_id);         
         
    /* Step 6 */ // creating a new wap bearer
    TUint32 wb_id;
    {
    //create new record             
    CCommsDbTableView* wap_bearer = aCommsDb->OpenTableLC(TPtrC(WAP_IP_BEARER));
    wap_bearer->InsertRecord(wb_id);            
    wap_bearer->WriteUintL(TPtrC(WAP_ACCESS_POINT_ID), wap_id);
    wap_bearer->WriteTextL(TPtrC(WAP_GATEWAY_ADDRESS), _L("0.0.0.0"));
    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->PutRecordChanges();
    CleanupStack::PopAndDestroy(wap_bearer);
    }
         
    /* Step 7 */ // Create or delete PROXIES
    {
    if ( aUseProxy )
      {  
      //create new record               
      CCommsDbTableView* view = aCommsDb->OpenTableLC(TPtrC(PROXIES));
      TUint32 proxy_id;
      view->InsertRecord(proxy_id);                 
      view->WriteUintL(TPtrC(PROXY_ISP), og_gprs_id);
      view->WriteBoolL(TPtrC(PROXY_USE_PROXY_SERVER), ETrue);
      view->WriteTextL(TPtrC(PROXY_SERVICE_TYPE), TPtrC(OUTGOING_GPRS));
      view->WriteLongTextL(TPtrC(PROXY_SERVER_NAME), _L("0.0.0.0"));
      view->WriteTextL(TPtrC(PROXY_PROTOCOL_NAME), _L("http"));
      view->WriteUintL(TPtrC(PROXY_PORT_NUMBER), 80);
      view->PutRecordChanges(EFalse,EFalse);
      CleanupStack::PopAndDestroy(view);
      }
    else
      { 
      //the apn not need proxy but has proxy record, need delete                 
      CCommsDbTableView* view = aCommsDb->OpenViewMatchingUintLC(TPtrC(PROXIES), TPtrC(PROXY_ISP), og_gprs_id);
      TInt error = view->GotoFirstRecord();
      while ( error == KErrNone )
          {
          TUint32 proxy_id;
          view->ReadUintL(TPtrC(COMMDB_ID), proxy_id);                     
          view->DeleteRecord();
          error = view->GotoNextRecord();
          }
      CleanupStack::PopAndDestroy(view);
      }
    }
    return iap_id;
    }

void CWolfEggReadDeviceInfo::CreateNewOgGprsL(CCommsDatabase* aCommsDb, const TDesC& aApnName, TUint32& aOgGprsId)
    {
    //create new record
    CCommsDbTableView* commsOgGprs = aCommsDb->OpenTableLC(TPtrC(OUTGOING_GPRS));  //_S("OutgoingGPRS")
    commsOgGprs->InsertRecord(aOgGprsId); //aOgGprsId was changed after calling InsertRecord()
         
    //Writes the wide (UNICODE) text from a 16 bit descriptor to a specific column within the current record.
    //The column is identified by the name supplied in the descriptor aColumn.
    //The length of the text cannot be greater than the value of the constant KCommsDbSvrMaxColumnNameLength,
    //otherwise the function leaves.
    //#define COMMDB_NAME    _S("Name")            // Name of the row
    commsOgGprs->WriteTextL(TPtrC(COMMDB_NAME), aApnName);
         
    //Writes the long text from a descriptor to a specific column within the current record.
    //The column is identified by the name supplied in the descriptor aColumn.  
    //#define GPRS_APN _S("APN")
    commsOgGprs->WriteLongTextL(TPtrC(GPRS_APN), aApnName);
         
    //IMPORT_C void WriteUintL(const TDesC &aColumn, const TUint32 &aValue);
    //Writes an unsigned integer value to a specific column within the current record. The column is identified
    //by the name supplied in the descriptor aColumn.
    //An earlier call to either UpdateRecord() or InsertRecord() must have been made before calling this function
    //otherwise the function raises a CommsDbServer 12 panic. If the column identified is the COMMDB_ID field,
    //than this function raises a CommsDbServer 13 panic. This panic is also raised if this function is called
    //after the view has been closed.
    //PutRecordChanges() must be called to store the changes.
    commsOgGprs->WriteUintL( TPtrC(GPRS_PDP_TYPE), 0);
    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);
         
    //Writes a Boolean value to a specific column within the current record.
    //The column is identified by the name supplied in the descriptor aColumn.
    commsOgGprs->WriteBoolL( TPtrC(GPRS_DATA_COMPRESSION), EFalse);
    commsOgGprs->WriteBoolL( TPtrC(GPRS_HEADER_COMPRESSION), EFalse);
    commsOgGprs->WriteBoolL( TPtrC(GPRS_ANONYMOUS_ACCESS), EFalse);
         
    commsOgGprs->WriteTextL( TPtrC(GPRS_IF_NETWORKS), _L("ip"));         
    commsOgGprs->WriteBoolL( TPtrC(GPRS_IF_PROMPT_FOR_AUTH), EFalse);         
    commsOgGprs->WriteUintL( TPtrC(GPRS_IF_AUTH_RETRIES), 0);
         
    _LIT(KNullIp, "0.0.0.0");
    commsOgGprs->WriteTextL( TPtrC(GPRS_IP_GATEWAY), KNullIp);         
    commsOgGprs->WriteBoolL( TPtrC(GPRS_IP_DNS_ADDR_FROM_SERVER), ETrue);
         
    commsOgGprs->WriteTextL( TPtrC(GPRS_IP_NAME_SERVER1), KNullIp);
    commsOgGprs->WriteTextL( TPtrC(GPRS_IP_NAME_SERVER2), KNullIp);
    commsOgGprs->WriteBoolL( TPtrC(GPRS_ENABLE_LCP_EXTENSIONS), EFalse);
    commsOgGprs->WriteBoolL( TPtrC(GPRS_DISABLE_PLAIN_TEXT_AUTH), ETrue);
    commsOgGprs->WriteBoolL( TPtrC(GPRS_IP_ADDR_FROM_SERVER), ETrue);
    commsOgGprs->WriteUintL( TPtrC(GPRS_AP_TYPE), 2);
    commsOgGprs->WriteUintL( TPtrC(GPRS_QOS_WARNING_TIMEOUT), 0xffffffff);
    commsOgGprs->PutRecordChanges();
    CleanupStack::PopAndDestroy(commsOgGprs);
    }

void CWolfEggReadDeviceInfo::CreateNewAccessPointL(CCommsDatabase* aCommsDb, const TDesC& aApnName, TUint32& aWapId)
    {
    //create new record
    CCommsDbTableView* commsAp = aCommsDb->OpenTableLC(TPtrC(WAP_ACCESS_POINT));
    commsAp->InsertRecord(aWapId);
  
    commsAp->WriteTextL(TPtrC(COMMDB_NAME), aApnName);
    commsAp->WriteTextL(TPtrC(WAP_CURRENT_BEARER), TPtrC(WAP_IP_BEARER));
    commsAp->PutRecordChanges();
    CleanupStack::PopAndDestroy(commsAp);
    }



------调用
        // create new apn
        commsDb->BeginTransaction();       
        HBufC *tempApn = HBufC::NewL(aCurrentAP.Length() * 2);
        tempApn->Des().Copy(aCurrentAP);
        TRAPD(err, CreateAPNL(commsDb, *tempApn, false, aCause));       
        if ( err == KErrNone )
           {
           isSetApSuccess = true;
           iIAPId = 0;
           commsDb->CommitTransaction();
           }
           else
           {
           commsDb->RollbackTransaction();
           }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值