applayerprotocols/httpservice/src/chttpcontentreader.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "chttpcontentreader.h"
       
    17 #include "mhttpdatasender.h"
       
    18 
       
    19 const TInt KFileReadSize = 16 * 1024;
       
    20 
       
    21 CHttpFileReader* CHttpFileReader::New(RFile aFile, MHttpDataSender& aReceiver)
       
    22     {
       
    23     CHttpFileReader* self = new CHttpFileReader(aFile, aReceiver);
       
    24     if(self)
       
    25         {
       
    26         if(self->Construct() != KErrNone)
       
    27             {
       
    28             delete self;
       
    29             self = NULL;
       
    30             }
       
    31         }
       
    32     return self;
       
    33     }
       
    34 
       
    35 TInt CHttpFileReader::Construct()
       
    36     {   
       
    37     iFile.Size(iTotalSize);
       
    38     return iContentBuffer.Create(KFileReadSize);
       
    39     }
       
    40 
       
    41 CHttpFileReader::CHttpFileReader(RFile aFile, MHttpDataSender& aReceiver)
       
    42 : CActive(EPriorityStandard),
       
    43 iFile(aFile),
       
    44 iDataSender(aReceiver)
       
    45     {
       
    46     CActiveScheduler::Add(this);
       
    47     }
       
    48 CHttpFileReader::~CHttpFileReader()
       
    49     {
       
    50     Cancel();
       
    51     iContentBuffer.Close();
       
    52     }
       
    53 
       
    54 void CHttpFileReader::Read()
       
    55     {
       
    56     iContentBuffer.Zero();
       
    57     iFile.Read(iContentBuffer, iStatus);
       
    58     SetActive();
       
    59     }
       
    60 
       
    61 // From CActive
       
    62 void CHttpFileReader::RunL()
       
    63     {
       
    64     User::LeaveIfError(iStatus.Int());
       
    65     iReadBytes += iContentBuffer.Length();
       
    66     iDataSender.Notify(iContentBuffer, iReadBytes == iTotalSize);
       
    67     }
       
    68 
       
    69 void CHttpFileReader::DoCancel()
       
    70     {
       
    71     iFile.ReadCancel(iStatus);
       
    72     }
       
    73 
       
    74 TInt CHttpFileReader::RunError(TInt aError)
       
    75     {
       
    76     iDataSender.Error(aError);
       
    77     return KErrNone;
       
    78     }    
       
    79