natfw/natfwclient/tsrc/ut_natfwclient/stubs/cncmsession_stub.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 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:    NATFW Connection multiplexer session abstraction.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <commdbconnpref.h>
       
    22 #include <e32math.h> 
       
    23 
       
    24 #include "cncmsession.h"
       
    25 #include "cncmstream.h"
       
    26 //#include "natfwmultiplexerconnectionobserverhandler.h"
       
    27 //#include "natfwlocaladdressresolver.h"
       
    28 #include "mncmconnectionmultiplexerobserver.h"
       
    29 //#include "cnatfwmultiplexericmpreceiver.h"
       
    30 #include "mncmsessionobserver.h"
       
    31 #include "ncmconnectionmultiplexerlogs.h"
       
    32 #include "cncmportstore.h"
       
    33 
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CNcmSession::CNcmSession
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CNcmSession::CNcmSession( TUint aSessionId,
       
    40     TUint32 aIapId,
       
    41     MNcmConnectionMultiplexerObserver& aObserver,
       
    42     MNcmSessionObserver& aSessionObserver ) :
       
    43     CActive( EPriorityStandard ),
       
    44     iSessionId( aSessionId ), iIapId( aIapId ), iObserver( aObserver ),
       
    45     iSessionObserver( aSessionObserver )
       
    46     {
       
    47     CActiveScheduler::Add( this );
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // CNcmSession::ConstructL
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 void CNcmSession::ConstructL( TUint aPortRangeStart,
       
    55                                            TUint aPortRangeStop )
       
    56     {
       
    57     iPortStore = CNcmPortStore::NewL( aPortRangeStart, aPortRangeStop );
       
    58     /*
       
    59     User::LeaveIfError( iSocketServ.Connect() );
       
    60 
       
    61     TCommDbConnPref pref;
       
    62     pref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt );
       
    63     pref.SetIapId( iIapId );  
       
    64                                                  
       
    65     User::LeaveIfError( iConnection.Open( iSocketServ ) );
       
    66     iConnection.Start( pref, iStatus );
       
    67   */
       
    68     TRequestStatus* status = &iStatus;
       
    69     iStatus = KRequestPending;
       
    70     SetActive();
       
    71     
       
    72     User::RequestComplete( status, KErrNone );
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CNcmSession::NewL
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 CNcmSession* CNcmSession::NewL( TUint aSessionId,
       
    80     TUint32 aIapId, TUint aPortRangeStart, TUint aPortRangeStop,
       
    81     MNcmConnectionMultiplexerObserver& aObserver,
       
    82     MNcmSessionObserver& aSessionObserver )
       
    83     {   
       
    84     CNcmSession* self =
       
    85         new( ELeave ) CNcmSession( aSessionId, aIapId,
       
    86             aObserver, aSessionObserver );
       
    87                     
       
    88     CleanupStack::PushL( self );
       
    89     self->ConstructL( aPortRangeStart, aPortRangeStop );
       
    90     CleanupStack::Pop( self );
       
    91     return self;
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CNcmSession::~CNcmSession
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 CNcmSession::~CNcmSession()
       
    99     {
       
   100     delete iPortStore;
       
   101     
       
   102     TInt ind( iStreams.Count() );
       
   103     
       
   104     while ( ind-- )
       
   105         {
       
   106         TRAP_IGNORE( RemoveStreamL( iStreams[ind]->StreamId() ) )
       
   107         }   
       
   108     
       
   109     //delete iIcmpReceiver;
       
   110     
       
   111     //iConnection.Close();    
       
   112     Cancel();
       
   113 
       
   114     //iSocketServ.Close();
       
   115     iStreams.Close();
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CNcmSession::CreateStreamL
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 TUint CNcmSession::CreateStreamL( TInt aQos,
       
   123     TUint aProtocol )
       
   124     {
       
   125     TUint streamId( GenerateStreamId() );
       
   126 
       
   127     CNcmStream* item = CNcmStream::NewL(
       
   128         iSessionId, streamId, aQos, aProtocol );
       
   129         
       
   130     CleanupStack::PushL( item );
       
   131     iStreams.AppendL( item ); 
       
   132     CleanupStack::Pop( item );
       
   133     
       
   134     return item->StreamId();
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // CNcmSession::RemoveStreamL
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CNcmSession::RemoveStreamL( TUint aStreamId )
       
   142     {    
       
   143     TUint streamIndex( StreamIndexL( aStreamId ) );
       
   144     
       
   145     delete iStreams[streamIndex];
       
   146     iStreams.Remove( streamIndex );
       
   147     }
       
   148     
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // CNcmSession::ConnectionId
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 TUint32 CNcmSession::IapId() const
       
   155     { 
       
   156     return iIapId;
       
   157     }
       
   158     
       
   159 // ---------------------------------------------------------------------------
       
   160 // CNcmSession::ConnectionId
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 TUint CNcmSession::SessionId() const
       
   164     {
       
   165     return iSessionId;
       
   166     }
       
   167 
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // From class CActive
       
   171 //
       
   172 // CNATFWMultiplexerSocketDestination::RunL
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 void CNcmSession::RunL()
       
   176     {
       
   177     __CONNECTIONMULTIPLEXER_INT1(
       
   178         "CNcmSession::RunL - iStatus: ", iStatus.Int() )
       
   179                    
       
   180     if ( iStatus != KErrNone )
       
   181         {
       
   182         iObserver.Notify( iSessionId, 0,
       
   183             MNcmConnectionMultiplexerObserver::ESessionCreated,
       
   184             iStatus.Int() );
       
   185             
       
   186         //iSessionObserver.SessionCreationFailed( iSessionId );
       
   187         }
       
   188     else
       
   189         {
       
   190 /*        
       
   191 #ifndef _DEBUG_EUNIT
       
   192         iIcmpReceiver = CNATFWMultiplexerIcmpReceiver::NewL( iSessionId,
       
   193                                                              iObserver,
       
   194                                                              iSocketServ );
       
   195 #endif
       
   196         CNATFWLocalAddressResolver* localAddressResolver(
       
   197             CNATFWLocalAddressResolver::NewLC( iSocketServ ) );
       
   198             
       
   199         localAddressResolver->GetLocalAddrL( iLocalAddr, iIapId );
       
   200         CleanupStack::PopAndDestroy( localAddressResolver );
       
   201 */                
       
   202         iObserver.Notify( iSessionId, 0,
       
   203             MNcmConnectionMultiplexerObserver::ESessionCreated,
       
   204             iStatus.Int() );
       
   205         }
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 // From class CActive
       
   210 //
       
   211 // DoCancel
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 void CNcmSession::DoCancel()
       
   215     {    
       
   216     iConnection.Close();
       
   217     // RConnection doesn't cancel an outstanding request at Close()
       
   218     // so we'll have to it "manually" here
       
   219     if( iStatus.Int() == KRequestPending )
       
   220         {
       
   221         TRequestStatus* status = &iStatus;
       
   222         User::RequestComplete( status, KErrCancel );
       
   223         }
       
   224     }
       
   225 
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // From class CActive
       
   229 //
       
   230 // CNcmSession::RunError
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 TInt CNcmSession::RunError( TInt aError )
       
   234     {
       
   235     __CONNECTIONMULTIPLEXER_INT1(
       
   236         "CNcmSession::RunError aError: ", aError )
       
   237   
       
   238     iObserver.Notify( iSessionId, 0,
       
   239         MNcmConnectionMultiplexerObserver::ESessionCreated,
       
   240         aError );
       
   241         
       
   242     iSessionObserver.SessionCreationFailed( iSessionId );
       
   243 
       
   244     aError = aError;
       
   245     return KErrNone;
       
   246     }
       
   247     
       
   248         
       
   249 // ---------------------------------------------------------------------------
       
   250 // CNATFWSession::StreamByIdL
       
   251 // ---------------------------------------------------------------------------
       
   252 //
       
   253 CNcmStream* CNcmSession::StreamByIdL(
       
   254     TUint aStreamId )
       
   255     {
       
   256     TInt ind( iStreams.Count() );
       
   257     
       
   258     while ( ind-- )
       
   259         {
       
   260         if ( iStreams[ind]->StreamId() == aStreamId )
       
   261             {
       
   262             return iStreams[ind];
       
   263             }
       
   264         }
       
   265     
       
   266     return NULL;
       
   267     }
       
   268     
       
   269 // ---------------------------------------------------------------------------
       
   270 // CNcmSession::StreamIndexL
       
   271 // ---------------------------------------------------------------------------
       
   272 //
       
   273 TUint CNcmSession::StreamIndexL( TUint aStreamId )
       
   274     {   
       
   275     TInt streamCount( iStreams.Count() );
       
   276     
       
   277     for ( TInt i = 0; i < streamCount; i++ )
       
   278         {
       
   279         if ( iStreams[i]->StreamId() == aStreamId )
       
   280             {
       
   281             return i;
       
   282             }
       
   283         }
       
   284     User::Leave( KErrNotFound );
       
   285     return KErrNone; // for warning removal on compile
       
   286     }
       
   287     
       
   288 // ---------------------------------------------------------------------------
       
   289 // CNcmSession::SocketServer
       
   290 // ---------------------------------------------------------------------------
       
   291 //
       
   292 RSocketServ& CNcmSession::SocketServer()
       
   293     {
       
   294     return iSocketServ;
       
   295     }
       
   296 
       
   297 
       
   298 // ---------------------------------------------------------------------------
       
   299 // CNcmSession::Connection
       
   300 // ---------------------------------------------------------------------------
       
   301 //
       
   302 RConnection& CNcmSession::Connection()
       
   303     {  
       
   304     return iConnection;
       
   305     }
       
   306     
       
   307 // -----------------------------------------------------------------------------
       
   308 // CNcmSession::GenerateStreamId
       
   309 // -----------------------------------------------------------------------------
       
   310 //
       
   311 TUint CNcmSession::GenerateStreamId() const
       
   312     {
       
   313     return ( static_cast<TUint>( Math::Random() ) );
       
   314     }
       
   315    
       
   316 
       
   317 // ---------------------------------------------------------------------------
       
   318 // CNcmSession::PortStore
       
   319 // ---------------------------------------------------------------------------
       
   320 //
       
   321 CNcmPortStore& CNcmSession::PortStore() const
       
   322     {
       
   323     __CONNECTIONMULTIPLEXER( "CNcmSession::PortStore" )
       
   324 
       
   325     return *iPortStore;
       
   326     }
       
   327 // ---------------------------------------------------------------------------
       
   328 // CNcmSession::LocalIPv4Address
       
   329 // ---------------------------------------------------------------------------
       
   330 //
       
   331 TInetAddr& CNcmSession::LocalIPv4Address()
       
   332     {
       
   333     return iIpv4Addr;
       
   334     }
       
   335 
       
   336 // ---------------------------------------------------------------------------
       
   337 // CNcmSession::LocalIPv6Address
       
   338 // ---------------------------------------------------------------------------
       
   339 //
       
   340 TInetAddr& CNcmSession::LocalIPv6Address()
       
   341     {
       
   342     return iIpv6Addr;
       
   343     }
       
   344 
       
   345 
       
   346 // ---------------------------------------------------------------------------
       
   347 // CNcmSession::IcmpError
       
   348 // ---------------------------------------------------------------------------
       
   349 //
       
   350 void CNcmSession::IcmpError( const TInetAddr& /*aAddress*/, TInetAddr& /*aLocalAddress*/,
       
   351         TInetAddr& /*aRemoteAddress*/ )
       
   352 {
       
   353 }