natfw/natfwstunplugin/inc/cstunasynccallback.h
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 #ifndef C_STUNASYNCCALLBACK_H
       
    22 #define C_STUNASYNCCALLBACK_H
       
    23 
       
    24 // INCLUDES
       
    25 #include <e32base.h>
       
    26 #include "tstunplugincallbackinfo.h"
       
    27 
       
    28 // FORWARD DECLARATIONS
       
    29 class MNATFWPluginObserver;
       
    30 
       
    31 
       
    32 // CLASS DECLARATION
       
    33 /**
       
    34  * CStunAsyncCallback is an active object used to guarantee that when the
       
    35  * function calls to the MNATFWPluginObserver are made, the upper layer 
       
    36  * can delete any STUN plugin related object it owns.
       
    37  */
       
    38 class CStunAsyncCallback : public CActive
       
    39     {
       
    40     
       
    41     friend class UT_CNATFWStunConnectionHandler;
       
    42     
       
    43 public: // Constructor and destructor
       
    44 
       
    45     /**
       
    46      * Two-phased constructor.
       
    47      * @param aStunPlugin The STUN plugin instance
       
    48      * @param aObserver Observer implementing the callback functions
       
    49      */
       
    50     static CStunAsyncCallback* NewL( 
       
    51         const CNATFWPluginApi& aStunPlugin, 
       
    52         MNATFWPluginObserver& aObserver );
       
    53 
       
    54     /**     
       
    55      * Frees the resources of CStunAsyncCallback. Any issued callback 
       
    56      * request that have not yet been executed, are discarded.
       
    57      *
       
    58      * @since   s60 3.2
       
    59      */
       
    60     ~CStunAsyncCallback();
       
    61 
       
    62 public: // New functions
       
    63 
       
    64     /**
       
    65      * Orders a specified callback function to be called, and provides all
       
    66      * necessary parameters.
       
    67      *
       
    68      * @since   s60 3.2     
       
    69      * @param   aFunction Identifies the function of MNATFWPluginObserver to 
       
    70      *          use
       
    71      * @param   aStreamId   Stream ID
       
    72      * @param   aErrorCode  Error reason
       
    73      * @param   aEventData  Event data
       
    74      */
       
    75     void MakeCallbackL( TStunPluginCallbackInfo::TFunction aFunction,
       
    76                         TUint aStreamId,
       
    77                         TInt aErrorCode,
       
    78                         TAny* aEventData );
       
    79 
       
    80     /**
       
    81      * Removes all pending callbacks, which have the specified stream id as a
       
    82      * parameter.
       
    83      *
       
    84      * @since   s60 3.2
       
    85      * @param   aStreamId   Stream ID
       
    86      */
       
    87     void CancelCallback( TUint aStreamId );
       
    88 
       
    89 protected: // From CActive
       
    90 
       
    91     /**
       
    92      * from CActive
       
    93      */
       
    94     void DoCancel();
       
    95 
       
    96     /**
       
    97      * from CActive
       
    98      */
       
    99     void RunL();
       
   100 
       
   101     /**
       
   102      * from CActive
       
   103      */
       
   104     TInt RunError( TInt aError );
       
   105 
       
   106 private: // Constructors
       
   107 
       
   108     CStunAsyncCallback();
       
   109 
       
   110     CStunAsyncCallback( const CNATFWPluginApi& aStunPlugin, 
       
   111         MNATFWPluginObserver& aObserver );
       
   112 
       
   113     CStunAsyncCallback( const CStunAsyncCallback& aAsyncCallback );
       
   114 
       
   115 private: // New functions, for internal use
       
   116 
       
   117     /**
       
   118      * Starts waiting for MakeCallbackL events.
       
   119      *
       
   120      * @since   s60 3.2
       
   121      */
       
   122     void WaitForRequestsL();
       
   123     
       
   124     /**
       
   125      * Wakes system up.
       
   126      *
       
   127      * @since   s60 3.2
       
   128      */
       
   129     void Wakeup();
       
   130 
       
   131     /**
       
   132      * Calls the oldest callback entry, if any.
       
   133      *
       
   134      * @since   s60 3.2
       
   135      */
       
   136     void ExecuteFirstCallback();
       
   137     
       
   138 private: // Data
       
   139 
       
   140     /**
       
   141      * STUN plugin instance
       
   142      */
       
   143     const CNATFWPluginApi& iStunPlugin;
       
   144 
       
   145     /**
       
   146      * Implements the callback functions
       
   147      */
       
   148     MNATFWPluginObserver& iObserver;
       
   149 
       
   150     /**
       
   151      * Callback requests that have not yet been executed
       
   152      */
       
   153     TSglQue<TStunPluginCallbackInfo> iPendingCallbacks;
       
   154     };
       
   155 
       
   156 #endif // C_STUNASYNCCALLBACK_H
       
   157