natplugins/natpnatfwsdpprovider/src/nspactive.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:  Async callback implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <sdpdocument.h>
       
    19 #include "nspsessionobserver.h"
       
    20 #include "nspactive.h"
       
    21 #include "nspcontroller.h"
       
    22 #include "nspevents.h"
       
    23 #include "nspsession.h"
       
    24 #include "nspdefs.h"
       
    25 
       
    26 // ======== MEMBER FUNCTIONS ========
       
    27 // ---------------------------------------------------------------------------
       
    28 // CNSPActive::CNSPActive
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 CNSPActive::CNSPActive( CNSPController& aController,
       
    32         TUint aSessionId, TUint aStreamId, TUint aTransactionId,
       
    33         MNATFWConnectivityObserver::TNATFWConnectivityEvent aEvent,
       
    34         CSdpDocument* aDocument )
       
    35      : CActive( EPriorityStandard ),
       
    36        iController( aController ),
       
    37        iSessionId( aSessionId ),
       
    38        iStreamId( aStreamId ),
       
    39        iTransactionId( aTransactionId ),
       
    40        iEvent( aEvent ),
       
    41        iDocument( aDocument )
       
    42     {
       
    43     CActiveScheduler::Add( this );
       
    44     }
       
    45 
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CNSPAsyncCallback::ConstructL
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 void CNSPActive::ConstructL( TUint aTimerInMicroSeconds )
       
    52     {
       
    53 	User::LeaveIfError( iTimer.CreateLocal() );
       
    54     TTimeIntervalMicroSeconds32 interval( aTimerInMicroSeconds );
       
    55     iTimer.After( iStatus, interval );
       
    56     SetActive();
       
    57     }
       
    58 
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // CNSPActive::NewL
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 CNSPActive* CNSPActive::NewL( CNSPController& aController,
       
    65             TUint aSessionId, TUint aStreamId, TUint aTransactionId,
       
    66             MNATFWConnectivityObserver::TNATFWConnectivityEvent aEvent,
       
    67             TUint aTimerInMicroSeconds, CSdpDocument* aDocument )
       
    68     {
       
    69     CNSPActive* self = CNSPActive::NewLC( aController,
       
    70             aSessionId, aStreamId, aTransactionId,
       
    71             aEvent, aTimerInMicroSeconds, aDocument );
       
    72     CleanupStack::Pop( self );
       
    73     return self;
       
    74     }
       
    75 
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // CNSPActive::NewLC
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 CNSPActive* CNSPActive::NewLC( CNSPController& aController,
       
    82             TUint aSessionId, TUint aStreamId, TUint aTransactionId,
       
    83             MNATFWConnectivityObserver::TNATFWConnectivityEvent aEvent,
       
    84             TUint aTimerInMicroSeconds, CSdpDocument* aDocument )
       
    85     {
       
    86     CNSPActive* self = new ( ELeave ) CNSPActive( aController,
       
    87             aSessionId, aStreamId, aTransactionId, aEvent, aDocument );
       
    88     CleanupStack::PushL( self );
       
    89     self->ConstructL( aTimerInMicroSeconds );
       
    90     return self;
       
    91     }
       
    92 
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CNSPActive::~CNSPActive
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 CNSPActive::~CNSPActive()
       
    99     {
       
   100     if ( IsActive() )
       
   101         {
       
   102         CActive::Cancel();
       
   103         delete iDocument;
       
   104         iDocument = NULL;
       
   105         }
       
   106     
       
   107     iTimer.Close();
       
   108     }
       
   109 
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CNSPActive::RunL
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 void CNSPActive::RunL()
       
   116     {
       
   117     NSPLOG_STR( "CNSPActive::RunL()" )
       
   118     
       
   119     const TInt index = iController.FindSession( iSessionId );
       
   120     const TInt activeIndex = iController.FindActiveObject( iTransactionId );
       
   121     
       
   122     if ( KErrNotFound != activeIndex )
       
   123         {
       
   124         iController.iActiveObjects.Remove( activeIndex );
       
   125         iController.iActiveObjects.Compress();
       
   126         }
       
   127     
       
   128     if ( KErrNotFound != index )
       
   129         {
       
   130         if ( iDocument )
       
   131             {
       
   132             // UPDATE
       
   133             MNSPSessionObserver& observer =
       
   134                     iController.iSessionArray[index]->SessionObserver();
       
   135             observer.UpdateSdp( iSessionId, iDocument );
       
   136             }
       
   137         else
       
   138             {
       
   139             // NOTIFY
       
   140             TEventReturnStatus status = iController.iSessionArray[index]->EventOccured(
       
   141             		iStreamId, iEvent, KErrTimedOut, NULL );
       
   142             iController.Callback( *iController.iSessionArray[index], status );
       
   143             }
       
   144         }
       
   145     else
       
   146         {
       
   147         NSPLOG_STR( "CNSPActive::RunL(), Session not found!!" )
       
   148         NSPDEBUG_PANIC( KErrNotFound );
       
   149         }
       
   150     
       
   151     delete this;
       
   152     }
       
   153 
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // CNSPActive::DoCancel
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 void CNSPActive::DoCancel()
       
   160     {
       
   161     NSPLOG_STR( "CNSPActive::DoCancel()" )
       
   162 	iTimer.Cancel();
       
   163     }
       
   164 
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CNSPAsyncCallback::RunError
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 TInt CNSPActive::RunError( TInt /*aError*/ )
       
   171     {
       
   172     NSPLOG_STR( "CNSPActive::RunError(), Should not come here!!" )
       
   173     return KErrNone;
       
   174     }
       
   175 
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // CNSPActive::SessionId
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 TUint CNSPActive::SessionId() const
       
   182     {
       
   183     return iSessionId;
       
   184     }
       
   185 
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // CNSPActive::TransactionId
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 TUint CNSPActive::TransactionId() const
       
   192     {
       
   193     return iTransactionId;
       
   194     }
       
   195 
       
   196 
       
   197 // end of file