natfw/natfwconnectionmultiplexer/src/cncmconnectionmultiplexer.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006-2008 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:    Connection multiplexer is responsible for handling network
       
    15 *                connections, send and receive data from the
       
    16 *                network and allow client to start media flow between
       
    17 *                connection multiplexer and socket media connection wrapper.
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 #include <in_sock.h>
       
    25  
       
    26 #include "cncmconnectionmultiplexer.h"
       
    27 #include "mncmconnectionmultiplexerobserver.h"
       
    28 #include "cncmportstore.h"
       
    29 #include "cncmmediasource.h"
       
    30 #include "ncmconnectionmultiplexerlogs.h"
       
    31 #include "cncmsession.h"
       
    32 #include "cncmstream.h"
       
    33 #include "cncmconnection.h"
       
    34 #include "natfwmediawrapper.h"
       
    35 #include "cncmcallbackexecuter.h"
       
    36 #include "ncmconnectionmultiplexerassert.h"
       
    37 #include "cncmconnectionobserverhandler.h"
       
    38 
       
    39 const TUint KFirstSessionId = 1;
       
    40 
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // CNcmConnectionMultiplexer::CNcmConnectionMultiplexer
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 CNcmConnectionMultiplexer::CNcmConnectionMultiplexer(
       
    47     MNcmConnectionMultiplexerObserver& aObserver ) :
       
    48     iObserver( aObserver ), iNextSessionId( KFirstSessionId )
       
    49     {
       
    50     }
       
    51 
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CNcmConnectionMultiplexer::NewL
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 EXPORT_C CNcmConnectionMultiplexer* CNcmConnectionMultiplexer::NewL(
       
    58         MNcmConnectionMultiplexerObserver& aObserver )
       
    59     {
       
    60     __CONNECTIONMULTIPLEXER( "CNcmConnectionMultiplexer::NewL" )
       
    61 
       
    62     CNcmConnectionMultiplexer* self =
       
    63         new (ELeave) CNcmConnectionMultiplexer( aObserver );
       
    64     CleanupStack::PushL( self );        
       
    65     self->ConstructL();
       
    66     CleanupStack::Pop( self );
       
    67     return self;
       
    68     }
       
    69 
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CNcmConnectionMultiplexer::ConstructL
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void CNcmConnectionMultiplexer::ConstructL()
       
    76     {
       
    77     iAsyncCallback = CNcmCallBackExecuter::NewL();
       
    78     }
       
    79 
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CNcmConnectionMultiplexer::~CNcmConnectionMultiplexer
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CNcmConnectionMultiplexer::~CNcmConnectionMultiplexer()
       
    86     {
       
    87     __CONNECTIONMULTIPLEXER( 
       
    88         "CNcmConnectionMultiplexer::~CNcmConnectionMultiplexer" )
       
    89         
       
    90     iSessions.ResetAndDestroy();
       
    91     delete iAsyncCallback;
       
    92     }
       
    93 
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CNcmConnectionMultiplexer::CreateSessionL
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 EXPORT_C TUint CNcmConnectionMultiplexer::CreateSessionL( TUint32 aIapId,
       
   100     TUint aPortRangeStart, TUint aPortRangeStop )
       
   101     {
       
   102     __CONNECTIONMULTIPLEXER_INT3(
       
   103         "CNcmConnectionMultiplexer::CreateSessionL - aIapId:", aIapId,
       
   104             "aPortRangeStart: ", aPortRangeStart, "aPortRangeStop: ", aPortRangeStop )
       
   105         
       
   106     CNcmSession* session = 
       
   107         CNcmSession::NewLC( iNextSessionId, aIapId,
       
   108             aPortRangeStart, aPortRangeStop, iObserver, *this );
       
   109         
       
   110     iSessions.AppendL( session );
       
   111     CleanupStack::Pop( session );
       
   112     
       
   113     iNextSessionId++;
       
   114     
       
   115     return session->SessionId();    
       
   116     }
       
   117 
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CNcmConnectionMultiplexer::CreateStreamL
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 EXPORT_C TUint CNcmConnectionMultiplexer::CreateStreamL( TUint aSessionId,
       
   124     TInt aQos, TUint aProtocol )
       
   125     {
       
   126     __CONNECTIONMULTIPLEXER_INT3(
       
   127         "CNcmConnectionMultiplexer::CreateStreamL - aSessionId:", aSessionId,
       
   128             "aQos: ", aQos, "aProtocol: ", aProtocol )
       
   129     
       
   130     CNcmSession* session( SessionByIdL( aSessionId ) );
       
   131     
       
   132     __ASSERT_ALWAYS( session->Initialized(), User::Leave( KErrNotReady ) ); 
       
   133     
       
   134     return ( session->CreateStreamL( aQos, aProtocol ) );
       
   135     }
       
   136 
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CNcmConnectionMultiplexer::GetStreamInfoL
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 EXPORT_C void CNcmConnectionMultiplexer::GetStreamInfoL( 
       
   143     TUint aStreamId, TUint32& aIapId, TInt& aQos,
       
   144     TUint& aProtocol )
       
   145     {
       
   146     __CONNECTIONMULTIPLEXER( "CNcmConnectionMultiplexer::GetStreamInfoL" )
       
   147     
       
   148     CNcmStream* stream( StreamByIdL( aStreamId ) );
       
   149        
       
   150     aIapId = SessionByStreamIdL( aStreamId )->IapId();
       
   151     aQos = stream->Qos();
       
   152     aProtocol = stream->StreamProtocol();
       
   153     }
       
   154 
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // CNcmConnectionMultiplexer::LocalIPAddressL
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 EXPORT_C TInetAddr& CNcmConnectionMultiplexer::LocalIPAddressL(
       
   161     TUint aStreamId, TUint aConnectionId )
       
   162     {
       
   163     return StreamByIdL( aStreamId )->
       
   164         ConnectionL( aConnectionId )->LocalAddress();
       
   165     }
       
   166  
       
   167     
       
   168 // ---------------------------------------------------------------------------
       
   169 // CNcmConnectionMultiplexer::ResolveDestinationAddressL
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 EXPORT_C void CNcmConnectionMultiplexer::ResolveDestinationAddressL(
       
   173     TUint aStreamId, const TDesC8& aAddress, TUint aPort,
       
   174     TInetAddr& aResult )
       
   175     {
       
   176     __CONNECTIONMULTIPLEXER(
       
   177         "CNcmConnectionMultiplexer::ResolveDestinationAddressL, FQDN" )
       
   178 
       
   179     SessionByStreamIdL( aStreamId )->ResolveDestinationAddressL(
       
   180             aAddress, aPort, aResult );
       
   181     }
       
   182  
       
   183    
       
   184 // ---------------------------------------------------------------------------
       
   185 // CNcmConnectionMultiplexer::CreateConnectionL
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 EXPORT_C TUint CNcmConnectionMultiplexer::CreateConnectionL( 
       
   189     TUint aStreamId, TUint aAddrFamily )
       
   190     {              
       
   191     __CONNECTIONMULTIPLEXER_INT2(
       
   192         "CNcmConnectionMultiplexer::CreateConnectionL - Entry, aStreamId:", aStreamId,
       
   193             "aAddrFamily: ", aAddrFamily )
       
   194 
       
   195     __CONNECTIONMULTIPLEXER_ASSERT_L( ( KAfInet == aAddrFamily || KAfInet6 == aAddrFamily ),
       
   196         KErrArgument );
       
   197         
       
   198     CNcmStream* stream( StreamByIdL( aStreamId ) );
       
   199     CNcmSession* session( SessionByStreamIdL( aStreamId ) );
       
   200 
       
   201     TInetAddr addr( KInetAddrNone, 0 );
       
   202     
       
   203     addr = ( KAfInet == aAddrFamily )
       
   204         ? session->LocalIPv4Address()
       
   205         : session->LocalIPv6Address();         
       
   206 
       
   207     __CONNECTIONMULTIPLEXER_ADDRLOG(
       
   208         "CNcmConnectionMultiplexer::CreateConnectionL - ADDRESS: ", addr )
       
   209 
       
   210     __ASSERT_ALWAYS( !addr.IsUnspecified(), User::Leave( KErrNotFound ) );
       
   211    
       
   212     addr.SetPort( session->PortStore().Port() );
       
   213     
       
   214     __CONNECTIONMULTIPLEXER_ADDRLOG(
       
   215         "CNcmConnectionMultiplexer::CreateConnectionL - PORT: ", addr.Port() )
       
   216                     
       
   217     // Create Connection
       
   218     return stream->CreateConnectionL(
       
   219             *this, stream->ConnectionObserverHandler(),
       
   220             session->SocketServer(),
       
   221             session->Connection(), addr, EFalse );
       
   222     }
       
   223 
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // CNcmConnectionMultiplexer::CreateConnectionL - overloaded
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 EXPORT_C TUint CNcmConnectionMultiplexer::CreateConnectionL( 
       
   230     TUint aStreamId, const TInetAddr& aLocalAddr )
       
   231     {
       
   232     __CONNECTIONMULTIPLEXER_ADDRLOG( 
       
   233         "CNcmConnectionMultiplexer::CreateConnectionL - overloaded - \
       
   234              Local address:", aLocalAddr )
       
   235                
       
   236     __CONNECTIONMULTIPLEXER_ASSERT_L( ( !aLocalAddr.IsUnspecified() ),
       
   237         KErrNotSupported );
       
   238 
       
   239     CNcmStream* stream( StreamByIdL( aStreamId ) );
       
   240     CNcmSession* session( SessionByStreamIdL( aStreamId ) );
       
   241 
       
   242     TInetAddr addr( KInetAddrNone, 0 );
       
   243     addr = aLocalAddr;            
       
   244                         
       
   245     // Create Connection
       
   246     return stream->CreateConnectionL(
       
   247             *this, stream->ConnectionObserverHandler(),
       
   248             session->SocketServer(),
       
   249             session->Connection(), addr, ETrue );
       
   250     }
       
   251 
       
   252 
       
   253 // ---------------------------------------------------------------------------
       
   254 // CNATFWConnectionMultiplexer::OpenTcpConnectionL
       
   255 // ---------------------------------------------------------------------------
       
   256 //
       
   257 EXPORT_C void CNcmConnectionMultiplexer::OpenTcpConnectionL(
       
   258     TUint aStreamId, TUint aConnectionId, TNATFWTcpConnectionSetup aConfig,
       
   259     const TInetAddr& aDestAddr )
       
   260     { 
       
   261     __CONNECTIONMULTIPLEXER_INT2(
       
   262         "CNcmConnectionMultiplexer::OpenTcpConnectionL - aStreamId:", aStreamId,
       
   263             "aConnectionId: ", aConnectionId )
       
   264     __CONNECTIONMULTIPLEXER_ADDRLOG( 
       
   265         "CNcmConnectionMultiplexer::OpenTcpConnectionL - aDestAddr: ", aDestAddr )
       
   266             
       
   267     StreamByIdL( aStreamId )->ConnectionL( aConnectionId )->
       
   268         OpenTcpConnectionL( aConfig, aDestAddr );
       
   269     }
       
   270 
       
   271 
       
   272 // ---------------------------------------------------------------------------
       
   273 // CNATFWConnectionMultiplexer::CloseTcpConnection
       
   274 // ---------------------------------------------------------------------------
       
   275 //
       
   276 EXPORT_C void CNcmConnectionMultiplexer::CloseTcpConnection(
       
   277     TUint aStreamId, TUint aConnectionId )
       
   278     {
       
   279     __CONNECTIONMULTIPLEXER_INT2(
       
   280         "CNcmConnectionMultiplexer::CloseTcpConnection - aStreamId:", aStreamId,
       
   281             "aConnectionId: ", aConnectionId )
       
   282     
       
   283     TRAP_IGNORE( this->CloseTcpConnectionL( aStreamId, aConnectionId ) )
       
   284     }
       
   285 
       
   286     
       
   287 // ---------------------------------------------------------------------------
       
   288 // CNATFWConnectionMultiplexer::CloseTcpConnectionL
       
   289 // ---------------------------------------------------------------------------
       
   290 //
       
   291 void CNcmConnectionMultiplexer::CloseTcpConnectionL(
       
   292     TUint aStreamId, TUint aConnectionId )
       
   293     {
       
   294     __CONNECTIONMULTIPLEXER(
       
   295         "CNATFWConnectionMultiplexer::CloseTcpConnectionL" )
       
   296         
       
   297      StreamByIdL( aStreamId )->ConnectionL( aConnectionId )->
       
   298         CloseTcpConnectionL();
       
   299     }
       
   300 
       
   301 
       
   302 // ---------------------------------------------------------------------------
       
   303 // CNcmConnectionMultiplexer::RemoveSessionL
       
   304 // ---------------------------------------------------------------------------
       
   305 //
       
   306 EXPORT_C void CNcmConnectionMultiplexer::RemoveSessionL( TUint aSessionId )
       
   307     {
       
   308     __CONNECTIONMULTIPLEXER_INT1(
       
   309         "CNcmConnectionMultiplexer::RemoveSessionL - aSessionId:", aSessionId )
       
   310 
       
   311     TInt sessionCount( iSessions.Count() );
       
   312     
       
   313     for ( TInt i = 0; i < sessionCount; i++ )
       
   314         {
       
   315         if ( iSessions[i]->SessionId() == aSessionId )
       
   316             {
       
   317             delete iSessions[i];
       
   318             iSessions.Remove( i );
       
   319             return;
       
   320             }
       
   321         }
       
   322     User::Leave( KErrNotFound );
       
   323     }
       
   324 
       
   325 
       
   326 // ---------------------------------------------------------------------------
       
   327 // CNcmConnectionMultiplexer::RemoveStreamL
       
   328 // ---------------------------------------------------------------------------
       
   329 //
       
   330 EXPORT_C void CNcmConnectionMultiplexer::RemoveStreamL( TUint aStreamId )
       
   331     {
       
   332     __CONNECTIONMULTIPLEXER_INT1(
       
   333         "CNcmConnectionMultiplexer::RemoveStreamL - aStreamId:", aStreamId )
       
   334 
       
   335     CNcmSession* session( SessionByStreamIdL( aStreamId ) );    
       
   336     session->RemoveStreamL( aStreamId );
       
   337     }
       
   338 
       
   339 
       
   340 // ---------------------------------------------------------------------------
       
   341 // CNcmConnectionMultiplexer::RemoveConnectionL
       
   342 // ---------------------------------------------------------------------------
       
   343 //
       
   344 EXPORT_C void CNcmConnectionMultiplexer::RemoveConnectionL(
       
   345     TUint aStreamId, TUint aConnectionId )
       
   346     {
       
   347     __CONNECTIONMULTIPLEXER_INT2(
       
   348         "CNcmConnectionMultiplexer::RemoveConnectionL - aStreamId:", aStreamId,
       
   349             "aConnectionId: ", aConnectionId )
       
   350     
       
   351     CNcmStream* stream( StreamByIdL( aStreamId ) );
       
   352     
       
   353     if ( stream->MediaConnectionId() == aConnectionId )
       
   354         {
       
   355         // media connection can't be deleted.        
       
   356         User::Leave( KErrPermissionDenied );
       
   357         }
       
   358         
       
   359     stream->RemoveConnectionL( aConnectionId );     
       
   360     }
       
   361 
       
   362 
       
   363 // ---------------------------------------------------------------------------
       
   364 // CNcmConnectionMultiplexer::RegisterIncomingConnectionObserverL
       
   365 // ---------------------------------------------------------------------------
       
   366 //
       
   367 EXPORT_C void CNcmConnectionMultiplexer::
       
   368     RegisterIncomingConnectionObserverL( TUint aStreamId,
       
   369         MNcmIncomingConnectionObserver& aObserver )
       
   370     {
       
   371     __CONNECTIONMULTIPLEXER(
       
   372         "CNcmConnectionMultiplexer::RegisterIncomingConnectionObserver" )
       
   373         
       
   374     StreamByIdL( aStreamId )->
       
   375         ConnectionObserverHandler().
       
   376         RegisterIncomingConnectionObserverL( aObserver );
       
   377     }
       
   378 
       
   379 
       
   380 // ---------------------------------------------------------------------------
       
   381 // CNcmConnectionMultiplexer::RegisterOutgoingConnectionObserverL
       
   382 // ---------------------------------------------------------------------------
       
   383 //
       
   384 EXPORT_C void CNcmConnectionMultiplexer::
       
   385     RegisterOutgoingConnectionObserverL(
       
   386         TUint aStreamId, MNcmOutgoingConnectionObserver& aObserver )
       
   387     {
       
   388     __CONNECTIONMULTIPLEXER(
       
   389         "CNcmConnectionMultiplexer::RegisterOutgoingConnectionObserver" )
       
   390 
       
   391     StreamByIdL( aStreamId )->
       
   392         ConnectionObserverHandler().
       
   393         RegisterOutgoingConnectionObserverL( aObserver );
       
   394     }
       
   395 
       
   396 
       
   397 // ---------------------------------------------------------------------------
       
   398 // CNcmConnectionMultiplexer::UnregisterIncomingConnectionObserverL
       
   399 // ---------------------------------------------------------------------------
       
   400 //
       
   401 EXPORT_C void CNcmConnectionMultiplexer::
       
   402     UnregisterIncomingConnectionObserverL(
       
   403         TUint aStreamId,MNcmIncomingConnectionObserver& aObserver )
       
   404     {
       
   405     __CONNECTIONMULTIPLEXER(
       
   406         "CNcmConnectionMultiplexer::UnregisterIncomingConnectionObserver" )
       
   407 
       
   408     StreamByIdL( aStreamId )->ConnectionObserverHandler().
       
   409         UnregisterIncomingConnectionObserverL( aObserver );
       
   410     }
       
   411 
       
   412 
       
   413 // ---------------------------------------------------------------------------
       
   414 // CNcmConnectionMultiplexer::UnregisterOutgoingConnectionObserverL
       
   415 // ---------------------------------------------------------------------------
       
   416 //
       
   417 EXPORT_C void CNcmConnectionMultiplexer::
       
   418     UnregisterOutgoingConnectionObserverL(
       
   419         TUint aStreamId, MNcmOutgoingConnectionObserver& aObserver )
       
   420     {
       
   421     __CONNECTIONMULTIPLEXER(
       
   422         "CNcmConnectionMultiplexer::UnregisterOutgoingConnectionObserver" )
       
   423 
       
   424     StreamByIdL( aStreamId )->ConnectionObserverHandler().
       
   425         UnregisterOutgoingConnectionObserverL( aObserver );
       
   426     }
       
   427 
       
   428 
       
   429 // ---------------------------------------------------------------------------
       
   430 // CNcmConnectionMultiplexer::RegisterConnectionObserverL
       
   431 // ---------------------------------------------------------------------------
       
   432 //
       
   433 EXPORT_C void CNcmConnectionMultiplexer::RegisterConnectionObserverL(
       
   434     TUint aStreamId, MNcmConnectionObserver& aObserver )
       
   435     {
       
   436     __CONNECTIONMULTIPLEXER(
       
   437         "CNcmConnectionMultiplexer::RegisterConnectionObserverL" )
       
   438 
       
   439     StreamByIdL( aStreamId )->
       
   440         ConnectionObserverHandler().
       
   441         RegisterConnectionObserverL( aObserver );
       
   442     }
       
   443 
       
   444 
       
   445 // ---------------------------------------------------------------------------
       
   446 // CNcmConnectionMultiplexer::UnregisterConnectionObserverL
       
   447 // ---------------------------------------------------------------------------
       
   448 //
       
   449 EXPORT_C void CNcmConnectionMultiplexer::UnregisterConnectionObserverL(
       
   450     TUint aStreamId, MNcmConnectionObserver& aObserver )
       
   451     {
       
   452     __CONNECTIONMULTIPLEXER(
       
   453         "CNcmConnectionMultiplexer::UnregisterConnectionObserverL" )
       
   454 
       
   455     StreamByIdL( aStreamId )->ConnectionObserverHandler().
       
   456         UnregisterConnectionObserverL( aObserver );
       
   457     }
       
   458 
       
   459 
       
   460 // ---------------------------------------------------------------------------
       
   461 // CNcmConnectionMultiplexer::RegisterMessageObserverL
       
   462 // ---------------------------------------------------------------------------
       
   463 //
       
   464 EXPORT_C void CNcmConnectionMultiplexer::RegisterMessageObserverL(
       
   465     TUint aStreamId, MNcmMessageObserver& aObserver )
       
   466     {
       
   467     StreamByIdL( aStreamId )->ConnectionObserverHandler().
       
   468         RegisterMessageObserver( aObserver );
       
   469     }
       
   470 
       
   471 
       
   472 // ---------------------------------------------------------------------------
       
   473 // CNcmConnectionMultiplexer::UnregisterMessageObserverL
       
   474 // ---------------------------------------------------------------------------
       
   475 //
       
   476 EXPORT_C void CNcmConnectionMultiplexer::UnregisterMessageObserverL(
       
   477     TUint aStreamId, MNcmMessageObserver& aObserver )
       
   478     {
       
   479     StreamByIdL( aStreamId )->ConnectionObserverHandler().
       
   480         UnregisterMessageObserver( aObserver );   
       
   481     }
       
   482         
       
   483 
       
   484 // ---------------------------------------------------------------------------
       
   485 // CNcmConnectionMultiplexer::RegisterMediaWrapperL
       
   486 // ---------------------------------------------------------------------------
       
   487 //
       
   488 EXPORT_C void CNcmConnectionMultiplexer::RegisterMediaWrapperL(
       
   489     MNATFWMediaWrapper* aMediaWrapper )
       
   490     {
       
   491     __CONNECTIONMULTIPLEXER(
       
   492         "CNcmConnectionMultiplexer::RegisterMediaWrapperL" )
       
   493         
       
   494     __ASSERT_ALWAYS( aMediaWrapper, User::Leave( KErrNotReady ) );
       
   495     
       
   496     TUint streamId( aMediaWrapper->StreamId() );
       
   497     
       
   498     CNcmStream* stream( StreamByIdL( streamId ) );
       
   499     CNcmSession* session( SessionByStreamIdL( streamId ) );
       
   500       
       
   501     stream->RegisterWrapperL( aMediaWrapper );
       
   502 
       
   503     TInetAddr addr( session->LocalIPv4Address() );
       
   504     
       
   505     if ( addr.IsUnspecified() )
       
   506         {
       
   507         addr = session->LocalIPv6Address();
       
   508         
       
   509         if ( addr.IsUnspecified() )
       
   510             {
       
   511             User::Leave( KErrNotReady );
       
   512             }
       
   513         }
       
   514 
       
   515     // Register media source for stream    
       
   516     stream->RegisterMediaSourceL( CNcmMediaSource::NewLC( *this,
       
   517         *stream->WrapperL(), SessionByStreamIdL( streamId )->SocketServer(),
       
   518         addr ) );
       
   519          
       
   520     CleanupStack::Pop();
       
   521     }
       
   522 
       
   523 
       
   524 // ---------------------------------------------------------------------------
       
   525 // CNcmConnectionMultiplexer::SendL
       
   526 // ---------------------------------------------------------------------------
       
   527 //
       
   528 EXPORT_C void CNcmConnectionMultiplexer::SendL( TUint aStreamId,
       
   529     TUint aConnectionId, const TDesC8& aMessage,
       
   530     MNcmSenderObserver* aSenderObserver )
       
   531     {
       
   532     __CONNECTIONMULTIPLEXER_INT2(
       
   533         "CNcmConnectionMultiplexer::SendL - aStreamId:", aStreamId,
       
   534             "aConnectionId: ", aConnectionId )
       
   535     
       
   536     CNcmConnection* connection = StreamByIdL( aStreamId )->
       
   537         ConnectionL( aConnectionId );
       
   538 
       
   539     connection->Send( aMessage, KAFUnspec, aSenderObserver );
       
   540     }
       
   541 
       
   542 
       
   543 // ---------------------------------------------------------------------------
       
   544 // CNcmConnectionMultiplexer::SendL
       
   545 // ---------------------------------------------------------------------------
       
   546 //
       
   547 EXPORT_C void CNcmConnectionMultiplexer::SendL( TUint aStreamId,
       
   548     TUint aConnectionId, const TDesC8& aMessage,
       
   549     const TInetAddr& aDestinationAddress, 
       
   550     MNcmSenderObserver* aSenderObserver )
       
   551     {
       
   552     __CONNECTIONMULTIPLEXER_INT2(
       
   553         "CNcmConnectionMultiplexer::SendL - aStreamId:", aStreamId,
       
   554             "aConnectionId: ", aConnectionId )
       
   555 
       
   556     CNcmConnection* connection(StreamByIdL( aStreamId )->ConnectionL(
       
   557         aConnectionId ) ); 
       
   558 
       
   559     connection->Send( aMessage, aDestinationAddress, aSenderObserver );
       
   560     }
       
   561 
       
   562 
       
   563 // ---------------------------------------------------------------------------
       
   564 // CNcmConnectionMultiplexer::SendL
       
   565 // ---------------------------------------------------------------------------
       
   566 //
       
   567 EXPORT_C void CNcmConnectionMultiplexer::SendL( TUint aStreamId,
       
   568     const TDesC8& aMessage, const TInetAddr& aNextHopAddress,
       
   569     const TInetAddr& aDestinationAddress )
       
   570     {
       
   571     __CONNECTIONMULTIPLEXER_INT1(
       
   572         "CNcmConnectionMultiplexer::SendL - aStreamId:", aStreamId )
       
   573     __CONNECTIONMULTIPLEXER_ADDRLOG(
       
   574         "CNcmConnectionMultiplexer::SendL - aDestinationAddress: ", aDestinationAddress )
       
   575     __CONNECTIONMULTIPLEXER_ADDRLOG(
       
   576         "CNcmConnectionMultiplexer::SendL - aNextHopAddress: ", aNextHopAddress )
       
   577     
       
   578     CNcmConnection* connection( NULL );
       
   579     CNcmStream* stream = StreamByIdL( aStreamId );
       
   580    
       
   581     connection = stream->ConnectionByDestinationAddressL( aNextHopAddress );  
       
   582 
       
   583     connection->Send( aMessage, aDestinationAddress, NULL );
       
   584     }
       
   585 
       
   586      
       
   587 // ---------------------------------------------------------------------------
       
   588 // CNcmConnectionMultiplexer::SendL
       
   589 // ---------------------------------------------------------------------------
       
   590 //
       
   591 EXPORT_C void CNcmConnectionMultiplexer::SendL( TUint aStreamId,
       
   592     TUint aConnectionId, const TDesC8& aMessage, TBool aSendDirectly,
       
   593     MNcmSenderObserver* aSenderObserver )
       
   594     {
       
   595     __CONNECTIONMULTIPLEXER( "CNcmConnectionMultiplexer::SendL - \
       
   596          overloaded, send message directly from connection" )
       
   597     __CONNECTIONMULTIPLEXER_INT2( "CNcmConnectionMultiplexer::SendL - \
       
   598         aStreamId:", aStreamId, "aConnectionId: ", aConnectionId )
       
   599         
       
   600     if ( aSendDirectly )
       
   601         {  
       
   602         StreamByIdL( aStreamId )->ConnectionL( aConnectionId )->
       
   603             SendDirectlyToNetwork( aMessage, aSenderObserver );
       
   604         }
       
   605     else
       
   606         {
       
   607         this->SendL( aStreamId, aConnectionId, aMessage, aSenderObserver );
       
   608         }
       
   609     }
       
   610 
       
   611 
       
   612 // ---------------------------------------------------------------------------
       
   613 // CNcmConnectionMultiplexer::CancelMessageSend
       
   614 // ---------------------------------------------------------------------------
       
   615 //
       
   616 EXPORT_C void CNcmConnectionMultiplexer::CancelMessageSend( TUint aStreamId,
       
   617     TUint aConnectionId, const MNcmSenderObserver* aSenderObserver )
       
   618     {
       
   619     __CONNECTIONMULTIPLEXER( "CNcmConnectionMultiplexer::CancelMessageSend " )
       
   620 
       
   621     TRAP_IGNORE( this->CancelMessageSendL( aStreamId, aConnectionId,
       
   622         aSenderObserver ) )
       
   623     }
       
   624 
       
   625 
       
   626 // ---------------------------------------------------------------------------
       
   627 // CNcmConnectionMultiplexer::CancelMessageSendL
       
   628 // ---------------------------------------------------------------------------
       
   629 //
       
   630 void CNcmConnectionMultiplexer::CancelMessageSendL( TUint aStreamId,
       
   631     TUint aConnectionId, const MNcmSenderObserver* aSenderObserver )
       
   632     {
       
   633     __CONNECTIONMULTIPLEXER( "CNcmConnectionMultiplexer::CancelMessageSendL " )
       
   634         
       
   635     StreamByIdL( aStreamId )->
       
   636         ConnectionL( aConnectionId )->CancelMessageSendL( aSenderObserver ); 
       
   637     }
       
   638 
       
   639     
       
   640 // ---------------------------------------------------------------------------
       
   641 // CNcmConnectionMultiplexer::PortStoreL
       
   642 // ---------------------------------------------------------------------------
       
   643 //
       
   644 EXPORT_C CNcmPortStore& CNcmConnectionMultiplexer::PortStoreL(
       
   645     TUint aSessionId )
       
   646     {
       
   647     __CONNECTIONMULTIPLEXER( "CNcmConnectionMultiplexer::PortStoreL" )
       
   648 
       
   649     return SessionByIdL( aSessionId )->PortStore();
       
   650     }
       
   651 
       
   652 
       
   653 // ---------------------------------------------------------------------------
       
   654 // CNcmConnectionMultiplexer::GetSessionInfoL
       
   655 // ---------------------------------------------------------------------------
       
   656 //
       
   657 EXPORT_C RSocketServ* CNcmConnectionMultiplexer::GetSessionInfoL(
       
   658     TUint aSessionId, TName& aConnectionName )
       
   659     {
       
   660     __CONNECTIONMULTIPLEXER_INT1(
       
   661         "CNcmConnectionMultiplexer::GetSessionInfoL - aSessionId:", aSessionId )
       
   662 
       
   663     CNcmSession* session( SessionByIdL( aSessionId ) );
       
   664             
       
   665     User::LeaveIfError( session->GetConnectionName( aConnectionName ) );
       
   666     return &session->SocketServer();
       
   667     }
       
   668     
       
   669 
       
   670 // ---------------------------------------------------------------------------
       
   671 // CNcmConnectionMultiplexer::SetSendingStateForMediaL
       
   672 // ---------------------------------------------------------------------------
       
   673 //
       
   674 EXPORT_C void CNcmConnectionMultiplexer::SetSendingStateForMediaL(
       
   675     TUint aStreamId, TUint aConnectionId, TNATFWStreamingState aState )
       
   676     {
       
   677     __CONNECTIONMULTIPLEXER_INT2(
       
   678         "CNcmConnectionMultiplexer::SetSendingStateForMediaL - \
       
   679          aStreamId:", aStreamId, "aConnectionId: ", aConnectionId )
       
   680     
       
   681     CNcmStream* stream( StreamByIdL( aStreamId ) );
       
   682     MNATFWMediaWrapper* wrapper = stream->WrapperL();
       
   683     TMultiplexerConnectionNotifyType type( EMultiplexerConnectionError );
       
   684     
       
   685     CNcmConnection* connection( stream->ConnectionL( aConnectionId ) );
       
   686     stream->SetMediaConnectionId( aConnectionId );
       
   687     
       
   688     if ( aState == EStreamingStateActive )
       
   689         {
       
   690         stream->ConnectionObserverHandler().
       
   691             RegisterMediaSourceObserver( *connection ); 
       
   692         wrapper->SetReceivingStateForMuxWrapper( aState );   
       
   693         type = EMultiplexerMediaSendingActivated;
       
   694         }
       
   695     else if ( aState == EStreamingStatePassive )
       
   696         {          
       
   697         stream->ConnectionObserverHandler().
       
   698             UnregisterMediaSourceObserver( *connection );
       
   699         wrapper->SetReceivingStateForMuxWrapper( aState );
       
   700         type = EMultiplexerMediaSendingDeactivated;
       
   701         }
       
   702     else
       
   703         {
       
   704         __CONNECTIONMULTIPLEXER_ASSERT_L( EFalse, KErrNotSupported );
       
   705         }
       
   706 
       
   707     TNcmCallBack callback( HandleCallBack, *this, aStreamId, aConnectionId,
       
   708                             type, KErrNone );
       
   709     iAsyncCallback->AddCallBackL( callback );
       
   710     }
       
   711 
       
   712     
       
   713 // ---------------------------------------------------------------------------
       
   714 // CNcmConnectionMultiplexer::SetReceivingStateForMediaL
       
   715 // ---------------------------------------------------------------------------
       
   716 //
       
   717 EXPORT_C void CNcmConnectionMultiplexer::SetReceivingStateForMediaL(
       
   718     TUint aStreamId, TUint aConnectionId, TNATFWStreamingState aState )
       
   719     {
       
   720     __CONNECTIONMULTIPLEXER_INT2(
       
   721         "CNcmConnectionMultiplexer::SetReceivingStateForMediaL - \
       
   722          aStreamId:", aStreamId, "aConnectionId: ", aConnectionId )
       
   723     
       
   724     CNcmStream* stream( StreamByIdL( aStreamId ) );
       
   725     TMultiplexerConnectionNotifyType type(
       
   726         EMultiplexerConnectionError );
       
   727 
       
   728     // Is connection real
       
   729     stream->ConnectionL( aConnectionId );
       
   730     stream->SetMediaConnectionId( aConnectionId );
       
   731           
       
   732     if ( EStreamingStateActive == aState )
       
   733         {
       
   734         type = EMultiplexerMediaReceivingActivated;
       
   735         }
       
   736     else if( EStreamingStatePassive == aState )
       
   737         {          
       
   738         type = EMultiplexerMediaReceivingDeactivated;
       
   739         }
       
   740     else
       
   741         {
       
   742         __CONNECTIONMULTIPLEXER_ASSERT_L( EFalse, KErrNotSupported );        
       
   743         }
       
   744                   
       
   745     stream->ConnectionObserverHandler().SetReceivingState( aState );
       
   746         
       
   747     TNcmCallBack callback( HandleCallBack, *this, aStreamId, aConnectionId,
       
   748                             type, KErrNone );
       
   749     iAsyncCallback->AddCallBackL( callback );
       
   750     }
       
   751 
       
   752 
       
   753 // ---------------------------------------------------------------------------
       
   754 // CNcmConnectionMultiplexer::SetSendingStateL
       
   755 // ---------------------------------------------------------------------------
       
   756 //
       
   757 EXPORT_C void CNcmConnectionMultiplexer::SetSendingStateL(
       
   758         TUint aStreamId, TUint aConnectionId, const TInetAddr& aDestAddr,
       
   759         TNATFWStreamingState aState )
       
   760     {
       
   761     __CONNECTIONMULTIPLEXER_INT2(
       
   762         "CNcmConnectionMultiplexer::SetSendingStateL - \
       
   763             aStreamId:", aStreamId, "aConnectionId: ", aConnectionId )
       
   764         
       
   765     StreamByIdL( aStreamId )->
       
   766         ConnectionL( aConnectionId )->SetSendingStateL( aDestAddr, aState );  
       
   767     }
       
   768     
       
   769     
       
   770 // ---------------------------------------------------------------------------
       
   771 // CNcmConnectionMultiplexer::SetReceivingStateL
       
   772 // ---------------------------------------------------------------------------
       
   773 //
       
   774 EXPORT_C void CNcmConnectionMultiplexer::SetReceivingStateL(
       
   775     TUint aStreamId, TUint aConnectionId, TNATFWStreamingState aState )
       
   776     {
       
   777     __CONNECTIONMULTIPLEXER_INT2(
       
   778         "CNcmConnectionMultiplexer::SetReceivingStateL - \
       
   779             aStreamId:", aStreamId, "aConnectionId: ", aConnectionId )
       
   780             
       
   781     StreamByIdL( aStreamId )->
       
   782         ConnectionL( aConnectionId )->SetReceivingStateL( aState );
       
   783     }
       
   784 
       
   785 
       
   786 // ---------------------------------------------------------------------------
       
   787 // CNcmConnectionMultiplexer::SetAcceptedFromAddressL
       
   788 // ---------------------------------------------------------------------------
       
   789 //
       
   790 EXPORT_C void CNcmConnectionMultiplexer::SetAcceptedFromAddressL( 
       
   791     TUint aStreamId, TUint aConnectionId, const TInetAddr& aAddress )
       
   792     {
       
   793     __CONNECTIONMULTIPLEXER_INT2(
       
   794         "CNcmConnectionMultiplexer::SetAcceptedFromAddressL - \
       
   795             aStreamId:", aStreamId, "aConnectionId: ", aConnectionId )  
       
   796     
       
   797     StreamByIdL( aStreamId )->
       
   798         ConnectionL( aConnectionId )->SetAcceptedFromAddressL( aAddress );
       
   799     }
       
   800 
       
   801 
       
   802 // ---------------------------------------------------------------------------
       
   803 // From class MNcmMultiplexerConnectionObserver
       
   804 //
       
   805 // CNcmConnectionMultiplexer::ConnectionError
       
   806 // ---------------------------------------------------------------------------
       
   807 //
       
   808 void CNcmConnectionMultiplexer::ConnectionError(
       
   809     TUint aSessionId, TUint aStreamId, TUint aConnectionId,
       
   810     TMultiplexerConnectionNotifyType aNotifyType, TInt aError )
       
   811     {
       
   812     __CONNECTIONMULTIPLEXER_INT1( 
       
   813         "CNcmConnectionMultiplexer::ConnectionError - ERROR: ", aError )
       
   814     
       
   815     CNcmStream* stream( StreamById( aStreamId ) ); 
       
   816     
       
   817     if ( stream )
       
   818         {
       
   819         // Notify connection observers
       
   820         stream->ConnectionObserverHandler().
       
   821             ConnectionNotify( aStreamId, aConnectionId, aNotifyType, aError );
       
   822                                                       
       
   823         // Lets notify stream user                  
       
   824         iObserver.Notify( aSessionId, aStreamId,
       
   825             MNcmConnectionMultiplexerObserver::EStreamError, aError );
       
   826         }
       
   827     }
       
   828 
       
   829 
       
   830 // ---------------------------------------------------------------------------
       
   831 // From class MNcmMultiplexerConnectionObserver
       
   832 //
       
   833 // CNcmConnectionMultiplexer::GetNewFreePort
       
   834 // ---------------------------------------------------------------------------
       
   835 //
       
   836 void CNcmConnectionMultiplexer::GetNewFreePort( TUint aStreamId,
       
   837     TUint aConnectionId, TUint& aPort )
       
   838     {
       
   839     __CONNECTIONMULTIPLEXER( 
       
   840         "CNcmConnectionMultiplexer::GetNewFreePort" )
       
   841         
       
   842     TRAP_IGNORE( GetNewFreePortL( aStreamId, aConnectionId, aPort ) )
       
   843     }
       
   844     
       
   845 
       
   846 // ---------------------------------------------------------------------------
       
   847 // From class MNcmMultiplexerConnectionObserver
       
   848 //
       
   849 // CNcmConnectionMultiplexer::ConnectionNotify
       
   850 // ---------------------------------------------------------------------------
       
   851 //
       
   852 void CNcmConnectionMultiplexer::ConnectionNotify( TUint aStreamId,
       
   853     TUint aConnectionId, TMultiplexerConnectionNotifyType aType,
       
   854     TInt aError )
       
   855     {    
       
   856     __CONNECTIONMULTIPLEXER_INT2(
       
   857         "CNcmConnectionMultiplexer::ConnectionNotify - \
       
   858             aStreamId:", aStreamId, "aConnectionId: ", aConnectionId )      
       
   859     __CONNECTIONMULTIPLEXER_INT2(
       
   860         "CNcmConnectionMultiplexer::ConnectionNotify - \
       
   861             aType:", aType, "aError: ", aError )  
       
   862              
       
   863     TRAP_IGNORE( this->ConnectionNotifyL( aStreamId, aConnectionId, aType,
       
   864         aError ) )      
       
   865     } 
       
   866 
       
   867 
       
   868 // ---------------------------------------------------------------------------
       
   869 // From class MNcmMultiplexerConnectionObserver
       
   870 //
       
   871 // CNcmConnectionMultiplexer::ConnectionNotifyL
       
   872 // ---------------------------------------------------------------------------
       
   873 //
       
   874 void CNcmConnectionMultiplexer::ConnectionNotifyL( TUint aStreamId,
       
   875     TUint aConnectionId, TMultiplexerConnectionNotifyType aType,
       
   876     TInt aError )
       
   877     {
       
   878     __CONNECTIONMULTIPLEXER( 
       
   879         "CNcmConnectionMultiplexer::ConnectionNotifyL" )
       
   880         
       
   881     TNcmCallBack callback( HandleCallBack, *this, aStreamId, aConnectionId,
       
   882                             aType, aError );
       
   883     iAsyncCallback->AddCallBackL( callback );        
       
   884     } 
       
   885  
       
   886          
       
   887 // ---------------------------------------------------------------------------
       
   888 // From class MNcmMultiplexerConnectionObserver
       
   889 //
       
   890 // CNcmConnectionMultiplexer::GetNewFreePortL
       
   891 // ---------------------------------------------------------------------------
       
   892 //
       
   893 void CNcmConnectionMultiplexer::GetNewFreePortL( TUint aStreamId,
       
   894     TUint /*aConnectionId*/, TUint& aPort )
       
   895     {
       
   896     __CONNECTIONMULTIPLEXER( 
       
   897         "CNcmConnectionMultiplexer::GetNewFreePortL" )
       
   898         
       
   899     aPort = SessionByStreamIdL( aStreamId )->PortStore().Port();
       
   900     }
       
   901  
       
   902        
       
   903 // ---------------------------------------------------------------------------
       
   904 // From class MNcmSessionObserver
       
   905 //
       
   906 // Called as a result for CreateSessionL() when wrapper is connected
       
   907 // ---------------------------------------------------------------------------
       
   908 //
       
   909 void CNcmConnectionMultiplexer::SessionCreationFailed( TUint aSessionId )
       
   910     {
       
   911     __CONNECTIONMULTIPLEXER(
       
   912         "CNcmConnectionMultiplexer::SessionCreationFailed" )
       
   913     
       
   914     TRAP_IGNORE( RemoveSessionL( aSessionId ) )
       
   915     }
       
   916 
       
   917 // ---------------------------------------------------------------------------
       
   918 // CNcmConnectionMultiplexer::SessionByIdL()
       
   919 // ---------------------------------------------------------------------------
       
   920 //       
       
   921 CNcmSession* CNcmConnectionMultiplexer::SessionByIdL(
       
   922     TUint aSessionId )
       
   923     {    
       
   924     TInt ind( iSessions.Count() );
       
   925     
       
   926     while ( ind-- )
       
   927         {
       
   928         if ( iSessions[ind]->SessionId() == aSessionId )
       
   929             {
       
   930             return iSessions[ind];
       
   931             }
       
   932         }
       
   933    
       
   934     User::Leave( KErrNotFound );
       
   935 #ifndef _DEBUG_EUNIT 
       
   936     return NULL;
       
   937 #endif
       
   938     }
       
   939  
       
   940     
       
   941 // ---------------------------------------------------------------------------
       
   942 // CNcmConnectionMultiplexer::StreamByIdL()
       
   943 // ---------------------------------------------------------------------------
       
   944 //       
       
   945 CNcmStream* CNcmConnectionMultiplexer::StreamByIdL(
       
   946     TUint aStreamId )
       
   947     {   
       
   948     TInt sessInd( iSessions.Count() );
       
   949     
       
   950     while ( sessInd-- )
       
   951         {
       
   952         CNcmStream* stream = iSessions[sessInd]->
       
   953             StreamByIdL( aStreamId );
       
   954             
       
   955         if ( stream )
       
   956             {
       
   957             return stream;
       
   958             }
       
   959         }
       
   960    
       
   961     User::Leave( KErrNotFound ); 
       
   962 #ifndef _DEBUG_EUNIT 
       
   963     return NULL;
       
   964 #endif
       
   965     }
       
   966 
       
   967 
       
   968 // ---------------------------------------------------------------------------
       
   969 // CNcmConnectionMultiplexer::StreamById()
       
   970 // ---------------------------------------------------------------------------
       
   971 //       
       
   972 CNcmStream* CNcmConnectionMultiplexer::StreamById(
       
   973     TUint aStreamId )
       
   974     {
       
   975     CNcmStream* stream( NULL );
       
   976     
       
   977     TRAP_IGNORE( ( stream = StreamByIdL( aStreamId ) ) )
       
   978  
       
   979     return stream;
       
   980     }
       
   981  
       
   982 
       
   983 // ---------------------------------------------------------------------------
       
   984 // CNcmConnectionMultiplexer::SessionByStreamIdL()
       
   985 // ---------------------------------------------------------------------------
       
   986 //       
       
   987 CNcmSession* CNcmConnectionMultiplexer::SessionByStreamIdL(
       
   988     TUint aStreamId )
       
   989     {   
       
   990     TInt sessInd( iSessions.Count() );
       
   991     
       
   992     while ( sessInd-- )
       
   993         {
       
   994         CNcmStream* stream = iSessions[sessInd]->
       
   995             StreamByIdL( aStreamId );
       
   996             
       
   997         if ( stream )
       
   998             {
       
   999             return iSessions[sessInd];
       
  1000             }
       
  1001         }
       
  1002     
       
  1003     User::Leave( KErrNotFound );
       
  1004 #ifndef _DEBUG_EUNIT 
       
  1005     return NULL;
       
  1006 #endif
       
  1007     }   
       
  1008 
       
  1009 
       
  1010 // ---------------------------------------------------------------------------
       
  1011 // From class MNcmMediaSourceObserver
       
  1012 //
       
  1013 // CNcmConnectionMultiplexer::WrapperSenderError
       
  1014 // ---------------------------------------------------------------------------
       
  1015 //
       
  1016 void CNcmConnectionMultiplexer::WrapperSenderError( TUint aStreamId,
       
  1017     TInt aError )
       
  1018     {
       
  1019     __CONNECTIONMULTIPLEXER_INT1( 
       
  1020         "CNcmConnectionMultiplexer::WrapperSenderObserver - Error: ", aError )
       
  1021     
       
  1022     TUint connectionId( 0 );
       
  1023     
       
  1024     TRAP_IGNORE( ( connectionId = StreamByIdL( aStreamId )->
       
  1025         MediaConnectionId() ) )
       
  1026         
       
  1027     this->ConnectionNotify( aStreamId, connectionId,
       
  1028         EMultiplexerConnectionError, aError );
       
  1029     }
       
  1030 
       
  1031 
       
  1032 // ---------------------------------------------------------------------------
       
  1033 // From class MNcmMediaSourceObserver
       
  1034 //
       
  1035 // CNcmConnectionMultiplexer::GetFreePort
       
  1036 // ---------------------------------------------------------------------------
       
  1037 //
       
  1038 void CNcmConnectionMultiplexer::GetFreePort( TUint aStreamId, TUint& aPort )
       
  1039     {
       
  1040     __CONNECTIONMULTIPLEXER( "CNcmConnectionMultiplexer::GetFreePort" )
       
  1041     
       
  1042     TRAP_IGNORE( ( aPort = SessionByStreamIdL( 
       
  1043         aStreamId )->PortStore().Port() ) )
       
  1044     }
       
  1045 
       
  1046 
       
  1047 // ---------------------------------------------------------------------------
       
  1048 // From class MNcmMediaSourceObserver
       
  1049 //
       
  1050 // CNcmConnectionMultiplexer::FirstMediaPacketSent
       
  1051 // ---------------------------------------------------------------------------
       
  1052 //
       
  1053 void CNcmConnectionMultiplexer::FirstMediaPacketSent( TUint aStreamId )
       
  1054     {
       
  1055     __CONNECTIONMULTIPLEXER_INT1(
       
  1056         "CNcmConnectionMultiplexer::FirstMediaPacketSent- aStreamId: ", aStreamId )
       
  1057  
       
  1058     TInt connectionId( 0 );
       
  1059     
       
  1060     TRAP_IGNORE(
       
  1061         ( connectionId = StreamByIdL( aStreamId )->MediaConnectionId() ) )
       
  1062     
       
  1063     TRAP_IGNORE( this->ConnectionNotifyL( aStreamId, connectionId,
       
  1064         EMultiplexerFirstMediaPacketSent, KErrNone ) )
       
  1065     }
       
  1066 
       
  1067 
       
  1068 // ---------------------------------------------------------------------------
       
  1069 // From class MNcmAsyncCallbackObserver
       
  1070 //
       
  1071 // CNcmConnectionMultiplexer::HandleCallBack
       
  1072 // ---------------------------------------------------------------------------
       
  1073 //
       
  1074 void CNcmConnectionMultiplexer::HandleCallBack( CBase& aObject,
       
  1075     TUint aStreamId, TUint aConnectionId,
       
  1076     TMultiplexerConnectionNotifyType aType, TInt aError )
       
  1077     {
       
  1078     CNcmConnectionMultiplexer& connMux(
       
  1079         static_cast<CNcmConnectionMultiplexer&>( aObject ) );
       
  1080     
       
  1081     TRAP_IGNORE( connMux.HandleCallBackL( aStreamId,
       
  1082                                         aConnectionId,
       
  1083                                         aType,
       
  1084                                         aError ) )
       
  1085     }
       
  1086 
       
  1087 
       
  1088 // ---------------------------------------------------------------------------
       
  1089 // CNcmConnectionMultiplexer::HandleCallBackL
       
  1090 // ---------------------------------------------------------------------------
       
  1091 //
       
  1092 void CNcmConnectionMultiplexer::HandleCallBackL( TUint aStreamId,
       
  1093     TUint aConnectionId, TMultiplexerConnectionNotifyType aType, TInt aError )
       
  1094     {
       
  1095     __CONNECTIONMULTIPLEXER( "CNcmConnectionMultiplexer::HandleCallBackL" )      
       
  1096                         
       
  1097     CNcmStream* stream( StreamByIdL( aStreamId ) );       
       
  1098     TUint sessionId( SessionByStreamIdL( aStreamId )->SessionId() );
       
  1099       
       
  1100     switch ( aType )
       
  1101         {
       
  1102         case EMultiplexerMediaReceivingActivated:
       
  1103             {          
       
  1104             iObserver.Notify( sessionId, aStreamId,
       
  1105                 MNcmConnectionMultiplexerObserver::
       
  1106                 EReceivingActivated, aError );                   
       
  1107             break;
       
  1108             }
       
  1109         case EMultiplexerMediaReceivingDeactivated:
       
  1110             {          
       
  1111             MNATFWMediaWrapper* wrapper = stream->WrapperL();
       
  1112             wrapper->SetReceivingStateForMuxWrapper( EStreamingStateActive );
       
  1113             iObserver.Notify( sessionId, aStreamId,
       
  1114                 MNcmConnectionMultiplexerObserver::
       
  1115                 EReceivingDeactivated, aError );                   
       
  1116             break;
       
  1117             }            
       
  1118         case EMultiplexerMediaSendingActivated:
       
  1119             {          
       
  1120             iObserver.Notify( sessionId, aStreamId,
       
  1121                 MNcmConnectionMultiplexerObserver::
       
  1122                 ESendingActivated, aError );                   
       
  1123             break;
       
  1124             }
       
  1125         case EMultiplexerMediaSendingDeactivated:
       
  1126             {          
       
  1127             MNATFWMediaWrapper* wrapper = stream->WrapperL();
       
  1128             wrapper->SetReceivingStateForMuxWrapper( EStreamingStatePassive );
       
  1129             iObserver.Notify( sessionId, aStreamId,
       
  1130                 MNcmConnectionMultiplexerObserver::
       
  1131                 ESendingDeactivated, aError );                   
       
  1132             break;
       
  1133             }
       
  1134                 
       
  1135         case EMultiplexerReceivingActivated:
       
  1136         case EMultiplexerSendingActivated:
       
  1137         case EMultiplexerReceivingDeactivated:     
       
  1138         case EMultiplexerSendingDeactivated:           
       
  1139         case EMultiplexerConnectionRemoved:
       
  1140         case EMultiplexerTcpSetupCompleted:
       
  1141         case EMultiplexerFirstMediaPacketSent:
       
  1142             {
       
  1143             stream->ConnectionObserverHandler().
       
  1144                 ConnectionNotify( aStreamId, aConnectionId, aType, aError );
       
  1145             break;
       
  1146             }             
       
  1147             
       
  1148         case EMultiplexerConnectionError:
       
  1149             { 
       
  1150             if( aConnectionId == stream->MediaConnectionId() )
       
  1151                 {
       
  1152                 iObserver.Notify( sessionId, aStreamId,
       
  1153                     MNcmConnectionMultiplexerObserver::EStreamError,
       
  1154                     aError );
       
  1155                 }
       
  1156                 
       
  1157             stream->ConnectionObserverHandler().
       
  1158                 ConnectionNotify( aStreamId, aConnectionId, aType, aError );
       
  1159             break;
       
  1160             }
       
  1161         }                   
       
  1162     }