locationmanager/ReverseGeocode/src/clientengine.cpp
branchRCL_3
changeset 57 2872ae438bf7
parent 53 29d87345eaeb
child 63 e538444823de
equal deleted inserted replaced
53:29d87345eaeb 57:2872ae438bf7
     1 /*
       
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Implementation of HTTP Client Engine.
       
    15 */
       
    16 
       
    17 //Symbian headers
       
    18 #include <http.h>
       
    19 #include <commdbconnpref.h>
       
    20 #include <connpref.h>
       
    21 #include <extendedconnpref.h>
       
    22 #include <commdb.h>
       
    23 #include <etel3rdparty.h>                // voice call notification
       
    24 #include <mmtsy_names.h>                 // kmmtsymodulename
       
    25 #include "locationmanagerdebug.h"
       
    26 #include "clientengine.h"
       
    27 
       
    28 // Used user agent for requests
       
    29 _LIT8(KUserAgent, "SimpleClient 1.0");
       
    30 
       
    31 // This client accepts all content types.
       
    32 _LIT8(KAccept, "*/*");
       
    33 
       
    34 // ----------------------------------------------------------------------------
       
    35 // CClientEngine::NewL()
       
    36 // ----------------------------------------------------------------------------
       
    37 CClientEngine* CClientEngine::NewL( MClientObserver& aObserver)
       
    38     {
       
    39     LOG("CClientEngine::NewL ,begin");
       
    40     CClientEngine* self = CClientEngine::NewLC( aObserver);
       
    41     CleanupStack::Pop( self );
       
    42     return self;
       
    43     }
       
    44 
       
    45 // ----------------------------------------------------------------------------
       
    46 // CClientEngine::NewLC()
       
    47 // ----------------------------------------------------------------------------
       
    48 CClientEngine* CClientEngine::NewLC(MClientObserver& aObserver)
       
    49     {
       
    50     LOG("CClientEngine::NewLC ,begin");
       
    51     CClientEngine* self = new ( ELeave ) CClientEngine( aObserver);
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructL();
       
    54     return self;
       
    55     }
       
    56 
       
    57 // ----------------------------------------------------------------------------
       
    58 // CClientEngine::CClientEngine()
       
    59 // ----------------------------------------------------------------------------
       
    60 CClientEngine::CClientEngine( MClientObserver& aObserver): 
       
    61                                 CActive( CActive::EPriorityStandard ),
       
    62                                 iObserver( aObserver ),
       
    63                                 iConnectionSetupDone( EFalse ),
       
    64                                 iPrevProfileId( -1 ),
       
    65                                 iMobility(NULL),
       
    66                                 iTransactionOpen( EFalse ),
       
    67                                 iUri(NULL)
       
    68     {
       
    69     }
       
    70 
       
    71 // ----------------------------------------------------------------------------
       
    72 // CClientEngine::~CClientEngine()
       
    73 // ----------------------------------------------------------------------------
       
    74 CClientEngine::~CClientEngine()
       
    75     {
       
    76     LOG("CClientEngine::~CClientEngine ,begin");
       
    77     Cancel();
       
    78 
       
    79     if ( iTransactionOpen )
       
    80         {
       
    81         iTransaction.Close();
       
    82         iTransactionOpen = EFalse;
       
    83         }
       
    84     
       
    85     if ( iMobility )
       
    86         {
       
    87         iMobility->Cancel();
       
    88         }
       
    89     delete iMobility;
       
    90     iMobility = NULL;
       
    91     
       
    92     if(iConnectionSetupDone)
       
    93         {
       
    94         iSession.Close();
       
    95         iConnection.Close();
       
    96         iSocketServ.Close();
       
    97         }
       
    98     delete iUri;
       
    99     iUri = NULL;
       
   100    
       
   101 	iCmManager.Close();
       
   102 
       
   103     
       
   104     // DON'T cose RMobilePhone object
       
   105 
       
   106 	LOG("CClientEngine::~CClientEngine ,end");
       
   107     }
       
   108 
       
   109 // ----------------------------------------------------------------------------
       
   110 // CClientEngine::ConstructL()
       
   111 // ----------------------------------------------------------------------------
       
   112 void CClientEngine::ConstructL()
       
   113   {
       
   114   LOG("CClientEngine::ConstructL ,begin");
       
   115   CActiveScheduler::Add(this);
       
   116   iCmManager.OpenL();
       
   117   LOG("CClientEngine::ConstructL ,end");
       
   118   }
       
   119 
       
   120 // ----------------------------------------------------------------------------
       
   121 // CClientEngine::CloseConnection()
       
   122 // ----------------------------------------------------------------------------
       
   123 void CClientEngine::CloseConnection()
       
   124     {
       
   125     LOG("CClientEngine::CloseConnection ,begin" );
       
   126     if ( iTransactionOpen )
       
   127         {
       
   128         iTransaction.Close();
       
   129         iTransactionOpen = EFalse;
       
   130         }
       
   131     
       
   132     if ( iMobility )
       
   133         {
       
   134 		iMobility->Cancel();
       
   135 		delete iMobility;
       
   136 		iMobility = NULL;
       
   137         }
       
   138 
       
   139     if(iConnectionSetupDone)
       
   140         { 
       
   141         iSession.Close();
       
   142         iConnection.Close();
       
   143         iSocketServ.Close();  
       
   144            
       
   145         iConnectionSetupDone = EFalse;
       
   146         }
       
   147 	LOG("CClientEngine::CloseConnection ,end");
       
   148     }
       
   149 
       
   150 
       
   151 // ----------------------------------------------------------------------------
       
   152 // CClientEngine::IsVisitorNetwork()
       
   153 // ----------------------------------------------------------------------------
       
   154 TBool CClientEngine::IsVisitorNetwork(const TMobileRoamingStatus& aRegNetworkStatus) const
       
   155     {
       
   156     LOG1("CClientEngine::IsVisitorNetwork. reg network status - %d",
       
   157 			(TInt) aRegNetworkStatus);
       
   158         
       
   159     return (aRegNetworkStatus == EMobileNationalRoaming ||
       
   160         aRegNetworkStatus== EMobileInternationalRoaming);
       
   161     
       
   162     }
       
   163 
       
   164 // ----------------------------------------------------------------------------
       
   165 // CClientEngine::IsWlanOnly()
       
   166 // ----------------------------------------------------------------------------
       
   167 TBool CClientEngine::IsWlanOnly(const TMobileRoamingStatus& aRoamingStatus,
       
   168                                 const TCmGenConnSettings& aGenConnSettings) const
       
   169     {
       
   170     LOG1("CClientEngine::IsVisitorNetwork. reg network status - %d",(TInt) aRoamingStatus);
       
   171     TBool wlanOnlyFlag = EFalse;
       
   172     switch(aRoamingStatus)
       
   173         {
       
   174         case EMobileRegHomeNetwork:
       
   175             LOG("Home network");
       
   176             wlanOnlyFlag = (aGenConnSettings.iCellularDataUsageHome == ECmCellularDataUsageDisabled);
       
   177             break;
       
   178         case EMobileNationalRoaming:
       
   179         case EMobileInternationalRoaming:
       
   180             LOG("Visitor network");
       
   181             wlanOnlyFlag = (aGenConnSettings.iCellularDataUsageVisitor == ECmCellularDataUsageDisabled);
       
   182             break;
       
   183         default:
       
   184             break;
       
   185         } // end of switch
       
   186     LOG1("Wlan only flag - %d", wlanOnlyFlag ? 1 : 0);
       
   187     return wlanOnlyFlag;
       
   188     }
       
   189 
       
   190 
       
   191 // ----------------------------------------------------------------------------
       
   192 // CClientEngine::UeRegNetworkStatus()
       
   193 // ----------------------------------------------------------------------------
       
   194 TMobileRoamingStatus CClientEngine::UeRegNetworkStatus()
       
   195     {
       
   196     LOG("CClientEngine::UeRegNetworkStatus() ,begin");
       
   197     TMobileRoamingStatus roamingStatus = EMobileNotRegistered;
       
   198     if(iObserver.IsRegisteredAtHomeNetwork())
       
   199         {
       
   200         // home network.
       
   201         roamingStatus = EMobileRegHomeNetwork;
       
   202         LOG("UE registered in home network");
       
   203         }
       
   204     else
       
   205         {
       
   206         // roaming network
       
   207         TBool homeNwInfoAvailableFlag = EFalse;
       
   208         const RMobilePhone::TMobilePhoneNetworkInfoV1& homeNwInfo = 
       
   209             iObserver.GetHomeNetworkInfo(homeNwInfoAvailableFlag);
       
   210         if(homeNwInfoAvailableFlag)
       
   211             {
       
   212             RMobilePhone::TMobilePhoneNetworkCountryCode countryCode = 
       
   213                         iObserver.GetCurrentRegisterNw().iCountryCode;
       
   214             if(countryCode.Compare(homeNwInfo.iCountryCode) == 0)
       
   215                 {
       
   216                 // national roaming..
       
   217                 LOG("UE is in nation roaming");
       
   218                 roamingStatus = EMobileNationalRoaming;
       
   219                 }
       
   220             else
       
   221                 {
       
   222                 // international roaming.
       
   223                 LOG("UE is in international roaming");
       
   224                 roamingStatus = EMobileInternationalRoaming;
       
   225                 }
       
   226             }                
       
   227         }
       
   228     if(roamingStatus == EMobileNotRegistered)
       
   229         {
       
   230         LOG("UE is not registered with the network. Offline mode.");
       
   231         }
       
   232 	LOG("CClientEngine::UeRegNetworkStatus ,end");
       
   233     return roamingStatus;
       
   234     }
       
   235 
       
   236 // ----------------------------------------------------------------------------
       
   237 // CClientEngine::IsDataConnectionAskAlwaysL()
       
   238 // ----------------------------------------------------------------------------
       
   239 TBool CClientEngine::IsDataConnectionAskAlwaysL() 
       
   240     {
       
   241     LOG("CClientEngine::IsDataConnectionAskAlwaysL ,begin");
       
   242     TMobileRoamingStatus roamingStatus = UeRegNetworkStatus();
       
   243         
       
   244 	TCmGenConnSettings genConnSettings;
       
   245     TBool retVal = EFalse;
       
   246 	iCmManager.ReadGenConnSettingsL(genConnSettings);
       
   247 
       
   248     LOG1("wlan usage - %d", genConnSettings.iUsageOfWlan);
       
   249     LOG1("Home usage - %d", genConnSettings.iCellularDataUsageHome);
       
   250     LOG1("Visitor usage - %d", genConnSettings.iCellularDataUsageVisitor);
       
   251     
       
   252 	if((IsWlanOnly(roamingStatus, genConnSettings) && genConnSettings.iUsageOfWlan == ECmUsageOfWlanManual) // wlan
       
   253 		|| (roamingStatus == EMobileRegHomeNetwork &&  // home
       
   254         		genConnSettings.iCellularDataUsageHome == ECmCellularDataUsageConfirm)
       
   255 		|| (IsVisitorNetwork(roamingStatus) &&  // roaming
       
   256     		 genConnSettings.iCellularDataUsageVisitor == ECmCellularDataUsageConfirm)
       
   257 		)
       
   258 		{
       
   259 		retVal = ETrue;
       
   260 		}
       
   261 	LOG("CClientEngine::IsDataConnectionAskAlwaysL ,end");
       
   262 	return retVal;
       
   263 	}
       
   264 
       
   265 // ----------------------------------------------------------------------------
       
   266 // CClientEngine::SetupConnectionL()
       
   267 // ----------------------------------------------------------------------------
       
   268 void CClientEngine::SetupConnectionL( const TConnectionOption aOption )
       
   269     {
       
   270 	LOG("CClientEngine::SetupConnectionL ,begin");
       
   271 	if ( aOption == ESilent && IsDataConnectionAskAlwaysL())
       
   272 		{
       
   273 		LOG("Silent mode. connection setup is asked always.");
       
   274         if ( iConnectionSetupDone )
       
   275             {
       
   276             LOG("Already connected. Close the connection\n");
       
   277             CloseConnection();
       
   278             }
       
   279 		User::Leave(KErrNotSupported);
       
   280 		}
       
   281     if ( iConnectionSetupDone )
       
   282         {
       
   283         // Connection setup is done
       
   284         LOG("Already connected.\n");
       
   285         User::Leave(KErrAlreadyExists);
       
   286         }
       
   287  
       
   288 	
       
   289     LOG1("SetupConnectionL: connection option: %d\n", aOption );
       
   290        
       
   291     // Open HTTP Session
       
   292     iSession.OpenL();
       
   293     User::LeaveIfError(iSocketServ.Connect());
       
   294     User::LeaveIfError(iConnection.Open(iSocketServ));
       
   295     
       
   296     if ( aOption == ESilent )
       
   297         {
       
   298         // Create overrides
       
   299         TConnPrefList prefList;
       
   300         TExtendedConnPref prefs;
       
   301         prefs.SetSnapPurpose( CMManager::ESnapPurposeInternet );
       
   302         prefs.SetNoteBehaviour( TExtendedConnPref::ENoteBehaviourConnSilent );
       
   303         prefList.AppendL( &prefs );
       
   304         
       
   305         iConnection.Start(prefList, iStatus);
       
   306         }
       
   307     else
       
   308         {
       
   309         iConnection.Start( iStatus );
       
   310         }
       
   311    
       
   312     
       
   313     SetActive();
       
   314 	LOG("CClientEngine::SetupConnectionL ,end");
       
   315     }
       
   316 
       
   317 // ----------------------------------------------------------------------------
       
   318 // CClientEngine::SetHeaderL()
       
   319 // ----------------------------------------------------------------------------
       
   320 void CClientEngine::SetHeaderL( RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue )
       
   321     {
       
   322     LOG("CClientEngine::SetHeaderL ,begin");
       
   323     RStringF valStr = iSession.StringPool().OpenFStringL( aHdrValue );
       
   324     CleanupClosePushL( valStr );
       
   325     THTTPHdrVal val(valStr);
       
   326     aHeaders.SetFieldL( iSession.StringPool().StringF( aHdrField, RHTTPSession::GetTable()), val);
       
   327     CleanupStack::PopAndDestroy();  // valStr
       
   328     LOG("CClientEngine::SetHeaderL ,end");
       
   329     }
       
   330 
       
   331 // ----------------------------------------------------------------------------
       
   332 // CClientEngine::IssueHTTPGetL()
       
   333 // ----------------------------------------------------------------------------
       
   334 void CClientEngine::IssueHTTPGetL( const TDesC8& aUri, const TConnectionOption aOption )
       
   335     {
       
   336     LOG("CClientEngine::IssueHTTPGetL ,begin");
       
   337     if ( IsActive() )
       
   338         {
       
   339         // If there is some request in pending state
       
   340         // return with out further processing
       
   341         // Should we leave here !?
       
   342         LOG("Client engine is already active");
       
   343         return;
       
   344         }
       
   345     
       
   346     delete iUri;
       
   347     iUri = NULL;
       
   348 
       
   349     iUri = aUri.AllocL();
       
   350 
       
   351     // Create HTTP connection
       
   352     TRAPD( err, SetupConnectionL( aOption ) );
       
   353     //If the Err is KErrNone, It will lead to RunL and
       
   354     //hence jump to the DoHTTPGetL() from there.
       
   355     
       
   356     if( err == KErrAlreadyExists )
       
   357         {
       
   358         DoHTTPGetL();
       
   359         }
       
   360     else if( err != KErrNone )
       
   361         {
       
   362         LOG("Connection failure. Leaving.");
       
   363         iObserver.ClientEvent( EHttpConnectionFailure );
       
   364         User::Leave(err);
       
   365         }
       
   366     iEngineState = EGet;
       
   367  	LOG("CClientEngine::IssueHTTPGetL ,end");
       
   368     }
       
   369 
       
   370 // ----------------------------------------------------------------------------
       
   371 // CClientEngine::DoHTTPGetL()
       
   372 // ----------------------------------------------------------------------------
       
   373 void CClientEngine::DoHTTPGetL()
       
   374     {
       
   375     LOG("CClientEngine::DoHTTPGetL ,begin");
       
   376     // Parse string to URI (as defined in RFC2396)
       
   377     TUriParser8 uri;
       
   378     uri.Parse( *iUri );
       
   379     
       
   380     // Get request method string for HTTP GET
       
   381     RStringF method = iSession.StringPool().StringF( HTTP::EGET,RHTTPSession::GetTable() );
       
   382     
       
   383     // Open transaction with previous method and parsed uri. This class will
       
   384     // receive transaction events in MHFRunL and MHFRunError.
       
   385     iTransaction = iSession.OpenTransactionL( uri, *this, method );
       
   386     iTransactionOpen = ETrue;
       
   387     
       
   388     // Set headers for request; user agent and accepted content type
       
   389     RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
       
   390     SetHeaderL( hdr, HTTP::EUserAgent, KUserAgent );
       
   391     SetHeaderL( hdr, HTTP::EAccept, KAccept );
       
   392     
       
   393     // Submit the transaction. After this the framework will give transaction
       
   394     // events via MHFRunL and MHFRunError.
       
   395     iTransaction.SubmitL();
       
   396     
       
   397     iObserver.ClientEvent( EHttpConnecting );
       
   398 	LOG("CClientEngine::DoHTTPGetL ,end");
       
   399 }
       
   400 
       
   401 // ----------------------------------------------------------------------------
       
   402 // CClientEngine::CancelTransaction()
       
   403 // ----------------------------------------------------------------------------
       
   404 void CClientEngine::CancelTransaction()
       
   405     {
       
   406     LOG("CClientEngine::CancelTransaction ,begin");
       
   407     iEngineState = EIdle;
       
   408     delete iUri; 
       
   409     iUri = NULL;
       
   410     
       
   411     // Close() also cancels transaction (Cancel() can also be used but
       
   412     // resources allocated by transaction must be still freed with Close())
       
   413     if( iTransactionOpen )
       
   414         {
       
   415         iTransaction.Close();
       
   416         iTransactionOpen = EFalse;
       
   417 
       
   418         iObserver.ClientEvent( EHttpTxCancelled );
       
   419         }
       
   420 	LOG("CClientEngine::CancelTransaction ,end");
       
   421     }
       
   422 
       
   423 // ----------------------------------------------------------------------------
       
   424 // CClientEngine::MHFRunL()
       
   425 // ----------------------------------------------------------------------------
       
   426 void CClientEngine::MHFRunL( RHTTPTransaction aTransaction, const THTTPEvent& aEvent )
       
   427     {
       
   428     LOG("CClientEngine::MHFRunL ,begin");
       
   429     switch ( aEvent.iStatus )
       
   430         {
       
   431         case THTTPEvent::EGotResponseHeaders:
       
   432             {
       
   433             // HTTP response headers have been received. Use
       
   434             // aTransaction.Response() to get the response. However, it's not
       
   435             // necessary to do anything with the response when this event occurs.
       
   436             iObserver.ClientEvent( EHttpHdrReceived );
       
   437             break;
       
   438             }
       
   439         case THTTPEvent::EGotResponseBodyData:
       
   440             {
       
   441             // Part (or all) of response's body data received. Use
       
   442             // aTransaction.Response().Body()->GetNextDataPart() to get the actual
       
   443             // body data.
       
   444         
       
   445             // Get the body data supplier
       
   446             MHTTPDataSupplier* body = aTransaction.Response().Body();
       
   447             TPtrC8 dataChunk;
       
   448         
       
   449             // GetNextDataPart() returns ETrue, if the received part is the last
       
   450             // one.
       
   451             TBool isLast = body->GetNextDataPart(dataChunk);
       
   452             iObserver.ClientBodyReceived(dataChunk);
       
   453         
       
   454             iObserver.ClientEvent( EHttpBytesReceieved );
       
   455 
       
   456             // NOTE: isLast may not be ETrue even if last data part received.
       
   457             // (e.g. multipart response without content length field)
       
   458             // Use EResponseComplete to reliably determine when body is completely
       
   459             // received.
       
   460             if( isLast )
       
   461                 {
       
   462                 iObserver.ClientEvent( EHttpBodyReceieved );
       
   463                 }
       
   464             // Always remember to release the body data.
       
   465             body->ReleaseData();
       
   466             break;
       
   467             }
       
   468         case THTTPEvent::EResponseComplete:
       
   469             {
       
   470             // Indicates that header & body of response is completely received.
       
   471             // No further action here needed.
       
   472 
       
   473             iObserver.ClientEvent( EHttpTxCompleted );
       
   474             break;
       
   475             }
       
   476         case THTTPEvent::ESucceeded:
       
   477             {
       
   478             // Indicates that transaction succeeded.
       
   479             iObserver.ClientEvent( EHttpTxSuccess );
       
   480             // Transaction can be closed now. It's not needed anymore.
       
   481             aTransaction.Close();
       
   482             iTransactionOpen = EFalse;
       
   483             break;
       
   484             }
       
   485         case THTTPEvent::EFailed:
       
   486             {
       
   487             // Transaction completed with failure.
       
   488             iObserver.ClientEvent( EHttpTxFailed );
       
   489             aTransaction.Close();
       
   490             iTransactionOpen = EFalse;
       
   491             break;
       
   492             }
       
   493         default:
       
   494             // There are more events in THTTPEvent, but they are not usually
       
   495             // needed. However, event status smaller than zero should be handled
       
   496             // correctly since it's error.
       
   497             {
       
   498             if ( aEvent.iStatus < 0 )
       
   499                 {
       
   500                 iObserver.ClientEvent( EHttpConnectionFailure );
       
   501                 // Close the transaction on errors
       
   502                 aTransaction.Close();
       
   503                 iTransactionOpen = EFalse;
       
   504                 }
       
   505                 break;
       
   506             }
       
   507         }
       
   508 	LOG("CClientEngine::MHFRunL ,end");
       
   509     }
       
   510 
       
   511 // ----------------------------------------------------------------------------
       
   512 // CClientEngine::MHFRunError()
       
   513 // ----------------------------------------------------------------------------
       
   514 TInt CClientEngine::MHFRunError( TInt /*aError*/, RHTTPTransaction /*aTransaction*/, const THTTPEvent& /*aEvent*/ )
       
   515     {
       
   516     LOG("CClientEngine::MHFRunError ,begin");
       
   517     // Just notify about the error and return KErrNone.
       
   518     CloseConnection();
       
   519     iObserver.ClientEvent(EHttpMhfRunError);
       
   520     return KErrNone;
       
   521     }
       
   522 
       
   523 // ----------------------------------------------------------------------------
       
   524 // CClientEngine::PreferredCarrierAvailable()
       
   525 // ----------------------------------------------------------------------------
       
   526 void CClientEngine::PreferredCarrierAvailable( TAccessPointInfo /*aOldAPInfo*/,
       
   527                                                TAccessPointInfo /*aNewAPInfo*/,
       
   528                                                TBool /*aIsUpgrade*/,
       
   529                                                TBool aIsSeamless )
       
   530     {
       
   531     LOG("CClientEngine::PreferredCarrierAvailable ,begin");
       
   532     if( !aIsSeamless && iMobility)
       
   533         {
       
   534         iMobility->MigrateToPreferredCarrier();
       
   535         }
       
   536 	LOG("CClientEngine::PreferredCarrierAvailable ,end");
       
   537     }
       
   538 
       
   539 // ----------------------------------------------------------------------------
       
   540 // CClientEngine::NewCarrierActive()
       
   541 // ----------------------------------------------------------------------------
       
   542 void CClientEngine::NewCarrierActive( TAccessPointInfo /*aNewAPInfo*/,
       
   543                                       TBool aIsSeamless )
       
   544     {
       
   545     LOG("CClientEngine::NewCarrierActive ,begin");
       
   546     if( !aIsSeamless && iMobility)
       
   547         {
       
   548         iMobility->NewCarrierAccepted();
       
   549         }
       
   550 	LOG("CClientEngine::NewCarrierActive ,end");
       
   551     }
       
   552 
       
   553 // ----------------------------------------------------------------------------
       
   554 // CClientEngine::Error()
       
   555 // ----------------------------------------------------------------------------
       
   556 void CClientEngine::Error(TInt /*aError*/)
       
   557     {
       
   558     LOG("CClientEngine::Error");
       
   559     }
       
   560 
       
   561 // ----------------------------------------------------------------------------
       
   562 // CClientEngine::DoCancel()
       
   563 // ----------------------------------------------------------------------------
       
   564 void CClientEngine::DoCancel()
       
   565     {
       
   566     LOG("CClientEngine::DoCancel");
       
   567     iConnection.Stop();
       
   568     }
       
   569 
       
   570 // ----------------------------------------------------------------------------
       
   571 // CClientEngine::DoCancel()
       
   572 // ----------------------------------------------------------------------------
       
   573 TInt  CClientEngine::RunError(TInt /*aError*/)
       
   574     {
       
   575     LOG("CClientEngine::RunError");
       
   576     // Just notify about the error and return KErrNone.
       
   577     CloseConnection();
       
   578     iObserver.ClientEvent( EHttpTxFailed );
       
   579     return KErrNone;
       
   580     }
       
   581 // ----------------------------------------------------------------------------
       
   582 // CClientEngine::RunL()
       
   583 // ----------------------------------------------------------------------------
       
   584 void CClientEngine::RunL()
       
   585     {
       
   586     LOG1("CClientEngine::RunL: error is: %d\n", iStatus.Int() );
       
   587     TInt statusCode = iStatus.Int();
       
   588     if ( statusCode == KErrNone )
       
   589         {
       
   590         // Connection done ok
       
   591         iConnectionSetupDone = ETrue;
       
   592         
       
   593         RStringPool strPool = iSession.StringPool();
       
   594 
       
   595         // Remove first session properties just in case.
       
   596         RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
       
   597         
       
   598         // Clear RConnection and Socket Server instances
       
   599         connInfo.RemoveProperty(strPool.StringF(HTTP::EHttpSocketServ,RHTTPSession::GetTable()));
       
   600         connInfo.RemoveProperty(strPool.StringF(HTTP::EHttpSocketConnection,RHTTPSession::GetTable()));
       
   601         
       
   602         // Clear the proxy settings
       
   603         connInfo.RemoveProperty(strPool.StringF(HTTP::EProxyUsage,RHTTPSession::GetTable()));
       
   604         connInfo.RemoveProperty(strPool.StringF(HTTP::EProxyAddress,RHTTPSession::GetTable()));
       
   605         
       
   606         // RConnection and Socket Server
       
   607         connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketServ, 
       
   608                                         RHTTPSession::GetTable()), 
       
   609                                 THTTPHdrVal (iSocketServ.Handle()) );
       
   610         
       
   611         TInt connPtr1 = REINTERPRET_CAST(TInt, &iConnection);
       
   612         connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketConnection, 
       
   613                                 RHTTPSession::GetTable() ), THTTPHdrVal (connPtr1) );    
       
   614 
       
   615         // Register for mobility API
       
   616 		if(iMobility)
       
   617 			{
       
   618 	        delete iMobility;
       
   619 			iMobility = NULL ;
       
   620 			}
       
   621         iMobility = CActiveCommsMobilityApiExt::NewL( iConnection, *this );
       
   622         // Start selected HTTP action
       
   623         switch( iEngineState )
       
   624             {
       
   625             case EIdle:
       
   626                 {
       
   627                 //
       
   628                 CancelTransaction();
       
   629                 break;
       
   630                 }
       
   631             case EGet:
       
   632                {
       
   633                DoHTTPGetL();
       
   634                break;
       
   635                }
       
   636             };
       
   637         }
       
   638     else
       
   639         {
       
   640         //handle error
       
   641         if ( statusCode == KErrPermissionDenied )
       
   642             {
       
   643             iObserver.ClientEvent( EHttpAuthFailed );
       
   644             }
       
   645         else
       
   646             {
       
   647             //Throw some general Transaction falure error!
       
   648             iObserver.ClientEvent( EHttpTxFailed );
       
   649             }
       
   650         CloseConnection();
       
   651         }
       
   652 	LOG("CClientEngine::RunL ,end");
       
   653     }
       
   654 
       
   655 // ----------------------------------------------------------------------------
       
   656 // CClientEngine::SilentConnectionAllowed()
       
   657 // ----------------------------------------------------------------------------
       
   658 TBool CClientEngine::SilentConnectionAllowed()
       
   659     {
       
   660     LOG("CClientEngine::SilentConnectionAllowed ,begin");
       
   661     TBool retVal = EFalse;
       
   662 	TRAPD(err, retVal = IsDataConnectionAskAlwaysL());
       
   663 	if(err == KErrNone)
       
   664 		{
       
   665 		// data connection is always ask... Silent connection is not allowed
       
   666 		retVal = !retVal;
       
   667 		}
       
   668 	LOG1("CClientEngine::SilentConnectionAllowed ,end. Ret - %d", retVal);
       
   669     return retVal;
       
   670     }
       
   671 
       
   672 // End of file
       
   673