natfw/natfwicecandidatehandler/inc/cicehostresolver.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:    Provides services for host candidate resolving.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef C_ICEHOSTRESOLVER_H
       
    22 #define C_ICEHOSTRESOLVER_H
       
    23 
       
    24 #include "natfwpluginapi.h"
       
    25 #include "natfwconnectivityapidefs.h"
       
    26 #include "miceconnectionobserver.h"
       
    27 #include "natfwinternaldefs.h"    //UNIT_TEST
       
    28 
       
    29 class CIceCallBackExecuter;
       
    30 class CIceConnection;
       
    31 
       
    32 /**
       
    33  *  Provides services for host candidate resolving.
       
    34  *
       
    35  *  @lib icecandidatehandler.dll
       
    36  *  @since S60 v3.2
       
    37  */
       
    38 class CIceHostResolver 
       
    39     : public CNATFWPluginApi, public MIceConnectionObserver
       
    40     {
       
    41 
       
    42     UNIT_TEST( UT_CIceHostResolver )
       
    43     UNIT_TEST( UT_CIceConnectivityCheck )
       
    44     UNIT_TEST( UT_CIceCheckList )
       
    45     
       
    46 public:
       
    47 
       
    48     /**  CallBack types */
       
    49     enum TCallBackType
       
    50         {
       
    51         ECallBackServerConnected   = 1,
       
    52         ECallBackCandidateFound    = 2
       
    53         };
       
    54 
       
    55     /**
       
    56      * Two-phased constructor.
       
    57      * @param aInitParams       Initialization parameters
       
    58      */
       
    59     static CIceHostResolver* NewL( TAny* aInitParams );
       
    60 
       
    61     /**
       
    62      * Destructor.
       
    63      */
       
    64     virtual ~CIceHostResolver();
       
    65     
       
    66     /**
       
    67      * Static handler function for callbacks.
       
    68      *
       
    69      * @since   S60 3.2
       
    70      * @param   aObject         The object reference
       
    71      * @param   aCallBackType   The callback to be executed
       
    72      */
       
    73     static void HandleCallBack( CBase& aObject, TInt aCallBackType );
       
    74     
       
    75     /**
       
    76      * Returns local address for specified stream and family.
       
    77      *
       
    78      * @since   S60 3.2
       
    79      * @param   aStreamId       The stream identifier
       
    80      * @param   aAddrFamily     The address family
       
    81      * @return  Local address
       
    82      */
       
    83     TInetAddr LocalAddress( TUint aStreamId, TUint aAddrFamily ) const;
       
    84     
       
    85 // from base class CNATFWPluginApi
       
    86 
       
    87     /**
       
    88      * From CNATFWPluginApi.
       
    89      *
       
    90      * Finds out a STUN Server and establishes a connection to it.
       
    91      * 
       
    92      * MNATFWPluginObserver::Notify is called with event code EServerConnected
       
    93      * when connecting has completed.
       
    94      *     
       
    95      * FetchCandidateL can be called after successful connecting.
       
    96      *
       
    97      * @since   S60 v3.2
       
    98      * @param   aSocketServ         The handle to socket server session
       
    99      * @param   aConnectionName     The unique name of the RConnection
       
   100      */
       
   101     void ConnectServerL( const RSocketServ& aSocketServ,
       
   102         const TName& aConnectionName );
       
   103         
       
   104     /**
       
   105      * From CNATFWPluginApi.
       
   106      *
       
   107      * Fetches available candidates for a specified stream using given
       
   108      * retransmission timeout for STUN transactions. 
       
   109      * 
       
   110      * RTO value 0 indicates default retransmission timeout as specified
       
   111      * in STUN specification.
       
   112      * 
       
   113      * @since   S60 v3.2
       
   114      * @param   aStreamId           Stream identifier
       
   115      * @param   aRtoValue           Retransmission timeout in milliseconds
       
   116      * @param   aAddrFamily         KAFUnspec / KAfInet / KAfInet6
       
   117      * @leave   KErrNotSupported NAT Protocol plugin does not support
       
   118      * operation.
       
   119      */
       
   120     void FetchCandidateL( TUint aStreamId, TUint aRtoValue,
       
   121         TUint aAddrFamily );
       
   122     
       
   123     
       
   124     /**
       
   125      * From CNATFWPluginApi.
       
   126      * Enables/disables media receiving for the specified local candidate.
       
   127      * 
       
   128      * Only those candidates given with MNATFWPluginObserver callbacks
       
   129      * can be controlled. NATFW stream can have only one active candidate
       
   130      * at a time. In other words, exactly one local candidate can be used
       
   131      * for media delivery in receiving, sending or both directions.
       
   132      * 
       
   133      * MNATFWPluginObserver::Notify is called with event code
       
   134      * EReceivingActivated/EReceivingDeactivated when status change has 
       
   135      * completed. While activated incoming data is delivered to the media
       
   136      * engine.
       
   137      * 
       
   138      * Receiving must be disabled prior to deleting plugin so that all
       
   139      * resources can be freed.
       
   140      * 
       
   141      * Note: If TURN is used media cannot be delivered until remote address
       
   142      * is known.
       
   143      * 
       
   144      * @since   S60 v3.2
       
   145      * @pre     FetchCandidate(/s) and possible ICE processing have completed
       
   146      * @param   aLocalCandidate The local end point for a media
       
   147      * @param   aState          The receiving state
       
   148      */
       
   149     void SetReceivingStateL( const CNATFWCandidate& aLocalCandidate,
       
   150         TNATFWStreamingState aState );
       
   151 
       
   152     /**
       
   153      * From CNATFWPluginApi.
       
   154      * Enables/disables media sending from the specified local candidate.
       
   155      * 
       
   156      * Only those candidates given with MNATFWPluginObserver callbacks
       
   157      * can be controlled. NATFW stream can have only one active candidate
       
   158      * at a time. In other words, exactly one local candidate can be used
       
   159      * for media delivery in receiving, sending or both directions.
       
   160      * 
       
   161      * Sending must be disabled prior to deleting plugin so that all
       
   162      * resources can be freed.
       
   163      * 
       
   164      * MNATFWPluginObserver::Notify is called with event code
       
   165      * ESendingActivated/ESendingDeactivated when status change has 
       
   166      * completed. While activated outgoing data from media engine is delivered
       
   167      * to the specified remote address.
       
   168      * 
       
   169      * @since   S60 v3.2
       
   170      * @pre     FetchCandidate(/s) and possible ICE processing have completed
       
   171      * @param   aLocalCandidate The local end point for a media
       
   172      * @param   aState          The sending state
       
   173      * @param   aDestAddr       The remote end point for a media
       
   174      */
       
   175     void SetSendingStateL( const CNATFWCandidate& aLocalCandidate,
       
   176         TNATFWStreamingState aState, const TInetAddr& aDestAddr );
       
   177     
       
   178     /**
       
   179      * From CNATFWPluginApi.
       
   180      * Gets identifier for a connection that is associated with the
       
   181      * given local end point.
       
   182      * 
       
   183      * @since   S60 v3.2
       
   184      * @param   aLocalCandidate     The local end point for a media
       
   185      * @param   aConnectionId       Reference to found id
       
   186      */
       
   187     void GetConnectionIdL( 
       
   188         const CNATFWCandidate& aLocalCandidate,
       
   189         TUint& aConnectionId );
       
   190     
       
   191     /**
       
   192      * From CNATFWPluginApi.
       
   193      * Get identifier of the plugin.
       
   194      * 
       
   195      * @since   S60 3.2
       
   196      * @return  Identifier of the plugin
       
   197      */
       
   198     const TDesC8& PluginIdentifier() const;
       
   199 
       
   200 // from base class MIceConnectionObserver
       
   201 
       
   202     /**
       
   203      * Notifies about connection state changes.
       
   204      *
       
   205      * @since   S60 v3.2
       
   206      * @param   aConnection         Notifying connection
       
   207      * @param   aType               Type of notify
       
   208      * @param   aError              Error code
       
   209      */
       
   210     void ConnectionNotify( CIceConnection& aConnection,
       
   211         TNotifyType aType, TInt aError );
       
   212     
       
   213 private:
       
   214 
       
   215     CIceHostResolver();
       
   216 
       
   217     void ConstructL( TAny* aInitParams );
       
   218     
       
   219     void DoHandleCallBack( TInt aCallBackType );
       
   220     
       
   221     CIceConnection* FindConnection( const CNATFWCandidate& aLocalCandidate );
       
   222     
       
   223     CIceConnection* FindConnection( const TInetAddr& aLocalAddr );
       
   224     
       
   225     TBool IsOwnedCandidate( const CNATFWCandidate& aLocalCandidate ) const;
       
   226 
       
   227 private: // data
       
   228 
       
   229 
       
   230     /**
       
   231      * Plugin identifier.
       
   232      * Own.
       
   233      */
       
   234     HBufC8* iPluginId;
       
   235     
       
   236     /**
       
   237      * Plugin observer.
       
   238      * Not Own.
       
   239      */
       
   240     MNATFWPluginObserver* iPluginObserver;
       
   241     
       
   242     /**
       
   243      * Interface to multiplexer services.
       
   244      * Not Own.
       
   245      */
       
   246     MNcmConnectionMultiplexer* iMultiplexer;
       
   247     
       
   248     /**
       
   249      * Host candidates pending posting.
       
   250      * Own.
       
   251      */
       
   252     RPointerArray<CNATFWCandidate> iHostCandidates;
       
   253     
       
   254     /**
       
   255      * CallBack executer for asynchronous callback generation.
       
   256      * Own.
       
   257      */
       
   258     CIceCallBackExecuter* iCallBackExecuter;
       
   259     
       
   260     /**
       
   261      * Host connections.
       
   262      * Own.
       
   263      */
       
   264     RPointerArray<CIceConnection> iConnections;
       
   265     };
       
   266 
       
   267 
       
   268 #endif // C_ICEHOSTRESOLVER_H