videoconnutility/connutility/src/vcxconnutilengine.cpp
branchRCL_3
changeset 48 13a33d82ad98
parent 0 822a42b6c3f1
equal deleted inserted replaced
47:826cea16efd9 48:13a33d82ad98
       
     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 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 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <mpxlog.h>
       
    22 #include <commdb.h>
       
    23 #include <basched.h>
       
    24 #include <cmmanagerext.h>
       
    25 #include <extendedconnpref.h>
       
    26 
       
    27 #include "vcxconnutilextengineobserver.h"
       
    28 #include "vcxconnutilengine.h"
       
    29 
       
    30 // CONSTANTS
       
    31 _LIT( KCommDBIapId, "IAP\\Id" );
       
    32 
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CVcxConnUtilEngine::NewL()
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CVcxConnUtilEngine* CVcxConnUtilEngine::NewL( MConnUtilExtEngineObserver* aObserver )
       
    39     {
       
    40     CVcxConnUtilEngine* self = CVcxConnUtilEngine::NewLC( aObserver );  
       
    41     CleanupStack::Pop( self ); // self;
       
    42     return self;
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CVcxConnUtilEngine::NewLC()
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CVcxConnUtilEngine* CVcxConnUtilEngine::NewLC( MConnUtilExtEngineObserver* aObserver )
       
    50     {
       
    51     CVcxConnUtilEngine* self = new (ELeave) CVcxConnUtilEngine();
       
    52     CleanupStack::PushL( self );
       
    53     self->iObserver = aObserver;
       
    54     self->ConstructL();
       
    55     return self;
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CVcxConnUtilEngine::CVcxNsConnUtilEngine()
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CVcxConnUtilEngine::CVcxConnUtilEngine( ) : 
       
    63     CActive( EPriorityStandard ),     
       
    64     iConnectionState( EVCxNotConnected )
       
    65     {
       
    66     CActiveScheduler::Add( this );
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CVcxConnUtilEngine::ConstructL()
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CVcxConnUtilEngine::ConstructL()
       
    74     {
       
    75     MPX_DEBUG1("vcxconnutil  ## CVcxConnUtilEngine::ConstructL() in");
       
    76        
       
    77     iCmManagerExt.OpenL();
       
    78         
       
    79     User::LeaveIfError( iSocketServer.Connect() );
       
    80            
       
    81     User::LeaveIfError( iConnectionMonitor.ConnectL() );    
       
    82     
       
    83     User::LeaveIfError( iConnectionMonitor.NotifyEventL( *this ) );
       
    84         
       
    85     // get all destination ids
       
    86     iCmManagerExt.AllDestinationsL( iDestinationArray );
       
    87     
       
    88     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::ConstructL() out" ); 
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CVcxConnUtilEngine::~CVcxNsConnUtilEngine()
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 CVcxConnUtilEngine::~CVcxConnUtilEngine()
       
    96     {
       
    97     
       
    98     if( iMobility )
       
    99         {
       
   100         // make sure observers are not being called
       
   101         // after receiving Error() from Cancel()
       
   102         iConnectionState = EVCxDisconnecting;
       
   103         iMobility->Cancel();
       
   104         delete iMobility;
       
   105         }
       
   106     
       
   107     if( IsActive() )
       
   108         {
       
   109         Cancel();
       
   110         }
       
   111     
       
   112     iConnection.Close();
       
   113         
       
   114     iSocketServer.Close();
       
   115       
       
   116     iCmManagerExt.Close();
       
   117     
       
   118     iConnectionMonitor.Close();
       
   119        
       
   120     delete iDestinationName;
       
   121     
       
   122     iDestinationArray.Close();
       
   123    
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CVcxConnUtilEngine::StartToConnect()
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 TInt CVcxConnUtilEngine::StartToConnect( TConnPref& aPref, TBool aConnAsync )
       
   131     {
       
   132     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::StartToConnect with TConnSnapPref in" );
       
   133         
       
   134     TInt err( KErrNone );
       
   135     if( EVCxConnected == iConnectionState  ||
       
   136         EVCxConnecting == iConnectionState )
       
   137         {
       
   138         return err;
       
   139         }
       
   140     iConnectionState = EVCxConnecting;  
       
   141     err = iConnection.Open( iSocketServer );
       
   142     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::StartToConnect connection opened" );
       
   143     if( err != KErrNone )
       
   144         {
       
   145         return err;
       
   146         }   
       
   147 
       
   148     if( !IsActive() )
       
   149         {
       
   150         if( aConnAsync )
       
   151             {
       
   152             MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::StartToConnect connecting async" );
       
   153             
       
   154             iConnection.Start( aPref, iStatus );
       
   155             SetActive();
       
   156             TRAP( err, iObserver->WaitL( EVCxPSConnectionStatus ) );
       
   157             if( err == KErrNone )
       
   158                 {
       
   159                 // save possible error code from async 
       
   160                 // connection creation
       
   161                 err = iConnectingResult;
       
   162                 }
       
   163             else if( err == KLeaveExit )
       
   164                 {
       
   165                 // app is closing, active scheduler is about to be closed.
       
   166                 // cancel connection waiting.
       
   167                 if( IsActive() )
       
   168                     {
       
   169                     Cancel();
       
   170                     }
       
   171                 }
       
   172             }
       
   173         else
       
   174             {
       
   175             MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::StartToConnect connecting sync" );
       
   176             err = iConnection.Start();
       
   177             if( err == KErrNone )
       
   178                 {
       
   179                 iConnectionState = EVCxConnected;
       
   180                 }
       
   181             }
       
   182         }
       
   183     
       
   184     if( iConnectionState != EVCxConnected )
       
   185         {
       
   186         iIapId = 0;
       
   187         }
       
   188 
       
   189     MPX_DEBUG2( "vcxconnutil  ## CVcxConnUtilEngine::StartToConnect with TConnSnapPref err: %d  out", err );
       
   190     return err;  
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CVcxConnUtilEngine::CreateMobility()
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 TInt CVcxConnUtilEngine::CreateMobility()
       
   198     {
       
   199     TInt err( KErrNone );
       
   200     if( iMobility )
       
   201         {
       
   202         iMobility->Cancel();        
       
   203         delete iMobility;
       
   204         iMobility = 0;
       
   205         }
       
   206     if( !iMobility  )
       
   207         {        
       
   208         TRAP( err, iMobility = CActiveCommsMobilityApiExt::NewL( iConnection, *this ) );
       
   209         }
       
   210     return err;
       
   211     }
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CVcxConnUtilEngine::Disconnect()
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 void  CVcxConnUtilEngine::Disconnect()
       
   218     {
       
   219     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::Disconnect in");
       
   220     if( iConnectionState != EVCxNotConnected )
       
   221         { 
       
   222         MPX_DEBUG1( "CVcxConnUtilEngine::Disconnect closing connection");
       
   223         iConnectionState = EVCxDisconnecting;
       
   224         if( iMobility )
       
   225             {
       
   226             iMobility->Cancel();
       
   227             delete iMobility;
       
   228             iMobility = NULL;
       
   229             }               
       
   230 
       
   231         iConnection.Close();
       
   232         iConnectionState = EVCxNotConnected;
       
   233         
       
   234         }      
       
   235     if( IsActive() )
       
   236         {
       
   237         Cancel();
       
   238         }
       
   239     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::Disconnect out");
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CVcxConnUtilEngine::PreferredCarrierAvailable()
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 void CVcxConnUtilEngine::PreferredCarrierAvailable( TAccessPointInfo aOldAPInfo ,
       
   247                                                       TAccessPointInfo aNewAPInfo,
       
   248                                                       TBool /*aIsUpgrade*/,
       
   249                                                       TBool aIsSeamless )
       
   250     {
       
   251     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::PreferredCarrierAvailable in");
       
   252     MPX_DEBUG2( "PreferredCarrierAvailable oldiap: %d", aOldAPInfo.AccessPoint() );
       
   253     MPX_DEBUG2( "PreferredCarrierAvailable newiap: %d", aNewAPInfo.AccessPoint() );
       
   254     MPX_DEBUG2( "PreferredCarrierAvailable seamless: %d", aIsSeamless );
       
   255     
       
   256     
       
   257     if ( !aIsSeamless && 
       
   258          aOldAPInfo.AccessPoint() > 0 &&
       
   259          aOldAPInfo.AccessPoint() != aNewAPInfo.AccessPoint() )             
       
   260         {                
       
   261         if( iConnectionState == EVCxRoamingAccepted )
       
   262             {
       
   263             // in this case we have a roaming ongoing at the
       
   264             // but we have not yet received NewCarrierActive
       
   265             // so networking has found yet better usable iap.
       
   266             // since everyone have allready accepted roaming we
       
   267             // can migrate it right away
       
   268             MPX_DEBUG1( "CVcxConnUtilEngine::PreferredCarrierAvailable  migrated due EVCxRoamingAccepted state" ); 
       
   269             iMobility->MigrateToPreferredCarrier();
       
   270             }
       
   271         else if( iConnectionState != EVCxRoamingRequest )
       
   272             {
       
   273             TBool allowRoam( EFalse );
       
   274             iConnectionState = EVCxRoamingRequest;
       
   275             
       
   276             TRAPD( err, allowRoam = iObserver->RequestIsRoamingAllowedL() );
       
   277             
       
   278             // there is a possibility, that client has disconnected during request
       
   279             // in that case, do nothing
       
   280             if( iConnectionState == EVCxNotConnected )
       
   281                 {                
       
   282                 return;
       
   283                 }
       
   284             
       
   285             if( err == KErrNone && allowRoam )
       
   286                 {
       
   287             
       
   288                 MPX_DEBUG1( "CVcxConnUtilEngine::PreferredCarrierAvailable migrated" ); 
       
   289   
       
   290                 iMobility->MigrateToPreferredCarrier();
       
   291                 iConnectionState = EVCxRoamingAccepted;
       
   292                 }
       
   293             else
       
   294                 {
       
   295                 MPX_DEBUG1( "CVcxConnUtilEngine::PreferredCarrierAvailable ignored" );
       
   296                 iMobility->IgnorePreferredCarrier();
       
   297                 iConnectionState = EVCxConnected;
       
   298                 // reset IAP / SNAP info to the pubsub
       
   299                 TRAPD( err, iObserver->IapChangedL() );
       
   300                 if( err != KErrNone )
       
   301                     {
       
   302                     // internal error, let's try to resolve connection
       
   303                     iConnectionState = EVCxError;
       
   304                     TRAP( err, iObserver->IapChangedL() );                    
       
   305                     }
       
   306                 }
       
   307             }
       
   308        else
       
   309             {
       
   310             MPX_DEBUG1( "CVcxConnUtilEngine::PreferredCarrierAvailable Allready roaming" ); 
       
   311             }
       
   312         }
       
   313     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::PreferredCarrierAvailable out" );
       
   314     }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // CVcxConnUtilEngine::NewCarrierActive()
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 void CVcxConnUtilEngine::NewCarrierActive( TAccessPointInfo /*aNewAPInfo*/, TBool aIsSeamless )
       
   321     {
       
   322     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::NewCarrierActive in");
       
   323      
       
   324     if ( aIsSeamless )
       
   325         {
       
   326         // It is Seamless. E.g. Mobile IP enabled.
       
   327         MPX_DEBUG1( "CVcxConnUtilEngine::NewCarrierActive seamless");
       
   328         iConnectionState = EVCxConnected;
       
   329         }
       
   330     else
       
   331         {
       
   332         MPX_DEBUG1( "CVcxConnUtilEngine::NewCarrierActive accepting new carrier");
       
   333          
       
   334         // We accept the new IAP / SNAP.
       
   335         iMobility->NewCarrierAccepted();
       
   336         iConnectionState = EVCxConnected;
       
   337         // change new IAP / SNAP info to the pubsub
       
   338         TRAPD( err, iObserver->IapChangedL() );
       
   339         if( err != KErrNone )
       
   340             {                    
       
   341             // internal error, let's try to resolve connection
       
   342             iMobility->NewCarrierRejected();
       
   343             iConnectionState = EVCxError;
       
   344             TRAP( err, iObserver->IapChangedL() ); 
       
   345             }
       
   346         }
       
   347     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::NewCarrierActive out" );
       
   348     }
       
   349 
       
   350 // -----------------------------------------------------------------------------
       
   351 // CVcxConnUtilEngine::EventL()
       
   352 // -----------------------------------------------------------------------------
       
   353 //
       
   354 void CVcxConnUtilEngine::EventL( const CConnMonEventBase &aConnMonEvent )
       
   355     {
       
   356     TInt eventType = aConnMonEvent.EventType();
       
   357         
       
   358     TInt connectionId = aConnMonEvent.ConnectionId();
       
   359 
       
   360     // for other events:
       
   361     // if not master instance or event does not concern
       
   362     // current connection or we are not connected, do not 
       
   363     // need to handle events 
       
   364     if( !iObserver->IsMaster() || 
       
   365         connectionId != iCurrentConnectionId ||
       
   366         iConnectionState != EVCxConnected )
       
   367         {
       
   368         return;
       
   369         }
       
   370   
       
   371     switch(eventType)
       
   372         {               
       
   373         case EConnMonConnectionStatusChange:
       
   374             {     
       
   375             const CConnMonConnectionStatusChange* event = 
       
   376                             static_cast<const CConnMonConnectionStatusChange*>( &aConnMonEvent );
       
   377 
       
   378             if( event->ConnectionStatus() == KLinkLayerClosed )
       
   379                 {
       
   380                 MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::EventL: KLinkLayerClosed ");
       
   381                 iObserver->IapChangedL();
       
   382                 }                
       
   383             }
       
   384             break;
       
   385         case EConnMonDeleteConnection:
       
   386             {
       
   387             iObserver->IapChangedL();
       
   388             }
       
   389             break;
       
   390         default:
       
   391             break;
       
   392         }
       
   393     }
       
   394 
       
   395 // -----------------------------------------------------------------------------
       
   396 // CVcxConnUtilEngine::Error()
       
   397 // -----------------------------------------------------------------------------
       
   398 //
       
   399 void CVcxConnUtilEngine::Error( TInt aError  )
       
   400     {
       
   401     MPX_DEBUG2( "vcxconnutil  ## CVcxConnUtilEngine::Error %d in", aError );
       
   402     if( aError != KErrNone )
       
   403         {
       
   404         // Error method is also called, when we call Cancel -method for iMobility
       
   405         // during disconnecting or during deallocation. Those are not concidered
       
   406         // as "errors" in the connection utility, so they do not require any
       
   407         // further handling
       
   408         if( iConnectionState != EVCxDisconnecting )
       
   409             {
       
   410             iConnectionState = EVCxError;
       
   411             TRAP_IGNORE( iObserver->IapChangedL() ); 
       
   412             }
       
   413         
       
   414         }
       
   415     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::Error out" );
       
   416     }
       
   417 
       
   418 // -----------------------------------------------------------------------------
       
   419 // CVcxConnUtilEngine::GetCmmDestinationIdL()
       
   420 // -----------------------------------------------------------------------------
       
   421 //
       
   422 TUint32 CVcxConnUtilEngine::GetCmmDestinationIdL( CMManager::TSnapPurpose aPurpose )
       
   423     {
       
   424     TUint32 destinationId( 0 );
       
   425     // get default destination id
       
   426     TCmDefConnValue defConnection;
       
   427     iCmManagerExt.ReadDefConnL( defConnection );
       
   428 
       
   429     // if default is setted to be destination, get it's ID         
       
   430     if( defConnection.iType == ECmDefConnDestination && 
       
   431         aPurpose == CMManager::ESnapPurposeUnknown )
       
   432         {
       
   433         destinationId = defConnection.iId;
       
   434         }
       
   435     else if( defConnection.iType == ECmDefConnConnectionMethod ||
       
   436              aPurpose != CMManager::ESnapPurposeUnknown )
       
   437         {
       
   438         // default connection is connection method,
       
   439         // search for the destination of it
       
   440         RArray<TUint32> destinations;
       
   441         CleanupClosePushL( destinations );            
       
   442         iCmManagerExt.AllDestinationsL(destinations);
       
   443             
       
   444         RCmDestinationExt destination;
       
   445         RCmConnectionMethodExt connectionMethod;
       
   446         TInt exists( KErrNotFound );
       
   447         TInt count = destinations.Count();
       
   448         for( TInt i = 0; i < count && exists != KErrNone; i++ )
       
   449             {
       
   450             destination = iCmManagerExt.DestinationL( destinations[ i ] );
       
   451             CleanupClosePushL( destination ); 
       
   452             
       
   453             // look for default destination id
       
   454             if( aPurpose == CMManager::ESnapPurposeUnknown )
       
   455                 {
       
   456                 // check if connection method belongs to destination
       
   457                 TRAP( exists, 
       
   458                   connectionMethod = destination.ConnectionMethodByIDL( 
       
   459                                                            defConnection.iId ) );
       
   460                 if( exists == KErrNone )
       
   461                     {
       
   462                     connectionMethod.Close();
       
   463                     // correct destination found
       
   464                     destinationId = destination.Id();                   
       
   465                     }                
       
   466                 }  
       
   467             // look for destination id based on purpose
       
   468             else
       
   469                 {
       
   470                 if( destination.MetadataL( CMManager::ESnapMetadataPurpose ) == 
       
   471                                             aPurpose )
       
   472                     {
       
   473                     // found, save destination id and end search
       
   474                     destinationId =  destination.Id();
       
   475                     exists = KErrNone;
       
   476                     }
       
   477                 }
       
   478             CleanupStack::PopAndDestroy( &destination ); 
       
   479             }
       
   480         CleanupStack::PopAndDestroy( &destinations );
       
   481         }
       
   482     return destinationId;
       
   483     }
       
   484 
       
   485 // -----------------------------------------------------------------------------
       
   486 // CVcxConnUtilEngine::PrepareConnectionDetailsL()
       
   487 // -----------------------------------------------------------------------------
       
   488 //
       
   489 TBool CVcxConnUtilEngine::PrepareConnectionDetailsL( TInt aDestinationID )
       
   490     {
       
   491     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::PrepareConnectionDetailsL in");
       
   492     TBool connectionOk( EFalse );
       
   493     
       
   494     ResetConnectionInfo();
       
   495  
       
   496     if( aDestinationID )
       
   497         {
       
   498      
       
   499         MPX_DEBUG2( "CVcxConnUtilEngine::PrepareConnectionDetailsL destinationID: %d", aDestinationID);
       
   500         iDestinationId = aDestinationID;
       
   501         RCmDestinationExt destination = iCmManagerExt.DestinationL( aDestinationID );
       
   502         CleanupClosePushL(destination);
       
   503         
       
   504         iDestinationName = destination.NameLC();        
       
   505         CleanupStack::Pop( iDestinationName );
       
   506         
       
   507         MPX_DEBUG2( "CVcxConnUtilEngine::PrepareConnectionDetailsL destination name: %S", iDestinationName);
       
   508                 
       
   509         TInt cmCount = destination.ConnectionMethodCount();
       
   510         MPX_DEBUG2( "CVcxConnUtilEngine::PrepareConnectionDetailsL method count: %d", cmCount);
       
   511         if( cmCount )
       
   512             {
       
   513             connectionOk = ETrue;
       
   514             }
       
   515         CleanupStack::PopAndDestroy( &destination );
       
   516         }
       
   517     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::PrepareConnectionDetailsL out");
       
   518     return connectionOk;
       
   519     }
       
   520 
       
   521 // -----------------------------------------------------------------------------
       
   522 // CVcxConnUtilEngine::IsIapConnected()
       
   523 // -----------------------------------------------------------------------------
       
   524 //
       
   525 TBool CVcxConnUtilEngine::IsIapConnected( TUint32 aIapId )
       
   526     {  
       
   527     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::IsIapConnected in");
       
   528     TBool connected( EFalse );
       
   529     TRAPD( err, connected = 
       
   530       iCmManagerExt.GetConnectionMethodInfoBoolL( aIapId, CMManager::ECmConnected ) )
       
   531     
       
   532     if( err != KErrNone )
       
   533         {
       
   534         connected = EFalse;
       
   535         }
       
   536     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::IsIapConnected out");
       
   537     return connected;
       
   538     }
       
   539 
       
   540 // -----------------------------------------------------------------------------
       
   541 // CVcxConnUtilEngine::FillActiveConnectionDetailsL()
       
   542 // -----------------------------------------------------------------------------
       
   543 //
       
   544 void CVcxConnUtilEngine::FillActiveConnectionDetailsL() 
       
   545     {
       
   546     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::FillActiveConnectionDetailsL in");
       
   547     // fill in connection information from the latest connection
       
   548     TRequestStatus status;
       
   549     TUint connectionCount(0);    
       
   550     iConnectionMonitor.GetConnectionCount(connectionCount, status);
       
   551     User::WaitForRequest( status );
       
   552     User::LeaveIfError(status.Int());
       
   553              
       
   554     if (connectionCount)
       
   555         {
       
   556         // fill in IAP Id
       
   557         iConnection.GetIntSetting( KCommDBIapId, iIapId );       
       
   558         MPX_DEBUG2( "CVcxConnUtilEngine::FillActiveConnectionDetailsL iap id: %d", iIapId );
       
   559         
       
   560         // get current connection id
       
   561         TBool found( EFalse );
       
   562         TUint subConnCount( 0 );
       
   563         for ( TInt i ( 1 ); i <= connectionCount && !found; i ++ )
       
   564             {
       
   565             TUint connectionId; 
       
   566             User::LeaveIfError( iConnectionMonitor.GetConnectionInfo( i, 
       
   567                                                                       connectionId, 
       
   568                                                                       subConnCount ) );          
       
   569             TUint iapIdToCheck;                                              
       
   570             iConnectionMonitor.GetUintAttribute( 
       
   571                                 connectionId, 0, KIAPId, iapIdToCheck, status );
       
   572             // Note: Codescanner generates here pointless warning. We need to get data synchronously.
       
   573             User::WaitForRequest ( status ); 
       
   574             User::LeaveIfError( status.Int() );
       
   575             
       
   576             if ( iapIdToCheck == iIapId ) 
       
   577                 { 
       
   578                 // found 
       
   579                 iCurrentConnectionId = connectionId; 
       
   580                 found = ETrue;
       
   581                 }                
       
   582             }
       
   583                       
       
   584         if( !iDestinationId )
       
   585             {
       
   586             // try to fill destination info if not yet gotten
       
   587             FillDestinationInfoL();
       
   588             }     
       
   589         }  
       
   590     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::FillActiveConnectionDetailsL out");
       
   591     }
       
   592   
       
   593 // -----------------------------------------------------------------------------
       
   594 // CVcxConnUtilEngine::IapId()
       
   595 // -----------------------------------------------------------------------------
       
   596 //
       
   597 TUint32 CVcxConnUtilEngine::IapId() const
       
   598     {
       
   599     MPX_DEBUG2( "vcxconnutil  ## CVcxConnUtilEngine::IapId %d", iIapId );
       
   600 
       
   601     return iIapId;
       
   602     }
       
   603 
       
   604 // -----------------------------------------------------------------------------
       
   605 // CVcxConnUtilEngine::DestinationId()
       
   606 // -----------------------------------------------------------------------------
       
   607 //
       
   608 TInt CVcxConnUtilEngine::DestinationId() const
       
   609     {
       
   610     return iDestinationId;
       
   611     }
       
   612 
       
   613 // -----------------------------------------------------------------------------
       
   614 // CVcxConnUtilEngine::ConnectionStatus()
       
   615 // -----------------------------------------------------------------------------
       
   616 //
       
   617 TVCxConnectionStatus CVcxConnUtilEngine::ConnectionStatus() const
       
   618     {
       
   619     MPX_DEBUG2( "vcxconnutil  ## CVcxConnUtilEngine::ConnectionStatus %d", iConnectionState );
       
   620     return iConnectionState;
       
   621     }
       
   622 
       
   623 // -----------------------------------------------------------------------------
       
   624 // CVcxConnUtilEngine::SetConnectionStatus()
       
   625 // -----------------------------------------------------------------------------
       
   626 //
       
   627 void CVcxConnUtilEngine::SetConnectionStatus( TVCxConnectionStatus aStatus )
       
   628     {
       
   629     iConnectionState = aStatus;
       
   630     }
       
   631 
       
   632 
       
   633 // -----------------------------------------------------------------------------
       
   634 // CVcxConnUtilEngine::DestinationName()
       
   635 // -----------------------------------------------------------------------------
       
   636 //
       
   637 TPtrC CVcxConnUtilEngine::DestinationName() const
       
   638     {
       
   639     if ( iDestinationName )
       
   640         {
       
   641         return iDestinationName->Des();
       
   642         } 
       
   643     return TPtrC();
       
   644     }
       
   645 
       
   646 // -----------------------------------------------------------------------------
       
   647 // CVcxConnUtilEngine::ResetConnectionInfo()
       
   648 // -----------------------------------------------------------------------------
       
   649 //
       
   650 void CVcxConnUtilEngine::ResetConnectionInfo()
       
   651     {
       
   652     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::ResetConnectionInfo in");
       
   653     iIapId = 0;
       
   654     delete iDestinationName;
       
   655     iDestinationName = 0;
       
   656     iDestinationId = 0;
       
   657     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::ResetConnectionInfo out");
       
   658     }
       
   659 
       
   660 // -----------------------------------------------------------------------------
       
   661 // CVcxConnUtilEngine::FillDestinationInfoL()
       
   662 // -----------------------------------------------------------------------------
       
   663 //
       
   664 void CVcxConnUtilEngine::FillDestinationInfoL( )
       
   665     {
       
   666     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::FillDestinationInfoL in");
       
   667     TInt count = iDestinationArray.Count();
       
   668     delete iDestinationName;
       
   669     iDestinationName = 0;
       
   670     iDestinationId = 0;
       
   671     
       
   672     TBool found( EFalse );
       
   673     for( TUint destIndex = 0; destIndex < count && !found; ++destIndex )
       
   674         {
       
   675         RCmDestinationExt destination = 
       
   676             iCmManagerExt.DestinationL( iDestinationArray[ destIndex ] );
       
   677         
       
   678         CleanupClosePushL( destination );
       
   679         TInt cmCount = destination.ConnectionMethodCount();
       
   680 
       
   681         for ( TUint methIndex = 0; methIndex < cmCount && !found; ++methIndex )
       
   682             {
       
   683             RCmConnectionMethodExt connectionMethod = destination.ConnectionMethodL( methIndex );
       
   684             CleanupClosePushL( connectionMethod );
       
   685             if( iIapId == connectionMethod.GetIntAttributeL( CMManager::ECmIapId ) )
       
   686                 {
       
   687                 // found, save data
       
   688                 iDestinationId = iDestinationArray[ destIndex ];
       
   689                 MPX_DEBUG2( "CVcxConnUtilEngine::FillDestinationInfoL destination found: %d", iDestinationId );
       
   690                 iDestinationName = destination.NameLC();                
       
   691                 CleanupStack::Pop( iDestinationName );
       
   692                 found = ETrue;
       
   693                 MPX_DEBUG2( "CVcxConnUtilEngine::FillDestinationInfoL snap name: %S", iDestinationName );
       
   694                 }
       
   695             CleanupStack::PopAndDestroy( &connectionMethod );
       
   696             }
       
   697         CleanupStack::PopAndDestroy( &destination );
       
   698         }
       
   699     MPX_DEBUG1( "vcxconnutil  ## CVcxConnUtilEngine::FillDestinationInfoL out");
       
   700     }
       
   701 
       
   702 // -----------------------------------------------------------------------------
       
   703 // CVcxConnUtilEngine::DoCancel()
       
   704 // -----------------------------------------------------------------------------
       
   705 //
       
   706 void CVcxConnUtilEngine::DoCancel()
       
   707     {
       
   708    
       
   709     if( iConnectionState == EVCxConnecting )
       
   710         {
       
   711         MPX_FUNC( "CVcxConnUtilEngine::DoCancel disconnect");
       
   712         Disconnect();
       
   713         }
       
   714     iConnectingResult = KErrCancel;
       
   715     iObserver->EndWait( EVCxPSConnectionStatus );
       
   716     }
       
   717 
       
   718 // -----------------------------------------------------------------------------
       
   719 // CVcxConnUtilEngine::RunL()
       
   720 // -----------------------------------------------------------------------------
       
   721 //
       
   722 void CVcxConnUtilEngine::RunL()
       
   723     {
       
   724     if ( iStatus.Int() != KErrNone )
       
   725         {
       
   726         iConnectingResult = iStatus.Int();
       
   727         iConnectionState = EVCxNotConnected;
       
   728         }
       
   729     else
       
   730         {
       
   731         iConnectingResult = KErrNone;
       
   732         if( iConnectionState == EVCxConnecting )
       
   733             {                            
       
   734             iConnectionState = EVCxConnected;
       
   735             }
       
   736         }
       
   737     iObserver->EndWait( EVCxPSConnectionStatus );
       
   738        
       
   739     }
       
   740 
       
   741 // -----------------------------------------------------------------------------
       
   742 // CVcxConnUtilEngine::QueryConn()
       
   743 // -----------------------------------------------------------------------------
       
   744 //
       
   745 TBool CVcxConnUtilEngine::QueryConn()
       
   746     {
       
   747     return iQueryConn;
       
   748     }
       
   749 
       
   750 // -----------------------------------------------------------------------------
       
   751 // CVcxConnUtilEngine::SetQueryConn()
       
   752 // -----------------------------------------------------------------------------
       
   753 //
       
   754 void CVcxConnUtilEngine::SetQueryConn( TBool aQueryConn )
       
   755     {
       
   756     iQueryConn = aQueryConn;
       
   757     }
       
   758 
       
   759 //  End of File