browserutilities/connectionmanager/Src/ConnectionObservers.cpp
changeset 0 dd21522fd290
child 36 0ed94ceaa377
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2002 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 the License "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: 
       
    15 *     This class provides connection/session related information.
       
    16 *	  Both the requested and the stored AP's are here.
       
    17 *
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 #include <nifman.h>
       
    24 #include <nifvar.h>
       
    25 #include <es_enum.h>
       
    26 #include <in_sock.h>
       
    27 
       
    28 #include "ConnectionObservers.h"
       
    29 #include "ConnectionManagerLogger.h"
       
    30 
       
    31 
       
    32 //--------------------------------------------------------------------------
       
    33 //CConnectionStageNotifierWCB::NewL()
       
    34 //--------------------------------------------------------------------------
       
    35 EXPORT_C CConnectionStageNotifierWCB* CConnectionStageNotifierWCB::NewL( TInt aPriority )
       
    36 	{
       
    37 	CConnectionStageNotifierWCB* self = CConnectionStageNotifierWCB::NewLC( aPriority );
       
    38 	CleanupStack::Pop();
       
    39 	return self;
       
    40 	}
       
    41 
       
    42 //--------------------------------------------------------------------------
       
    43 //CConnectionStageNotifierWCB::NewLC()
       
    44 //--------------------------------------------------------------------------
       
    45 EXPORT_C CConnectionStageNotifierWCB* CConnectionStageNotifierWCB::NewLC( TInt aPriority )
       
    46 	{
       
    47 	CConnectionStageNotifierWCB* self = new ( ELeave ) CConnectionStageNotifierWCB( aPriority );	
       
    48 	CleanupStack::PushL( self );
       
    49 	return self;
       
    50 	}
       
    51 
       
    52 //--------------------------------------------------------------------------
       
    53 //CConnectionStageNotifierWCB::StartNotificationL()
       
    54 //--------------------------------------------------------------------------
       
    55 EXPORT_C void 
       
    56     CConnectionStageNotifierWCB::StartNotificationL( TInt /*aStageToObserve*/, 
       
    57                                                      MConnectionStageObserver* /*aObserver*/, 
       
    58                                                      TBool /*aCompleteIfAlreadyAtStage*/ )	
       
    59 	{
       
    60     User::Leave( KErrNotSupported );
       
    61 	}
       
    62 
       
    63 //--------------------------------------------------------------------------
       
    64 //CConnectionStageNotifierWCB::~CConnectionStageNotifierWCB()
       
    65 //--------------------------------------------------------------------------
       
    66 EXPORT_C CConnectionStageNotifierWCB::~CConnectionStageNotifierWCB()
       
    67 	{
       
    68 	CLOG_WRITE("~CConnectionStageNotifierWCB");
       
    69 	
       
    70 	Cancel();
       
    71 	
       
    72 	CLOG_WRITE("Canceled");
       
    73     // if there's nothing to cancel
       
    74     // DoCancel is not called.
       
    75     // We need to close agent manually from here
       
    76     DoCloseAgent();
       
    77     
       
    78     CLOG_CLOSE;
       
    79 	}
       
    80 
       
    81 //--------------------------------------------------------------------------
       
    82 //CConnectionStageNotifierWCB::CConnectionStageNotifierWCB()
       
    83 //--------------------------------------------------------------------------
       
    84 CConnectionStageNotifierWCB::CConnectionStageNotifierWCB( TInt aPriority ) : CActive( aPriority )
       
    85 	{
       
    86 	CLOG_CREATE;
       
    87 	CLOG_NAME_1( _L("StageNotifier_%x"), this );
       
    88 	
       
    89 	CActiveScheduler::Add( this );
       
    90 	}
       
    91 
       
    92 //--------------------------------------------------------------------------
       
    93 //CConnectionStageNotifierWCB::DoCancel()
       
    94 //--------------------------------------------------------------------------
       
    95 void CConnectionStageNotifierWCB::DoCancel()
       
    96 	{
       
    97 	CLOG_ENTERFN( "DoCancel()" );
       
    98 	iConnection.CancelProgressNotification();
       
    99     DoCloseAgent();
       
   100 
       
   101     iMultiObserver = NULL;
       
   102     iStages = NULL;
       
   103     iNumOfStages = 0;
       
   104 	}
       
   105 
       
   106 //--------------------------------------------------------------------------
       
   107 //CConnectionStageNotifierWCB::RunL()
       
   108 //--------------------------------------------------------------------------
       
   109 void CConnectionStageNotifierWCB::RunL()
       
   110 	{
       
   111 	CLOG_ENTERFN("CConnectionStageNotifierWCB::RunL()");
       
   112     CLOG_WRITE_1( "CConnectionStageNotifierWCB Stage: %d", iProgressBuf().iStage );
       
   113 
       
   114     if( !iMultiObserver )
       
   115         {
       
   116 	    if ( iProgressBuf().iStage == iStageToObserve )
       
   117 		    {
       
   118             CLOG_WRITE( "Stage achived" );
       
   119 		    DoCloseAgent();
       
   120 		    iObserver->ConnectionStageAchievedL();
       
   121 		    }
       
   122 	    else//reissuing request
       
   123 		    {
       
   124             CLOG_WRITE( "Restarting progress notif." );
       
   125 		    iConnection.ProgressNotification(  iProgressBuf, iStatus );//reissuing request
       
   126 		    SetActive();
       
   127 		    }
       
   128         }
       
   129     else
       
   130         {
       
   131         if( IsAnyStageReached( iProgressBuf().iStage ) )
       
   132             {
       
   133             iMultiObserver->ConnectionStageAchievedL( iProgressBuf().iStage );
       
   134             }
       
   135 		else{
       
   136 			//reissuing request
       
   137 			iConnection.ProgressNotification( iProgressBuf, iStatus );//issuing request
       
   138 			SetActive();
       
   139 			}
       
   140         }
       
   141 	}
       
   142 
       
   143 
       
   144 //--------------------------------------------------------------------------
       
   145 //CConnectionStageNotifierWCB::StartNotificationL()
       
   146 //--------------------------------------------------------------------------
       
   147 EXPORT_C void 
       
   148     CConnectionStageNotifierWCB::StartNotificationL( TName* aConnName, 
       
   149                                                      TInt aStageToObserve, 
       
   150                                                      MConnectionStageObserver* aObserver, 
       
   151                                                      TBool aCompleteIfAlreadyAtStage )	
       
   152 	{
       
   153     CLOG_ENTERFN( "StartNotificationL1" );
       
   154 
       
   155 	__ASSERT_DEBUG( aObserver, User::Panic(  KNullDesC, KErrArgument ) );
       
   156 	iObserver = aObserver;
       
   157 	iStageToObserve = aStageToObserve;
       
   158 
       
   159 
       
   160     DoOpenAgentL( aConnName );
       
   161       
       
   162     TNifProgress progress;
       
   163 
       
   164     iConnection.Progress( progress );//initial progress may be important to save whether it is unconnected now
       
   165 	if ( progress.iStage == aStageToObserve && aCompleteIfAlreadyAtStage )
       
   166 		{
       
   167 		DoCloseAgent();
       
   168 		TRAP_IGNORE( iObserver->ConnectionStageAchievedL() );
       
   169 		}
       
   170 	else
       
   171 		{
       
   172 			
       
   173 			/* No need to call Setactive() in the case if connection is already active, that is why checking isActive 
       
   174 			connection, if not then only activating it, For instance Incase of Connection Change from real IAP to VPN on the 
       
   175 			same real IAP using which VPN configurations were made then the existing connection would not be disconnected 
       
   176 			but a new VPN tunnel will be created on top of it.So connection is already active, it should not call SetActive() 
       
   177 			if the active object request has been issued already, new request should be issued only incase of a new connection altogether*/
       
   178 			if(!IsActive())
       
   179 			{
       
   180 				iConnection.ProgressNotification( iProgressBuf, iStatus );//issuing request
       
   181 				SetActive();
       
   182 			}
       
   183 		}
       
   184     }
       
   185 
       
   186 //--------------------------------------------------------------------------
       
   187 //CConnectionStageNotifierWCB::StartNotificationL()
       
   188 //--------------------------------------------------------------------------
       
   189 EXPORT_C void 
       
   190     CConnectionStageNotifierWCB::StartNotificationL( TName* aConnName, 
       
   191                                                      TInt* aStages, 
       
   192                                                      TInt aNumOfStages,
       
   193                                                      MConnectionMultiStageObserver* aObserver,
       
   194                                                      TBool aCompleteIfAlreadyAtStage )	
       
   195 	{
       
   196     CLOG_ENTERFN( "StartNotificationL2" );
       
   197 
       
   198     __ASSERT_DEBUG( aStages, User::Panic(  KNullDesC, KErrArgument ) );
       
   199     __ASSERT_DEBUG( aNumOfStages > 0 , User::Panic(  KNullDesC, KErrArgument ) );
       
   200     __ASSERT_DEBUG( aObserver, User::Panic(  KNullDesC, KErrArgument ) );
       
   201 
       
   202     iStages = aStages;
       
   203     iNumOfStages = aNumOfStages;
       
   204     iMultiObserver = aObserver;
       
   205 
       
   206     DoOpenAgentL( aConnName );
       
   207 
       
   208 	TNifProgress progress;
       
   209 	iConnection.Progress( progress );//initial progress may be important to save whether it is unconnected now
       
   210 	if ( IsAnyStageReached( progress.iStage ) && aCompleteIfAlreadyAtStage )
       
   211 		{
       
   212 		DoCloseAgent();
       
   213 		TRAP_IGNORE( iMultiObserver->ConnectionStageAchievedL( progress.iStage ) );
       
   214 		}
       
   215 	else
       
   216 		{
       
   217 		if(!IsActive())
       
   218 			{
       
   219 		    iConnection.ProgressNotification( iProgressBuf, iStatus );//issuing request
       
   220 		    SetActive();
       
   221 		    }
       
   222 		}
       
   223     }
       
   224 
       
   225 //--------------------------------------------------------------------------
       
   226 //CConnectionStageNotifierWCB::DoOpenAgent
       
   227 //--------------------------------------------------------------------------
       
   228 void CConnectionStageNotifierWCB::DoOpenAgentL( TName* aConnName )
       
   229     {
       
   230     CLOG_ENTERFN( "CConnectionStageNotifierWCB::DoOpenAgentL" );
       
   231     TInt err( KErrNone );
       
   232     if( (err = iServer.Connect()) == KErrNone )
       
   233         {
       
   234         err = iConnection.Open( iServer, *aConnName );
       
   235         if( !err )
       
   236             {
       
   237             TBuf<64> query;
       
   238             TUint32 apId;
       
   239             TUint32 netId;
       
   240 
       
   241             query.Format( _L("%s\\%s"), IAP, COMMDB_ID );
       
   242             if( iConnection.GetIntSetting( query, apId ) == KErrNone )
       
   243                 {
       
   244                 query.Format( _L("%s\\%s"), IAP, IAP_NETWORK );
       
   245                 if( iConnection.GetIntSetting( query, netId ) == KErrNone )
       
   246                     {
       
   247                     TPckgBuf<TConnectionInfo> connInfo;
       
   248 
       
   249                     connInfo().iIapId = apId;
       
   250                     connInfo().iNetId = netId;
       
   251                     CLOG_WRITE_2( "IAP ID: %d, NET ID: %d", connInfo().iIapId, connInfo().iNetId );
       
   252 
       
   253                     iConnection.Close();
       
   254                     if( iConnection.Open( iServer, KAfInet ) == KErrNone )
       
   255                         {
       
   256                         err = iConnection.Attach( connInfo, RConnection::EAttachTypeMonitor );
       
   257                         CLOG_WRITE_1( "Attach result: %d", err );
       
   258                         }
       
   259                     }
       
   260                 }
       
   261             }
       
   262         }
       
   263 
       
   264     if( err )
       
   265         {
       
   266         iConnection.Close();
       
   267         iServer.Close();
       
   268         User::Leave( err );
       
   269         }
       
   270     }
       
   271 
       
   272 //--------------------------------------------------------------------------
       
   273 //CConnectionStageNotifierWCB::DoCloseAgent
       
   274 //--------------------------------------------------------------------------
       
   275 void CConnectionStageNotifierWCB::DoCloseAgent()
       
   276     {
       
   277     CLOG_ENTERFN( "CConnectionStageNotifierWCB::DoCloseAgent()" );
       
   278     iConnection.Close();
       
   279     iServer.Close();
       
   280     }
       
   281 
       
   282 //--------------------------------------------------------------------------
       
   283 //CConnectionStageNotifierWCB::IsAnyStageReached()
       
   284 //--------------------------------------------------------------------------
       
   285 TBool CConnectionStageNotifierWCB::IsAnyStageReached( TInt aCurrentStage )
       
   286     {
       
   287     for( TInt i = 0; i < iNumOfStages; ++i )
       
   288         {
       
   289         if( iStages[i] == aCurrentStage )
       
   290             {
       
   291             return ETrue;
       
   292             }
       
   293         }
       
   294 
       
   295     return EFalse;
       
   296     }
       
   297 
       
   298 //EOF