natfw/natfwclient/src/natfwstream.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:   
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "mnatfwsocketmediaconnwrapper.h"
       
    22 #include "mnatfwconnectivityobserver.h"
       
    23 #include "natfwpluginapi.h"
       
    24 #include "natfwstream.h"
       
    25 #include "natfwsession.h"
       
    26 #include "mnatfwregistrationcontroller.h"
       
    27 #include "natfwsocketmediaconnwrapper.h"
       
    28 #include "cncmconnectionmultiplexer.h"
       
    29 #include "cncmportstore.h"
       
    30 #include "cnatfwasynccallback.h"
       
    31 #include "natfwclientlogs.h"
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CNATFWStream::CNATFWStream
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CNATFWStream::CNATFWStream(
       
    40         MNATFWRegistrationController& aController,
       
    41         CNcmConnectionMultiplexer& aMultiplexer,
       
    42         CNatFwAsyncCallback& aAsyncCallback,
       
    43         CNATFWSession& aContext,
       
    44         TUint aProtocol, TInt aQoS )
       
    45     :
       
    46     iQoS( aQoS ),
       
    47     iProtocol( aProtocol ),
       
    48     iController( aController ),
       
    49     iMultiplexer( aMultiplexer ),
       
    50     iAsyncCallback( aAsyncCallback ),
       
    51     iContext( aContext )
       
    52     {
       
    53     }
       
    54 
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CNATFWStream::ConstructL
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 void CNATFWStream::ConstructL()
       
    61     {
       
    62     iStreamId = iMultiplexer.CreateStreamL( iContext.SessionId(),
       
    63         iQoS, iProtocol );
       
    64     }
       
    65 
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CNATFWStream::NewL
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 CNATFWStream* CNATFWStream::NewL(
       
    72         MNATFWRegistrationController& aController,
       
    73         CNcmConnectionMultiplexer& aMultiplexer,
       
    74         CNatFwAsyncCallback& aAsyncCallback,
       
    75         CNATFWSession& aContext,
       
    76         TUint aProtocol, TInt aQoS )
       
    77     {
       
    78     CNATFWStream* self = CNATFWStream::NewLC( aController, aMultiplexer,
       
    79         aAsyncCallback, aContext, aProtocol, aQoS );
       
    80     CleanupStack::Pop( self );
       
    81     return self;
       
    82     }
       
    83 
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // CNATFWStream::NewLC
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 CNATFWStream* CNATFWStream::NewLC(
       
    90         MNATFWRegistrationController& aController,
       
    91         CNcmConnectionMultiplexer& aMultiplexer,
       
    92         CNatFwAsyncCallback& aAsyncCallback,
       
    93         CNATFWSession& aContext,
       
    94         TUint aProtocol, TInt aQoS )
       
    95     {
       
    96     CNATFWStream* self = new ( ELeave ) CNATFWStream( aController,
       
    97         aMultiplexer, aAsyncCallback, aContext, aProtocol, aQoS );
       
    98     CleanupStack::PushL( self );
       
    99     self->ConstructL();
       
   100     return self;
       
   101     }
       
   102 
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // CNATFWStream::~CNATFWStream
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 CNATFWStream::~CNATFWStream()
       
   109     {
       
   110     __NATFWCLIENT("CNATFWStream::~CNATFWStream")
       
   111 
       
   112     iPlugin = NULL;
       
   113     TInt err = KErrNone;
       
   114     TRAP( err, iMultiplexer.RemoveStreamL( iStreamId ) );
       
   115 
       
   116     __NATFWCLIENT_INT1( "CNATFWStream::~CNATFWStream end, ERR:", err )
       
   117     }
       
   118 
       
   119 
       
   120 // Non-derived function
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // Return unique identifier of the stream.
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 TUint CNATFWStream::StreamId() const
       
   127     {
       
   128     return iStreamId;
       
   129     }
       
   130 
       
   131 // Derived function
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CNATFWStream::CreateWrapperL
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 MNATFWSocketMediaConnWrapper& CNATFWStream::CreateWrapperL( )
       
   138     {
       
   139     __NATFWCLIENT("CNATFWStream::CreateWrapperL")
       
   140 
       
   141     CNATFWSocketMediaConnWrapper* wrapper =
       
   142         CNATFWSocketMediaConnWrapper::NewL(
       
   143         iMultiplexer.PortStoreL( iContext.SessionId() ).Port(),
       
   144         iProtocol, iStreamId );
       
   145 
       
   146     // Ownership transfered to Connection Multiplexer
       
   147     iMultiplexer.RegisterMediaWrapperL( wrapper );
       
   148     return *wrapper;
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CNATFWStream::SetProtocolPlugin
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CNATFWStream::SetProtocolPlugin( CNATFWPluginApi* aPlugin )
       
   156     {
       
   157     __NATFWCLIENT("CNATFWStream::SetProtocolPlugin")
       
   158     iPlugin = aPlugin;
       
   159     }
       
   160 
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // CNATFWStream::FetchCandidateL
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 void CNATFWStream::FetchCandidateL( TUint aAddrFamily )
       
   167     {
       
   168     __NATFWCLIENT("CNATFWStream::FetchCandidateL")
       
   169     __ASSERT_ALWAYS( iPlugin, User::Leave( KErrNotReady ) );
       
   170 
       
   171     iPlugin->FetchCandidateL( iStreamId, 0, aAddrFamily );
       
   172     }
       
   173 
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // CNATFWStream::FetchCandidatesL
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 void CNATFWStream::FetchCandidatesL( TUint aCollectionId,
       
   180         TUint aComponentId, TUint aAddrFamily )
       
   181     {
       
   182     __NATFWCLIENT("CNATFWStream::FetchCandidatesL")
       
   183     __ASSERT_ALWAYS( iPlugin, User::Leave( KErrNotReady ) );
       
   184 
       
   185     iPlugin->FetchCandidatesL( 
       
   186         aCollectionId, iStreamId, aComponentId, aAddrFamily );
       
   187     }
       
   188 
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CNATFWStream::SetCredentialsL
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 void CNATFWStream::SetCredentialsL(
       
   195     const CNATFWCandidate& aCandidate,
       
   196     const CNATFWCredentials& aCredentials )
       
   197     {
       
   198     __NATFWCLIENT("CNATFWStream::SetCredentialsL")
       
   199     __ASSERT_ALWAYS( iPlugin, User::Leave( KErrNotReady ) );
       
   200 
       
   201     iPlugin->SetCredentialsL( aCandidate, aCredentials );
       
   202     }
       
   203 
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 // CNATFWStream::SetReceivingStateL
       
   207 // ---------------------------------------------------------------------------
       
   208 //
       
   209 void CNATFWStream::SetReceivingStateL( 
       
   210         const CNATFWCandidate& aLocalCandidate,
       
   211         TNATFWStreamingState aState )
       
   212     {
       
   213     TUint connectionForMedia( 0 );
       
   214     iPlugin->GetConnectionIdL( aLocalCandidate, connectionForMedia );
       
   215 
       
   216     iPlugin->SetReceivingStateL( aLocalCandidate, aState );
       
   217     iMultiplexer.SetReceivingStateForMediaL( 
       
   218         iStreamId, connectionForMedia, aState );
       
   219     }
       
   220 
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CNATFWStream::SetSendingStateL
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CNATFWStream::SetSendingStateL(
       
   227         const CNATFWCandidate& aLocalCandidate,
       
   228         TNATFWStreamingState aState, const TInetAddr& aDestAddr )
       
   229     {
       
   230     iDestAddr = aDestAddr;
       
   231     TUint connectionForMedia( 0 );
       
   232     iPlugin->GetConnectionIdL( aLocalCandidate, connectionForMedia );
       
   233 
       
   234     iPlugin->SetSendingStateL( aLocalCandidate, aState, aDestAddr );
       
   235     iMultiplexer.SetSendingStateForMediaL(
       
   236         iStreamId, connectionForMedia, aState );
       
   237     }
       
   238 
       
   239 
       
   240 // ---------------------------------------------------------------------------
       
   241 // CNATFWStream::Notify
       
   242 // ---------------------------------------------------------------------------
       
   243 //
       
   244 void CNATFWStream::Notify( TUint aSessionId, TUint aStreamId,
       
   245     MNcmConnectionMultiplexerObserver::TNotifyType aType, TInt aError )
       
   246     {
       
   247     __NATFWCLIENT_INT2(
       
   248         "CNATFWStream::Notify, SESSION:", aSessionId, "STREAM:", aStreamId )
       
   249 
       
   250     switch ( aType )
       
   251         {
       
   252         case MNcmConnectionMultiplexerObserver::EReceivingActivated:
       
   253             {
       
   254             __NATFWCLIENT_INT1(
       
   255                 "CNATFWStream::Notify, EReceivingActivated, ERR:", aError )
       
   256 
       
   257             DoNotify( aSessionId, aStreamId,
       
   258                 MNATFWConnectivityObserver::EReceivingActivated, aError );
       
   259             }
       
   260             break;
       
   261 
       
   262         case MNcmConnectionMultiplexerObserver::EReceivingDeactivated:
       
   263             {
       
   264             __NATFWCLIENT_INT1(
       
   265                 "CNATFWStream::Notify, EReceivingDeactivated, ERR:", aError )
       
   266 
       
   267             DoNotify( aSessionId, aStreamId,
       
   268                 MNATFWConnectivityObserver::EReceivingDeactivated, aError );
       
   269             }
       
   270             break;
       
   271 
       
   272         case MNcmConnectionMultiplexerObserver::ESendingActivated:
       
   273             {
       
   274             __NATFWCLIENT_INT1(
       
   275                 "CNATFWStream::Notify, ESendingActivated, ERR:", aError )
       
   276 
       
   277             DoNotify( aSessionId, aStreamId,
       
   278                 MNATFWConnectivityObserver::ESendingActivated, aError );
       
   279             }
       
   280             break;
       
   281 
       
   282         case MNcmConnectionMultiplexerObserver::ESendingDeactivated:
       
   283             {
       
   284             __NATFWCLIENT_INT1(
       
   285                 "CNATFWStream::Notify, ESendingDeactivated, ERR:", aError )
       
   286 
       
   287             DoNotify( aSessionId, aStreamId,
       
   288                 MNATFWConnectivityObserver::ESendingDeactivated, aError );
       
   289             }
       
   290             break;
       
   291 
       
   292         case MNcmConnectionMultiplexerObserver::EStreamError:
       
   293             {
       
   294             __NATFWCLIENT_INT1(
       
   295                 "CNATFWStream::Notify, EStreamError, ERR:", aError )
       
   296 
       
   297             DoNotify( aSessionId, aStreamId,
       
   298                 MNATFWConnectivityObserver::EGeneralError, aError );
       
   299             }
       
   300             break;
       
   301 
       
   302         default:
       
   303             __NATFWCLIENT("CNATFWStream::Notify, DEFAULT")
       
   304 
       
   305             ASSERT( EFalse );
       
   306             break;
       
   307         }
       
   308     }
       
   309 
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // CNATFWStream::DoNotify
       
   313 // ---------------------------------------------------------------------------
       
   314 //
       
   315 void CNATFWStream::DoNotify( TUint aSessionId, TUint aStreamId,
       
   316     MNATFWConnectivityObserver::TNATFWConnectivityEvent aEvent, TInt aError )
       
   317     {
       
   318 
       
   319     CNatFwCallbackInfo::TFunction func =
       
   320         static_cast<CNatFwCallbackInfo::TFunction>( aEvent );
       
   321 
       
   322     TRAP_IGNORE( iAsyncCallback.MakeCallbackL( iController, func,
       
   323         aSessionId, aStreamId, aError, NULL ) )
       
   324     }
       
   325