upnp/upnpstack/dlnawebserver/inc/upnphttpchunkfiletransferreader.h
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 /** @file
       
     2 * Copyright (c) 2005-2006 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:  CUpnpHttpChunkFileTransferReader is a class responsible for 
       
    15 *                asynchronous TCP reading and controlling the encoded data
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef C_CUPNPHTTPCHUNKFILETRANSFERREADER_H
       
    22 #define C_CUPNPHTTPCHUNKFILETRANSFERREADER_H
       
    23 
       
    24 
       
    25 #include <e32base.h>
       
    26 #include <in_sock.h>
       
    27 #include <f32file.h>
       
    28 
       
    29 
       
    30 class CUpnpTcpSession;
       
    31 class CUpnpHttpFileTransferBuffer;
       
    32 class CUpnpHttpFileAccess;
       
    33 class CUpnpHttpFileTransferReader;
       
    34 class CUpnpHttpChunkParser;
       
    35 
       
    36 /**
       
    37  *  CUpnpHttpChunkFileTransferReader is responsible for asynchronous reading.
       
    38  *  It reads chunked-encoded data and process it  
       
    39  *  @lib DLNAWebServer.lib
       
    40  *  @since Series60 3.2
       
    41  */
       
    42 NONSHARABLE_CLASS (CUpnpHttpChunkFileTransferReader) : public CUpnpHttpFileTransferReader
       
    43     {
       
    44 
       
    45 public: // Constructors and destructors
       
    46     
       
    47     /**
       
    48     * CUpnpHttpChunkFileTransferReader factory method.
       
    49     * @since Series60 3.2
       
    50     * @param aSession session that runs and supervises reader.
       
    51     * @param aSocket socket from which data will be read.
       
    52     * @param aPriority priority with which the reader will be working.
       
    53     * @param aReadPortion - size of the buffer to read from the socket
       
    54     * @param aBufferSize - the buffer size
       
    55     * @return new CUpnpHttpChunkFileTransferReader object's instance.
       
    56     */
       
    57     static CUpnpHttpChunkFileTransferReader* NewL( CUpnpTcpSession& aSession,
       
    58                                         RSocket& aSocket,
       
    59                                         TThreadPriority aPriority,                                        
       
    60                                         TInt aReadPortion,
       
    61                                         TInt aBufferSize);
       
    62     
       
    63     /**
       
    64     * Virtual destructor.
       
    65     * @since Series60 3.2
       
    66     */                             
       
    67     virtual ~CUpnpHttpChunkFileTransferReader();             
       
    68      
       
    69 
       
    70 private: // Constructors and destructors
       
    71 
       
    72     /**
       
    73     * CUpnpHttpChunkFileTransferReader constructor.
       
    74     * @since Series60 3.2
       
    75     * @param aSession session that runs and supervises reader.
       
    76     * @param aSocket socket from which data will be read.
       
    77     * @param aPriority priority with which the reader will be working.
       
    78     * @param aHandle handle for logging for this thread.
       
    79     * @param aPriority priority with which the reader will be working.
       
    80     * @param aReadPortion - size of the buffer to read from the socket
       
    81     * @param aBufferSize - the buffer size
       
    82     */
       
    83     CUpnpHttpChunkFileTransferReader( CUpnpTcpSession& aSession,
       
    84                            RSocket& aSocket,
       
    85                            TThreadPriority aPriority,
       
    86                            TInt aReadPortion,
       
    87                            TInt aBufferSize);
       
    88     /**
       
    89     * By default Symbian 2nd phase constructor is private.
       
    90     * @since Series60 3.2
       
    91     */
       
    92     void ConstructL();
       
    93     
       
    94     /**
       
    95     * Remaing number of bytes to read.
       
    96     * @since Series60 3.2    
       
    97     * @return TInt
       
    98     */
       
    99     TInt RemainingBytes();
       
   100     
       
   101     /**
       
   102     * Starts reading in asynchronous mode.
       
   103     * @since Series60 3.2
       
   104     */
       
   105     void StartL();   
       
   106 
       
   107 private:
       
   108 
       
   109     /**
       
   110     * Issues reading in asynchronous mode.
       
   111     * @since Series60 3.2
       
   112     */
       
   113     void RunL();
       
   114     
       
   115     /**
       
   116     * Invoked when RunL leaves.
       
   117     */
       
   118     TInt RunError( TInt aErr );
       
   119     
       
   120     /**
       
   121      * Parse - decodes chunked-encoding     
       
   122      * @since S60 3.2
       
   123      * @param buffer
       
   124      * @param position in the buffer
       
   125      * @return error code
       
   126      */
       
   127     TInt Parse( TDes8& aBuffer, TInt& aPos );
       
   128    
       
   129 protected:
       
   130 
       
   131 	/**
       
   132     * Bytes to be read from the socket
       
   133     * @since Series60 3.2    
       
   134     * @return TInt
       
   135     */
       
   136     TInt ReadBufferSize();   
       
   137     
       
   138     /**
       
   139     * Handle buffer of data
       
   140     * @since Series60 3.2    
       
   141     * @return TBool if all data handled
       
   142     */
       
   143     TBool HandleL();   
       
   144     
       
   145     /**
       
   146     * Finish the session
       
   147     * @since Series60 3.2
       
   148     */
       
   149     void Finish();  
       
   150     
       
   151     
       
   152     /**
       
   153     * Reads from socket
       
   154     * @since Series60 3.2    
       
   155     */
       
   156     void ReadFromSocket();
       
   157     
       
   158     /**
       
   159     * Resets the reader
       
   160     * @since Series60 3.2    
       
   161     */
       
   162     void Reset();
       
   163 
       
   164     /**
       
   165     * Handles read data - trims the buffer and save data to file
       
   166     * @since Series60 5.0
       
   167     * @return TInt 
       
   168     */
       
   169     TInt HandleReadDataL( TInt aPieceToRead );
       
   170                       
       
   171 private: 
       
   172 
       
   173 	//parser for chunked-encoding
       
   174     CUpnpHttpChunkParser* iParser;
       
   175 
       
   176     //decoded data
       
   177     TInt iDecoded;    
       
   178     };
       
   179 
       
   180 
       
   181 #endif // C_CUPNPHTTPCHUNKFILETRANSFERREADER_H
       
   182 
       
   183 // End Of File