natfw/natfwstunturnclient/inc/casynccallback.h
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 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 #ifndef C_ASYNCCALLBACK_H
       
    22 #define C_ASYNCCALLBACK_H
       
    23 
       
    24 // INCLUDES
       
    25 #include <e32base.h>
       
    26 #include "tstuncallbackinfo.h"
       
    27 
       
    28 // FORWARD DECLARATIONS
       
    29 class MSTUNClientObserver;
       
    30 class CBinding;
       
    31 
       
    32 // CLASS DECLARATION
       
    33 /*
       
    34  * CAsyncCallback is an active object used to guarantee that when the function
       
    35  * calls to the MSTUNClientObserver are made, the upper layer can delete any
       
    36  * STUN client related object it owns.
       
    37  */
       
    38 class CAsyncCallback : public CActive
       
    39     {
       
    40 public: // Constructor and destructor
       
    41 
       
    42     /**
       
    43      * Creates a new instance of CAsyncCallback.
       
    44      *
       
    45      * @param aObserver Observer implementing the callback functions
       
    46      * @return value New CAsyncCallback object. Ownership is transferred.
       
    47      */
       
    48     static CAsyncCallback* NewL( MSTUNClientObserver& aObserver );
       
    49 
       
    50     /**     
       
    51      * Frees the resources of CAsyncCallback. Any issued callback request that
       
    52      * have not yet been executed, are discarded.
       
    53      */
       
    54     ~CAsyncCallback();
       
    55 
       
    56 public: // From CActive
       
    57 
       
    58     void DoCancel();
       
    59 
       
    60     void RunL();
       
    61 
       
    62     TInt RunError( TInt aError );
       
    63 
       
    64 public: // New functions
       
    65 
       
    66     /**
       
    67      * Orders a specified callback function to be called, and provides all
       
    68      * necessary parameters.
       
    69      *     
       
    70      * @param aFunction Identifies the function of MSTUNClientObserver to use
       
    71      * @param aBinding STUN binding
       
    72      * @param aErrorCode Error reason
       
    73      * @param aClient STUN client     
       
    74      */
       
    75     void MakeCallbackL( TSTUNCallbackInfo::TFunction aFunction,
       
    76                         const CBinding* aBinding,
       
    77                         TInt aErrorCode = KErrNone,
       
    78                         const CSTUNClient* aClient = NULL );
       
    79 
       
    80     /**
       
    81      * Removes all pending callbacks, which have the specified binding as a
       
    82      * parameter.
       
    83      *
       
    84      * @param aBinding STUN binding     
       
    85      */
       
    86     void CancelCallback( const CBinding& aBinding );
       
    87 
       
    88     /**
       
    89      * Calls the oldest callback entry, if any.
       
    90      *
       
    91      * @param aBinding STUN binding     
       
    92      */
       
    93     void ExecuteFirstCallback();
       
    94 
       
    95 private: // Constructors
       
    96 
       
    97     CAsyncCallback();
       
    98 
       
    99     CAsyncCallback( MSTUNClientObserver& aObserver );
       
   100 
       
   101     CAsyncCallback( const CAsyncCallback& aAsyncCallback );
       
   102 
       
   103 private: // New functions, for internal use
       
   104 
       
   105     /**
       
   106      * Starts waiting for MakeCallbackL events.
       
   107      */
       
   108     void WaitForRequests();
       
   109 
       
   110     void Wakeup();
       
   111 
       
   112 private: // Data
       
   113 
       
   114     // Implements the callback functions
       
   115     MSTUNClientObserver& iObserver;
       
   116 
       
   117     // Callback requests that have not yet been executed
       
   118     TSglQue<TSTUNCallbackInfo> iPendingCallbacks;
       
   119 
       
   120 private: // For testing purposes
       
   121 
       
   122 #ifdef TEST_EUNIT
       
   123     friend class CAsyncCallbackTest;
       
   124     friend class CSTUNClientTest;
       
   125 #endif
       
   126     };
       
   127 
       
   128 #endif // end of C_ASYNCCALLBACK_H
       
   129 
       
   130 // End of File