natfw/natfwstunplugin/tsrc/ut_cnatfwstunplugin/stubs/cncmstream_stub.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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 stream abstraction.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include "cncmstream.h"
       
    23 #include "ncmconnectionmultiplexerlogs.h"
       
    24 #include "ncmconnectionmultiplexerassert.h"
       
    25 #include "natfwmediawrapper.h"
       
    26 #include "cncmconnectionobserverhandler.h"
       
    27 #include "cncmconnection.h"
       
    28 
       
    29 const TUint KFirstConnectionId = 1;
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // CNcmStream::CNcmStream
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 CNcmStream::CNcmStream( TUint aSessionId,
       
    36     TUint aStreamId, TInt aQos, TUint aProtocol ):
       
    37     iSessionId( aSessionId ), iStreamId( aStreamId ), iQos( aQos ),
       
    38     iStreamProtocol( aProtocol ),
       
    39     iNextConnectionId( KFirstConnectionId ),
       
    40     iMediaConnectionId( 0 )
       
    41     {
       
    42     }
       
    43 
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CNcmStream::NewL
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CNcmStream* CNcmStream::NewL( TUint aSessionId,
       
    50     TUint aStreamId, TInt aQos, TUint aProtocol )
       
    51     {
       
    52     __CONNECTIONMULTIPLEXER( "CNcmStream::NewL" )
       
    53     
       
    54     CNcmStream* self =
       
    55         CNcmStream::NewLC( aSessionId, aStreamId, aQos, aProtocol );
       
    56             
       
    57     CleanupStack::Pop( self );
       
    58     return self;
       
    59     }
       
    60 
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // CNcmStream::NewLC
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CNcmStream* CNcmStream::NewLC( TUint aSessionId,
       
    67     TUint aStreamId, TInt aQos, TUint aProtocol )
       
    68     {
       
    69     __CONNECTIONMULTIPLEXER( "CNcmStream::NewLC" )
       
    70     
       
    71     CNcmStream* self =
       
    72         new( ELeave ) CNcmStream( aSessionId, aStreamId, aQos, aProtocol );
       
    73         
       
    74     CleanupStack::PushL( self );
       
    75     self->ConstructL();
       
    76     return self;
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CNcmStream::ConstructL
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 void CNcmStream::ConstructL()
       
    84     {
       
    85     /*
       
    86     iConnectionObserverHandler =
       
    87         CNcmConnectionObserverHandler::NewL();
       
    88     */
       
    89     }
       
    90     
       
    91 // ---------------------------------------------------------------------------
       
    92 // CNcmStream::~CNcmStream
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 CNcmStream::~CNcmStream()
       
    96     {
       
    97     /*
       
    98     __CONNECTIONMULTIPLEXER_INT1(
       
    99         "CNcmStream::~CNcmStream, CONN_COUNT: ", 
       
   100         iConnections.Count() )
       
   101     
       
   102     TInt ind( KErrNotFound );
       
   103     while ( KErrNotFound != ( ind = iConnections.Count() - 1 ) )
       
   104         {
       
   105         TUint connectionId = iConnections[ind]->ConnectionId();
       
   106         
       
   107         delete iConnections[ind];
       
   108         iConnections.Remove( ind );
       
   109         
       
   110         if ( iConnectionObserverHandler )
       
   111             {
       
   112             iConnectionObserverHandler->ConnectionNotify( iStreamId,
       
   113                 connectionId, EMultiplexerConnectionRemoved, KErrNone );
       
   114             }
       
   115         }
       
   116     iConnections.Close();
       
   117     
       
   118     if ( iWrapper )
       
   119         {
       
   120         iWrapper->Close();  
       
   121         }
       
   122     
       
   123     iWrapper = NULL;
       
   124     delete iConnectionObserverHandler;
       
   125     */
       
   126     }
       
   127 /*    
       
   128 // ---------------------------------------------------------------------------
       
   129 // CNcmStream::CreateConnectionL
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 TUint CNcmStream::CreateConnectionL(
       
   133         MNcmMultiplexerConnectionObserver& aObserver,
       
   134         CNcmConnectionObserverHandler& 
       
   135         aConnectionObserverHandler )
       
   136     {   
       
   137     CNcmConnection* multiplexer(
       
   138         CNcmConnection::NewL( iSessionId, iStreamId,
       
   139             iNextConnectionId, iLocalAddr, aObserver,
       
   140             aConnectionObserverHandler ) );
       
   141                                          
       
   142     CleanupStack::PushL( multiplexer );
       
   143     
       
   144     iConnections.AppendL( multiplexer );
       
   145     
       
   146     iNextConnectionId++;
       
   147     CleanupStack::Pop( multiplexer ); 
       
   148     return multiplexer->ConnectionId();
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CNcmStream::RemoveConnectionL
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CNcmStream::RemoveConnectionL( TUint aConnectionId )
       
   156     {
       
   157     __CONNECTIONMULTIPLEXER_INT1(
       
   158         "CNcmStream::Remove - RemoveConnectionL: ", aConnectionId )
       
   159     
       
   160     TInt count( iConnections.Count() );
       
   161     TBool found( EFalse );
       
   162         
       
   163     for ( TInt i = 0; i < count; i++ )
       
   164         {
       
   165         if ( iConnections[i]->ConnectionId() == aConnectionId )
       
   166             {      
       
   167             delete iConnections[i];  
       
   168             iConnections.Remove( i );
       
   169             found = ETrue;
       
   170             break;
       
   171             }
       
   172         }
       
   173        
       
   174     if ( !found )
       
   175         {
       
   176         User::Leave( KErrNotFound );
       
   177         }
       
   178     } 
       
   179 */   
       
   180 // ---------------------------------------------------------------------------
       
   181 // CNcmStream::StreamId
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 TUint CNcmStream::StreamId() const
       
   185     {
       
   186     return iStreamId;
       
   187     }
       
   188 
       
   189 /*
       
   190 // ---------------------------------------------------------------------------
       
   191 // CNcmStream::Qos
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 TInt CNcmStream::Qos() const
       
   195     {
       
   196     return iQos;
       
   197     }
       
   198 
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // CNcmStream::SetQos
       
   202 // ---------------------------------------------------------------------------
       
   203 //
       
   204 void CNcmStream::SetQos( TInt aQos )
       
   205     {
       
   206     __CONNECTIONMULTIPLEXER_INT1( "CNcmStream::SetQos - aQos: ", aQos )
       
   207     
       
   208     iQos = aQos;
       
   209     }
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // CNcmStream::ConnectionL
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 CNcmConnection* CNcmStream::ConnectionL(
       
   216     TUint aConnectionId )
       
   217     {
       
   218     __CONNECTIONMULTIPLEXER_INT1(
       
   219         "CNcmStream::ConnectionL - aConnectionId: ", aConnectionId )
       
   220     
       
   221     TInt count( iConnections.Count() );
       
   222     
       
   223     for ( TInt i = 0; i < count; i++ )
       
   224         {
       
   225         if ( iConnections[i]->ConnectionId() == aConnectionId )
       
   226             {
       
   227             return iConnections[i];
       
   228             }
       
   229         }
       
   230     User::Leave( KErrNotFound );    
       
   231 #ifndef _DEBUG_EUNIT
       
   232     return NULL;
       
   233 #endif
       
   234     }
       
   235 
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // CNcmStream::RegisterWrapperL
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CNcmStream::RegisterWrapperL(
       
   242     MNATFWMediaWrapper* aWrapper )
       
   243     {
       
   244     __CONNECTIONMULTIPLEXER( 
       
   245         "CNcmStream::RegisterWrapperL" )
       
   246     __CONNECTIONMULTIPLEXER_ASSERT_L( NULL != aWrapper, KErrArgument );
       
   247     __CONNECTIONMULTIPLEXER_ASSERT_L( NULL == iWrapper, KErrAlreadyExists );
       
   248         
       
   249     iWrapper = aWrapper;
       
   250     }
       
   251 
       
   252 
       
   253 // ---------------------------------------------------------------------------
       
   254 // CNcmStream::WrapperL
       
   255 // ---------------------------------------------------------------------------
       
   256 //
       
   257 MNATFWMediaWrapper& CNcmStream::WrapperL()
       
   258     {
       
   259     __CONNECTIONMULTIPLEXER( "CNcmStream::WrapperL" )
       
   260     __CONNECTIONMULTIPLEXER_ASSERT_L( NULL != iWrapper, KErrNotReady );
       
   261 
       
   262     return *iWrapper;
       
   263     }
       
   264 
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // CNcmStream::StreamProtocol
       
   268 // ---------------------------------------------------------------------------
       
   269 //
       
   270 TUint CNcmStream::StreamProtocol() const
       
   271     {
       
   272     __CONNECTIONMULTIPLEXER( 
       
   273         "CNcmStream::StreamProtocol" )
       
   274 
       
   275     return iStreamProtocol;
       
   276     }
       
   277 
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 // CNcmStream::SetStreamProtocol
       
   281 // ---------------------------------------------------------------------------
       
   282 //
       
   283 void CNcmStream::SetStreamProtocol(
       
   284     TUint aProtocol )
       
   285     {
       
   286     __CONNECTIONMULTIPLEXER( 
       
   287         "CNcmStream::SetStreamProtocol" )
       
   288         
       
   289     iStreamProtocol = aProtocol;
       
   290     }
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // SetPendingDefaultConnection
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 TUint CNcmStream::DefaultConnectionId() const
       
   297     {
       
   298     __CONNECTIONMULTIPLEXER( 
       
   299         "CNcmStream::DefaultConnectionId ")
       
   300         
       
   301     return iDefaultConnectionId;
       
   302     }
       
   303 */
       
   304 // ---------------------------------------------------------------------------
       
   305 // CNcmStream::SetLocalAddr
       
   306 // ---------------------------------------------------------------------------
       
   307 //
       
   308 /*void CNcmStream::SetLocalAddr( const TInetAddr& aLocalAddr )
       
   309     {
       
   310     iLocalAddr = aLocalAddr; 
       
   311     iLocalAddr.SetPort( aLocalAddr.Port() ); 
       
   312     } */
       
   313 
       
   314 // ---------------------------------------------------------------------------
       
   315 // CNcmStream::LocalAddress
       
   316 // ---------------------------------------------------------------------------
       
   317 //
       
   318 /*TInetAddr& CNcmStream::LocalAddress()
       
   319     {
       
   320     return iLocalAddr; 
       
   321     }*/
       
   322 /*
       
   323 // ---------------------------------------------------------------------------
       
   324 // CNcmStream::Port()
       
   325 // ---------------------------------------------------------------------------
       
   326 //
       
   327 TUint CNcmStream::Port() const
       
   328     {
       
   329     return iLocalAddr.Port(); 
       
   330     }
       
   331 
       
   332 // ---------------------------------------------------------------------------
       
   333 // CNcmStream::SetPort()
       
   334 // ---------------------------------------------------------------------------
       
   335 //
       
   336 void CNcmStream::SetPort( TUint aPort )
       
   337     {
       
   338     iLocalAddr.SetPort( aPort ); 
       
   339     }
       
   340         
       
   341 // -----------------------------------------------------------------------------
       
   342 // CNcmStream::ConnectionObserverHandler
       
   343 // -----------------------------------------------------------------------------
       
   344 //    
       
   345 CNcmConnectionObserverHandler&
       
   346     CNcmStream::ConnectionObserverHandler()   
       
   347     {
       
   348     return *iConnectionObserverHandler;
       
   349     }
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // CNcmStream::ConnectionIdByDestinationAddressL(
       
   353 // ---------------------------------------------------------------------------
       
   354 //
       
   355 CNcmConnection*
       
   356     CNcmStream::ConnectionByDestinationAddressL(
       
   357     const TInetAddr& aDestinationAddress )
       
   358     {
       
   359     __CONNECTIONMULTIPLEXER( 
       
   360         "CNcmStream::ConnectionByDestinationAddressL" ) 
       
   361            
       
   362     TInt ind( iConnections.Count() );
       
   363     
       
   364     while ( ind-- )
       
   365         {
       
   366         if ( iConnections[ind]->Destination()->
       
   367             CheckSenderValidityToSending( aDestinationAddress ) )
       
   368             {
       
   369             return iConnections[ind];
       
   370             }
       
   371         }
       
   372     
       
   373     User::Leave( KErrNotFound );   
       
   374 #ifndef _DEBUG_EUNIT
       
   375     return NULL;
       
   376 #endif
       
   377     }   
       
   378 
       
   379 // ---------------------------------------------------------------------------
       
   380 // CNcmStream::RegisterMediaSourceL
       
   381 // ---------------------------------------------------------------------------
       
   382 //
       
   383 void CNcmStream::RegisterMediaSourceL( CNcmMediaSource* aMediaSource )
       
   384     {
       
   385     iConnectionObserverHandler->RegisterMediaSourceL( aMediaSource );
       
   386     }
       
   387 
       
   388 // ---------------------------------------------------------------------------
       
   389 // CNcmStream::IcmpErrorReceived
       
   390 // ---------------------------------------------------------------------------
       
   391 //
       
   392 TBool CNcmStream::IcmpErrorReceived() const
       
   393     {
       
   394     return iIcmpErrorReceived; 
       
   395     }
       
   396 
       
   397 // ---------------------------------------------------------------------------
       
   398 // CNcmStream::SetIcmpErrorReceived
       
   399 // ---------------------------------------------------------------------------
       
   400 //
       
   401 void CNcmStream::SetIcmpErrorReceived( TBool aIcmpErrorReceived )
       
   402     {
       
   403     iIcmpErrorReceived = aIcmpErrorReceived; 
       
   404     }
       
   405   */