void CMainControlEngine::GetIapNumFromFile() { TBuf<255> nParmValue; iDBEngine->GetSystemParmWithSQL(KIAPNUM,nParmValue); if(nParmValue.Length ()==0) { // open the IAP communications database CCommsDatabase* commDB = CCommsDatabase::NewL(EDatabaseTypeIAP); CleanupStack::PushL(commDB); // initialize a view CCommsDbConnectionPrefTableView* commDBView = commDB->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionUnknown); //CCommsDbConnectionPrefTableView* commDBView = commDB->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionOutgoing); // go to the first record TInt err=commDBView->GotoFirstRecord(); if(err==KErrNotFound) { iIapValue=-1; } else { // Declare a prefTableView Object. CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref; // read the connection preferences commDBView->ReadConnectionPreferenceL(pref); TUint32 iap= pref.iBearer.iIapId; iIapValue=((TInt)iap); //保存到数据库中 SetIapNum(iIapValue); } // pop and destroy the IAP View CleanupStack::PopAndDestroy(commDBView); // pop and destroy the database object CleanupStack::PopAndDestroy(commDB); } else { TLex temp(nParmValue); temp.Val( iIapValue); } }
TBool CConnectionManager::SetupConnection() { TInt iCurrentProfileId; iBearerFilter = EApBearerTypeAllBearers; ASSERT(iRepository); // Check whether we are offline or online iRepository->Get(KProEngActiveProfile, iCurrentProfileId); // Close the connection only if // a) this is not the first time and // b) the profile has changed and // c) either the previous or the current profile is Offline (5 = Offline) if (iPreviousProfileId != -1 && iPreviousProfileId != iCurrentProfileId && (iPreviousProfileId == EConnectionStatus::Disconnected || iCurrentProfileId == EConnectionStatus::Disconnected)) { // Close and uninitialize iConnectionSetup = EFalse; iSessionHttp .Close(); iConnection .Close(); iServerSocket.Close(); } // Save current profile id iPreviousProfileId = iCurrentProfileId; // Try to find an existing connection. If connection has not been set up, // iConnection is not initialized and FindExistingConnection() fails. // Thus, in that case, finding must not be carried out. if (iConnectionSetup && !FindExistingConnection()) { iConnectionSetup = EFalse; } if (iConnectionSetup) { // Connection setup is done iNewConnection = EFalse; return ETrue; } // Open RHTTPSession with default protocol ("HTTP/TCP") iSessionHttp.OpenL(); // Install this class as the callback for authentication requests. When // page requires authentication the framework calls GetCredentialsL to get // user name and password. InstallAuthenticationL(iSessionHttp); // In offline, only WLAN connections are available if (iCurrentProfileId == EConnectionStatus::Disconnected) { iBearerFilter = EApBearerTypeWLAN; } // Show IAP selection dialog /*CActiveApDb* aDb = CActiveApDb::NewL(); CleanupStack::PushL(aDb); CApSettingsHandler* settings = CApSettingsHandler::NewLC ( *aDb , ETrue , EApSettingsSelListIsPopUp , EApSettingsSelMenuSelectNormal , KEApIspTypeAll , iBearerFilter , KEApSortNameAscending , 0 , EVpnFilterBoth , ETrue ); TInt iapRet = settings->RunSettingsL(0, iSelectedConnectionId); CleanupStack::PopAndDestroy(settings); CleanupStack::PopAndDestroy(aDb); if (iapRet != KApUiEventSelected) { // Exit no selection User::Leave(KErrNotReady); } else*/ // open the IAP communications database CCommsDatabase* commDB = CCommsDatabase::NewL(EDatabaseTypeIAP); CleanupStack::PushL(commDB); // initialize a view CCommsDbConnectionPrefTableView* commDBView = commDB->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionUnknown); // go to the first record User::LeaveIfError(commDBView->GotoFirstRecord()); CCommsDbConnectionPrefTableView::TCommDbIapBearer bearer; bearer.iBearerSet = iBearerFilter; // Declare a prefTableView Object. CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref; pref.iBearer = bearer; pref.iDirection = ECommDbConnectionDirectionOutgoing; // read the connection preferences commDBView->ReadConnectionPreferenceL(pref); iSelectedConnectionId = pref.iBearer.iIapId; // pop and destroy the IAP View CleanupStack::PopAndDestroy(commDBView); // pop and destroy the database object CleanupStack::PopAndDestroy(commDB); iNewConnection = ETrue; // IAP Selected // Open socket server and start the connection User::LeaveIfError(iServerSocket.Connect(KESockDefaultMessageSlots)); User::LeaveIfError(iConnection.Open(iServerSocket, KConnectionTypeDefault)); // Now we have the iap Id. Use it to connect for the connection TCommDbConnPref connectPref; // Setup preferences connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); // Sets the CommDb ID of the IAP to use for this connection connectPref.SetIapId(iSelectedConnectionId); // Sets direction connectPref.SetDirection(ECommDbConnectionDirectionOutgoing); connectPref.SetBearerSet(iBearerFilter); // Start connection User::LeaveIfError(iConnection.Start(connectPref)); //TInt retval = iConnection.Start(); //User::LeaveIfError(retval); // Set the sessions connection info... RStringPool strPool = iSessionHttp.StringPool(); RHTTPConnectionInfo connInfo = iSessionHttp.ConnectionInfo(); // ...to use our socket server and connection connInfo.SetPropertyL(strPool.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable()), THTTPHdrVal (iServerSocket.Handle())); // ...to use our connection connInfo.SetPropertyL(strPool.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable()), THTTPHdrVal (REINTERPRET_CAST(TInt, &(iConnection)))); iConnectionSetup = ETrue; return ETrue; }
// ---------------------------------------------------------------------------- // CClientEngine::SetupConnectionL() // // The method set the internet access point and connection setups. // ---------------------------------------------------------------------------- void CClientEngine::SetupConnectionL() { if( iConnectionSetupDone ) return; iConnectionSetupDone = ETrue; //open socket server and start the connection User::LeaveIfError(iSocketServ.Connect()); User::LeaveIfError(iConnection.Open(iSocketServ)); TCommDbConnPref connectPref; TUint32 iapID; if(iSetIap == EFalse) { // open the IAP communications database CCommsDatabase* commDB = CCommsDatabase::NewL(EDatabaseTypeIAP); CleanupStack::PushL(commDB); // initialize a view CCommsDbConnectionPrefTableView* commDBView = commDB->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionUnknown); // go to the first record User::LeaveIfError(commDBView->GotoFirstRecord()); // Declare a prefTableView Object. CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref; // read the connection preferences commDBView->ReadConnectionPreferenceL(pref); iapID = pref.iBearer.iIapId; // pop and destroy the IAP View CleanupStack::PopAndDestroy(commDBView); // pop and destroy the database object CleanupStack::PopAndDestroy(commDB); // setup preferences connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); connectPref.SetDirection(ECommDbConnectionDirectionUnknown); connectPref.SetBearerSet(ECommDbBearerGPRS); //Sets the CommDb ID of the IAP to use for this connection connectPref.SetIapId(iapID); }else{ connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); connectPref.SetDirection(ECommDbConnectionDirectionUnknown); connectPref.SetBearerSet(ECommDbBearerGPRS); //Sets the CommDb ID of the IAP to use for this connection connectPref.SetIapId(iIapId); } User::LeaveIfError(iConnection.Start(connectPref)); //set the sessions connection info RStringPool strPool = iSession.StringPool(); RHTTPConnectionInfo connInfo = iSession.ConnectionInfo(); //to use our socket server and connection connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable() ), THTTPHdrVal (iSocketServ.Handle()) ); connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable() ), THTTPHdrVal (REINTERPRET_CAST(TInt, &(iConnection))) ); }