natfw/natfwsocketmediaconnwrapper/inc/natfwsocketmediaconnwrapper.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:    Implements Socket Media Connection Wrapper IF and 
       
    15                  Socket Media Wrapper IF
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #ifndef C_SOCKET_MEDIA_CONN_WRAPPER_H
       
    23 #define C_SOCKET_MEDIA_CONN_WRAPPER_H
       
    24 
       
    25 
       
    26 #include <e32base.h>
       
    27 #include <es_sock.h>
       
    28 
       
    29 #include "mnatfwsocketmediaconnwrapper.h"
       
    30 #include "natfwmediawrapper.h"
       
    31 #include "natfwsockethandler.h"
       
    32 
       
    33 class MNATFWMediaWrapperObserver;
       
    34 class MNATFWSocketReceiverObserver;
       
    35 class MNATFWSocketSenderObserver;
       
    36 
       
    37 /**
       
    38  *  A basic media interface for attaching socket-based medias into nat 
       
    39  *  framework.
       
    40  *
       
    41  *  Socket Media Connection Wrapper implements a proxy pattern, between
       
    42  *  the NAT Framework user and internal use of the NAT Connectivity Framework.
       
    43  *
       
    44  *  @lib socketmediaconnwrapper.dll
       
    45  *  @since S60 v3.2
       
    46  */
       
    47 NONSHARABLE_CLASS ( CNATFWSocketMediaConnWrapper ) : public CBase, 
       
    48     public MNATFWSocketMediaConnWrapper, public MNATFWMediaWrapper,
       
    49     public MNATFWSocketReceiverObserver, public MNATFWSocketSenderObserver
       
    50   
       
    51     {
       
    52     friend class UT_MNATFWMediaWrapper;
       
    53 
       
    54 public:
       
    55     
       
    56     /**
       
    57      * Two-phased constructor.
       
    58      * @param aObserver media observer
       
    59      * @param aPort     wrapper's local port
       
    60      * @param aProtocol used protocol
       
    61      * @param aStreamId stream id
       
    62      */    
       
    63     IMPORT_C static CNATFWSocketMediaConnWrapper* NewL( TUint aPort, 
       
    64         TUint aProtocol, TUint aStreamId );
       
    65 
       
    66     virtual ~CNATFWSocketMediaConnWrapper();
       
    67 
       
    68    
       
    69 // from base class MNATFWSocketMediaConnWrapper
       
    70 
       
    71     /**
       
    72      * From MNATFWSocketMediaConnWrapper
       
    73      * Returns The stream ID which wrapper is associated with
       
    74      *
       
    75      * @since S60 v3.2
       
    76      * @return stream Id
       
    77      */
       
    78     IMPORT_C TUint StreamId();
       
    79     
       
    80     /**
       
    81      * From  MNATFWSocketMediaConnWrapper
       
    82      * Establishes TCP connection between mediaengine and NATFW. Connection
       
    83      * will be established in specified direction.
       
    84      * 
       
    85      * MNsmcwTcpConnectionObserver::ConnectingCompleted will be called when
       
    86      * connection is established.
       
    87      * 
       
    88      * @since   S60 v3.2
       
    89      * @param   aSetup      TCP connection setup configuration
       
    90      * @param   aObserver   Client to notify when connected
       
    91      */
       
    92     void OpenTcpConnectionL( TNATFWTcpConnectionSetup aSetup, 
       
    93                                    MNsmcwTcpConnectionObserver& aObserver );
       
    94                                    
       
    95     /**
       
    96      * From MNATFWSocketMediaConnWrapper
       
    97      * Closes TCP connection.
       
    98      *
       
    99      * MNsmcwTcpConnectionObserver::ConnectingCompleted is called with error
       
   100      * code KErrCancel if TCP connection establishment is ongoing.
       
   101      *
       
   102      * @since S60 v3.2
       
   103      */
       
   104     void CloseTcpConnection();
       
   105     
       
   106     /**
       
   107      * From MNATFWSocketMediaConnWrapper
       
   108      * User of NAT Connectivity Framework fetch the reserved local IP which
       
   109      * is used as destination address
       
   110      * 
       
   111      * @param aSocketToSendForPeer Address for receiving data
       
   112      * @since S60 v3.2
       
   113      * @return void
       
   114      */
       
   115     IMPORT_C void OutgoingAddr( TSockAddr& aSocketToSendForPeer );
       
   116     
       
   117     /**
       
   118      * From MNATFWSocketMediaConnWrapper
       
   119      * User of NAT Connectivity Framework sets local socket address for 
       
   120      * incoming packets. Wrapper connecting to remote address is started.
       
   121      *
       
   122      * @param aSocketToReceiveFromPeer Destination address for sending
       
   123      * @since S60 v3.2
       
   124      * @return void
       
   125      */
       
   126     IMPORT_C void SetIncomingAddrL( 
       
   127         const TSockAddr& aSocketToReceiveFromPeer );
       
   128         
       
   129     /**
       
   130      * From MNATFWSocketMediaConnWrapper
       
   131      * Enables/disables datapath between mediaengine and NATFW regarding
       
   132      * media receiving.
       
   133      * 
       
   134      * @since S60 v3.2
       
   135      * @param   aState          The receiving state
       
   136      * @return void
       
   137      */
       
   138     IMPORT_C void SetReceivingStateL( TNATFWStreamingState aState );
       
   139     
       
   140     /**
       
   141      * From MNATFWSocketMediaConnWrapper
       
   142      * Enables/disables datapath between mediaengine and NATFW regarding
       
   143      * media sending.
       
   144      * 
       
   145      * @since S60 v3.2
       
   146      * @param   aState          The sending state
       
   147      * @return void
       
   148      */
       
   149     IMPORT_C void SetSendingStateL( TNATFWStreamingState aState );
       
   150     
       
   151     
       
   152 // from base class MNATFWMediaWrapper     
       
   153     
       
   154     
       
   155     /**
       
   156      * From MNATFWMediaWrapper
       
   157      * Enables wrapper to forward packets from mediaengine to connection
       
   158      * multiplexer.
       
   159      * 
       
   160      * @since S60 v3.2
       
   161      * @param   aState          The sending state
       
   162      * @return void
       
   163      */     
       
   164     IMPORT_C void SetReceivingStateForMuxWrapper( TNATFWStreamingState aState );      
       
   165        
       
   166     /**
       
   167      * From MNATFWMediaWrapper
       
   168      * Send data to connected media engine.
       
   169      *
       
   170      * @param aStreamPortion a reference to buffer to be sent
       
   171      * @since S60 v3.2
       
   172      * @return void
       
   173      */
       
   174     IMPORT_C void SendL( const TDesC8& aStreamPortion );
       
   175     
       
   176     /**
       
   177      * From MNATFWMediaWrapper
       
   178      * Register media observer.
       
   179      *
       
   180      * @since S60 v3.2
       
   181      * @param aObserver  media observer 
       
   182      * @param aServer    socket server handle
       
   183      * @param aLocalAddr wrapper's local address
       
   184      * @return void   
       
   185      */
       
   186     IMPORT_C void RegisterMediaWrapperObserverL( 
       
   187         MNATFWMediaWrapperObserver* aObserver,
       
   188         const RSocketServ& aServer,
       
   189         const TInetAddr& aLocalAddr );
       
   190 
       
   191     /**
       
   192      * Closes wrapper instance by deleting it.
       
   193      *
       
   194      * @since S60 v3.2
       
   195      * @return void
       
   196      */
       
   197     IMPORT_C void Close();
       
   198  
       
   199     /**
       
   200      * Gets wrapper's local and remote addresses
       
   201      *
       
   202      * @since S60 v3.2
       
   203      * @param aLocalAddr    wrapper's local address 
       
   204      * @param aRemoteAddr   wrapper's remote addresse
       
   205      * @return void   
       
   206      */
       
   207     IMPORT_C void GetAddresses( TInetAddr& aLocalAddr, TInetAddr& aRemoteAddr );
       
   208         
       
   209 // from base class MNATFWSocketSenderObserver
       
   210 
       
   211     /**
       
   212      * From MNATFWSocketSenderObserver
       
   213      * Returns with completition code of sending operation
       
   214      *
       
   215      * @param aError system-wide error code
       
   216      * @since S60 v3.2
       
   217      * @return void
       
   218      */
       
   219     void SendingCompleted( TInt aError );
       
   220     
       
   221 // from base class MNATFWSocketReceiverObserver
       
   222     
       
   223     /**
       
   224      * From MNATFWSocketReceiverObserver
       
   225      * Delivers buffer to multiplexer
       
   226      *
       
   227      * @param aStreamPortion stream portion which were sent by client
       
   228      * @since S60 v3.2
       
   229      * @return void
       
   230      */
       
   231     void DeliverBuffer( TDes8& aStreamPortion );
       
   232         
       
   233     
       
   234 private:
       
   235     
       
   236     CNATFWSocketMediaConnWrapper( );
       
   237     
       
   238     void ConstructL( TUint aProtocol, TUint aStreamId, TUint aPort  );
       
   239 
       
   240 
       
   241 private: // data
       
   242 
       
   243     /**
       
   244      * ID which identifies streams
       
   245      */
       
   246     TUint iStreamId;
       
   247     
       
   248     /**
       
   249      * Socket handler
       
   250      * Own.
       
   251      */    
       
   252     CNATFWSocketHandler* iHandler;
       
   253     
       
   254     /**
       
   255      * Observer
       
   256      * Not own.
       
   257      */
       
   258     MNATFWMediaWrapperObserver* iMediaObserver;
       
   259     
       
   260    };
       
   261 
       
   262 
       
   263 #endif // C_SOCKET_MEDIA_CONN_WRAPPER_H