Thanks,
I have found a example days ago,and don't understand it clearly, the source code will be post latter. I wonder why define two CApAccessPointItem objects?
After I have test and debug it for times, but no difference found,and it can create an AP successfully. So why use the second one?
The code(I have modified it many times):
Code:
void CCreate::Create()
{
TInt errorCode;
//CUtils::WriteLog(KLogName,_L("Starting create..."));
CCommsDatabase* db = CCommsDatabase::NewL();
CleanupStack::PushL(db);
TInt err = db->BeginTransaction();
// Create a wlan AP and fill its mandatory fields.
CApAccessPointItem* wlanAp = CApAccessPointItem::NewLC();
//CApAccessPointItem* wlanNewItem = CApAccessPointItem::NewLC();//
wlanAp->SetNamesL(KApName);
wlanAp->SetBearerTypeL(EApBearerTypeWLAN);
wlanAp->WriteTextL(EApWlanNetworkName, KNetworkName); // Give corrct Data as per the router configuration //L!nkSys@MdpNok!a
//Lan network mode should be 1 for infrastructure, 0 for adhoc
wlanAp->WriteUint(EApWlanNetworkMode, 0);
wlanAp->WriteUint(EApWlanChannelId, 3);
// Setting up advanced settings for IP addressing
wlanAp->WriteTextL(EApWlanIpAddr, KIPAddress);
wlanAp->WriteTextL(EApWlanIpNetMask, KIPMask);
wlanAp->WriteTextL(EApWlanIpGateway, KIPGatway);
TBool val = ETrue;
TUint32 apid;
CApDataHandler* handler = CApDataHandler::NewLC(*db);
apid = handler->CreateFromDataL(*wlanAp);
handler->UpdateAccessPointDataL(*wlanAp, val);
//handler->AccessPointDataL(apid, *wlanNewItem); //copy AP data to wlanNewItem???
CApUtils *aputil = CApUtils::NewLC(*db);
TUint32 wapuid = wlanAp->WapUid(); //get the AP ID
TInt Iap = aputil->IapIdFromWapIdL(wapuid); //Get the Iap record ID for a given AP ID
TUint32 newalanid;
wlanAp->ReadUint(EApIapServiceId, newalanid);
//wlanNewItem->ReadUint(EApIapServiceId, newalanid);//
TBuf<50> logBuf;
logBuf.AppendFormat(_L("ServiceID = %d"),newalanid);
CUtils::WriteLog(KLogName,logBuf);
//TBuf<50> ibuff;//
//wlanNewItem->ReadTextL(EApWlanNetworkName, ibuff);//
//TUint32 newAPId = wlanNewItem->WapUid();//
CCommsDbTableView* wLanServiceTable = db->OpenViewMatchingUintLC(TPtrC(
WLAN_SERVICE), TPtrC(WLAN_SERVICE_ID), newalanid);
errorCode = wLanServiceTable->GotoFirstRecord();
if (errorCode == KErrNone)
{
wLanServiceTable->UpdateRecord();
}
else
{
TUint32 dummyUid(10); //KUidNone
User::LeaveIfError(wLanServiceTable->InsertRecord(dummyUid));
wLanServiceTable->WriteUintL(TPtrC(WLAN_SERVICE_ID), apid);
}
wLanServiceTable->PutRecordChanges();
err = db->CommitTransaction();
CleanupStack::PopAndDestroy(5);
}