natfw/natfwsocketmediaconnwrapper/inc/natfwsockethandler.h
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2007-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:    Handles socket connecting
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef C_NATFWSOCKETHANDLER_H
       
    22 #define C_NATFWSOCKETHANDLER_H
       
    23 
       
    24 #include <es_sock.h>
       
    25 #include "natfwconnectivityapidefs.h"
       
    26 
       
    27 #include "natfwsocketsender.h"
       
    28 #include "natfwsocketreceiver.h"
       
    29 #include "natfwmediawrapperobserver.h"
       
    30 #include "mnsmcwtcpconnectionobserver.h"
       
    31 
       
    32 class CNATFWSocketMediaConnWrapper;
       
    33 
       
    34 /**
       
    35  *  Socket handler
       
    36  *  Handles socket connecting and own's socket
       
    37  *
       
    38  *  @lib socketmediaconnwrapper.dll
       
    39  *  @since S60 v3.2
       
    40  */
       
    41 NONSHARABLE_CLASS( CNATFWSocketHandler ) : public CActive
       
    42     {
       
    43 
       
    44     friend class ut_cnatfwsockethandler;
       
    45     friend class UT_MNATFWMediaWrapper; 
       
    46 
       
    47     enum TSenderState
       
    48         {
       
    49         EUnitialized = 1,
       
    50         EGettingConnection = 2,
       
    51         EConnected  = 3,
       
    52         ESending = 4
       
    53         };
       
    54 
       
    55     enum TReceiverState
       
    56         {
       
    57         ENotReceiving = 1,
       
    58         EReceiving = 2
       
    59         };
       
    60 
       
    61 public:
       
    62 
       
    63     /**
       
    64      * Two-phased constructor.
       
    65      * @param aRecObs   receiver observer
       
    66      * @param aSendObs  sending observer
       
    67      * @param aProtocol used protocol
       
    68      * @param aPort     wrapper's local port    
       
    69      */
       
    70     static CNATFWSocketHandler* NewL( MNATFWSocketReceiverObserver& aRecObs,
       
    71         MNATFWSocketSenderObserver& aSendObs, TUint aProtocol, TUint aPort );
       
    72         
       
    73     /**
       
    74      * Two-phased constructor.
       
    75      * @param aRecObs   receiver observer
       
    76      * @param aSendObs  sending observer
       
    77      * @param aProtocol used protocol
       
    78      * @param aPort     wrapper's local port    
       
    79      */  
       
    80     static CNATFWSocketHandler* NewLC( MNATFWSocketReceiverObserver& aRecObs,
       
    81         MNATFWSocketSenderObserver& aSendObs, TUint aProtocol, TUint aPort );
       
    82 
       
    83     /**
       
    84     * Destructor.
       
    85     */
       
    86     virtual ~CNATFWSocketHandler();
       
    87         
       
    88     /**
       
    89      * Get local address
       
    90      *
       
    91      * @since S60 v3.2
       
    92      * @param aSocketToSendForPeer Address for send data
       
    93      * @return void
       
    94      */    
       
    95     void LocalAddress( TSockAddr& aSocketToSendForPeer );
       
    96  
       
    97     /**
       
    98      * Gets wrapper's remote address
       
    99      *
       
   100      * @since S60 v3.2
       
   101      * @param aRemoteAddress   wrapper's remote address
       
   102      * @return void   
       
   103      */  
       
   104     void GetRemoteAddress( TSockAddr& aRemoteAddress );
       
   105        
       
   106     /**
       
   107      * User of NAT Connectivity Framework sets address for incoming packets
       
   108      * Wrapper connecting to remote address is started.
       
   109      *
       
   110      * @since S60 v3.2
       
   111      * @param aSocketToSendForPeer Address for send data
       
   112      * @return void
       
   113      */
       
   114     void SetAddrL( const TSockAddr& aSocketToSendForPeer );
       
   115     
       
   116     /**
       
   117      * Enables/disables datapath between mediaengine and NATFW regarding
       
   118      * media receiving.
       
   119      * 
       
   120      * @since S60 v3.2
       
   121      * @return void
       
   122      */  
       
   123     void SetReceivingStateL( );
       
   124 
       
   125     /**
       
   126      * Enables/disables datapath between mediaengine and NATFW regarding
       
   127      * media sending.
       
   128      * 
       
   129      * @since S60 v3.2
       
   130      * @return void
       
   131      */
       
   132     void SetSendingStateL( );
       
   133     
       
   134     /**
       
   135      * Enables wrapper to forward packets from mediaengine to connection
       
   136      * multiplexer.
       
   137      * 
       
   138      * @since S60 v3.2
       
   139      * @param   aState          The sending state
       
   140      * @return void
       
   141      */     
       
   142     void SetReceivingStateForMuxWrapper( TNATFWStreamingState aState );    
       
   143             
       
   144     /**
       
   145      * Send data to connected media engine.
       
   146      *
       
   147      * @since S60 v3.2
       
   148      * @param aStreamPortion a reference to buffer where received data put
       
   149      * @return void
       
   150      */   
       
   151      void SendL( const TDesC8& aStreamPortion );
       
   152     
       
   153     /**
       
   154      * Setting function for local address.
       
   155      *
       
   156      * @since S60 v3.2
       
   157      * @param aSocketServer socket server to be set
       
   158      * @param aLocalAddress local address to be set
       
   159      * @return void
       
   160      */    
       
   161     void SetLocalAddress( const RSocketServ& aSocketServer,
       
   162                           const TSockAddr& aLocalAddress );
       
   163 
       
   164     /**
       
   165      * Sets media observer.
       
   166      *
       
   167      * @since S60 v3.2
       
   168      * @param aMediaObserver Media observer
       
   169      * @return void
       
   170      */ 
       
   171     void SetMediaObserverL( MNATFWMediaWrapperObserver* aMediaObserver );
       
   172     
       
   173     /**
       
   174      * Cancels wrapper's send operations.
       
   175      *
       
   176      * @since S60 v3.2
       
   177      * @return void
       
   178      */
       
   179     void DeactivateSending(); 
       
   180     
       
   181     /**
       
   182      * Cancels wrapper's receive operations.
       
   183      *
       
   184      * @since S60 v3.2
       
   185      * @return void
       
   186      */
       
   187     void DeactivateReceiving();
       
   188 
       
   189     /**
       
   190      * Establishes TCP connection between mediaengine and NATFW. Connection
       
   191      * will be established in specified direction.
       
   192      * 
       
   193      * MNsmcwTcpConnectionObserver::ConnectingCompleted will be called when
       
   194      * connection is established.
       
   195      * 
       
   196      * @since   S60 v3.2
       
   197      * @param   aSetup      TCP connection setup configuration
       
   198      * @param   aObserver   Client to notify when connected
       
   199      */
       
   200     void OpenTcpConnectionL( TNATFWTcpConnectionSetup aSetup,
       
   201                              MNsmcwTcpConnectionObserver& aObserver );
       
   202                               
       
   203     /**
       
   204      * Closes TCP connection.
       
   205      *
       
   206      * MNsmcwTcpConnectionObserver::ConnectingCompleted is called with error
       
   207      * code KErrCancel if TCP connection establishment is ongoing.
       
   208      *
       
   209      * @since S60 v3.2
       
   210      */
       
   211     void CloseTcpConnection();
       
   212     
       
   213 
       
   214 private:
       
   215 
       
   216     CNATFWSocketHandler( TUint aPort );
       
   217 
       
   218     void ConstructL( MNATFWSocketReceiverObserver& aRecObs,
       
   219         MNATFWSocketSenderObserver& aSendObs, TUint aProtocol );
       
   220     
       
   221 // from base class CActive
       
   222     
       
   223     /* From CActive
       
   224      * 
       
   225      *
       
   226      * @since S60 v3.2
       
   227      */
       
   228     void RunL();
       
   229     
       
   230     /* From CActive
       
   231      * 
       
   232      *
       
   233      * @since S60 v3.2
       
   234      */
       
   235     void DoCancel();     
       
   236 
       
   237 private: // data
       
   238 
       
   239     /**
       
   240      * Data sender
       
   241      * Own.
       
   242      */
       
   243     CNATFWSocketSender* iSender;
       
   244 
       
   245     /**
       
   246      * Data receiver
       
   247      * Own.
       
   248      */
       
   249     CNATFWSocketReceiver* iReceiver;
       
   250 
       
   251     /**
       
   252      * Used protocol udp or tcp
       
   253      */
       
   254     TUint iProtocol;
       
   255 
       
   256     /**
       
   257      * Socket
       
   258      */
       
   259     RSocket iSocket;
       
   260     
       
   261     /**
       
   262      * Socket server
       
   263      */
       
   264     RSocketServ iSocketServer;
       
   265     
       
   266     /**
       
   267      * Remote address
       
   268      */
       
   269     TInetAddr iRemoteAddress;
       
   270         
       
   271     /**
       
   272      * Local address
       
   273      */
       
   274     TInetAddr iLocalAddress;
       
   275     
       
   276     /**
       
   277      * Socket's local port
       
   278      */
       
   279     TUint iPort;
       
   280 
       
   281     /**
       
   282      * Descripts sender states.
       
   283      */
       
   284     TSenderState iSendState;
       
   285     
       
   286     /**
       
   287      * Media observer.
       
   288      * Not own.
       
   289      */
       
   290     MNATFWMediaWrapperObserver* iMediaObserver;
       
   291     
       
   292     /**
       
   293      * Listening socket for a passive TCP connection
       
   294      */
       
   295     RSocket iListeningSocket;
       
   296     
       
   297     /**
       
   298      * TCP connection type
       
   299      */
       
   300     TNATFWTcpConnectionSetup iTcpConnectionType;
       
   301     
       
   302     /**
       
   303      * TCP connection observer
       
   304      * Not own.
       
   305      */
       
   306     MNsmcwTcpConnectionObserver* iTcpConnectionObserver;
       
   307     
       
   308     /**
       
   309      * Receiver state
       
   310      */
       
   311     TReceiverState iReceiveState;    
       
   312      
       
   313     };
       
   314 
       
   315 #endif // C_NATFWSOCKETHANDLER_H