natfw/natfwicecandidatehandler/inc/cicesessiondata.h
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006-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:    Holds various session related data.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #ifndef CNATFWCANDIDATESTORAGE_H
       
    23 #define CNATFWCANDIDATESTORAGE_H
       
    24 
       
    25 #include <e32base.h>
       
    26 #include "natfwcredentials.h"
       
    27 #include "natfwconnectivityapidefs.h"
       
    28 #include "natfwcandidate.h"
       
    29 #include "natfwinternaldefs.h"    //UNIT_TEST
       
    30 
       
    31 class CIceStreamCollection;
       
    32 class MNATFWPluginObserver;
       
    33 class TInetAddr;
       
    34 
       
    35 /**
       
    36  *  Stores all session related data like candidates and credentials.
       
    37  *
       
    38  *  Eliminates redundant candidates and generates foundations for them.
       
    39  *
       
    40  *  @lib icecandidatehandler.dll
       
    41  *  @since S60 v3.2
       
    42  */
       
    43 class CIceSessionData : public CBase
       
    44     {
       
    45 
       
    46     UNIT_TEST( UT_CIceSessionData )
       
    47     
       
    48 public:
       
    49 
       
    50     /**
       
    51      * Two-phased constructor.
       
    52      * @param aDomain                   Domain used
       
    53      * @param aIapId                    Internet access point identifier
       
    54      */
       
    55     static CIceSessionData* NewL( 
       
    56         const TDesC8& aDomain, TUint32 aIapId );
       
    57 
       
    58     /**
       
    59      * Two-phased constructor.
       
    60      * @param aDomain                   Domain used
       
    61      * @param aIapId                    Internet access point identifier
       
    62      */
       
    63     static CIceSessionData* NewLC( 
       
    64         const TDesC8& aDomain, TUint32 aIapId );
       
    65 
       
    66     /**
       
    67      * Destructor.
       
    68      */
       
    69     virtual ~CIceSessionData();
       
    70 
       
    71    /**
       
    72      * Adds peer reflexive candidate.
       
    73      *
       
    74      * @since   S60 v3.2
       
    75      * @param   aPeerCandidate          Peer reflexive candidate
       
    76      * @param   aIsRemoteCand           Whether candidate is remote one
       
    77      */
       
    78     void AddPeerReflexiveCandidateL( CNATFWCandidate* aPeerCandidate, 
       
    79         TBool aIsRemoteCand );
       
    80 
       
    81     /**
       
    82      * Finds local candidate based on transport address info.
       
    83      *
       
    84      * @since   S60 v3.2
       
    85      * @param   aTransportAddr          Transport address
       
    86      * @return  Found candidate or NULL if not found
       
    87      */
       
    88     const CNATFWCandidate* FindLocalCandidate( 
       
    89         const TInetAddr& aTransportAddr ) const;
       
    90 
       
    91     /**
       
    92      * Finds local candidate.
       
    93      *
       
    94      * @since   S60 v3.2
       
    95      * @param   aStreamCollectionId     Stream collection identifier
       
    96      * @param   aComponentId            Component identifier
       
    97      * @param   aType                   Candidate type to found
       
    98      * @return  Found candidate or NULL if not found
       
    99      */
       
   100     const CNATFWCandidate* FindLocalCandidate( 
       
   101         TUint aStreamCollectionId,
       
   102         TUint aComponentId,
       
   103         CNATFWCandidate::TCandidateType aType ) const;
       
   104 
       
   105     /**
       
   106      * Finds remote candidate based on transport address info.
       
   107      *
       
   108      * @since   S60 v3.2
       
   109      * @param   aTransportAddr          Transport address
       
   110      * @return  Found candidate or NULL if not found 
       
   111      */
       
   112     const CNATFWCandidate* FindRemoteCandidate( 
       
   113         const TInetAddr& aTransportAddr ) const;
       
   114 
       
   115     /**
       
   116      * Gets local candidates.
       
   117      *
       
   118      * @since S60 v3.2
       
   119      * @param aStreamCollectionId       Stream collection identifier
       
   120      * @param aStreamId                 Stream identifier
       
   121      * @param aLocalCandidates          Found candidates. Caller is 
       
   122      *      responsible of deleting the contents of the array.
       
   123      */
       
   124     void GetLocalCandidates(
       
   125         const TUint aStreamCollectionId,
       
   126         const TUint aStreamId,
       
   127         RPointerArray<CNATFWCandidate>& aLocalCandidates );
       
   128 
       
   129     /**
       
   130      * Gets local candidates.
       
   131      *
       
   132      * @since S60 v3.2
       
   133      * @param aStreamCollectionId       Stream collection identifier
       
   134      * @param aLocalCandidates          Found candidates. Caller is 
       
   135      *      responsible of deleting the contents of the array.
       
   136      */
       
   137     void GetLocalCandidates(
       
   138         const TUint aStreamCollectionId,
       
   139         RPointerArray<CNATFWCandidate>& aLocalCandidates );
       
   140     
       
   141     /**
       
   142      * Gets local candidates.
       
   143      *
       
   144      * @since S60 v3.2
       
   145      * @param aLocalCandidates          Found candidates. Caller is 
       
   146      *      responsible of deleting the contents of the array.
       
   147      */
       
   148     void GetLocalCandidates(
       
   149         RPointerArray<CNATFWCandidate>& aLocalCandidates );
       
   150     
       
   151     /**
       
   152      * Deletes stream collection.
       
   153      *
       
   154      * @since   S60 3.2
       
   155      * @param   aStreamCollectionId     The ID identifying collection
       
   156      */
       
   157     void DeleteCollection( TUint aStreamCollectionId );
       
   158                     
       
   159     /**
       
   160      * Adds new credentials for stream collection.
       
   161      *
       
   162      * @since   S60 3.2
       
   163      * @param   aCredentials         Credentials for stream collection
       
   164      */
       
   165     void AddCredentialsL( 
       
   166         const CNATFWCredentials& aCredentials );
       
   167 
       
   168     /**
       
   169      * Returns all credentials used in a session.
       
   170      *
       
   171      * @since   S60 3.2
       
   172      * @return  Credentials list
       
   173      */
       
   174     const RPointerArray<CNATFWCredentials>& Credentials() const;
       
   175     
       
   176     /**
       
   177      * Returns credentials for specified stream and utilization direction.
       
   178      *
       
   179      * @since   S60 3.2
       
   180      * @param   aStreamId               The stream identifier
       
   181      * @param   aDirection              The utilization direction
       
   182      * @return  Credentials
       
   183      */
       
   184     const CNATFWCredentials* Credentials( 
       
   185         TUint aStreamId,
       
   186         CNATFWCredentials::TUtilizationDirection aDirection ) const;
       
   187 
       
   188     /**
       
   189      * Adds a remote candidate.
       
   190      *
       
   191      * @since   S60 3.2
       
   192      * @param   aRemoteCandidate        The candidate to add
       
   193      */
       
   194     void AddRemoteCandidateL( CNATFWCandidate* aRemoteCandidate );
       
   195     
       
   196     /**
       
   197      * Gets remote candidates.
       
   198      *
       
   199      * @since   S60 3.2
       
   200      * @param   aStreamCollectionId     Returned candidates have this stream
       
   201      *          collection id
       
   202      * @param   aComponentId            Returned candidates have this component id
       
   203      * @param   aRemoteCandidates candidates are returned in this array.
       
   204      *          Caller is responsible of deleting the contents of the
       
   205      *          array.
       
   206      */
       
   207     void GetRemoteCandidatesL( 
       
   208         TUint aStreamCollectionId,
       
   209         TUint aComponentId,
       
   210         RPointerArray<CNATFWCandidate>& aRemoteCandidates ); 
       
   211                     
       
   212     /**
       
   213      * Adds remote candidates.
       
   214      *
       
   215      * @param   aRemoteCandidates       Remote candidates to add
       
   216      */
       
   217     void AddRemoteCandidatesL( 
       
   218         RPointerArray<CNATFWCandidate>& aRemoteCandidates );
       
   219 
       
   220     /**
       
   221      * Gets remote candidates.
       
   222      *
       
   223      * @since   S60 3.2
       
   224      * @param   aStreamCollectionId     Collection where to find candidates
       
   225      * @param   aRemoteCandidates       Returned candidates.
       
   226      *          Caller is responsible of deleting the contents of the
       
   227      *          array.
       
   228      */
       
   229     void GetRemoteCandidatesL( const TUint aStreamCollectionId,
       
   230         RPointerArray<CNATFWCandidate>& aRemoteCandidates );
       
   231 
       
   232     /**
       
   233      * Adds a local candidate.
       
   234      *
       
   235      * @since  S60 3.2
       
   236      * @param  aLocalCandidate          The candidate to add
       
   237      * @return ETrue if candidate was redundant
       
   238      */
       
   239     TBool AddLocalCandidateL( CNATFWCandidate* aLocalCandidate );
       
   240     
       
   241     /**
       
   242      * Gets identifiers for all stream collections in a session.
       
   243      * 
       
   244      * @since   S60 3.2
       
   245      * @param   aStreamCollIds          Collection ids returned
       
   246      */                                        
       
   247     void GetStreamCollectionIdsL( 
       
   248         RArray<TUint>& aStreamCollIds ) const;
       
   249     
       
   250     /**
       
   251      * Creates a new stream collection.
       
   252      *
       
   253      * @since   S60 3.2
       
   254      * @param   aStreamCollectionId     The identifier for new collection
       
   255      */
       
   256     void CreateCollectionL( TUint aStreamCollectionId );
       
   257      
       
   258     /**
       
   259      * Returns collection identifier.
       
   260      *
       
   261      * @since   S60 3.2
       
   262      * @param   aStreamCollectionId     The identifier for collection
       
   263      */
       
   264     CIceStreamCollection* CollectionL( TUint aStreamCollectionId );
       
   265 
       
   266     /**
       
   267      * Finds collection where specified media component belongs.
       
   268      *
       
   269      * @since   S60 3.2
       
   270      * @param   aStreamId               The media component
       
   271      * @param   aCollectionId           On return collection id
       
   272      * @return  System wide error code
       
   273      */
       
   274     TInt GetCollectionIdForComponent( 
       
   275         TUint aStreamId, TUint& aCollectionId );
       
   276     
       
   277     /**
       
   278      * Cleanups all data related to the specified stream.
       
   279      *
       
   280      * @since   S60 v3.2
       
   281      * @param   aStreamId               The stream identifier
       
   282      */
       
   283     void CleanupStreamData( TUint aStreamId );
       
   284      
       
   285     /**
       
   286      * Removes all local candidates in a session.
       
   287      *
       
   288      * @since   S60 v3.2
       
   289      */
       
   290     void RemoveLocalCandidates();
       
   291 
       
   292     /**
       
   293      * Removes all remote candidates in a session.
       
   294      *
       
   295      * @since   S60 v3.2
       
   296      */
       
   297     void RemoveRemoteCandidates();
       
   298 
       
   299     /**
       
   300      * Sets new role.
       
   301      *
       
   302      * @since   S60 v3.2
       
   303      * @param   aRole                   The role
       
   304      */    
       
   305     void SetRole( TNATFWIceRole aRole );
       
   306 
       
   307     /**
       
   308      * Returns current role.
       
   309      *
       
   310      * @since   S60 v3.2
       
   311      * @return  Current role
       
   312      */
       
   313     TNATFWIceRole Role() const;
       
   314     
       
   315     /**
       
   316      * Sets new tie-breaker value.
       
   317      *
       
   318      * @since   S60 v3.2
       
   319      * @param   aTieBreaker             The tie-breaker value
       
   320      */
       
   321     void SetTieBreaker( TUint64 aTieBreaker );
       
   322 
       
   323     /**
       
   324      * Returns current tie-breaker value.
       
   325      *
       
   326      * @since   S60 v3.2
       
   327      * @return  Current tie-breaker
       
   328      */
       
   329     TUint64 TieBreaker() const;
       
   330     
       
   331     /**
       
   332      * Returns domain.
       
   333      *
       
   334      * @since   S60 v3.2
       
   335      * @return  Domain
       
   336      */
       
   337     const TDesC8& Domain() const;
       
   338     
       
   339     /**
       
   340      * Returns internet access point identifier.
       
   341      *
       
   342      * @since   S60 v3.2
       
   343      * @return  Internet access point identifier
       
   344      */
       
   345     TUint32 IapId() const;
       
   346 
       
   347     /**
       
   348      * Sets value of the TA timer in milliseconds.
       
   349      *
       
   350      * @since   S60 v3.2
       
   351      * @param   aTaTimerValue           The value for the timer
       
   352      */
       
   353     void SetTaTimerValue( TUint aTaTimerValue );
       
   354 
       
   355     /**
       
   356      * Returns value of the TA timer in milliseconds.
       
   357      *
       
   358      * @since   S60 v3.2
       
   359      * @return  TA timer value
       
   360      */
       
   361     TUint TaTimerValue() const;
       
   362     
       
   363 private:
       
   364         
       
   365 
       
   366     CIceSessionData( TUint32 aIapId );
       
   367 
       
   368     void ConstructL( const TDesC8& aDomain );
       
   369 
       
   370     TBool IsRedundantCandidate( const CNATFWCandidate& aLocalCandidate,
       
   371         const RPointerArray<CNATFWCandidate>& aCandidateArray ) const;
       
   372 
       
   373     void AssignFoundationForCandidateL( CNATFWCandidate& aLocalCandidate );
       
   374 
       
   375     CIceStreamCollection* FindStreamCollectionById( 
       
   376         TUint aCollectionId );
       
   377 
       
   378     const TDesC8& GenerateRandomIdentifier();
       
   379     
       
   380     void UpdateUserNamesL( CNATFWCredentials& aCredentials );
       
   381 
       
   382 private: // data
       
   383 
       
   384     /**
       
   385      * Tie-breaker used for role conflict determination in the session.
       
   386      */
       
   387     TUint64 iTieBreaker;
       
   388     
       
   389     /**
       
   390      * The current role.
       
   391      */
       
   392     TNATFWIceRole iRole;
       
   393     
       
   394     /**
       
   395      * Domain in which session is created.
       
   396      * Own.
       
   397      */
       
   398     HBufC8* iDomain;
       
   399     
       
   400     /**
       
   401      * Internet access point identifier.
       
   402      */
       
   403     TUint32 iIapId;
       
   404     
       
   405     /**
       
   406      * Stream collections.
       
   407      * Own.
       
   408      */
       
   409     RPointerArray<CIceStreamCollection> iStreamCollections;
       
   410     
       
   411     /**
       
   412      * Credentials.
       
   413      * Own.
       
   414      */
       
   415     RPointerArray<CNATFWCredentials> iCredentialsList;
       
   416     
       
   417     /**
       
   418      * Local candidates resolved so far.
       
   419      * Own.
       
   420      */
       
   421     RPointerArray<CNATFWCandidate> iLocalCandidateList;
       
   422     
       
   423     /**
       
   424      * Remote candidates known.
       
   425      * Own.
       
   426      */
       
   427     RPointerArray<CNATFWCandidate> iRemoteCandidateList;
       
   428     
       
   429     /**
       
   430      * Temporary variable for credentials generation.
       
   431      * Own.
       
   432      */
       
   433     RBuf8 iTempIdentifier;
       
   434 
       
   435     /**
       
   436      * Value for the TA timer.
       
   437      */
       
   438     TUint iTaTimerValue;
       
   439     };
       
   440 
       
   441 
       
   442 #endif // CNATFWCANDIDATESTORAGE_H