testexecfw/statsrv/device/source/statapi/inc/stat_tcpip.h
changeset 0 3e07fef1e154
equal deleted inserted replaced
-1:000000000000 0:3e07fef1e154
       
     1 /*
       
     2 * Copyright (c) 2005-2009 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 /********************************************************************************
       
    21  *
       
    22  * Stat TCP/IP Transport
       
    23  *
       
    24  *******************************************************************************/
       
    25 #ifndef __STATTCPIP_H__
       
    26 #define __STATTCPIP_H__
       
    27 
       
    28 /********************************************************************************
       
    29  *
       
    30  * System Includes
       
    31  *
       
    32  *******************************************************************************/
       
    33 #include <es_sock.h>
       
    34 
       
    35 /********************************************************************************
       
    36  *
       
    37  * Local Includes
       
    38  *
       
    39  *******************************************************************************/
       
    40 #include "stat_interfaces.h"
       
    41 #include "ntoh.h"
       
    42 
       
    43 /********************************************************************************
       
    44  *
       
    45  * Definitions
       
    46  *
       
    47  *******************************************************************************/
       
    48 const TUint KStatHeaderSize	= 8;
       
    49 const TUint KLittleStatPort = 3000;
       
    50 const TUint KLittleStatListenQueue = 1;
       
    51 
       
    52 /********************************************************************************
       
    53  *
       
    54  * CStatTransportTCPIP - Top-level of the transport. Creates and waits on the 
       
    55  * listening socket. When a new data socket is created it creates the reader
       
    56  * and writer passing the socket to them. After that, the object simply routes
       
    57  * read/write calls/cancels to the appopriate objects.
       
    58  *
       
    59  *******************************************************************************/
       
    60 class CStatTransportTCPIP : public CActive, public MStatNetwork
       
    61 {
       
    62 public:
       
    63 	// construction
       
    64 	static CStatTransportTCPIP *NewL( void );
       
    65 	CStatTransportTCPIP();
       
    66 	~CStatTransportTCPIP();
       
    67 
       
    68 	// from MStatNetwork
       
    69 	TInt GetPacketSize();
       
    70 	TInt InitialiseL( MNotifyStatTransport *iTransport );
       
    71 	TInt ConnectL( TDesC *aRemoteHost );
       
    72 	TInt RequestSend( TDesC8 *aCommandData, const TUint aDataLength );
       
    73 	TInt RequestReceive( TUint aByteCount );
       
    74 	TInt Disconnect( void );
       
    75 	TInt Release( void );
       
    76 	TText8 *Error( void );
       
    77 	TUint NtoHl( TUint aValue ) const;
       
    78 	TUint HtoNl( TUint aValue ) const;
       
    79 	TBool PadPacket( TUint size ) const;
       
    80 
       
    81 	// from CActive 
       
    82 	void RunL( void );
       
    83 	void DoCancel( void );
       
    84 
       
    85 private:
       
    86 	void ConstructL( void );
       
    87 
       
    88 private:
       
    89 	enum TStatTransportStatus { EIdle, EError, EInitialised, EConnecting, EConnected, 
       
    90 			EDisconnectingData, EDisconnectingListen, EDisconnected };
       
    91 
       
    92 private:
       
    93 	TStatTransportStatus iTransportStatus;
       
    94 	TReadWriteStatus iRWStatus;
       
    95 	MNotifyStatTransport *iTransport;
       
    96 	TInt iMaxPacketSize;
       
    97 
       
    98 	HBufC8 *iBuffer;
       
    99 	TPtr8 *iBufferPtr;
       
   100 
       
   101  	RSocket iListenSocket;
       
   102  	RSocket iDataSocket;
       
   103  	RSocketServ iSocketServ;
       
   104 	
       
   105 };
       
   106 
       
   107 inline TUint CStatTransportTCPIP::NtoHl( TUint aValue ) const
       
   108 {
       
   109 	return ( ntohl( aValue ) );
       
   110 }
       
   111 
       
   112 inline TUint CStatTransportTCPIP::HtoNl( TUint aValue ) const
       
   113 {
       
   114 	return ( htonl( aValue ) );
       
   115 }
       
   116 
       
   117 inline TBool CStatTransportTCPIP::PadPacket( TUint ) const
       
   118 {
       
   119 	return ( EFalse );
       
   120 }
       
   121 
       
   122 #endif // __STATTCPIP_H__