realtimenetprots/sipfw/SIP/ConnectionMgr/src/CConnectionContainer.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name          : CConnectionContainer.cpp
       
    15 // Part of       : ConnectionMgr
       
    16 // Implementation
       
    17 // Version       : SIP/4.0
       
    18 //
       
    19 
       
    20 
       
    21 
       
    22 #include "CConnectionContainer.h"
       
    23 #include "CConnectionMonitor.h"
       
    24 #include "sipnetworkobserver.h"
       
    25 #include "SipLogs.h"
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CConnectionContainer::NewL
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 CConnectionContainer* CConnectionContainer::NewL( 
       
    32     MSIPNetworkObserver& aObserver )
       
    33 	{
       
    34 	CConnectionContainer* self = 
       
    35 		new( ELeave ) CConnectionContainer( aObserver );
       
    36 	CleanupStack::PushL( self );
       
    37 	self->ConstructL();
       
    38 	CleanupStack::Pop( self );
       
    39 	return self;
       
    40 	}
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CConnectionContainer::CConnectionContainer
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CConnectionContainer::CConnectionContainer( MSIPNetworkObserver& aObserver ) :
       
    47 	CActive( CActive::EPriorityStandard ),
       
    48 	iObserver( aObserver )
       
    49 	{
       
    50 	CActiveScheduler::Add( this );
       
    51 	}
       
    52 	
       
    53 // -----------------------------------------------------------------------------
       
    54 // CConnectionContainer::ConstructL
       
    55 // -----------------------------------------------------------------------------
       
    56 //	
       
    57 void CConnectionContainer::ConstructL()
       
    58 	{	
       
    59 	iMonitor = CConnectionMonitor::NewL(iObserver,iConnection);
       
    60 	}
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CConnectionContainer::~CConnectionContainer
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CConnectionContainer::~CConnectionContainer()
       
    67 	{
       
    68 	delete iMonitor;
       
    69 	iConnection.Close();	
       
    70 	Cancel();
       
    71 	}
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CConnectionContainer::RunL
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 void CConnectionContainer::RunL()
       
    78 	{
       
    79 	__SIP_INT_LOG1( "CConnectionContainer::RunL", iStatus.Int() )
       
    80 	
       
    81 	iMonitor->StartMonitoring();
       
    82 
       
    83 	iObserver.NetworkStateChanged( MSIPNetworkObserver::ENetworkConnected,
       
    84 	                               iStatus.Int() );
       
    85 	}
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CConnectionContainer::DoCancel
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 void CConnectionContainer::DoCancel()
       
    92 	{
       
    93 	iConnection.Close();
       
    94 	}
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CConnectionContainer::Connection
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 RConnection& CConnectionContainer::Connection()
       
   101 	{
       
   102 	return iConnection;
       
   103 	}
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CConnectionContainer::OpenConnection
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 TInt CConnectionContainer::OpenConnection( TUint32 aIapId,
       
   110 										   RSocketServ& aServer )
       
   111 	{
       
   112 	__SIP_INT_LOG1( "CConnectionContainer::OpenConnection entered", aIapId )
       
   113 	
       
   114 	TInt err = KErrNone;
       
   115 	if( !IsActive() )
       
   116 		{
       
   117 		err = OpenConnection( aServer );
       
   118 
       
   119 		if (!err)
       
   120 			{
       
   121 		// Set connection preferences
       
   122 		iExtPrefs.SetIapId( aIapId );
       
   123 		TRAPD(error, iPrefList.AppendL(&iExtPrefs));
       
   124 		if(error)
       
   125 			{
       
   126 		return error;
       
   127 			}
       
   128     		// Start connecting
       
   129     		iConnection.Start( iPrefList, iStatus );
       
   130     		SetActive();
       
   131 			}
       
   132 		}
       
   133 		
       
   134 	__SIP_INT_LOG1( "CConnectionContainer::OpenConnection returns", err )	
       
   135 		
       
   136 	return err;
       
   137 	}
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CConnectionContainer::CloseConnection
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 void CConnectionContainer::CloseConnection()
       
   144 	{
       
   145 	__SIP_LOG( "CConnectionContainer::CloseConnection returns" )
       
   146 	
       
   147 	iMonitor->StopMonitoring();
       
   148 	iConnection.Close();	
       
   149 	Cancel();
       
   150 	
       
   151 	__SIP_LOG( "CConnectionContainer::CloseConnection returns" )
       
   152 	}
       
   153 	
       
   154 // -----------------------------------------------------------------------------
       
   155 // CConnectionContainer::MonitorConnectionClosure
       
   156 // -----------------------------------------------------------------------------
       
   157 //	
       
   158 TInt CConnectionContainer::MonitorConnectionClosure( RSocketServ& aServer )
       
   159     {
       
   160     TInt err = OpenConnection( aServer );
       
   161         
       
   162     if ( !err )
       
   163         {
       
   164         iMonitor->MonitorConnectionClosure();
       
   165         }
       
   166     
       
   167     return err;
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CConnectionContainer::OpenConnection
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 TInt CConnectionContainer::OpenConnection( RSocketServ& aServer )
       
   175 	{
       
   176     TInt err( KErrNone );
       
   177     // If iConnection is already open don't reopen it.
       
   178 	if( !iConnection.SubSessionHandle() )
       
   179         {
       
   180         err = iConnection.Open( aServer );
       
   181         }
       
   182     return err;
       
   183 	}
       
   184 	
       
   185 // End of File