hti/HtiServicePlugins/HtiIpProxyServicePlugin/IPProxyEngine/Src/CIPProxyEngine.cpp
branchRCL_3
changeset 59 8ad140f3dd41
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of the main class for IPProxyEngine
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CIPProxyEngine.h"
       
    22 #include "Ctcpportlistener.h"
       
    23 #include "CLocalTCPConnection.h"
       
    24 #include "Csocketrouter.h"
       
    25 #include "MIPProxyEngineObserver.h"
       
    26 #include "MHostConnection.h"
       
    27 #include "MAbstractConnection.h"
       
    28 
       
    29 #define DEBUG_FILENAME "IPProxyEngine.log"
       
    30 #include "DebugPrint.h"
       
    31 
       
    32 const TInt KPeerDisconnectDelay = 60000000;  //60 seconds
       
    33 
       
    34 // ============================= LOCAL FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CleanupSocket RSocket pointer cleanup operation
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 LOCAL_C void CleanupSocket( TAny* aPtr )
       
    41     {
       
    42     RSocket* socket = ( RSocket* ) aPtr;
       
    43     if ( socket )
       
    44         {
       
    45         socket->Close();
       
    46         delete socket;
       
    47         }
       
    48     }
       
    49 
       
    50 // ============================ MEMBER FUNCTIONS ===============================
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CIPProxyEngine::CIPProxyEngine
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CIPProxyEngine::CIPProxyEngine( MAbstractConnection* aConnection )
       
    57     : CActive( EPriorityStandard ), iAbstractConnection( aConnection )
       
    58     {
       
    59     __ASSERT_DEBUG( iAbstractConnection, User::Invariant() );
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CIPProxyEngine::ConstructL
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 void CIPProxyEngine::ConstructL()
       
    67     {
       
    68     DEBUG_PRINT( DEBUG_STRING( "CSocketRouter::ConstructL()" ) );
       
    69 
       
    70     User::LeaveIfError( iTimer.CreateLocal() );
       
    71     User::LeaveIfError( iSocketServ.Connect() );
       
    72 
       
    73     iHostConnection = iAbstractConnection->GetHostConnection();
       
    74     __ASSERT_DEBUG( iHostConnection, User::Invariant() );
       
    75     iHostConnection->SetObserver( this );
       
    76 
       
    77     // Peer array. Granularity 10 suits fine.
       
    78     iPeerListenerArray = new (ELeave) CArrayPtrFlat<CTCPPortListener> ( 10 );
       
    79 
       
    80     // Local TCP connections array
       
    81     iLocalConnArray = new (ELeave) CArrayPtrFlat<CLocalTCPConnection> ( 5 );
       
    82 
       
    83     iSocketRouter = CSocketRouter::NewL( this );
       
    84 
       
    85     CActiveScheduler::Add( this );
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CIPProxyEngine::NewL
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 CIPProxyEngine* CIPProxyEngine::NewL( MAbstractConnection* aConnection )
       
    93     {
       
    94     CIPProxyEngine* self = CIPProxyEngine::NewLC( aConnection );
       
    95     CleanupStack::Pop();
       
    96 
       
    97     return self;
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CIPProxyEngine::NewLC
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 CIPProxyEngine* CIPProxyEngine::NewLC( MAbstractConnection* aConnection )
       
   105     {
       
   106     CIPProxyEngine* self = new( ELeave ) CIPProxyEngine( aConnection );
       
   107     CleanupStack::PushL( self );
       
   108 
       
   109     self->ConstructL();
       
   110     return self;
       
   111     }
       
   112 
       
   113 
       
   114 // Destructor
       
   115 CIPProxyEngine::~CIPProxyEngine()
       
   116     {
       
   117     Cancel();
       
   118     iTimer.Close();
       
   119     delete iSocketRouter;
       
   120 
       
   121     if ( iPeerListenerArray )
       
   122         {
       
   123         iPeerListenerArray->ResetAndDestroy();
       
   124         delete iPeerListenerArray;
       
   125         }
       
   126     if ( iLocalConnArray )
       
   127         {
       
   128         iLocalConnArray->ResetAndDestroy();
       
   129         delete iLocalConnArray;
       
   130         }
       
   131 
       
   132     iSocketServ.Close();
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CIPProxyEngine::RunL
       
   137 // This is called when the timer expires
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 void CIPProxyEngine::RunL()
       
   141     {
       
   142     DEBUG_PRINT( DEBUG_STRING( "CIPProxyEngine::RunL()" ) );
       
   143     DEBUG_PRINT( DEBUG_STRING( "    peer count = %d" ),
       
   144         iSocketRouter->SocketCount() );
       
   145 
       
   146     if ( iSocketRouter->SocketCount() == 0 )
       
   147         {
       
   148         iHostConnection->IssueDisconnect();
       
   149         }
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CIPProxyEngine::DoCancel
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CIPProxyEngine::DoCancel()
       
   157     {
       
   158     iTimer.Cancel();
       
   159     DEBUG_PRINT( DEBUG_STRING( "Timeout timer cancelled" ) );
       
   160     }
       
   161 
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CIPProxyEngine::SetObserver
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 void CIPProxyEngine::SetObserver( MIPProxyEngineObserver* aObserver )
       
   168     {
       
   169     iObserver = aObserver;
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CIPProxyEngine::AddPeerListeningPortL
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void CIPProxyEngine::AddPeerListeningPortL( TInt aPort )
       
   177     {
       
   178     DEBUG_PRINT( DEBUG_STRING(
       
   179         "CIPProxyEngine::AddPeerListeningPortL(%d)" ), aPort );
       
   180 
       
   181     CTCPPortListener* newListener = CTCPPortListener::NewLC( aPort, this );
       
   182     iPeerListenerArray->AppendL( newListener );
       
   183     if ( iListening )
       
   184         {
       
   185         newListener->IssueListen();
       
   186         }
       
   187     CleanupStack::Pop( newListener );
       
   188 
       
   189     DEBUG_PRINT( DEBUG_STRING(
       
   190         "CIPProxyEngine::AddPeerListeningPortL, Adding also UDP listener(%d)" ),
       
   191          aPort );
       
   192 
       
   193     // Adding also UDP listener for the port
       
   194     iSocketRouter->AddUDPSocketL( aPort );
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CIPProxyEngine::StartListening
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 void CIPProxyEngine::StartListening()
       
   202     {
       
   203     DEBUG_PRINT( DEBUG_STRING(
       
   204         "CIPProxyEngine::StartListening()" ) );
       
   205     TInt peerListenerArrayCount = iPeerListenerArray->Count();
       
   206     for ( TInt i = 0; i < peerListenerArrayCount; i++ )
       
   207         {
       
   208         iPeerListenerArray->At( i )->IssueListen();
       
   209         }
       
   210     iListening = ETrue;
       
   211 
       
   212     AssureConnectionL();
       
   213     }
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // CIPProxyEngine::StopListening
       
   217 // -----------------------------------------------------------------------------
       
   218 //
       
   219 void CIPProxyEngine::StopListening()
       
   220     {
       
   221     DEBUG_PRINT( DEBUG_STRING(
       
   222         "CIPProxyEngine::StopListening()" ) );
       
   223 
       
   224     TInt peerListenerArrayCount = iPeerListenerArray->Count();
       
   225     for ( TInt i = 0; i < peerListenerArrayCount; i++ )
       
   226         {
       
   227         iPeerListenerArray->At( i )->Cancel();
       
   228         }
       
   229     iListening = EFalse;
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CIPProxyEngine::DisconnectAllConnections
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 void CIPProxyEngine::DisconnectAllConnections()
       
   237     {
       
   238     }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CIPProxyEngine::ConnectionAcceptedL
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 void CIPProxyEngine::ConnectionAcceptedL( RSocket* aSocket )
       
   245     {
       
   246     DEBUG_PRINT( DEBUG_STRING(
       
   247         "CIPProxyEngine::ConnectionAcceptedL()" ) );
       
   248 
       
   249     Cancel();   //Possible timeout timer
       
   250 
       
   251     CleanupStack::PushL( TCleanupItem( CleanupSocket, aSocket ) );
       
   252     iSocketRouter->AddPeerSocketL( aSocket );
       
   253     CleanupStack::Pop(); //aSocket
       
   254 
       
   255     AssureConnectionL();
       
   256     }
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // CIPProxyEngine::ErrorL
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 void CIPProxyEngine::ErrorL( TInt aErrorCode )
       
   263     {
       
   264     DEBUG_PRINT( DEBUG_STRING(
       
   265         "CIPProxyEngine::ErrorL(%d)" ), aErrorCode );
       
   266     }
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // CIPProxyEngine::ObserverLeaved
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 void CIPProxyEngine::ObserverLeaved( TInt aLeaveCode )
       
   273     {
       
   274     DEBUG_PRINT( DEBUG_STRING(
       
   275         "CIPProxyEngine::ObserverLeaved(%d)" ), aLeaveCode );
       
   276     if ( iObserver )
       
   277         {
       
   278         iObserver->ObserverLeaved( aLeaveCode );
       
   279         }
       
   280     }
       
   281 
       
   282 
       
   283 // -----------------------------------------------------------------------------
       
   284 // CIPProxyEngine::ConnectionEstablishedL
       
   285 // -----------------------------------------------------------------------------
       
   286 //
       
   287 void CIPProxyEngine::ConnectionEstablishedL()
       
   288     {
       
   289     // Connection to host established via bluetooth
       
   290 
       
   291     DEBUG_PRINT( DEBUG_STRING(
       
   292         "CIPProxyEngine::ConnectionEstablishedL()" ) );
       
   293 
       
   294     MSocket* socket = iAbstractConnection->GetSocket();
       
   295     if ( socket )
       
   296         {
       
   297         iSocketRouter->SetHostSocketL( socket );
       
   298         iSocketRouter->StartRouting();
       
   299         }
       
   300     }
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // CIPProxyEngine::HostConnectionErrorL
       
   304 // -----------------------------------------------------------------------------
       
   305 //
       
   306 void CIPProxyEngine::HostConnectionErrorL( TInt aErrorCode )
       
   307     {
       
   308     DEBUG_PRINT( DEBUG_STRING(
       
   309         "CIPProxyEngine::HostConnectionErrorL(%d)" ), aErrorCode );
       
   310     iHostConnection->IssueDisconnect();
       
   311     iSocketRouter->RemoveAllPeers();
       
   312     iSocketRouter->StopRouting();
       
   313     iSocketRouter->ResetQueue();
       
   314     }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // CIPProxyEngine::HostConnectionObserverLeaved
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 void CIPProxyEngine::HostConnectionObserverLeaved( TInt aLeaveCode )
       
   321     {
       
   322     DEBUG_PRINT( DEBUG_STRING(
       
   323         "CIPProxyEngine::HostConnectionObserverLeaved(%d)" ), aLeaveCode );
       
   324     if ( iObserver )
       
   325         {
       
   326         iObserver->ObserverLeaved( aLeaveCode );
       
   327         }
       
   328     }
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // CIPProxyEngine::LocalTCPConnectionEstablishedL
       
   332 // -----------------------------------------------------------------------------
       
   333 //
       
   334 void CIPProxyEngine::LocalTCPConnectionEstablishedL( TUint aPort )
       
   335     {
       
   336     // Connection to local host (via TCP connection) established.
       
   337 
       
   338     DEBUG_PRINT( DEBUG_STRING(
       
   339         "CIPProxyEngine::LocalTCPConnectionEstablishedL(), port=%d" ), aPort );
       
   340 
       
   341     // TCP connection that was initiated from the PC side, got connected
       
   342     DEBUG_PRINT( DEBUG_STRING(
       
   343         "CIPProxyEngine::ConnectionEstablishedL() -\
       
   344          Local conn. was connected, adding the socket to socket router" ) );
       
   345 
       
   346     TInt connIndex = FindLocalTCPConn( aPort );
       
   347     if ( connIndex >= 0 )
       
   348         {
       
   349         CLocalTCPConnection* conn = iLocalConnArray->At( connIndex );
       
   350         iSocketRouter->AddPeerSocketL( conn->Socket() );
       
   351         // Socket router took ownership of the socket
       
   352         conn->SetSocketOwnership( EFalse );
       
   353         // Connection was established,
       
   354         conn->Cancel();
       
   355         }
       
   356     }
       
   357 
       
   358 // -----------------------------------------------------------------------------
       
   359 // CIPProxyEngine::LocalTCPConnectionErrorL
       
   360 // -----------------------------------------------------------------------------
       
   361 //
       
   362 void CIPProxyEngine::LocalTCPConnectionErrorL( TInt aPort, TInt aErrorCode )
       
   363     {
       
   364     DEBUG_PRINT( DEBUG_STRING(
       
   365         "CIPProxyEngine::LocalTCPConnectionErrorL(%d)" ), aErrorCode );
       
   366 
       
   367     TInt connIndex = FindLocalTCPConn( aPort );
       
   368     if ( connIndex >= 0 )
       
   369         {
       
   370         RSocket* localSocket = iLocalConnArray->At( connIndex )->Socket();
       
   371         iSocketRouter->RemovePeerSocket( localSocket );
       
   372         iLocalConnArray->Delete( connIndex );
       
   373         }
       
   374     }
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // CIPProxyEngine::LocalTCPConnectionObserverLeaved
       
   378 // -----------------------------------------------------------------------------
       
   379 //
       
   380 void CIPProxyEngine::LocalTCPConnectionObserverLeaved( TInt aPort,
       
   381                                                        TInt aLeaveCode )
       
   382     {
       
   383     DEBUG_PRINT( DEBUG_STRING(
       
   384         "CIPProxyEngine::HostConnectionObserverLeaved(%d), port%d" ),
       
   385         aLeaveCode, aPort );
       
   386     if ( iObserver )
       
   387         {
       
   388         iObserver->ObserverLeaved( aLeaveCode );
       
   389         }
       
   390     }
       
   391 
       
   392 // -----------------------------------------------------------------------------
       
   393 // CIPProxyEngine::SocketRouterErrorL
       
   394 // -----------------------------------------------------------------------------
       
   395 //
       
   396 void CIPProxyEngine::SocketRouterErrorL(
       
   397     const MSocket* /*aSocket*/, TInt aErrorCode )
       
   398     {
       
   399     DEBUG_PRINT( DEBUG_STRING(
       
   400         "CIPProxyEngine::SocketRouterErrorL(%d)" ), aErrorCode );
       
   401 
       
   402     if ( aErrorCode == -6305 )  //BT disconnected
       
   403         {
       
   404         iHostConnection->IssueDisconnect();
       
   405         iSocketRouter->RemoveAllPeers();
       
   406         iSocketRouter->StopRouting();
       
   407         iSocketRouter->ResetQueue();
       
   408         }
       
   409     }
       
   410 
       
   411 // -----------------------------------------------------------------------------
       
   412 // CIPProxyEngine::ObserverLeaved
       
   413 // -----------------------------------------------------------------------------
       
   414 //
       
   415 void CIPProxyEngine::ObserverLeaved(
       
   416     const MSocket* /*aSocket*/, TInt aLeaveCode )
       
   417     {
       
   418     DEBUG_PRINT( DEBUG_STRING(
       
   419         "CIPProxyEngine::ObserverLeaved(%d)" ), aLeaveCode );
       
   420     if ( iObserver )
       
   421         {
       
   422         iObserver->ObserverLeaved( aLeaveCode );
       
   423         }
       
   424     }
       
   425 
       
   426 // -----------------------------------------------------------------------------
       
   427 // CIPProxyEngine::PeerDisconnectedL
       
   428 // -----------------------------------------------------------------------------
       
   429 //
       
   430 void CIPProxyEngine::PeerDisconnectedL( const MSocket* aSocket )
       
   431     {
       
   432     DEBUG_PRINT( DEBUG_STRING(
       
   433         "CIPProxyEngine::PeerDisconnectedL(), localPort= %d. remotePort=%d" ),
       
   434         aSocket->LocalPort(), aSocket->RemotePort() );
       
   435 
       
   436     // Check if the socket was a local TCP connection socket
       
   437     TInt indexOfConn = -1;
       
   438     indexOfConn = FindLocalTCPConn( aSocket->RemotePort() );
       
   439     if ( indexOfConn >= 0 )
       
   440         {
       
   441         // Notify PC side that the connection was disconnected
       
   442         iSocketRouter->SendCloseTCPConnection( aSocket->RemotePort() );
       
   443 
       
   444         DEBUG_PRINT( DEBUG_STRING(
       
   445             "CIPProxyEngine::PeerDisconnectedL(), Deleting local connection." ),
       
   446             aSocket->LocalPort(), aSocket->RemotePort() );
       
   447         iLocalConnArray->Delete( indexOfConn );
       
   448         }
       
   449 
       
   450     Cancel();
       
   451     iTimer.After( iStatus, KPeerDisconnectDelay );
       
   452     SetActive();
       
   453     DEBUG_PRINT( DEBUG_STRING( "Timeout timer activated" ) );
       
   454 
       
   455     if ( iSocketRouter->SocketCount() == 0 )
       
   456         {
       
   457         iSocketRouter->StopRouting();
       
   458         }
       
   459     }
       
   460 
       
   461 // -----------------------------------------------------------------------------
       
   462 // CIPProxyEngine::HostDisconnectedL
       
   463 // -----------------------------------------------------------------------------
       
   464 //
       
   465 void CIPProxyEngine::HostDisconnectedL( const MSocket* /*aSocket*/ )
       
   466     {
       
   467     iHostConnection->IssueDisconnect();
       
   468     if ( iSocketRouter->IsRouting() )
       
   469         {
       
   470         iSocketRouter->StopRouting();
       
   471         }
       
   472     iSocketRouter->ResetQueue();
       
   473     iSocketRouter->RemoveAllPeers();
       
   474     }
       
   475 
       
   476 // -----------------------------------------------------------------------------
       
   477 // CIPProxyEngine::OpenLocalTCPConnectionL
       
   478 // -----------------------------------------------------------------------------
       
   479 //
       
   480 void CIPProxyEngine::OpenLocalTCPConnectionL( TUint aPort )
       
   481     {
       
   482     DEBUG_PRINT( DEBUG_STRING(
       
   483         "CIPProxyEngine::OpenLocalTCPConnectionL(), port=%d"), aPort );
       
   484 
       
   485     CLocalTCPConnection* newConn =
       
   486         CLocalTCPConnection::NewLC( this, aPort );
       
   487 
       
   488     DEBUG_PRINT( DEBUG_STRING(
       
   489         "CIPProxyEngine::OpenLocalTCPConnectionL(), Issuing connection") );
       
   490     iLocalConnArray->AppendL( newConn );
       
   491     CleanupStack::Pop( newConn );
       
   492 
       
   493     newConn->IssueConnectL();
       
   494     }
       
   495 
       
   496 // -----------------------------------------------------------------------------
       
   497 // CIPProxyEngine::OpenListeningTCPConnectionL
       
   498 // -----------------------------------------------------------------------------
       
   499 //
       
   500 void CIPProxyEngine::OpenListeningTCPConnectionL( TUint aPort )
       
   501     {
       
   502     DEBUG_PRINT( DEBUG_STRING(
       
   503         "CIPProxyEngine::OpenListeningTCPConnectionL(), port=%d"), aPort );
       
   504 
       
   505     TInt count = iPeerListenerArray->Count();
       
   506     for ( TInt i = 0; i < count; i++ )
       
   507         {
       
   508         if ( iPeerListenerArray->At( i )->Port() == aPort )
       
   509             {
       
   510             // Port already listening
       
   511             return;
       
   512             }
       
   513         }
       
   514 
       
   515     // AddPeerListeningPortL will call IssueListen() only if iListening is set
       
   516     // to ETrue
       
   517     iListening = ETrue;
       
   518     AddPeerListeningPortL( aPort );
       
   519     AssureConnectionL();
       
   520     }
       
   521 
       
   522 // -----------------------------------------------------------------------------
       
   523 // CIPProxyEngine::CloseTCPConnection
       
   524 // -----------------------------------------------------------------------------
       
   525 //
       
   526 void CIPProxyEngine::CloseTCPConnection( TUint aPort )
       
   527     {
       
   528     DEBUG_PRINT( DEBUG_STRING(
       
   529         "CIPProxyEngine::CloseTCPConnection(), port=%d"), aPort );
       
   530 
       
   531     // Delete local TCP connections
       
   532     TInt index = FindLocalTCPConn( aPort );
       
   533     if ( index > -1 )
       
   534         {
       
   535         CLocalTCPConnection* conn = iLocalConnArray->At( index );
       
   536         iLocalConnArray->Delete( index );
       
   537         delete conn;
       
   538 
       
   539         DEBUG_PRINT( DEBUG_STRING(
       
   540             "CIPProxyEngine::CloseTCPConnection(), conn deleted.") );
       
   541         }
       
   542     
       
   543     // stop listening on this port
       
   544     TInt peerListenerArrayCount = iPeerListenerArray->Count();
       
   545     for ( TInt i = 0; i < peerListenerArrayCount; i++ )
       
   546         {
       
   547         CTCPPortListener* listener = iPeerListenerArray->At( i );
       
   548         if(listener->Port() == aPort)
       
   549             {
       
   550             listener->Cancel();
       
   551             iPeerListenerArray->Delete(i);
       
   552             delete listener;
       
   553             break;
       
   554             }
       
   555         }
       
   556     
       
   557     if(iPeerListenerArray->Count() == 0)
       
   558         {
       
   559         iListening = EFalse;
       
   560         }
       
   561     }
       
   562 
       
   563 // -----------------------------------------------------------------------------
       
   564 // CIPProxyEngine::CloseAllTCPConnections
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 void CIPProxyEngine::CloseAllTCPConnections()
       
   568     {
       
   569     DEBUG_PRINT( DEBUG_STRING(
       
   570         "CIPProxyEngine::CloseAllTCPConnections()" ) );
       
   571 
       
   572     iSocketRouter->ResetQueue();
       
   573     iSocketRouter->RemoveAllPeers();
       
   574 
       
   575     iLocalConnArray->ResetAndDestroy();
       
   576     
       
   577     StopListening();
       
   578 
       
   579     if ( iPeerListenerArray )
       
   580         {
       
   581         iPeerListenerArray->ResetAndDestroy();
       
   582         }
       
   583     }
       
   584 
       
   585 // -----------------------------------------------------------------------------
       
   586 // CIPProxyEngine::FindLocalTCPConn
       
   587 // -----------------------------------------------------------------------------
       
   588 //
       
   589 TInt CIPProxyEngine::FindLocalTCPConn( TUint aPort )
       
   590     {
       
   591     DEBUG_PRINT( DEBUG_STRING(
       
   592         "CIPProxyEngine::FindLocalTCPConn(), port=%d"), aPort );
       
   593     for ( TInt i = 0; i < iLocalConnArray->Count(); i++ )
       
   594         {
       
   595         if ( iLocalConnArray->At(i)->Port() == aPort )
       
   596             {
       
   597             return i;
       
   598             }
       
   599         }
       
   600     return -1;
       
   601     }
       
   602 
       
   603 // -----------------------------------------------------------------------------
       
   604 // CIPProxyEngine::AssureConnectionL
       
   605 // -----------------------------------------------------------------------------
       
   606 //
       
   607 void CIPProxyEngine::AssureConnectionL()
       
   608     {
       
   609     DEBUG_PRINT( DEBUG_STRING(
       
   610         "AssureConnectionL()" ) );
       
   611     if ( iHostConnection->IsConnected() )
       
   612         {
       
   613         DEBUG_PRINT( DEBUG_STRING(
       
   614             "AssureConnectionL, connected" ) );
       
   615         if ( !iSocketRouter->IsRouting() )
       
   616             {
       
   617             DEBUG_PRINT( DEBUG_STRING(
       
   618                 "AssureConnectionL, starting routing" ) );
       
   619             iSocketRouter->StartRouting();
       
   620             }
       
   621         }
       
   622     else
       
   623         {
       
   624         DEBUG_PRINT( DEBUG_STRING(
       
   625             "AssureConnectionL, not connected, connecting" ) );
       
   626         iHostConnection->IssueConnectL();
       
   627         }
       
   628     }
       
   629 //  End of File