hti/HtiServicePlugins/HtiIpProxyServicePlugin/IPProxyEngine/Src/Csocketreader.h
branchRCL_3
changeset 59 8ad140f3dd41
parent 0 a03f92240627
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     1 /*
       
     2 * Copyright (c) 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:  Socket reader
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CSOCKETREADER_H
       
    21 #define CSOCKETREADER_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <es_sock.h>
       
    26 #include <in_sock.h>
       
    27 
       
    28 
       
    29 // CONSTANTS
       
    30 const TInt KReadBufferSize = 8*1024;  //bytes
       
    31 
       
    32 // FORWARD DECLARATIONS
       
    33 class MSocketReaderObserver;
       
    34 class RSocket;
       
    35 class CDesC8Array;
       
    36 
       
    37 // CLASS DECLARATION
       
    38 
       
    39 /**
       
    40 *  Socket reader. ActiveObject that reads data from opened RSocket.
       
    41 */
       
    42 NONSHARABLE_CLASS( CSocketReader ) : public CActive
       
    43     {
       
    44     public:  // Constructors and destructor
       
    45 
       
    46         /**
       
    47         * Factory function.
       
    48         * @param aSocket Opened RSocket session from where data is read.
       
    49         * @param aUDPRemotePort Peer ends port.
       
    50         * @return New CSocketReader instance.
       
    51         */
       
    52         static CSocketReader* NewL( RSocket& aSocket,
       
    53             TInt aUDPRemotePort = -1 );
       
    54 
       
    55         /**
       
    56         * Factory function.
       
    57         * @param aSocket Opened RSocket session from where data is read.
       
    58         * @param aUDPRemotePort Peer ends port.
       
    59         * @return New CSocketReader instance.
       
    60         */
       
    61         static CSocketReader* NewLC( RSocket& aSocket,
       
    62             TInt aUDPRemotePort = -1 );
       
    63 
       
    64         /**
       
    65         * Destructor.
       
    66         */
       
    67         ~CSocketReader();
       
    68 
       
    69     public: // New functions
       
    70 
       
    71         /**
       
    72         * Sets observer.
       
    73         * @param aObserver Pointer to observer.
       
    74         */
       
    75         void SetObserver( MSocketReaderObserver* aObserver );
       
    76 
       
    77         /**
       
    78         * Starts reading the socket.
       
    79         */
       
    80         void Start();
       
    81 
       
    82     private:
       
    83         /**
       
    84         * Starts reading the socket.
       
    85         */
       
    86         void IssueRead();
       
    87 
       
    88     protected: // Functions from base classes
       
    89 
       
    90         /**
       
    91         * From CActive. Pending request has been completed.
       
    92         */
       
    93         void RunL();
       
    94 
       
    95         /**
       
    96         * From CActive. Pending request has been cancelled.
       
    97         */
       
    98         void DoCancel();
       
    99 
       
   100         /**
       
   101         * From CActive. RunL has leaved.
       
   102         */
       
   103         TInt RunError( TInt aError );
       
   104 
       
   105 
       
   106     private:
       
   107 
       
   108         /**
       
   109         * Default constructor.
       
   110         */
       
   111         CSocketReader( RSocket& aSocket, TInt aUDPRemotePort = -1 );
       
   112 
       
   113         /**
       
   114         * 2nd phase constructor.
       
   115         */
       
   116         void ConstructL();
       
   117 
       
   118     private:    // Data
       
   119         TSockXfrLength iReceivedDataLength;
       
   120         TBuf8<KReadBufferSize> iReadBuffer;
       
   121         MSocketReaderObserver* iObserver;
       
   122         RSocket& iSocket;
       
   123         const TInt iUDPRemotePort;
       
   124         TInetAddr iUDPRemoteAddr;
       
   125     };
       
   126 
       
   127 #endif      // CSOCKETREADER_H
       
   128 
       
   129 // End of File