multimediacommsengine/mmcefloorctrlplugin/src/fcconnectioncontainer.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005-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 "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:    Floor Control
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "fcconnectioncontainer.h"
       
    22 #include "fcconnectionnotifier.h"
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // CFCFCConnectionContainer::NewL
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 CFCConnectionContainer* CFCConnectionContainer::NewL( MFCConnectionNotifier& aNotifier )
       
    29 	{	
       
    30 	CFCConnectionContainer* self = 
       
    31 		new( ELeave ) CFCConnectionContainer( aNotifier );
       
    32 	return self;
       
    33 	}
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CFCFCConnectionContainer::CFCFCConnectionContainer
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CFCConnectionContainer::CFCConnectionContainer( MFCConnectionNotifier& aNotifier ) :
       
    40 	CActive( CActive::EPriorityStandard ),
       
    41 	iNotifier( aNotifier )
       
    42 	{
       
    43 	CActiveScheduler::Add( this );
       
    44 	}
       
    45 	
       
    46 // -----------------------------------------------------------------------------
       
    47 // CFCConnectionContainer::~CFCConnectionContainer
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CFCConnectionContainer::~CFCConnectionContainer()
       
    51 	{
       
    52 	
       
    53 	iConnection.Close();	
       
    54 	Cancel();
       
    55 	}
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CFCConnectionContainer::Connection
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 RConnection& CFCConnectionContainer::Connection()
       
    62 	{
       
    63 	return iConnection;
       
    64 	}
       
    65 // -----------------------------------------------------------------------------
       
    66 // CFCConnectionContainer::RunL
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 void CFCConnectionContainer::RunL()
       
    70 	{
       
    71 	TInt status = iStatus.Int();
       
    72 	if (status != KErrCancel)
       
    73 		{
       
    74 		iNotifier.ConnectionStarted(status );		
       
    75 		}
       
    76 	}
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CFCConnectionContainer::DoCancel
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CFCConnectionContainer::DoCancel()
       
    83 	{
       
    84 	iConnection.Close();
       
    85 	// RConnection doesn't cancel an outstanding request at Close()
       
    86 	// so we'll have to it "manually" here
       
    87 	if( iStatus.Int() == KRequestPending )
       
    88 		{
       
    89 		TRequestStatus* status = &iStatus;
       
    90 		User::RequestComplete( status, KErrCancel );
       
    91 		}
       
    92 	}
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CFCConnectionContainer::OpenConnection
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 TInt CFCConnectionContainer::OpenConnection( TUint32 aIapId,
       
    99 										   RSocketServ& aServer )
       
   100 	{
       
   101 	TInt err = KErrNone;
       
   102 	if( !IsActive() )
       
   103 		{
       
   104 		// If iConnection is already open don't reopen it.
       
   105 		if( !iConnection.SubSessionHandle() )
       
   106 			{
       
   107 			err = iConnection.Open( aServer );
       
   108 			}
       
   109 		if (!err)
       
   110 			{
       
   111 			// Set connection preferences
       
   112 			iPrefs.SetDialogPreference( ECommDbDialogPrefDoNotPrompt );
       
   113 			iPrefs.SetDirection( ECommDbConnectionDirectionOutgoing );
       
   114 			iPrefs.SetIapId( aIapId );
       
   115 			// Start connecting
       
   116 			iConnection.Start( iPrefs, iStatus );
       
   117 			SetActive();
       
   118 			}
       
   119 		}
       
   120 	return err;
       
   121 	}
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CFCConnectionContainer::CloseConnection
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CFCConnectionContainer::CloseConnection()
       
   128 	{
       
   129 	iConnection.Close();	
       
   130 	Cancel();
       
   131 	}