multimediacommscontroller/mmcccontroller/src/mccasynclinkcreator.cpp
changeset 0 1bce908db942
child 49 64c62431ac08
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     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 "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 MCC session creator active object
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <mmf/common/mmfcontrollerframework.h>
       
    22 #include <e32math.h>
       
    23 #include <es_sock.h>
       
    24 #include "mccasynclinkcreator.h"
       
    25 #include "mcculdlclient.h"
       
    26 #include "masynclinkcreationobserver.h"
       
    27 
       
    28 #ifdef _DEBUG
       
    29 #include <e32svr.h>
       
    30 #define TRACE_LINK_CREATOR
       
    31 #endif
       
    32 
       
    33 #ifdef VOIP_TRACE_ENABLED
       
    34 #include <voip_trace.h>
       
    35 #endif
       
    36 
       
    37 
       
    38 // ======== MEMBER FUNCTIONS ========
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // C++ Default constructor
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CMccAsyncLinkCreator::CMccAsyncLinkCreator( 
       
    45     MAsyncLinkCreationObserver& aObserver, CMccUlDlClient* aSession ) : 
       
    46     CActive( EPriorityStandard ), iObserver( aObserver ),
       
    47     iClientData( TMccCreateLinkPckg() ), iSession( aSession )
       
    48     {
       
    49     CActiveScheduler::Add( this );
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // Static constructor, does not leave instance in cleanupstack
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CMccAsyncLinkCreator* CMccAsyncLinkCreator::NewL( 
       
    57     MAsyncLinkCreationObserver& aObserver, 
       
    58     CMccUlDlClient* aSession )
       
    59     {
       
    60     CMccAsyncLinkCreator* self = 
       
    61         CMccAsyncLinkCreator::NewLC( aObserver, aSession );
       
    62     CleanupStack::Pop( self );
       
    63     return self;
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // Static constructor, leaves instance in cleanupstack
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CMccAsyncLinkCreator* CMccAsyncLinkCreator::NewLC( 
       
    71     MAsyncLinkCreationObserver& aObserver, 
       
    72     CMccUlDlClient* aSession )
       
    73     {
       
    74     CMccAsyncLinkCreator* self =
       
    75         new ( ELeave ) CMccAsyncLinkCreator( aObserver, aSession );
       
    76     CleanupStack::PushL( self );
       
    77 
       
    78     return self;
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // Destructor
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CMccAsyncLinkCreator::~CMccAsyncLinkCreator()
       
    86     {
       
    87     this->Cancel();
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // From class CActive
       
    92 // Active object eventhandler
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 void CMccAsyncLinkCreator::RunL()
       
    96     {
       
    97     #ifdef TRACE_LINK_CREATOR
       
    98         RDebug::Print( _L("CMccAsyncLinkCreator::RunL status: %d"),
       
    99            iStatus.Int() );
       
   100     #endif
       
   101     
       
   102     if( KErrNone == iStatus.Int() )
       
   103         {
       
   104         if ( iLinkCreated == EFalse )
       
   105             {                                                           
       
   106             iSession->CreateRtpSessionL( iClientData().iLinkID,
       
   107                                          iClientData().iLocalAddress.Port(),
       
   108                                          iClientData().iIpTOS,
       
   109                                          iClientData().iMediaSignaling );
       
   110             iLinkCreated = ETrue;
       
   111             }
       
   112 
       
   113         TRAPD( error, iSession->GetLocalIpAddressesL( iClientData() ) );
       
   114         
       
   115         #ifdef TRACE_LINK_CREATOR
       
   116             RDebug::Print( _L("CMccAsyncLinkCreator::RunL complete request: %d"),
       
   117                 error );
       
   118         #endif
       
   119         
       
   120         this->CompleteRequest( error );
       
   121         }
       
   122     else
       
   123         {
       
   124         #ifdef TRACE_LINK_CREATOR
       
   125             RDebug::Print( _L("CMccAsyncLinkCreator::RunL ERR: %d"), 
       
   126                 iStatus.Int() );
       
   127         #endif
       
   128         
       
   129         // Connection process failed for some reason, so complete the client
       
   130         this->CompleteRequest( iStatus.Int() );
       
   131         }
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // From class CActive
       
   136 // Active object request cancellation
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 void CMccAsyncLinkCreator::DoCancel()
       
   140     {
       
   141     if( iSession )
       
   142         {
       
   143         #ifdef TRACE_LINK_CREATOR
       
   144             RDebug::Print( _L("CMccAsyncLinkCreator::DoCancel iSession") );
       
   145         #endif
       
   146 
       
   147         TRAP_IGNORE( iSession->CloseLinkL( iClientData().iLinkID ) );
       
   148         
       
   149         // Null the session in order to avoid looping if this object
       
   150         // is deleted inside callback (docancel is re-entried)
       
   151         iSession = NULL; 
       
   152         
       
   153         iObserver.CreationProcessEnd( iClientData, NULL, KErrCancel );
       
   154         }
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // From class CActive
       
   159 // RunL error handling
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 TInt CMccAsyncLinkCreator::RunError( TInt aError )
       
   163     {
       
   164     #ifdef TRACE_LINK_CREATOR
       
   165         RDebug::Print( _L("CMccAsyncLinkCreator::RunError ERR: %d"), aError );
       
   166     #endif
       
   167     
       
   168     // We have a leave when RunL is executing
       
   169     CompleteRequest( aError );
       
   170 
       
   171     if ( aError != KErrNoMemory )
       
   172         {
       
   173         aError = KErrNone;
       
   174         }
       
   175     
       
   176     return aError;
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------------------------
       
   180 // Completes the client request with given error code
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 void CMccAsyncLinkCreator::CompleteRequest( TInt aError )
       
   184     {
       
   185     #ifdef TRACE_LINK_CREATOR
       
   186         RDebug::Print( _L("CMccAsyncLinkCreator::CompleteRequest") );
       
   187     #endif
       
   188 
       
   189     // Notify controller that we are through with the link creation
       
   190     // process so it can delete this link creator. Resolved addresses
       
   191     // and ports are also passed to the controller. 
       
   192     iObserver.CreationProcessEnd( iClientData, this, aError );
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // CMccAsyncLinkCreator::StartLinkCreationL
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 void CMccAsyncLinkCreator::StartLinkCreationL( TMMFMessage& aMessage )
       
   200     {
       
   201     #ifdef TRACE_LINK_CREATOR
       
   202         RDebug::Print( _L("CMccAsyncLinkCreator::StartLinkCreationL") );
       
   203     #endif
       
   204 
       
   205     __ASSERT_ALWAYS( !IsActive(), User::Leave( KErrInUse ) );
       
   206     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   207      
       
   208     aMessage.ReadData1FromClientL( iClientData );
       
   209 
       
   210     iSession->CreateLinkL( iClientData().iLinkID, iClientData().iLinkType );
       
   211     iSession->InitializeLinkL( iStatus,
       
   212                                iClientData().iLinkID,
       
   213                                iClientData().iIapId );
       
   214 
       
   215     this->SetActive();
       
   216     aMessage.WriteDataToClientL( iClientData );
       
   217     }
       
   218     
       
   219     
       
   220 // ---------------------------------------------------------------------------
       
   221 // CMccAsyncLinkCreator::GetSessionId
       
   222 // ---------------------------------------------------------------------------
       
   223 //
       
   224 
       
   225 TUint32 CMccAsyncLinkCreator::GetSessionId()
       
   226  	{
       
   227 	return iSession->GetSessionId();
       
   228  	}
       
   229 
       
   230 
       
   231 // ======== GLOBAL FUNCTIONS ========