natfw/natfwconnectionmultiplexer/inc/cncmconnectionmultiplexer.h
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006-2008 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:    Connection multiplexer is responsible for handling network
       
    15 *                connections, sending and receiving data from the
       
    16 *                network and allows client to start media flow between
       
    17 *                connection multiplexer and socket media connection wrapper. 
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 #ifndef C_CNCMCONNECTIONMULTIPLEXER_H
       
    25 #define C_CNCMCONNECTIONMULTIPLEXER_H
       
    26 
       
    27 #include <e32base.h>
       
    28 
       
    29 #include "natfwconnectivityapidefs.h"
       
    30 #include "mncmmultiplexerconnectionobserver.h"
       
    31 #include "mncmsessionobserver.h"
       
    32 #include "mncmconnectionmultiplexer.h"
       
    33 #include "mncmmediasourceobserver.h"
       
    34 
       
    35 class TInetAddr;
       
    36 class MNcmConnectionMultiplexerObserver;
       
    37 class MNcmMultiplexerConnectionObserver;
       
    38 class MNcmIncomingConnectionObserver;
       
    39 class MNcmOutgoingConnectionObserver;
       
    40 class MNATFWMediaWrapper;
       
    41 class CNcmPortStore;
       
    42 class CNcmConnectionObserverHandler;
       
    43 class RSocket;
       
    44 class RConnection;
       
    45 class RSocketServ;
       
    46 class CNcmSession;
       
    47 class CNcmStream;
       
    48 class MNATFWMediaWrapper;
       
    49 class MNcmSenderObserver;
       
    50 class CNcmCallBackExecuter;
       
    51 
       
    52 /**
       
    53  *  Connection multiplexer is responsible for handling network
       
    54  *  connections, send and receive data from the network. It allows client
       
    55  *  to start data flow between connection multiplexer and socket media
       
    56  *  connection wrapper.
       
    57  *
       
    58  *  Connection Multiplexer have one session per IAP and in session can be
       
    59  *  multiple streams and in streams can be multiple connections.
       
    60  *
       
    61  *  @lib connectionmux.lib
       
    62  *  @since S60 v3.2
       
    63  */
       
    64 class CNcmConnectionMultiplexer : public CBase,
       
    65     public MNcmConnectionMultiplexer,
       
    66     public MNcmMultiplexerConnectionObserver,
       
    67     public MNcmSessionObserver,
       
    68     public MNcmMediaSourceObserver
       
    69     {
       
    70 
       
    71     friend class UT_CNcmConnectionMultiplexer;
       
    72     
       
    73 public:
       
    74 
       
    75     /** 
       
    76      * Two-phased constructor
       
    77      *
       
    78      * @param   aObserver      Observer for Connection Multiplexer
       
    79      */
       
    80     IMPORT_C static CNcmConnectionMultiplexer* NewL(
       
    81         MNcmConnectionMultiplexerObserver& aObserver );
       
    82 
       
    83     /** 
       
    84      * Destructor
       
    85      */
       
    86     virtual ~CNcmConnectionMultiplexer();
       
    87 
       
    88     /** 
       
    89      * Creates a new session. On return the client received identifier for
       
    90      * the session. The session is ready to be used when the client receives
       
    91      * MNcmConnectionMultiplexerObserver::Notify callback with event code 
       
    92      * ESessionCreated.
       
    93      *
       
    94      * @since   S60 v3.2
       
    95      * @param   aIapId              The IAP used for a conection
       
    96      * @param   aPortRangeStart     Port range start for session
       
    97      * @param   aPortRangeStop      Port range stop for session
       
    98      * @return  The ID for the created session.
       
    99      */
       
   100     IMPORT_C TUint CreateSessionL( TUint32 aIapId, TUint aPortRangeStart,
       
   101         TUint aPortRangeStop );
       
   102     
       
   103     /**
       
   104      * Creates a new stream.
       
   105      *
       
   106      * This is done synchronously.
       
   107      *
       
   108      * @since   S60 v3.2
       
   109      * @param   aSessionId      The ID identifying session
       
   110      * @param   aQos            The desired quality of service
       
   111      * @param   aProtocol       The protocol to be used,
       
   112      *                          KProtocolInetUdp / KProtocolInetTcp
       
   113      * @return  The ID for the created stream.
       
   114      */
       
   115     IMPORT_C TUint CreateStreamL( TUint aSessionId, TInt aQos,
       
   116         TUint aProtocol );
       
   117     
       
   118     /** 
       
   119      * Removes session and all its streams and streams connections
       
   120      *
       
   121      * This is done synchronously.  
       
   122      *
       
   123      * @since   S60 v3.2
       
   124      * @param   aSessionId      The ID identifying session
       
   125      * @return  void
       
   126      */
       
   127     IMPORT_C void RemoveSessionL( TUint aSessionId );
       
   128     
       
   129     /** 
       
   130      * Removes stream and all its connections.
       
   131      *
       
   132      * This is done synchronously.
       
   133      *
       
   134      * @since   S60 v3.2
       
   135      * @param   aStreamId     The ID identifying stream
       
   136      * @return  void
       
   137      */
       
   138     IMPORT_C void RemoveStreamL( TUint aStreamId );
       
   139 
       
   140     /**
       
   141      * Registers a media wrapper into stream. Ownership of wrapper is
       
   142      * also transferred to Connection Multiplexer.
       
   143      *
       
   144      * @since   S60 v3.2
       
   145      * @param   aMediaWrapper   Pointer to Socket Media Connection Wrapper
       
   146      * @return  void
       
   147      */
       
   148     IMPORT_C void RegisterMediaWrapperL( MNATFWMediaWrapper* aMediaWrapper );
       
   149 
       
   150     /**
       
   151      * Receives port store associated to session
       
   152      *
       
   153      * @since   S60 v3.2
       
   154      * @param   aSessionId    The ID identifying session
       
   155      * @return  Port store used on session
       
   156      */    
       
   157     IMPORT_C CNcmPortStore& PortStoreL( TUint aSessionId );
       
   158     
       
   159     /**
       
   160      * Gets the socket server handle and the unique name of
       
   161      * the RConnection used by the connection multiplexer session.
       
   162      *
       
   163      * @since   S60 v3.2
       
   164      * @param   aSessionId              The ID identifying session
       
   165      * @param   aConnectionName         The unique name of the RConnection
       
   166      * @return  handle to socket server   
       
   167      */
       
   168     IMPORT_C RSocketServ* GetSessionInfoL( TUint aSessionId, 
       
   169         TName& aConnectionName );  
       
   170                       
       
   171     /**
       
   172      * Enables/disables media flow from Connection Multiplexer to 
       
   173      * Socket Media Connection Wrapper for the specified connection.
       
   174      *
       
   175      * The receiving is enabled/disabled when the client receives
       
   176      * MNcmConnectionMultiplexerObserver::Notify callback with event code 
       
   177      * EReceivingActivated/EReceivingDeactivated.
       
   178      * While incoming data from network is passed to Socket Media Connection
       
   179      * Wrapper if receiving for media is activated.
       
   180      *
       
   181      * @since   S60 v3.2
       
   182      * @param   aStreamId           The ID identifying stream
       
   183      * @param   aConnectionId       The ID identifying connection
       
   184      * @param   aState              The receiving state
       
   185      * @return  void
       
   186      */
       
   187     IMPORT_C void SetReceivingStateForMediaL( TUint aStreamId,
       
   188         TUint aConnectionId, TNATFWStreamingState aState );
       
   189     
       
   190     /**
       
   191      * Enables/disables media flow from Socket Media Connection Wrapper to 
       
   192      * Connection Multiplexer for the specified connection.
       
   193      *
       
   194      * The sending is enabled/disabled when the client receives
       
   195      * MNcmConnectionMultiplexerObserver::Notify callback with event code 
       
   196      * ESendingActivated/ESendingDeactivated. While incoming data from
       
   197      * Socket Media Connection Wrapper is delivered to specified connection
       
   198      * which is used to send media to network if sending for media is
       
   199      * activated.
       
   200      *
       
   201      * @since   S60 3.2
       
   202      * @param   aStreamId           The ID identifying stream
       
   203      * @param   aConnectionId       The ID identifying connection
       
   204      * @param   aState              The sending state
       
   205      * @return  void
       
   206      */
       
   207     IMPORT_C void SetSendingStateForMediaL( TUint aStreamId,
       
   208         TUint aConnectionId, TNATFWStreamingState aState );
       
   209 
       
   210     /**
       
   211      * Resolves the destination IP address from FQDN.
       
   212      * ( Address and port )
       
   213 
       
   214      * @since   S60 v3.2
       
   215      * @param   aStreamId      The ID identifying stream
       
   216      * @param   aAddress       The Destination FQDN
       
   217      * @param   aPort          The Destination port
       
   218      * @param   aResult        On return contains the resolved IP address
       
   219      * @return  void
       
   220      */
       
   221     IMPORT_C void ResolveDestinationAddressL( TUint aStreamId,
       
   222         const TDesC8& aAddress, TUint aPort, TInetAddr& aResult );
       
   223                 
       
   224 // from base class MNcmConnectionMultiplexer
       
   225 
       
   226     /**
       
   227      * Creates a new connection for stream. Will use same protocol as
       
   228      * used in stream. Address family specifies address family
       
   229      * which is used to choose whether IPv4 or IPv6 connection will be made.
       
   230      *
       
   231      * This is done synchronously.
       
   232      * 
       
   233      * @since   S60 v3.2
       
   234      * @param   aStreamId       The ID identifying stream
       
   235      * @param   aAddrFamily     The address family(KAfInet/KAfInet6)
       
   236      *                          KAfInet, IPv4 local address is used
       
   237      *                          KAfInet6, IPv6 local address is used
       
   238      * @return  The ID for the created connection
       
   239      * @leave KErrNotSupported If specified local address hasn't found
       
   240      */
       
   241     IMPORT_C TUint CreateConnectionL( TUint aStreamId, TUint aAddrFamily );
       
   242 
       
   243     /**
       
   244      * Overloaded CreateConnectionL
       
   245      * Creates a new connection for stream. Will use same protocol as
       
   246      * used in stream. Connection is made by using specified local address.
       
   247      *
       
   248      * This is done synchronously.
       
   249      * 
       
   250      * @since   S60 v3.2
       
   251      * @param   aStreamId       The ID identifying stream
       
   252      * @param   aLocalAddr      The specified local address.
       
   253      * @return  The ID for the created connection
       
   254      */
       
   255     IMPORT_C TUint CreateConnectionL( TUint aStreamId,
       
   256         const TInetAddr& aLocalAddr );
       
   257         
       
   258     /**
       
   259      * Removes the specified connection.
       
   260      * 
       
   261      * @since   S60 v3.2
       
   262      * @param   aStreamId       The ID identifying stream
       
   263      * @param   aConnectionnId  The ID identifying connection
       
   264      * @return  void
       
   265      */
       
   266     IMPORT_C void RemoveConnectionL( TUint aStreamId, TUint aConnectionnId );
       
   267         
       
   268     /**
       
   269      * Fetches stream specific information which is formerly stored, while
       
   270      * stream was created
       
   271      *
       
   272      * @since   S60 v3.2
       
   273      * @param   aStreamId       The ID identifying stream
       
   274      * @param   aIapId          IAP Id for session
       
   275      * @param   aQos            The quality of service
       
   276      * @param   aProtocol       KProtocolInetUdp / KProtocolInetTcp
       
   277      * @return  void
       
   278      */
       
   279     IMPORT_C void GetStreamInfoL( TUint aStreamId, TUint32& aIapId,
       
   280         TInt& aQos, TUint& aProtocol );
       
   281 
       
   282     /**
       
   283      * Returns the local IP address and port of specified connection.
       
   284      *
       
   285      * @since   S60 v3.2
       
   286      * @param   aStreamId       The ID identifying stream
       
   287      * @param   aConnectionId   The ID identifying connection
       
   288      * @return  Local IP address
       
   289      */
       
   290     IMPORT_C TInetAddr& LocalIPAddressL( TUint aStreamId,
       
   291         TUint aConnectionId );
       
   292             
       
   293     /**
       
   294      * Establishes TCP connection. Connection will be established in specified
       
   295      * direction using given connection setup.
       
   296      *
       
   297      * MNcmConnectionObserver::ConnectionNotify is called with event code
       
   298      * ETcpSetupCompleted when connection setup is completed.
       
   299      * 
       
   300      * SetReceivingStateL/SetSendingStateL can be called normally after
       
   301      * successfull connection initialization.
       
   302      * 
       
   303      * @since   S60 3.2
       
   304      * @param   aStreamId       The ID identifying stream
       
   305      * @param   aConnectionId   The ID identifying connection
       
   306      * @param   aConfig         TCP connection setup configuration
       
   307      * @param   aDestAddr       The destination address for active connection
       
   308      * @return  void
       
   309      */      
       
   310     IMPORT_C void OpenTcpConnectionL( TUint aStreamId, TUint aConnectionId,
       
   311         TNATFWTcpConnectionSetup aConfig, const TInetAddr& aDestAddr );
       
   312 
       
   313     /**
       
   314      * Closes TCP connection or cancels in-progress connection process.
       
   315      *
       
   316      * If TCP connection establishment is in-progress 
       
   317      * MNcmConnectionObserver::Notify is called with event code 
       
   318      * ETcpConnSetupCompleted and error code KErrCancel. 
       
   319      *
       
   320      * After successful connection closing SetupTcpConnectionL can be
       
   321      * called again with different destination address.
       
   322      * 
       
   323      * @since   S60 3.2
       
   324      * @param   aStreamId       The ID identifying stream
       
   325      * @param   aConnectionId   The ID identifying connection
       
   326      * @return  void
       
   327      */
       
   328     IMPORT_C void CloseTcpConnection( TUint aStreamId, TUint aConnectionId );
       
   329                 
       
   330     /**
       
   331      * Registers an observer for observing incoming messages in
       
   332      * specific stream. This method won't register observer again if
       
   333      * client have allready registered.
       
   334      *
       
   335      * @since   S60 v3.2
       
   336      * @param   aStreamId       The ID identifying stream
       
   337      * @param   aObserver       Observer to be registered
       
   338      * @return  void
       
   339      */
       
   340     IMPORT_C void RegisterIncomingConnectionObserverL( TUint aStreamId,
       
   341         MNcmIncomingConnectionObserver& aObserver );
       
   342 
       
   343     /**
       
   344      * Registers an observer for outgoing messages in specific
       
   345      * stream. This method won't register observer again if
       
   346      * client have allready registered.
       
   347      *
       
   348      * @since   S60 v3.2
       
   349      * @param   aStreamId       The ID identifying stream
       
   350      * @param   aObserver       Observer to be registered
       
   351      * @return  void
       
   352      */
       
   353     IMPORT_C void RegisterOutgoingConnectionObserverL( TUint aStreamId,
       
   354         MNcmOutgoingConnectionObserver& aObserver );
       
   355 
       
   356     /**
       
   357      * Unregisters specified observer.
       
   358      *
       
   359      * @since   S60 v3.2
       
   360      * @param   aStreamId       The ID identifying stream
       
   361      * @param   aObserver       Observer to be unregistered
       
   362      * @return  void
       
   363      */
       
   364     IMPORT_C void UnregisterIncomingConnectionObserverL( TUint aStreamId,
       
   365         MNcmIncomingConnectionObserver& aObserver );
       
   366 
       
   367     /**
       
   368      *  Unregisters specified observer.
       
   369      *
       
   370      * @since   S60 v3.2
       
   371      * @param   aStreamId       The ID identifying stream
       
   372      * @param   aObserver       Observer to be unregistered
       
   373      * @return  void
       
   374      */
       
   375     IMPORT_C void UnregisterOutgoingConnectionObserverL( TUint aStreamId,
       
   376         MNcmOutgoingConnectionObserver& aObserver );
       
   377       
       
   378     /**
       
   379      * Registers an observer for connection notifies.
       
   380      * This method won't register observer again if
       
   381      * client have allready registered.
       
   382      *
       
   383      * @since   S60 v3.2
       
   384      * @param   aStreamId       The ID identifying stream
       
   385      * @param   aObserver       Observer to be registered
       
   386      * @return  void
       
   387      */
       
   388     IMPORT_C void RegisterConnectionObserverL( TUint aStreamId,
       
   389         MNcmConnectionObserver& aObserver );
       
   390 
       
   391     /**
       
   392      *  Unregisters specified observer.
       
   393      *
       
   394      * @since S60 v3.2
       
   395      * @param   aStreamId       The ID identifying stream
       
   396      * @param   aObserver       Observer to be unregistered
       
   397      * @return void
       
   398      */
       
   399     IMPORT_C void UnregisterConnectionObserverL( TUint aStreamId,
       
   400         MNcmConnectionObserver& aObserver );
       
   401 
       
   402     /**
       
   403      * Registers an observer for receive incoming and outgoing message
       
   404      * notifications. All notifications are offered first to this observer.
       
   405      * There can be only one registered observer at a time.
       
   406      * Message observer is allowed to make modifications to offered
       
   407      * messages.
       
   408      *
       
   409      * @since   S60 v3.2
       
   410      * @param   aStreamId       The ID identifying stream
       
   411      * @param   aObserver       Observer to be registered
       
   412      * @return  void
       
   413      */
       
   414     IMPORT_C void RegisterMessageObserverL( TUint aStreamId,
       
   415         MNcmMessageObserver& aObserver );
       
   416 
       
   417     /**
       
   418      * Unregisters an observer for receiving incoming and outgoing message
       
   419      * notifications.
       
   420      *
       
   421      * @since S60 v3.2
       
   422      * @param aStreamId A stream ID
       
   423      * @param aObserver to be unregistered
       
   424      * @return void
       
   425      */
       
   426     IMPORT_C void UnregisterMessageObserverL( TUint aStreamId,
       
   427         MNcmMessageObserver& aObserver );
       
   428         
       
   429     /**
       
   430      * Sends a message from specified connection to network.
       
   431      *
       
   432      * @since   S60 v3.2
       
   433      * @param   aStreamId           The ID identifying stream
       
   434      * @param   aConnectionId       The ID identifying connection
       
   435      * @param   aMessage            A message to be copied and
       
   436      *                              then sent asynchronously.
       
   437      * @param   aSenderObserver     Observer for this send.
       
   438      * @return  void
       
   439      */
       
   440     IMPORT_C void SendL( TUint aStreamId, TUint aConnectionId,
       
   441         const TDesC8& aMessage, MNcmSenderObserver* aSenderObserver = NULL );
       
   442     
       
   443     /**
       
   444      * Overloaded SendL
       
   445      * Sends a message from specified connection to network. 
       
   446      * Destination address parameter tells
       
   447      * the destination address for the message. 
       
   448      *
       
   449      * @since   S60 v3.2
       
   450      * @param   aStreamId               The ID identifying stream
       
   451      * @param   aConnectionId           The ID identifying conenction
       
   452      * @param   aMessage                A message to be copied and
       
   453      *                                  then sent asynchronously.
       
   454      * @param   aDestinationAddress     Destination address
       
   455      * @param   aSenderObserver         Observer for this send.
       
   456      * @return  void
       
   457      */
       
   458     IMPORT_C void SendL( TUint aStreamId, TUint aConnectionId,
       
   459         const TDesC8& aMessage, const TInetAddr& aDestinationAddress,
       
   460         MNcmSenderObserver* aSenderObserver = NULL );
       
   461 
       
   462     /**
       
   463      * Overloaded SendL
       
   464      * Sends a message from connection which is found by next hop address.
       
   465      * Destination address parameter tells the destination address for
       
   466      * the message. 
       
   467      *
       
   468      * @since   S60 v3.2
       
   469      * @param   aStreamId               The ID identifying stream
       
   470      * @param   aMessage                A message
       
   471      * @param   aNextHopAddress         Specifies the IP address of the next
       
   472      *                                  hop in the route
       
   473      *                                  will be used to find connection which
       
   474      *                                  will be used for sending.
       
   475      * @param   aDestinationAddress     Destination address.
       
   476      * @return  void
       
   477      */
       
   478     IMPORT_C void SendL( TUint aStreamId, const TDesC8& aMessage,
       
   479         const TInetAddr& aNextHopAddress,
       
   480         const TInetAddr& aDestinationAddress );
       
   481         
       
   482     /**
       
   483      * Overloaded SendL
       
   484      * Sends a message directly from connection. Will not offer this
       
   485      * message to any registered observers if aSendDirectly is set to
       
   486      * ETrue
       
   487      *
       
   488      * @since   S60 v3.2
       
   489      * @param   aStreamId           The ID identifying stream
       
   490      * @param   aConnectionId       The ID identifying conenction
       
   491      * @param   aMessage            A message
       
   492      * @param   aSendDirectly       if ETrue sends a message directly.
       
   493      *                              Will not offer this message to any
       
   494      *                              registered observers.
       
   495      *                              normally and will be offered registered
       
   496      *                              observers.
       
   497      * @param   aSenderObserver     Observer for this send.
       
   498      * @return  void
       
   499      */
       
   500     IMPORT_C void SendL( TUint aStreamId, TUint aConnectionId,
       
   501         const TDesC8& aMessage, TBool aSendDirectly,
       
   502         MNcmSenderObserver* aSenderObserver = NULL );
       
   503     
       
   504     /**
       
   505      * Cancels sender observer's message send processes.
       
   506      *
       
   507      * Client MUST call its destructor on this method and cancel all send
       
   508      * processes which it is observing( Client have used SendL with 
       
   509      * sender observer param ), otherwise there can be panic.
       
   510      *
       
   511      * @since   S60 v3.2
       
   512      * @param   aStreamId           The ID identifying stream
       
   513      * @param   aConnectionId       The ID identifying connection         
       
   514      * @param   aSenderObserver     Observer which observing
       
   515      *                              message send processes 
       
   516      * @return  void
       
   517      */
       
   518      IMPORT_C void CancelMessageSend( TUint aStreamId, TUint aConnectionId,
       
   519         const MNcmSenderObserver* aSenderObserver );
       
   520         
       
   521 
       
   522     /**
       
   523      * Enables/disables data receiving for the specified connection.
       
   524      *
       
   525      * MNcmConnectionObserver::ConnectionNotify is called with event code
       
   526      * EReceivingActivated/EReceivingDeactivated when status change
       
   527      * has completed. While incoming data is received from network.
       
   528      *
       
   529      * Connection receives can be use for sending
       
   530      * after successful sending activation.
       
   531      *
       
   532      * @since   S60 v3.2
       
   533      * @param   aStreamId           The ID identifying stream
       
   534      * @param   aConnectionId       The ID identifying connection
       
   535      * @param   aState              The receiving state
       
   536      * @return  void
       
   537      */
       
   538     IMPORT_C void SetReceivingStateL( TUint aStreamId, TUint aConnectionId,
       
   539         TNATFWStreamingState aState );
       
   540     
       
   541     /**
       
   542      * Enables/disables data sending for the specified connection.
       
   543      * Function can be called again with new destination address while
       
   544      * sending is in activated state.
       
   545      *
       
   546      * MNcmConnectionObserver::ConnectionNotify is called with event code
       
   547      * ESendingActivated/ESendingDeactivated when status change
       
   548      * has completed.
       
   549      *
       
   550      * Connection can be use for sending after successful sending activation.
       
   551      *
       
   552      * Destination address for TCP-connection is given in 
       
   553      * active TCP-connection setup.
       
   554      *
       
   555      * @since   S60 3.2
       
   556      * @param   aStreamId           The ID identifying stream
       
   557      * @param   aConnectionId       The ID identifying connection
       
   558      * @param   aDestAddr           The destination address where
       
   559      *                              the client wants to connect to
       
   560      * @param   aState              The sending state
       
   561      * @return  void
       
   562      */
       
   563     IMPORT_C void SetSendingStateL( TUint aStreamId, TUint aConnectionId,
       
   564         const TInetAddr& aDestAddr, TNATFWStreamingState aState );
       
   565     
       
   566     /**
       
   567      * Sets address from which incoming data is accepted from this moment
       
   568      * onwards. Binds connection to the specified remote address. Unbinding
       
   569      * can be done by setting unspecified address.
       
   570      *
       
   571      * @since   S60 v3.2
       
   572      * @param   aStreamId           The ID identifying stream
       
   573      * @param   aConnectionId       The ID identifying connection
       
   574      * @param   aAddress            The remote address
       
   575      */
       
   576     IMPORT_C void SetAcceptedFromAddressL( TUint aStreamId, 
       
   577         TUint aConnectionId, const TInetAddr& aAddress );
       
   578     
       
   579     /**
       
   580      * Static handler function for callbacks.
       
   581      *
       
   582      * @since   S60 3.2
       
   583      * @param   aObject         The object reference
       
   584      * @param   aStreamId       The ID identifying stream
       
   585      * @param   aConnectionId   The ID identifying connection     
       
   586      * @param   aType           The notify type
       
   587      * @param   aError          The error code
       
   588      * @return  void
       
   589      */    
       
   590     static void HandleCallBack( CBase& aObject, TUint aStreamId,
       
   591         TUint aConnectionId, TMultiplexerConnectionNotifyType aType,
       
   592         TInt aError );
       
   593             
       
   594 // from base class MNcmMultiplexerConnectionObserver
       
   595 
       
   596     /**
       
   597      * From MNcmMultiplexerConnectionObserver
       
   598      *
       
   599      * Called by connection when transfer error occurs on it
       
   600      *
       
   601      * @since   S60 v3.2
       
   602      * @param   aSessionId          The ID identifying session
       
   603      * @param   aStreamId           The ID identifying stream
       
   604      * @param   aConnectionId       The ID identifying connection
       
   605      * @param   aNotifyType         Type of notify
       
   606      * @param   aError              The error code
       
   607      * @return void
       
   608      */
       
   609     void ConnectionError( TUint aSessionId, TUint aStreamId,
       
   610         TUint aConnectionId,
       
   611         TMultiplexerConnectionNotifyType aNotifyType, TInt aError );
       
   612 
       
   613     /**
       
   614      * From MNcmMultiplexerConnectionObserver
       
   615      *
       
   616      * Called by socket destination object when action completes
       
   617      * (or error is reached)
       
   618      *
       
   619      * @since   S60 v3.2
       
   620      * @param   aStreamId           The ID identifying stream
       
   621      * @param   aConnectionId       The ID identifying connection
       
   622      * @param   aType               Type of notify
       
   623      * @param   aError              Error code
       
   624      * @return  void
       
   625      */
       
   626     void ConnectionNotify( TUint aStreamId, TUint aConnectionId,
       
   627                            TMultiplexerConnectionNotifyType aType,
       
   628                            TInt aError );
       
   629 
       
   630     /**
       
   631      * From MNcmMultiplexerConnectionObserver
       
   632      *
       
   633      * Called by socket destination object when current
       
   634      * local port is already in use.
       
   635      * Gets new free port.
       
   636      *
       
   637      * @since   S60 v3.2
       
   638      * @param   aStreamId           The ID identifying stream
       
   639      * @param   aConnectionId       The ID identifying connection     
       
   640      * @param   aPort               New free port
       
   641      * @return  void
       
   642      */
       
   643     void GetNewFreePort( TUint aStreamId, TUint aConnectionId, TUint& aPort );
       
   644         
       
   645 // from base class MNcmMediaSourceObserver
       
   646 
       
   647     /**
       
   648      * From MNcmMediaSourceObserver
       
   649      *
       
   650      * Called by Media Source after wrapper has had sending error
       
   651      *
       
   652      * @since   S60 v3.2
       
   653      * @param   aStreamId           The ID identifying stream   
       
   654      * @param   aError              The error code
       
   655      * @return  void
       
   656      */
       
   657     void WrapperSenderError( TUint aStreamId, TInt aError );
       
   658     
       
   659     /**
       
   660      * From MNcmMediaSourceObserver
       
   661      *
       
   662      * Called by Media Source if current local port is already in use.
       
   663      * Gets new free port.
       
   664      *
       
   665      * @since   S60 v3.2
       
   666      * @param   aStreamId           The ID identifying stream   
       
   667      * @param   aPort               New free port
       
   668      * @return  void
       
   669      */ 
       
   670     void GetFreePort( TUint aStreamId, TUint& aPort );
       
   671 
       
   672     /**
       
   673      * From MNcmMediaSourceObserver
       
   674      *
       
   675      * Notifies that the first media packet is sent to
       
   676      * the remote address.
       
   677      *
       
   678      * @since   S60 v3.2
       
   679      * @param   aStreamId           The ID identifying stream
       
   680      * @return  void
       
   681      */     
       
   682     void FirstMediaPacketSent( TUint aStreamId );
       
   683         
       
   684 // from base class MNcmSessionObserver
       
   685 
       
   686     /**
       
   687      * From MNcmSessionObserver
       
   688      *
       
   689      * Notifies that session creation is failed.
       
   690      *
       
   691      * @since   S60 v3.2
       
   692      * @param   aSessionId      The ID identifying session
       
   693      * @return  void
       
   694      */
       
   695     void SessionCreationFailed( TUint aSessionId );
       
   696 
       
   697 private:
       
   698 
       
   699     void ConstructL();
       
   700 
       
   701     CNcmConnectionMultiplexer(
       
   702         MNcmConnectionMultiplexerObserver& aObserver );
       
   703     
       
   704     CNcmSession* SessionByIdL( TUint aSessionId );
       
   705     
       
   706     CNcmStream* StreamByIdL( TUint aStreamId );
       
   707     
       
   708     CNcmStream* StreamById( TUint aStreamId );
       
   709     
       
   710     CNcmSession* SessionByStreamIdL( TUint aStreamId );
       
   711  
       
   712     void ConnectionNotifyL( TUint aStreamId, TUint aConnectionId,
       
   713         TMultiplexerConnectionNotifyType aType, TInt aError );
       
   714     
       
   715     void GetNewFreePortL( TUint aStreamId, TUint aConnectionId,
       
   716         TUint& aPort );
       
   717 
       
   718     void HandleCallBackL( TUint aStreamId, TUint aConnectionId,
       
   719         TMultiplexerConnectionNotifyType aType, TInt aError );
       
   720         
       
   721     void CloseTcpConnectionL( TUint aStreamId, TUint aConnectionId );
       
   722 
       
   723     void CancelMessageSendL( TUint aStreamId, TUint aConnectionId,
       
   724         const MNcmSenderObserver* aSenderObserver );
       
   725             
       
   726 private: // data
       
   727 
       
   728     /**
       
   729      * Observer for this connection multiplexer
       
   730      * Not own.
       
   731      */
       
   732     MNcmConnectionMultiplexerObserver& iObserver;
       
   733     
       
   734     /**
       
   735      *  Next unused session ÍD 
       
   736      */
       
   737     TUint iNextSessionId;
       
   738     
       
   739     /**
       
   740      * Created sessions.
       
   741      * Own.
       
   742      */
       
   743     RPointerArray<CNcmSession> iSessions;
       
   744 
       
   745     /**
       
   746      * Async callback executer
       
   747      * Own.
       
   748      */    
       
   749     CNcmCallBackExecuter* iAsyncCallback;   
       
   750     };
       
   751 
       
   752 
       
   753 #endif // C_CNCMCONNECTIONMULTIPLEXER_H