hotspotfw/internetconnectivitytestservice/src/ictsengine.cpp
changeset 0 56b72877c1cb
child 2 6e4b6261703d
equal deleted inserted replaced
-1:000000000000 0:56b72877c1cb
       
     1 /*
       
     2 * Copyright (c) 2006 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:   Actual implementation of DLL. 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <apgcli.h>
       
    20 #include <eikenv.h> 
       
    21 #include <apgtask.h>
       
    22 #include <coemain.h> 
       
    23 #include <cmmanagerext.h>
       
    24 #include <cmmanagerdef.h>
       
    25 #include <f32file.h> 
       
    26 
       
    27 #include "ictsengine.h"
       
    28 #include "internetconnectivitycrkeys.h"
       
    29 #include "ictsasyncwait.h"
       
    30 #include "am_debug.h"
       
    31 #include "hotspotclientserver.h"
       
    32 
       
    33 
       
    34 using namespace CMManager;
       
    35 
       
    36 // ======== MEMBER FUNCTIONS ========
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // CIctsEngine::CIctsEngine
       
    40 // C++ default constructor can NOT contain any code, that
       
    41 // might leave.
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CIctsEngine::CIctsEngine( TUint32 aIapId, 
       
    45                           TUint32 aNetworkId,
       
    46                           MIctsObserver& aClient ) :
       
    47 iIapId( aIapId ), iNetworkId( aNetworkId ), iPollingStatus( EFalse ), 
       
    48 iRepository( NULL ), iClient( aClient )
       
    49     {
       
    50     
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CIctsEngine::ConstructL
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 void CIctsEngine::ConstructL()
       
    58     {
       
    59     DEBUG("CIctsEngine::ConstructL");
       
    60     _LIT8(KIp, "http://connectivity-test.ext.nokia.com/");
       
    61     
       
    62     // CenRep uses UTF 16
       
    63     HBufC16* uriBuffer = HBufC16::NewLC( KMaxIpLength );
       
    64     TPtr16 uriPtr = uriBuffer->Des();
       
    65     // For HTTP FW change it to 8bit
       
    66     HBufC8* uriBuffer8 = HBufC8::NewLC( KMaxIpLength );
       
    67     TPtr8 uriPtr8 = uriBuffer8->Des();
       
    68     TRAPD(err, iRepository = CRepository::NewL( 
       
    69                                     KCRUidInternetConnectivitySettings ) );
       
    70     if ( KErrNone == err )
       
    71         {
       
    72         TInt err = iRepository->Get( KIctsIpDestination, uriPtr );
       
    73         uriPtr8.Copy( uriPtr );
       
    74         iIPAddress = uriPtr8;
       
    75         if ( KErrNone != err )
       
    76             {
       
    77             iIPAddress = KIp();
       
    78             }
       
    79         }
       
    80     else
       
    81         {   
       
    82         iIPAddress = KIp();
       
    83         }
       
    84     CleanupStack::PopAndDestroy(uriBuffer8);
       
    85     CleanupStack::PopAndDestroy(uriBuffer);
       
    86     iPollingIntervalTimer = CIctsPollingIntervalTimer::NewL( *this );
       
    87     
       
    88     iPollingTimeTimer = CIctsPollingTimeTimer::NewL( *this );
       
    89     
       
    90     iHttpHandler = CIctsHttpHandler::NewL( *this, KHttpResponseTime );
       
    91     
       
    92     RCmManagerExt cmManager;
       
    93     cmManager.OpenL();
       
    94     CleanupClosePushL( cmManager );
       
    95     
       
    96     iEasyWlanIapId = cmManager.EasyWlanIdL();
       
    97     DEBUG1("CIctsEngine::ConstructL iEasyWlanIapId %d", iEasyWlanIapId );
       
    98     CleanupStack::PopAndDestroy( &cmManager );
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CIctsEngine::NewL
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 CIctsEngine* CIctsEngine::NewL( TUint32 aIapId, 
       
   106                                                 TUint32 aNetworkId,
       
   107                                                 MIctsObserver& aClient
       
   108                                                  )
       
   109     {
       
   110     CIctsEngine* self =  new (ELeave) CIctsEngine( aIapId, 
       
   111                                                                    aNetworkId,
       
   112                                                                    aClient );
       
   113     CleanupStack::PushL( self );
       
   114     self->ConstructL();                                                            
       
   115     CleanupStack::Pop( self );
       
   116     return self;
       
   117     }
       
   118 
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CIctsEngine::~CIctsEngine
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 CIctsEngine::~CIctsEngine()
       
   125     {
       
   126     DEBUG("CIctsEngine::~CIctsEngine()");
       
   127     if ( iRepository )
       
   128         {
       
   129         delete iRepository;
       
   130         }
       
   131     
       
   132     if ( iPollingIntervalTimer )
       
   133         {
       
   134         delete iPollingIntervalTimer;
       
   135         }
       
   136     
       
   137     if ( iPollingTimeTimer )
       
   138         {
       
   139         delete iPollingTimeTimer;
       
   140         }
       
   141     
       
   142     if ( iHttpHandler )
       
   143         {
       
   144         delete iHttpHandler;
       
   145         }
       
   146         
       
   147     iHsServer.Close();
       
   148     DEBUG("CIctsEngine::~CIctsEngine() DONE");
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CIctsEngine::Start
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CIctsEngine::StartL()
       
   156     { 
       
   157     DEBUG("CIctsEngine::StartL()");
       
   158     if ( CheckSettingL() == EIctsRunAutomatically )
       
   159         {
       
   160         TInt result = iHttpHandler->SendHttpRequestL( iIPAddress , iIapId, iNetworkId );
       
   161             
       
   162         // Sending HTTP request did not succeed. RConnection failed.
       
   163         if ( KErrNone != result )
       
   164             {
       
   165             iClient.ConnectivityObserver( EConnectionNotOk, iString );
       
   166             }
       
   167         }
       
   168     else 
       
   169         {
       
   170         iClient.ConnectivityObserver( EConnectionNotOk, iString );
       
   171         }
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // CIctsEngine::CancelStart
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 void CIctsEngine::CancelStartL()
       
   179     { 
       
   180     DEBUG("CIctsEngine::CancelStartL()");
       
   181     iHttpHandler->CancelHttpRequestL(); 
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // CIctsEngine::StartPolling
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 void CIctsEngine::StartPolling( TInt aTime, 
       
   189                                         TInt aInterval )
       
   190     {
       
   191     DEBUG("CIctsEngine::StartPolling()");
       
   192     iPollingStatus = ETrue;
       
   193     iPollingInterval = aInterval;
       
   194     // Do not send right away HTTP request since most likely it will fail. -> hotspot browser case.
       
   195     iPollingIntervalTimer->After( KStartPollingWait );
       
   196     iPollingTimeTimer->After( aTime + KStartPollingWait );
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 // CIctsEngine::StopPolling
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 void CIctsEngine::StopPolling()
       
   204     {
       
   205     DEBUG("CIctsEngine::StopPolling()");
       
   206     iPollingIntervalTimer->Cancel();
       
   207     iPollingTimeTimer->Cancel();
       
   208     iPollingStatus = EFalse;
       
   209     }
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // CIctsEngine::CheckSettingL
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 TInt CIctsEngine::CheckSettingL()
       
   216     {
       
   217     DEBUG("CIctsEngine::CheckSettingL()");
       
   218     // Check connectivity test setting from CenRep
       
   219     TInt ret( EIctsRunAutomatically );
       
   220     iRepository->Get( KIctsTestPermission, ret );
       
   221     
       
   222     return ret;
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // CIctsEngine::PollingIntervalTimeout
       
   227 // ---------------------------------------------------------------------------
       
   228 // 
       
   229 void CIctsEngine::PollingIntervalTimeout()
       
   230     {
       
   231     DEBUG("CIctsEngine::PollingIntervalTimeout()");
       
   232     TRAPD( err, iHttpHandler->SendHttpRequestL( iIPAddress , 
       
   233                                             iIapId, 
       
   234                                             iNetworkId ));
       
   235         
       
   236     if ( KErrNone != err )
       
   237         {
       
   238         DEBUG1("CIctsEngine::PollingIntervalTimeout() err: %d", err);
       
   239         StopPolling();
       
   240         iClient.ConnectivityObserver( EConnectionNotOk, iString );    
       
   241         }
       
   242     iPollingIntervalTimer->After( iPollingInterval );
       
   243     }
       
   244     
       
   245 // ---------------------------------------------------------------------------
       
   246 // CIctsEngine::PollingTimeTimeout
       
   247 // ---------------------------------------------------------------------------
       
   248 // 
       
   249 void CIctsEngine::PollingTimeTimeout()
       
   250     {
       
   251     DEBUG("CIctsEngine::PollingTimeTimeout()");
       
   252     StopPolling();
       
   253     iClient.ConnectivityObserver( ETimeout, iString );
       
   254     }
       
   255 
       
   256 // ---------------------------------------------------------------------------
       
   257 // CIctsEngine::HttpEventL
       
   258 // ---------------------------------------------------------------------------
       
   259 //  
       
   260 void CIctsEngine::HttpEventL( TIctsTestResult aResult, TDesC& aString )
       
   261     {
       
   262     DEBUG("CIctsEngine::HttpEventL()");
       
   263    
       
   264     if( iPollingStatus )
       
   265         {
       
   266         DEBUG("CIctsEngine::HttpEventL() polling");
       
   267         // We are polling. Send only EConnectionOk result to client.
       
   268         // Otherwise continue polling.
       
   269         if ( aResult == EConnectionOk)   
       
   270             {
       
   271             DEBUG("CIctsEngine::HttpEventL() EConnectionOk");
       
   272             StopPolling();
       
   273             iClient.ConnectivityObserver( aResult, aString );
       
   274             }
       
   275     
       
   276         }
       
   277     else
       
   278         {
       
   279         DEBUG("CIctsEngine::HttpEventL() not polling");
       
   280         iClient.ConnectivityObserver( aResult, aString );
       
   281         DEBUG("CIctsEngine::HttpEventL() result sent");
       
   282         }
       
   283     }
       
   284 
       
   285 // End of File