internetradio2.0/networkcontrollersrc/irnetworkcontroller.cpp
changeset 14 896e9dbc5f19
parent 12 608f67c22514
child 15 065198191975
equal deleted inserted replaced
12:608f67c22514 14:896e9dbc5f19
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <centralrepository.h>
       
    20 #include <commsdattypesv1_1.h>
       
    21 #include <commdb.h>
       
    22 #include <commdbconnpref.h>
       
    23 #include <featdiscovery.h>
       
    24 #include <features.hrh>
       
    25 #include <ProfileEngineSDKCRKeys.h>
       
    26 #include <httpstringconstants.h>
       
    27 #include <StringLoader.h>
       
    28 #include <data_caging_path_literals.hrh>
       
    29 #include <extendedconnpref.h>
       
    30 
       
    31 #include "irdebug.h"
       
    32 #include "irfilteredapreader.h"
       
    33 #include "irnetworkcontroller.h"
       
    34 #include "irnetworkobserver.h"
       
    35 #include "irsettings.h"
       
    36 
       
    37 #include "iractivenetworkobserver.h"
       
    38 
       
    39 
       
    40 const TInt KMaxIRUAProfLength = 250; // Max length of the UAProf string
       
    41 const TInt KIRDefaultUAProfBufferSize = 0x80;
       
    42 const TUint KIRESockMessageSlots = 16;
       
    43 const TInt KArraySize = 5;
       
    44 const TInt KWlanStringMaxLength = 9;
       
    45 const TInt KTwo = 2;
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 //  define in WebUtilsSDKCRKeys.h
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 const TUid KCRUidWebUtils = {0x101F8731};//Web APIs removal and Internet Radio build break
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // define in WebUtilsInternalCRKeys.h
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 // Compatability fragment of useragent string
       
    58 const TUint32 KWebUtilsUsrAg2 =	0x00000001;
       
    59 
       
    60 // PlatformVersion fragment of useragent string
       
    61 const TUint32 KWebUtilsUsrAg3 =	0x00000002;
       
    62 
       
    63 // MidPVersion fragment of useragent string
       
    64 const TUint32 KWebUtilsUsrAg4 =	0x00000003;
       
    65 
       
    66 // CLDConfiguration fragment of useragent string
       
    67 const TUint32 KWebUtilsUsrAg5 =	0x00000004;
       
    68 
       
    69 // Url to useragent profile
       
    70 const TUint32 KWebUtilsUaProf =	0x00000008;
       
    71 
       
    72 
       
    73 // To Format the UAProf string
       
    74 _LIT(KIRUAProfSpace," ");
       
    75 
       
    76 // WLan (generic) name string
       
    77 _LIT(KIRWLanName,"Easy WLAN");
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 //  Creates an Instance of CIRNetworkController
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 EXPORT_C CIRNetworkController* CIRNetworkController::OpenL(MIRNetworkController* aObserver)
       
    84 {
       
    85     IRLOG_DEBUG( "CIRNetworkController::OpenL - Entering" );
       
    86     CIRNetworkController* networkController = reinterpret_cast<CIRNetworkController*>(Dll::Tls());
       
    87 
       
    88     if (!networkController)
       
    89     {
       
    90         networkController = new (ELeave) CIRNetworkController;
       
    91         CleanupClosePushL(*networkController);
       
    92         networkController->iSingletonInstances = 1;
       
    93         networkController->ConstructL(aObserver);
       
    94         User::LeaveIfError(Dll::SetTls(networkController));
       
    95         networkController->iSingletonInstances = 0;
       
    96         CleanupStack::Pop(networkController);
       
    97 	}
       
    98     networkController->iSingletonInstances++;
       
    99     
       
   100     if (NULL != aObserver)
       
   101     {
       
   102         networkController->iObserver = aObserver;
       
   103         networkController->iIRNetworkObserver->SetObserver(aObserver);
       
   104     }
       
   105     
       
   106     IRLOG_DEBUG( "CIRNetworkController::OpenL - Exiting." );
       
   107     return networkController;
       
   108 }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // Conditionally destroys the IRNetworkController object
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 EXPORT_C void CIRNetworkController::Close()
       
   115 {
       
   116     IRLOG_DEBUG2( "CIRNetworkController::Close - singleton instances=%d", iSingletonInstances );
       
   117     iSingletonInstances--;
       
   118     
       
   119     if( iSingletonInstances == 0 )
       
   120     {
       
   121         delete this;
       
   122     }
       
   123     IRLOG_DEBUG( "CIRNetworkController::Close - Exiting." );
       
   124 }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 //  CIRNetworkController::GetIRConnection
       
   128 //  Returns the instance of RConnection
       
   129 //  The same RConnection object is used across the entire iRAPP components to
       
   130 //  provide central arbiter and monitoring of Network Connection
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 EXPORT_C RConnection& CIRNetworkController::GetIRConnection()
       
   134 {
       
   135     IRLOG_DEBUG( "CIRNetworkController::GetIRConnection - Entering" );
       
   136     // If the RConnection is open return the reference
       
   137     switch(iNetworkConnectionState)
       
   138     {
       
   139     case EIRNetworkConnectionActive:
       
   140     {
       
   141         // Connection is active and ready to use return the reference
       
   142         return (*iIRNetworkConnection);
       
   143     }
       
   144 	
       
   145     case EIRNetworkConnectionInActive:
       
   146     {
       
   147         // Connection is not active and application cannot continue hence panic
       
   148         _LIT(KComponentName,"NetworkController");
       
   149         User::Panic(KComponentName,KErrCouldNotConnect);
       
   150     }
       
   151     break;
       
   152 	
       
   153     default:
       
   154     {
       
   155         // no implementation
       
   156     }
       
   157     break;
       
   158     }
       
   159 	
       
   160     // Inserted to remove the compiler warning
       
   161     IRLOG_DEBUG( "CIRNetworkController::GetIRConnection - Exiting." );
       
   162     return (*iIRNetworkConnection);
       
   163 }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 //  CIRNetworkController::GetIRSocketServer
       
   167 //  Returns the instance of RSocketServ
       
   168 //  The same RSocketServ object is used across the entire iRAPP components to
       
   169 //  provide central arbiter and monitoring of Network Connection
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 EXPORT_C RSocketServ& CIRNetworkController::GetIRSocketServer()
       
   173 {
       
   174     IRLOG_DEBUG( "CIRNetworkController::GetIRSocketServer - Entering" );
       
   175     switch(iSocketServerConnectionState)
       
   176     {
       
   177     case EIRSocketServerActive:
       
   178     {
       
   179         // Connection to Socket Server is active hence return the reference
       
   180         return iIRSocketServer;
       
   181     }
       
   182 	
       
   183     case EIRSocketServerInActive:
       
   184     {
       
   185         // Connection to Socket Server not open hence open and return the reference
       
   186         // Connection is not active and application cannot continue hence panic
       
   187         _LIT(KComponentName,"NetworkController");
       
   188         User::Panic(KComponentName,KErrCouldNotConnect);
       
   189     }
       
   190     break;
       
   191 	
       
   192     default:
       
   193     {
       
   194         // no implemenatation
       
   195     }
       
   196     break;
       
   197 	}
       
   198     
       
   199     // Inserted to remove the compiler warning
       
   200     IRLOG_DEBUG( "CIRNetworkController::GetIRSocketServer - Exiting." );
       
   201     return iIRSocketServer;
       
   202 }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 //  CIRNetworkController::GetWapProfString
       
   206 //  Returns a HBufC pointer to the x-wap-profile string
       
   207 //  Transfers the ownership of the returned HBufC8 object
       
   208 //  The caller must takecare of deleting the returned object
       
   209 // ---------------------------------------------------------------------------
       
   210 //
       
   211 EXPORT_C HBufC8* CIRNetworkController::GetWapProfString()
       
   212 {
       
   213     IRLOG_DEBUG( "CIRNetworkController::GetWapProfString" );
       
   214     return iIRWapProf;
       
   215 }
       
   216 
       
   217 // ---------------------------------------------------------------------------
       
   218 //  CIRNetworkController::GetUAProfString
       
   219 //  Returns a HBufC pointer to the UAProf string
       
   220 //  Transfers the ownership of the returned HBufC8 object
       
   221 //  The caller must takecare of deleting the returned object
       
   222 // ---------------------------------------------------------------------------
       
   223 //
       
   224 EXPORT_C HBufC8* CIRNetworkController::GetUAProfString()
       
   225 {
       
   226     IRLOG_DEBUG( "CIRNetworkController::GetUAProfString" );
       
   227     return iIRUAProf;
       
   228 }
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 //  CIRNetworkController::GetNetworkStatus
       
   232 //  Returns the variable which indicates if connection is active or not
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 EXPORT_C TBool CIRNetworkController::GetNetworkStatus() const
       
   236 {
       
   237     IRLOG_DEBUG( "CIRNetworkController::GetNetworkStatus" );
       
   238     return iIsConnectedToNetwork;
       
   239 }
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 // CIRNetworkController::GetIAPId
       
   243 // Gets the IAP Id of the chosen IAP
       
   244 // ---------------------------------------------------------------------------
       
   245 //
       
   246 EXPORT_C TInt CIRNetworkController::GetIAPId(TUint32& aIapId) const
       
   247 {
       
   248     IRLOG_DEBUG( "CIRNetworkController::GetIAPId - Entering" );
       
   249     TInt retVal(KErrNone);
       
   250     if(iIsConnectedToNetwork)
       
   251     {
       
   252         if ( iIRNetworkObserver->iIsIAPIdAvailable )
       
   253         {
       
   254             aIapId = iIRNetworkObserver->iIAPId;
       
   255         }
       
   256     }
       
   257     else
       
   258     {
       
   259         retVal = KErrNotFound;
       
   260     }
       
   261     IRLOG_DEBUG( "CIRNetworkController::GetIAPId - Exiting." );
       
   262     return retVal;
       
   263 }
       
   264 
       
   265 // ---------------------------------------------------------------------------
       
   266 //  CIRNetworkController::ChooseAccessPointL
       
   267 //  Configures the Access Point which is used by all the components for network
       
   268 //  connectivity
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 
       
   272 
       
   273 EXPORT_C void CIRNetworkController::ChooseAccessPointL(TBool aDefaultConnection)
       
   274 {
       
   275     IRLOG_DEBUG( "CIRNetworkController::ChooseAccessPointL - Entering" );
       
   276     if (iHandingOver)
       
   277     {
       
   278         if (iObserver)
       
   279         {
       
   280             iObserver->IRNetworkEventL(ENetworkConnectionConnecting);
       
   281         }
       
   282         IRLOG_DEBUG("CIRNetworkController::ChooseAccessPointL, ALR is handing over, Exiting");
       
   283         return;
       
   284     }
       
   285     
       
   286     iIRNetworkObserver->SetNetworkMonitoring(ETrue);
       
   287     iDefaultConnection = aDefaultConnection;
       
   288 	
       
   289     // Always validate the Access Points status
       
   290     if ( ValidateAccessPointsL() )
       
   291     { 
       
   292         if(NULL != iMobility)
       
   293         {
       
   294          iMobility->Cancel();
       
   295          delete iMobility;
       
   296          iMobility = NULL;
       
   297         }
       
   298 
       
   299         // Connect to the Symbian Socket Server
       
   300         iIRNetworkConnection->Close();
       
   301         iIRSocketServer.Close();
       
   302         TInt ReturnErrorCode = iIRSocketServer.Connect( KIRESockMessageSlots );
       
   303         
       
   304         if(ReturnErrorCode != KErrNone )
       
   305         {
       
   306             // Error in opening the connection to SocketServer
       
   307             iSocketServerConnectionState = EIRSocketServerInActive;
       
   308             IRLOG_DEBUG( "CIRNetworkController::ChooseAccessPointL - Exiting (1)." );
       
   309             return ;
       
   310         }
       
   311 		
       
   312         // Connection to RSocketServ is sucessful
       
   313         iSocketServerConnectionState = EIRSocketServerActive;
       
   314         
       
   315         // Open the RConnection over the iIRSocketServer
       
   316         ReturnErrorCode = iIRNetworkConnection->Open(iIRSocketServer);
       
   317 
       
   318         if( ReturnErrorCode != KErrNone )
       
   319         {
       
   320             // Error in opening the connection
       
   321             iNetworkConnectionState = EIRNetworkConnectionInActive;
       
   322             IRLOG_DEBUG( "CIRNetworkController::ChooseAccessPointL - Exiting (2)." );
       
   323             return ;
       
   324         }
       
   325         
       
   326         //Added for ALR/SNAP
       
   327         if(!IsActive())
       
   328         {
       
   329             if (iDefaultConnection)
       
   330             {
       
   331                 TConnPrefList prefList;
       
   332                 TExtendedConnPref extPrefs;
       
   333 
       
   334                 extPrefs.SetSnapPurpose(CMManager::ESnapPurposeInternet);
       
   335                 extPrefs.SetNoteBehaviour(TExtendedConnPref::ENoteBehaviourConnDisableNotes);
       
   336                 prefList.AppendL(&extPrefs);
       
   337                 iIRNetworkConnection->Start(prefList, iStatus);
       
   338             }
       
   339             else
       
   340             {
       
   341                 TCommDbConnPref connPref;
       
   342                 connPref.SetDialogPreference(ECommDbDialogPrefPrompt);
       
   343                 iIRNetworkConnection->Start(connPref, iStatus) ;
       
   344             }
       
   345             
       
   346             // Set the NetworkController state
       
   347             iNetworkControllerState = EConnectingToNetwork;
       
   348 
       
   349             SetActive();
       
   350             iIsConnectRequestIssued = ETrue;
       
   351             if (iObserver)
       
   352             {
       
   353                 IRLOG_DEBUG( "CIRNetworkController::ChooseAccessPointL - notify ENetworkConnectionConnecting" );
       
   354                 iObserver->IRNetworkEventL(ENetworkConnectionConnecting);
       
   355             }
       
   356         }
       
   357             
       
   358         IRLOG_DEBUG( "CIRNetworkController::ChooseAccessPointL - Exiting (3)." );
       
   359         return;
       
   360     }
       
   361     else
       
   362     {
       
   363         iObserver->IRNetworkEventL(EAccessPointSelectionCancelled);
       
   364     }
       
   365     IRLOG_DEBUG( "CIRNetworkController::ChooseAccessPointL - Exiting (4)." );
       
   366 }
       
   367 
       
   368 EXPORT_C void CIRNetworkController::CancelConnecting()
       
   369 {
       
   370     IRLOG_DEBUG("CIRNetworkController::CancelConnecting(), Entering");
       
   371     iIRNetworkObserver->Cancel();
       
   372     Cancel();
       
   373     ResetConnectionStatus();
       
   374     IRLOG_DEBUG("CIRNetworkController::CancelConnecting(), Exiting");
       
   375 }
       
   376 
       
   377 // ---------------------------------------------------------------------------
       
   378 //  CIRNetworkController::IsOfflineMode
       
   379 //  This api is used to determine if the phone is in offline mode
       
   380 // ---------------------------------------------------------------------------
       
   381 //
       
   382 EXPORT_C TBool CIRNetworkController::IsOfflineMode()
       
   383 {
       
   384     IRLOG_DEBUG( "CIRNetworkController::IsOfflineMode" );
       
   385     // System defined value for offline mode is 5
       
   386     const TInt KOfflineMode = 5;
       
   387 	TInt returnValue = 0;
       
   388     returnValue = DetermineCurrentProfile();
       
   389     if (returnValue == KOfflineMode)
       
   390     {
       
   391         IRLOG_DEBUG( "CIRNetworkController::IsOfflineMode - Exiting (1)." );
       
   392         return ETrue;
       
   393     }
       
   394     IRLOG_DEBUG( "CIRNetworkController::IsOfflineMode - Exiting (2)." );
       
   395     return EFalse;
       
   396 }
       
   397 
       
   398 // ---------------------------------------------------------------------------
       
   399 //  CIRNetworkController::IsWlanSupported
       
   400 //  This api is used to determine if the phone supports WLan usage
       
   401 // ---------------------------------------------------------------------------
       
   402 //
       
   403 EXPORT_C TBool CIRNetworkController::IsWlanSupported() const
       
   404 {
       
   405     IRLOG_DEBUG( "CIRNetworkController::IsWlanSupported" );
       
   406     return iIsWlanSupported;
       
   407 }
       
   408 
       
   409 // ---------------------------------------------------------------------------
       
   410 // CIRNetworkController::ResetConnectionStatus
       
   411 //  Reset the connection status to Disconnected statet
       
   412 // ---------------------------------------------------------------------------
       
   413 //
       
   414 EXPORT_C void CIRNetworkController::ResetConnectionStatus()
       
   415 {
       
   416     IRLOG_DEBUG( "CIRNetworkController::ResetConnectionStatus - Entering" );
       
   417     iIsConnectRequestIssued = EFalse;
       
   418     iNetworkConnectionState = EIRNetworkConnectionInActive;
       
   419     iIsConnectedToNetwork = EFalse;
       
   420     iConnectionPresent = EFalse;
       
   421     IRLOG_DEBUG( "CIRNetworkController::ResetConnectionStatus - Exiting." );
       
   422 }
       
   423 
       
   424 // ---------------------------------------------------------------------------
       
   425 // CIRNetworkController::IdentifyConnectionType
       
   426 // Used to determine the type of connection
       
   427 // ---------------------------------------------------------------------------
       
   428 //
       
   429 EXPORT_C TIRConnectionType CIRNetworkController::IdentifyConnectionType() const
       
   430 {
       
   431     IRLOG_DEBUG( "CIRNetworkController::IdentifyConnectionType" );
       
   432     IRRDEBUG2("CIRNetworkController::IdentifyConnectionType - Entering iConnectionType = %d", iIRNetworkObserver->iIRConnectionType);
       
   433 
       
   434     return iIRNetworkObserver->iIRConnectionType;
       
   435 }
       
   436 
       
   437 // ---------------------------------------------------------------------------
       
   438 // CIRNetworkController::DetermineCurrentProfile
       
   439 // Used to determine the current profile
       
   440 // ---------------------------------------------------------------------------
       
   441 //
       
   442 TInt CIRNetworkController::DetermineCurrentProfile() const
       
   443 {
       
   444     IRLOG_DEBUG( "CIRNetworkController::DetermineCurrentProfile" );
       
   445     TInt value = KErrNone;
       
   446     TRAPD(err,
       
   447             CRepository* cRepositoryHandle = CRepository::NewLC(KCRUidProfileEngine );
       
   448             cRepositoryHandle->Get(KProEngActiveProfile,value);
       
   449             CleanupStack::PopAndDestroy(cRepositoryHandle); )
       
   450     if (err != KErrNone)
       
   451     {
       
   452         value = err;
       
   453     }
       
   454 
       
   455     IRLOG_DEBUG( "CIRNetworkController::DetermineCurrentProfile - Exiting." );
       
   456     return value;
       
   457 }
       
   458 
       
   459 // ---------------------------------------------------------------------------
       
   460 // CIRNetworkController::CheckFeatureL
       
   461 // Pops up the access point list.
       
   462 // ---------------------------------------------------------------------------
       
   463 //
       
   464 TBool CIRNetworkController::CheckFeatureL(TInt aFeatureId) const
       
   465 {
       
   466     IRLOG_DEBUG( "CIRNetworkController::CheckFeatureL" );
       
   467     return CFeatureDiscovery::IsFeatureSupportedL(aFeatureId);
       
   468 }
       
   469 
       
   470 // ---------------------------------------------------------------------------
       
   471 // CIRNetworkController::CIRNetworkController
       
   472 // Default C++ Constructor
       
   473 // ---------------------------------------------------------------------------
       
   474 //
       
   475 CIRNetworkController::CIRNetworkController(): CActive(
       
   476 	CActive::EPriorityHigh )
       
   477 {
       
   478     // Add the AO to the ActiveScheduler
       
   479     IRLOG_DEBUG( "CIRNetworkController::CIRNetworkController- Entering" );
       
   480     CActiveScheduler::Add(this);
       
   481     // Initialize the states
       
   482     iNetworkConnectionState = EIRNetworkConnectionInActive;
       
   483     iSocketServerConnectionState = EIRSocketServerInActive;
       
   484     iNetworkControllerState = EInActive;
       
   485 
       
   486     IRLOG_DEBUG( "CIRNetworkController::CIRNetworkController - Exiting." );
       
   487 }
       
   488 
       
   489 // ---------------------------------------------------------------------------
       
   490 //  CIRNetworkController::~CIRNetworkController
       
   491 //  Default C++ Destructor
       
   492 // ---------------------------------------------------------------------------
       
   493 //
       
   494 CIRNetworkController::~CIRNetworkController()
       
   495 {
       
   496     IRLOG_DEBUG( "CIRNetworkController::~CIRNetworkController- Entering" );
       
   497     _LIT(KErrorMsg,"Method Close not called");
       
   498     __ASSERT_ALWAYS(iSingletonInstances == 0, User::Panic(KErrorMsg, KErrCorrupt));
       
   499 
       
   500     if(NULL != iMobility)
       
   501     {
       
   502      iMobility->Cancel();
       
   503      delete iMobility;
       
   504      iMobility = NULL;
       
   505     }
       
   506 
       
   507     if (IsActive())
       
   508     {
       
   509         Cancel();
       
   510     }
       
   511     if (iIRNetworkConnection)
       
   512     {
       
   513         iIRNetworkConnection->Close();
       
   514         delete iIRNetworkConnection;
       
   515     }
       
   516 
       
   517     // Set all the state variables to indicate network connection is closed
       
   518     delete iIRUAProf;
       
   519     delete iIRWapProf;
       
   520     if (iIRSettings)
       
   521     {
       
   522         iIRSettings->Close();
       
   523         iIRSettings = NULL;
       
   524     }
       
   525     delete iIRNetworkObserver;
       
   526     iIRSocketServer.Close();
       
   527 
       
   528     if (iIapList)
       
   529     {
       
   530         iIapList->Reset();
       
   531         delete iIapList;
       
   532         iIapList = NULL;
       
   533     }
       
   534 
       
   535     if (iDataTransferTracker)
       
   536     {
       
   537         delete iDataTransferTracker;
       
   538         iDataTransferTracker = NULL;
       
   539     }
       
   540     if (iLogoDataTransferTracker)
       
   541     {
       
   542         delete iLogoDataTransferTracker;
       
   543         iLogoDataTransferTracker = NULL;
       
   544     }
       
   545     iObserver = NULL;
       
   546 
       
   547     iActiveNetworkObserverArray.Close();
       
   548 
       
   549     Dll::FreeTls();
       
   550     IRLOG_DEBUG( "CIRNetworkController::~CIRNetworkController - Exiting." );
       
   551 }
       
   552 
       
   553 // ---------------------------------------------------------------------------
       
   554 //  CIRNetworkController::ConstructL
       
   555 //  Second Phase construction.
       
   556 //	aObserver pointer to the observer class if an observer is needed
       
   557 // ---------------------------------------------------------------------------
       
   558 //
       
   559 void CIRNetworkController::ConstructL( MIRNetworkController* aObserver )
       
   560 {
       
   561     IRLOG_DEBUG( "CIRNetworkController::ConstructL- Entering" );
       
   562     iObserver = aObserver;
       
   563     iIRNetworkObserver = CIRNetworkObserver::NewL(this);
       
   564     iIRNetworkObserver->SetObserver(iObserver);
       
   565 
       
   566     // Create instance of DataTransferTracker (Byte Counter Impl)
       
   567     iDataTransferTracker = CIRDataTransferTracker::NewL();
       
   568     iLogoDataTransferTracker = CIRDataTransferTracker::NewL();
       
   569 
       
   570     iIRNetworkConnection = new (ELeave) RConnection;
       
   571 
       
   572     iIRSettings = CIRSettings::OpenL();
       
   573 
       
   574     BuildUAProfStringL();
       
   575     iIapList = new (ELeave) CDesCArrayFlat(KArraySize);
       
   576 
       
   577     QueryCommsForIAPL();
       
   578 
       
   579     IRLOG_DEBUG( "CIRNetworkController::ConstructL - Exiting." );
       
   580 }
       
   581 
       
   582 // ---------------------------------------------------------------------------
       
   583 //  CIRNetworkController::QueryCommsForIAPL
       
   584 //  Determines the available access points using CommsDat Api
       
   585 //  voilates PCLint Error 40 --Undeclared identifier 'KFeatureIdProtocolWlan'
       
   586 //  as defined in featureinfo.h
       
   587 // ---------------------------------------------------------------------------
       
   588 //
       
   589 void CIRNetworkController::QueryCommsForIAPL()
       
   590 {
       
   591     IRLOG_DEBUG( "CIRNetworkController::QueryCommsForIAPL- Entering" );
       
   592 
       
   593     // Reset all the comms info
       
   594     iIapList->Reset();
       
   595     
       
   596 #ifndef __WINS__
       
   597     CIRFilteredApReader* filteredReader = CIRFilteredApReader::
       
   598     NewLC( CIRFilteredApReader::KIRFilterWAPOnly |
       
   599             CIRFilteredApReader::KIRFilterWAPMandatory |
       
   600             CIRFilteredApReader::KIRFilterEasyWLAN );
       
   601 
       
   602     CCDIAPRecord* iapRecord = filteredReader->FirstRecordL();
       
   603 
       
   604     while ( iapRecord )
       
   605     {
       
   606         CleanupStack::PushL( iapRecord );
       
   607 
       
   608         iIapList->AppendL( iapRecord->iRecordName.GetL() );
       
   609 
       
   610         CleanupStack::PopAndDestroy( iapRecord );
       
   611         iapRecord = filteredReader->NextRecordL();
       
   612     }
       
   613     CleanupStack::PopAndDestroy( filteredReader );
       
   614 #else
       
   615     CMDBSession* dbSession = CMDBSession::NewL(CMDBSession::LatestVersion());
       
   616     CleanupStack::PushL(dbSession);
       
   617 
       
   618     CMDBRecordSet<CCDIAPRecord>* iapSet = new (ELeave) CMDBRecordSet<
       
   619             CCDIAPRecord> (KCDTIdIAPRecord);
       
   620     CleanupStack::PushL(iapSet);
       
   621 
       
   622     TRAP_IGNORE(iapSet->LoadL(*dbSession));
       
   623     
       
   624     for (TInt i = 0; i < iapSet->iRecords.Count(); i++)
       
   625     {
       
   626         CCDIAPRecord* iapRecord =
       
   627                 static_cast<CCDIAPRecord*> (iapSet->iRecords[i]);
       
   628         iIapList->AppendL(iapRecord->iRecordName.GetL());
       
   629     }
       
   630     CleanupStack::PopAndDestroy(2, dbSession);
       
   631 
       
   632 #endif
       
   633     
       
   634     // If WLan is supported on the device then add the WLan option
       
   635     // to the IAP List
       
   636 #ifndef __WINS__
       
   637     iIsWlanSupported = CheckFeatureL(KFeatureIdProtocolWlan);
       
   638     if( iIsWlanSupported )
       
   639     {
       
   640         TBuf<KWlanStringMaxLength> wlanString;
       
   641         wlanString.Copy(KIRWLanName);
       
   642         iIapList->AppendL(wlanString);
       
   643     }
       
   644 #endif
       
   645 
       
   646     iIapList->Compress();
       
   647 
       
   648     IRLOG_DEBUG( "CIRNetworkController::QueryCommsForIAPL - Exiting." );
       
   649 }
       
   650 
       
   651 
       
   652 // ---------------------------------------------------------------------------
       
   653 // CIRNetworkController::BuildUAProfStringL
       
   654 // Queries the system and extracts the UAProf information
       
   655 //  Used by IRDataProvider and IRStreamSource
       
   656 // ---------------------------------------------------------------------------
       
   657 //
       
   658 void CIRNetworkController::BuildUAProfStringL()
       
   659 {
       
   660     IRLOG_DEBUG( "CIRNetworkController::BuildUAProfStringL- Entering" );
       
   661     // Create space on heap for the UAProf String
       
   662     iIRUAProf = HBufC8::NewL(KMaxIRUAProfLength);
       
   663     iIRWapProf = HBufC8::NewL(KMaxIRUAProfLength);
       
   664     HBufC* cenRepPtr;
       
   665     TPtr8 irUAProf = iIRUAProf->Des();
       
   666     TPtr8 irWapProf = iIRWapProf->Des();
       
   667     irUAProf.Append(iIRSettings->GetIrappVersionL());
       
   668 
       
   669     cenRepPtr = NULL;
       
   670     irUAProf.Append(KIRUAProfSpace);
       
   671     // extract UAProf sub-string from cenrep
       
   672     cenRepPtr = CentralRepositoryStringValueL(KCRUidWebUtils, KWebUtilsUsrAg3);
       
   673     // append it to form the UAProf
       
   674     irUAProf.Append(cenRepPtr->Des());
       
   675     delete cenRepPtr;
       
   676     cenRepPtr = NULL;
       
   677 
       
   678     irUAProf.Append(KIRUAProfSpace);
       
   679     // extract UAProf sub-string from cenrep
       
   680     cenRepPtr = CentralRepositoryStringValueL(KCRUidWebUtils, KWebUtilsUsrAg2);
       
   681     // append it to form the UAProf
       
   682     irUAProf.Append(cenRepPtr->Des());
       
   683     delete cenRepPtr;
       
   684     cenRepPtr = NULL;
       
   685 
       
   686     irUAProf.Append(KIRUAProfSpace);
       
   687     // extract UAProf sub-string from cenrep
       
   688     cenRepPtr = CentralRepositoryStringValueL(KCRUidWebUtils, KWebUtilsUsrAg4);
       
   689     // append it to form the UAProf
       
   690     irUAProf.Append(cenRepPtr->Des());
       
   691     delete cenRepPtr;
       
   692     cenRepPtr = NULL;
       
   693 
       
   694     irUAProf.Append(KIRUAProfSpace);
       
   695     // extract UAProf sub-string from cenrep
       
   696     cenRepPtr = CentralRepositoryStringValueL(KCRUidWebUtils, KWebUtilsUsrAg5);
       
   697     // append it to form the UAProf
       
   698     irUAProf.Append(cenRepPtr->Des());
       
   699     delete cenRepPtr;
       
   700     cenRepPtr = NULL;
       
   701     // trim out the quotes
       
   702     irUAProf.Delete(irUAProf.Length() - 1, 1);
       
   703     // extract x-wap-profile string from cenrep
       
   704     cenRepPtr = CentralRepositoryStringValueL(KCRUidWebUtils, KWebUtilsUaProf);
       
   705     // append it to form the UAProf
       
   706     irWapProf.Copy(cenRepPtr->Des());
       
   707     delete cenRepPtr;
       
   708     cenRepPtr = NULL;
       
   709 
       
   710     IRLOG_DEBUG( "CIRNetworkController::BuildUAProfStringL - Exiting." );
       
   711 }
       
   712 
       
   713 // ---------------------------------------------------------------------------
       
   714 // CIRNetworkController::CentralRepositoryStringValueL
       
   715 // Retrievs the string from Central Repository for the specified key and cen rep uid
       
   716 // Transfers the ownership of the returned HBufC object
       
   717 // The caller must takecare of deleting the returned object*
       
   718 // ---------------------------------------------------------------------------
       
   719 //
       
   720 HBufC* CIRNetworkController::CentralRepositoryStringValueL(
       
   721 	const TUid& aRepositoryUid, TUint32 aKey ) const
       
   722 {
       
   723     IRLOG_DEBUG( "CIRNetworkController::CentralRepositoryStringValueL- Entering" );
       
   724     CRepository* pRepository = CRepository::NewL(aRepositoryUid);
       
   725     CleanupStack::PushL(pRepository);
       
   726 
       
   727     TInt length = KIRDefaultUAProfBufferSize;
       
   728     HBufC* valueString = HBufC::NewLC(length);
       
   729     TInt error(KErrTooBig);
       
   730     do
       
   731     {
       
   732         TPtr ptr = valueString->Des();
       
   733         error = pRepository->Get(aKey, ptr);
       
   734         if (error == KErrTooBig)
       
   735         {
       
   736             CleanupStack::PopAndDestroy(valueString);
       
   737             length = KTwo * length;
       
   738             valueString = HBufC::NewLC(length);
       
   739         }
       
   740     } while (error == KErrTooBig);
       
   741 
       
   742     if (error)
       
   743     {
       
   744         TPtr ptr = valueString->Des();
       
   745         ptr.Copy(KNullDesC());
       
   746     }
       
   747 
       
   748     CleanupStack::Pop(valueString);
       
   749     CleanupStack::PopAndDestroy(pRepository);
       
   750     IRLOG_DEBUG( "CIRNetworkController::CentralRepositoryStringValueL - Exiting." );
       
   751     return valueString;
       
   752 }
       
   753 
       
   754 // ---------------------------------------------------------------------------
       
   755 //  CIRNetworkController::ValidateAccessPointsL(
       
   756 //  Validates the access point availablity etc.
       
   757 //  voilates PCLint Error 40 --Undeclared identifier 'KFeatureIdProtocolWlan'
       
   758 //  as defined in featureinfo.h
       
   759 // ---------------------------------------------------------------------------
       
   760 //
       
   761 TBool CIRNetworkController::ValidateAccessPointsL()
       
   762 {
       
   763     IRLOG_DEBUG( "CIRNetworkController::ValidateAccessPointsL- Entering" );
       
   764     TBool status = ETrue;
       
   765 #ifndef __WINS__
       
   766     // Check if the phone is in offline mode
       
   767     // If yes, do not allow GPRS access
       
   768     // If phone is in offline mode and device does not support
       
   769     // WIFI then exit the application
       
   770     // Do not make this check in Wins
       
   771     //violates PC Lint error : Error 40: Undeclared identifier KFeatureIdProtocolWlan
       
   772     if( IsOfflineMode() && !(CheckFeatureL(KFeatureIdProtocolWlan)) )
       
   773     {
       
   774         // The phone is in offline mode and WLan is not available
       
   775         iObserver->IRNetworkEventL(EDisplayOfflineMode);
       
   776         status = EFalse;
       
   777     }
       
   778     // If phone is not in offline mode and no access points are defined
       
   779     // check if device has WIFI support then try to launch WIFI
       
   780     // selection if there is no support then display a message
       
   781     if( !IsOfflineMode() && iIapList->MdcaCount() == 0 )
       
   782     {
       
   783         // Check if there is WIFI support
       
   784         //violates PC Lint error : Error 40: Undeclared identifier KFeatureIdProtocolWlan
       
   785         if(!CheckFeatureL(KFeatureIdProtocolWlan))
       
   786         {
       
   787             iObserver->IRNetworkEventL(EDisplayNoAccessPointsDefined);
       
   788             status = EFalse;
       
   789         }
       
   790     }
       
   791 #endif
       
   792     IRLOG_DEBUG( "CIRNetworkController::ValidateAccessPointsL - Exiting." );
       
   793     return status;
       
   794 }
       
   795 
       
   796 
       
   797 // Derived from CActive
       
   798 
       
   799 // ---------------------------------------------------------------------------
       
   800 // CIRNetworkController::RunL
       
   801 // The function is called by the active scheduler when a request completion event occurs,
       
   802 // ---------------------------------------------------------------------------
       
   803 //
       
   804 
       
   805 void CIRNetworkController::RunL()
       
   806 {
       
   807     IRLOG_INFO2( "CIRNetworkController::RunL - iStatus=%d", iStatus.Int() );
       
   808     iHandingOver = EFalse;
       
   809 
       
   810     TInt statusCode = iStatus.Int();
       
   811 
       
   812     if (iStatus == KErrNone)
       
   813     {
       
   814         HandleRunLSuccessL();
       
   815     }
       
   816     else
       
   817     {
       
   818         HandleRunLErrorL(statusCode);
       
   819     }
       
   820     IRLOG_DEBUG( "CIRNetworkController::RunL - Exiting." );
       
   821 }
       
   822 
       
   823 // ---------------------------------------------------------------------------
       
   824 //  CIRNetworkController::DoCancel()
       
   825 //  Cancels the pending requests on the CIRNetworkController Active object
       
   826 // ---------------------------------------------------------------------------
       
   827 //
       
   828 void CIRNetworkController::DoCancel()
       
   829 {
       
   830     IRLOG_DEBUG( "CIRNetworkController::DoCancel - Entering" );
       
   831 
       
   832     if(NULL != iMobility)
       
   833     {
       
   834      iMobility->Cancel();
       
   835      delete iMobility;
       
   836      iMobility = NULL;
       
   837     }
       
   838 
       
   839     iIRNetworkConnection->Stop();
       
   840     iIRNetworkConnection->Close();
       
   841     iIRSocketServer.Close();
       
   842     IRLOG_DEBUG( "CIRNetworkController::DoCancel - Exiting." );
       
   843 }
       
   844 
       
   845 // ---------------------------------------------------------
       
   846 // CIRNetworkController::InitializeHttpSession
       
   847 // ---------------------------------------------------------
       
   848 EXPORT_C void CIRNetworkController::InitializeHttpSessionL(const RHTTPSession& aHTTPSession, 
       
   849 											MIRDataTransferTracker::TIRTransferCategory aCategory)
       
   850 {
       
   851     IRLOG_DEBUG("CVRConnection::InitializeHttpSessionL - enter");
       
   852 
       
   853     iDataTransferTracker->BindL(aHTTPSession, aCategory);
       
   854 
       
   855     RStringF sockserv = aHTTPSession.StringPool().StringF(
       
   856             HTTP::EHttpSocketServ, RHTTPSession::GetTable());
       
   857     CleanupClosePushL(sockserv);
       
   858 
       
   859     RStringF connection = aHTTPSession.StringPool().StringF(
       
   860             HTTP::EHttpSocketConnection, RHTTPSession::GetTable());
       
   861     CleanupClosePushL(connection);
       
   862 
       
   863     RHTTPConnectionInfo cInfo = aHTTPSession.ConnectionInfo();
       
   864     cInfo.SetPropertyL(sockserv, THTTPHdrVal(iIRSocketServer.Handle()));
       
   865     cInfo.SetPropertyL(connection, THTTPHdrVal(
       
   866             reinterpret_cast<TInt> (iIRNetworkConnection)));
       
   867     CleanupStack::PopAndDestroy(&connection); // sockserv.close, connection.close
       
   868     CleanupStack::PopAndDestroy(&sockserv); // sockserv.close, connection.close
       
   869 
       
   870     IRLOG_DEBUG("CIRNetworkController::InitializeHttpSessionL - exit");
       
   871 }
       
   872 
       
   873 // ---------------------------------------------------------
       
   874 // CIRNetworkController::RegisterLogoDataTransferTrackerL
       
   875 // ---------------------------------------------------------
       
   876 EXPORT_C void CIRNetworkController::RegisterLogoDataTransferTrackerL(RHTTPSession& aHTTPSession)
       
   877 {
       
   878     IRLOG_DEBUG("CVRConnection::InitializeHttpSessionL - enter");
       
   879 
       
   880     iLogoDataTransferTracker->BindL(aHTTPSession,
       
   881             MIRDataTransferTracker::EIRTransferCategoryIsds);
       
   882 
       
   883     RStringF sockserv = aHTTPSession.StringPool().StringF(
       
   884             HTTP::EHttpSocketServ, RHTTPSession::GetTable());
       
   885     CleanupClosePushL(sockserv);
       
   886 
       
   887     RStringF connection = aHTTPSession.StringPool().StringF(
       
   888             HTTP::EHttpSocketConnection, RHTTPSession::GetTable());
       
   889     CleanupClosePushL(connection);
       
   890 
       
   891     RHTTPConnectionInfo cInfo = aHTTPSession.ConnectionInfo();
       
   892     cInfo.SetPropertyL(sockserv, THTTPHdrVal(iIRSocketServer.Handle()));
       
   893     cInfo.SetPropertyL(connection, THTTPHdrVal(
       
   894             reinterpret_cast<TInt> (iIRNetworkConnection)));
       
   895     CleanupStack::PopAndDestroy(&connection); // sockserv.close, connection.close
       
   896     CleanupStack::PopAndDestroy(&sockserv); // sockserv.close, connection.close	
       
   897 
       
   898     // Subscribe to logo byte counter info
       
   899     iLogoDataTransferTracker->SetObserver(this);
       
   900 
       
   901     IRLOG_DEBUG("CIRNetworkController::RegisterLogoDataTransferTrackerL - exit");
       
   902 }
       
   903 
       
   904 // ---------------------------------------------------------
       
   905 // CIRNetworkController::DataTransferTracker()
       
   906 // ---------------------------------------------------------
       
   907 
       
   908 EXPORT_C MIRDataTransferTracker& CIRNetworkController::DataTransferTracker()
       
   909 {
       
   910     IRLOG_DEBUG("CIRNetworkController::DataTransferTracker");
       
   911     return *iDataTransferTracker;
       
   912 }
       
   913 
       
   914 // ---------------------------------------------------------
       
   915 // CIRNetworkController::LogoDataTransferTracker()
       
   916 // ---------------------------------------------------------
       
   917 
       
   918 EXPORT_C MIRDataTransferTracker& CIRNetworkController::LogoDataTransferTracker()
       
   919 {
       
   920     IRLOG_DEBUG("CIRNetworkController::LogoDataTransferTracker");
       
   921     return *iLogoDataTransferTracker;
       
   922 }
       
   923 
       
   924 // ---------------------------------------------------------
       
   925 // CIRNetworkController::LogoDataTransferTracker()
       
   926 // ---------------------------------------------------------
       
   927 
       
   928 void CIRNetworkController::HandleDataTransferEventL( 
       
   929 		const MIRDataTransferTracker::TIRDataTransferPckg& aData )
       
   930 {
       
   931     IRLOG_DEBUG("CIRNetworkController::HandleDataTransferEventL - Entering");
       
   932     iDataTransferTracker->RawDataTransferredL(aData.iBytesSentTotal,
       
   933             aData.iBytesReceivedTotal,
       
   934             MIRDataTransferTracker::EIRTransferCategoryIsds);
       
   935     IRLOG_DEBUG("CIRNetworkController::HandleDataTransferEventL - Exiting");
       
   936 }
       
   937 
       
   938 // ---------------------------------------------------------
       
   939 // CIRNetworkController::PreferredCarrierAvailable()
       
   940 // ---------------------------------------------------------
       
   941 
       
   942 void CIRNetworkController::PreferredCarrierAvailable( TAccessPointInfo aOldAPInfo,
       
   943                                             TAccessPointInfo aNewAPInfo,
       
   944                                             TBool aIsUpgrade,
       
   945                                             TBool aIsSeamless )
       
   946 {
       
   947     IRLOG_DEBUG("CIRNetworkController::PreferredCarrierAvailable - Entering");
       
   948 
       
   949     (void)aOldAPInfo;
       
   950     (void)aNewAPInfo;
       
   951     (void)aIsUpgrade;
       
   952     IRLOG_DEBUG5("CIRNetworkController::PreferredCarrierAvailable, old ap : %d, new ap : %d, aIsUpgrade : %d, aIsSeamless : %d", 
       
   953                  aOldAPInfo.AccessPoint(), aNewAPInfo.AccessPoint(), aIsUpgrade, aIsSeamless);
       
   954     
       
   955     if (aIsSeamless)
       
   956     {
       
   957         // It is Seamless. E.g. Mobile IP enabled.
       
   958     }
       
   959     else
       
   960     {
       
   961         // sockets used by the connection should be closed here.
       
   962 
       
   963         // We ask to migrate to the Preferred Carrier.
       
   964         if (!IsOfflineMode())
       
   965         {
       
   966             //handling over connection may take some time, during handling over connection,
       
   967             //application should be in disconnected state
       
   968             TRAP_IGNORE(iObserver->IRNetworkEventL(ENetworkConnectionDisconnected);)
       
   969             
       
   970             iIRNetworkObserver->SetNetworkMonitoring(EFalse);
       
   971             
       
   972             iMobility->MigrateToPreferredCarrier();
       
   973             iHandingOver = ETrue;
       
   974         }
       
   975     }
       
   976 
       
   977     IRLOG_DEBUG("CIRNetworkController::PreferredCarrierAvailable - Exiting");
       
   978 }
       
   979 
       
   980 
       
   981 // ---------------------------------------------------------
       
   982 // CIRNetworkController::NewCarrierActive()
       
   983 // ---------------------------------------------------------
       
   984 void CIRNetworkController::NewCarrierActive( TAccessPointInfo aNewAPInfo, TBool aIsSeamless )
       
   985 {
       
   986     IRLOG_DEBUG("CIRNetworkController::NewCarrierActive - Entering");
       
   987     (void)aNewAPInfo;
       
   988     IRLOG_DEBUG3("CIRNetworkController::NewCarrierActive, new ap : %d, aIsSeamless : %d",
       
   989                  aNewAPInfo.AccessPoint(), aIsSeamless);
       
   990     
       
   991     if (aIsSeamless)
       
   992     {
       
   993         // It is Seamless. E.g. Mobile IP enabled.
       
   994     }
       
   995     else
       
   996     {
       
   997         // sockets used by the connection should be re-opened here.
       
   998         // We accept the new IAP.
       
   999 
       
  1000         iMobility->NewCarrierAccepted();
       
  1001 
       
  1002         iIsConnectRequestIssued = EFalse;
       
  1003         iNetworkConnectionState = EIRNetworkConnectionActive;
       
  1004         iIsConnectedToNetwork = ETrue;
       
  1005         iConnectionPresent = ETrue;
       
  1006         
       
  1007         iIRNetworkObserver->SetNetworkMonitoring(ETrue);
       
  1008         iIRNetworkObserver->InitializeNetworkObserver();    
       
  1009     }
       
  1010 
       
  1011     IRLOG_DEBUG("CIRNetworkController::NewCarrierActive - Exiting");
       
  1012 }
       
  1013 
       
  1014 
       
  1015 // ---------------------------------------------------------
       
  1016 // CIRNetworkController::Error()
       
  1017 // ---------------------------------------------------------
       
  1018 void CIRNetworkController::Error( TInt /*aError*/ )
       
  1019 {
       
  1020     IRLOG_DEBUG("CIRNetworkController::Error");
       
  1021     // Does nothing for the moment
       
  1022 }
       
  1023 	
       
  1024 // ---------------------------------------------------------
       
  1025 // HandleRunLSuccessL()
       
  1026 // Handles the success case of Network connection in RunL
       
  1027 // ---------------------------------------------------------
       
  1028 void CIRNetworkController::HandleRunLSuccessL()
       
  1029 {
       
  1030     IRLOG_DEBUG("CIRNetworkController::HandleRunLSuccessL - Entering");
       
  1031 
       
  1032     switch (iNetworkControllerState)
       
  1033     {
       
  1034     case EConnectingToNetwork:
       
  1035     {
       
  1036         iIsConnectedToNetwork = ETrue;
       
  1037         // Connection to network sucessful
       
  1038         iNetworkConnectionState = EIRNetworkConnectionActive;
       
  1039         iConnectionPresent = ETrue;
       
  1040         iIsConnectRequestIssued = EFalse;
       
  1041         iIRNetworkObserver->InitializeNetworkObserver();
       
  1042     }
       
  1043         break;
       
  1044     default:
       
  1045     {
       
  1046         // no implementation
       
  1047     }
       
  1048         break;
       
  1049     }
       
  1050 
       
  1051     if (!iMobility)
       
  1052     {
       
  1053         iMobility = CActiveCommsMobilityApiExt::NewL(*iIRNetworkConnection,
       
  1054                 *this);
       
  1055     }
       
  1056     IRLOG_DEBUG("CIRNetworkController::HandleRunLSuccessL - Exiting");
       
  1057 }
       
  1058 
       
  1059 
       
  1060 // ---------------------------------------------------------
       
  1061 // HandleRunLErrorL()
       
  1062 // Handles the error case of Network connection in RunL
       
  1063 // ---------------------------------------------------------
       
  1064 void CIRNetworkController::HandleRunLErrorL(TInt aStatusCode )
       
  1065 {
       
  1066     IRLOG_DEBUG("CIRNetworkController::HandleRunLErrorL - Entering");
       
  1067 	
       
  1068     switch(iNetworkControllerState)
       
  1069 	{
       
  1070 		case EConnectingToNetwork:
       
  1071 		{
       
  1072 		    // Connection to network failure
       
  1073 			iNetworkConnectionState = EIRNetworkConnectionInActive;
       
  1074             iIsConnectedToNetwork = EFalse;
       
  1075             iConnectionPresent = EFalse;
       
  1076             iIsConnectRequestIssued = EFalse;
       
  1077             if (aStatusCode != KErrCancel)
       
  1078             {
       
  1079                 if (iDefaultConnection)
       
  1080                 {
       
  1081                     //give user the second chance to select access point manually
       
  1082                     ChooseAccessPointL(EFalse);
       
  1083                 }
       
  1084                 else
       
  1085                 {
       
  1086                     iObserver->IRNetworkEventL(EDisplayNetworkMessageNoConnectivity);
       
  1087                 }
       
  1088             }
       
  1089             else
       
  1090             {
       
  1091                 iObserver->IRNetworkEventL(EAccessPointSelectionCancelled);
       
  1092                 ResetPendingRequests(EFalse);
       
  1093             }
       
  1094         }
       
  1095         break;
       
  1096         
       
  1097         default:
       
  1098         {
       
  1099             // no implementation
       
  1100         }
       
  1101         break;
       
  1102     }
       
  1103 
       
  1104     IRLOG_DEBUG("CIRNetworkController::HandleRunLErrorL - Exiting");
       
  1105 }
       
  1106 
       
  1107 // ---------------------------------------------------------
       
  1108 // Registers the observer that will be notified for 
       
  1109 // a network connection.
       
  1110 // Observer requires notification to reissue pending request
       
  1111 // ---------------------------------------------------------
       
  1112 	
       
  1113 EXPORT_C  void CIRNetworkController::RegisterActiveNetworkObserverL(MIRActiveNetworkObserver&
       
  1114 																	 aActiveNetworkObserver)
       
  1115 {
       
  1116     IRLOG_DEBUG("CIRNetworkController::RegisterActiveNetworkObserverL - Entering");
       
  1117     iActiveNetworkObserverArray.AppendL(&aActiveNetworkObserver);
       
  1118     IRLOG_DEBUG("CIRNetworkController::RegisterActiveNetworkObserverL - Exiting");
       
  1119 }
       
  1120 // ---------------------------------------------------------------------------
       
  1121 // DeleteActiveNetworkObserver()
       
  1122 // Used to remove an observer for roaming events from the observer array
       
  1123 // ---------------------------------------------------------------------------
       
  1124 EXPORT_C void CIRNetworkController::DeleteActiveNetworkObserver(MIRActiveNetworkObserver&
       
  1125 																 aActiveNetworkObserver)
       
  1126 {
       
  1127     IRLOG_DEBUG("CIRNetworkController::DeleteActiveNetworkObserver - Entering");
       
  1128     TInt index = iActiveNetworkObserverArray.Find(&aActiveNetworkObserver);
       
  1129 
       
  1130     if (index != KErrNotFound)
       
  1131     {
       
  1132         iActiveNetworkObserverArray.Remove(index);
       
  1133     }
       
  1134 
       
  1135     IRLOG_DEBUG("CIRNetworkController::DeleteActiveNetworkObserver - Exiting");
       
  1136 }
       
  1137 	
       
  1138 // ---------------------------------------------------------------------------
       
  1139 // NotifyActiveNetworkObserversL()
       
  1140 // Used to notify all observers for network events about a change in network event
       
  1141 // ---------------------------------------------------------------------------
       
  1142 EXPORT_C void CIRNetworkController::NotifyActiveNetworkObserversL(TIRNetworkEvent aEvent)
       
  1143 {
       
  1144     IRLOG_DEBUG("CIRNetworkController::NotifyActiveNetworkObserversL - Entering");
       
  1145 
       
  1146     for (TInt i = iActiveNetworkObserverArray.Count() - 1; i >= 0; i--)
       
  1147     {
       
  1148         iActiveNetworkObserverArray[i]->NotifyActiveNetworkObserversL(aEvent);
       
  1149     }
       
  1150 
       
  1151     IRLOG_DEBUG("CIRNetworkController::NotifyActiveNetworkObserversL - Exiting");
       
  1152 }
       
  1153 // ---------------------------------------------------------
       
  1154 // IsHandingOverConnection()
       
  1155 // Indicates if the Hand over of Network connection has happened
       
  1156 // ---------------------------------------------------------    
       
  1157 EXPORT_C  TBool CIRNetworkController::IsHandingOverConnection()
       
  1158 {
       
  1159 	IRLOG_DEBUG("CIRNetworkController::IsHandingOverConnection - Entering");
       
  1160     IRLOG_DEBUG("CIRNetworkController::IsHandingOverConnection - Exiting");
       
  1161 	return iHandingOver;
       
  1162 }
       
  1163 
       
  1164 // -----------------------------------------------------------
       
  1165 // Reset member iHandingOver to EFalse.
       
  1166 // -----------------------------------------------------------
       
  1167 void CIRNetworkController::ResetHandingOverConnection()
       
  1168 {
       
  1169     IRLOG_DEBUG("CIRNetworkController::ResetHandingOverConnection(), Entering");
       
  1170     iHandingOver = EFalse;
       
  1171     IRLOG_DEBUG("CIRNetworkController::ResetHandingOverConnection(), Exiting");
       
  1172 }
       
  1173 
       
  1174 // -----------------------------------------------------------------------------
       
  1175 // Notifies observers when user cancels network connection, to reset 
       
  1176 // the pending requests  
       
  1177 // ResetPendingRequests()
       
  1178 // -----------------------------------------------------------------------------
       
  1179 void CIRNetworkController::ResetPendingRequests(TBool aValue)
       
  1180 {
       
  1181     for (TInt i = 0; i < iActiveNetworkObserverArray.Count(); i++)
       
  1182     {
       
  1183         iActiveNetworkObserverArray[i]->ResetPendingRequests(aValue);
       
  1184     }
       
  1185 }