natfw/natfwconnectionmultiplexer/src/cncmcallbackexecuter.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:    Executes client specified callbacks.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "cncmcallbackexecuter.h"
       
    22 #include "ncmconnectionmultiplexerlogs.h"
       
    23 
       
    24 // ======== MEMBER FUNCTIONS ========
       
    25 
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // CNcmCallBackExecuter::CNcmCallBackExecuter
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 CNcmCallBackExecuter::CNcmCallBackExecuter() : CActive( EPriorityStandard )
       
    32     {
       
    33     CActiveScheduler::Add( this );
       
    34     }
       
    35 
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CNcmCallBackExecuter::NewL
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CNcmCallBackExecuter* CNcmCallBackExecuter::NewL()
       
    42     {
       
    43     CNcmCallBackExecuter* self = CNcmCallBackExecuter::NewLC();
       
    44     CleanupStack::Pop( self );
       
    45     return self;
       
    46     }
       
    47 
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CNcmCallBackExecuter::NewLC
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CNcmCallBackExecuter* CNcmCallBackExecuter::NewLC()
       
    54     {
       
    55     CNcmCallBackExecuter* self 
       
    56         = new( ELeave ) CNcmCallBackExecuter();
       
    57     CleanupStack::PushL( self );
       
    58     self->WaitForRequestsL();
       
    59     return self;
       
    60     }
       
    61 
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CNcmCallBackExecuter::~CNcmCallBackExecuter
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CNcmCallBackExecuter::~CNcmCallBackExecuter()
       
    68     {
       
    69     Cancel();
       
    70     iCallBacks.Close();
       
    71     }
       
    72 
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CNcmCallBackExecuter::AddCallBackL
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CNcmCallBackExecuter::AddCallBackL( const TNcmCallBack& aCallBack )
       
    79     {
       
    80     __CONNECTIONMULTIPLEXER( "CNcmCallBackExecuter::AddCallBackL" )
       
    81     
       
    82     if ( iStatus == KRequestPending )
       
    83         {
       
    84         Wakeup();
       
    85         }
       
    86         
       
    87     iCallBacks.AppendL( aCallBack );
       
    88     }
       
    89 
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CNcmCallBackExecuter::ExecuteFirstCallback
       
    93 // Handle one callback request and wait for the next one. If there are more
       
    94 // callbacks, complete the asynchronous request so that RunL will soon be 
       
    95 // called again.
       
    96 // ---------------------------------------------------------------------------
       
    97 //    
       
    98 void CNcmCallBackExecuter::ExecuteFirstCallback()
       
    99     {
       
   100     TNcmCallBack* callback = &iCallBacks[0];
       
   101     callback->CallBack();
       
   102 
       
   103     iCallBacks.Remove( 0 );
       
   104       
       
   105     if ( iCallBacks.Count() )
       
   106         {
       
   107         Wakeup();
       
   108         }
       
   109     }
       
   110 
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // CNcmCallBackExecuter::WaitForRequestsL
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 void CNcmCallBackExecuter::WaitForRequestsL()
       
   117     {
       
   118     __ASSERT_ALWAYS( !IsActive(), User::Leave( KErrNotReady ) );
       
   119 
       
   120     iStatus = KRequestPending;
       
   121     SetActive();
       
   122     }
       
   123 
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CNcmCallBackExecuter::Wakeup
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 void CNcmCallBackExecuter::Wakeup()
       
   130     {
       
   131     TRequestStatus* status = &iStatus;
       
   132     User::RequestComplete( status, KErrNone );
       
   133     }
       
   134     
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // From class CActive.
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 void CNcmCallBackExecuter::RunL()
       
   141     {
       
   142     __CONNECTIONMULTIPLEXER( "CNcmCallBackExecuter::RunL" )
       
   143     __ASSERT_ALWAYS( iCallBacks.Count(), User::Leave( KErrNotFound ) );
       
   144     
       
   145     WaitForRequestsL();
       
   146     ExecuteFirstCallback();
       
   147     }
       
   148 
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // From class CActive.
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 void CNcmCallBackExecuter::DoCancel()
       
   155     {
       
   156     __CONNECTIONMULTIPLEXER( "CNcmCallBackExecuter::DoCancel" )
       
   157     
       
   158     iCallBacks.Reset();
       
   159     
       
   160     if ( iStatus == KRequestPending )
       
   161         {
       
   162         TRequestStatus* status = &iStatus;    
       
   163         User::RequestComplete( status, KErrCancel );
       
   164         }
       
   165     }