Esempio n. 1
0
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;
}
Esempio n. 2
0
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
	    if ( gSelectedConnectionId == -1 )
	    	gSelectedConnectionId = SelectIAP();
	    
	    iSelectedConnectionId =  gSelectedConnectionId;
	    
    	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;
}