|
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 |
|
17 #include "chttpdatareceiver.h" |
|
18 #include "chttpclienttransaction.h" |
|
19 #include "chttpcontentwriter.h" |
|
20 |
|
21 CHttpDataReceiver::CHttpDataReceiver(RHTTPTransaction aTrans, CHttpClientTransaction& aClientTrans) |
|
22 : iTransaction(aTrans),iClientTrans(aClientTrans) |
|
23 { |
|
24 } |
|
25 |
|
26 CHttpDataReceiver::~CHttpDataReceiver() |
|
27 { |
|
28 delete iFileWriter; |
|
29 } |
|
30 |
|
31 TInt CHttpDataReceiver::SetFile(RFile& aFile) |
|
32 { |
|
33 iFileWriter = CHttpFileWriter::New(aFile, *this); |
|
34 return iFileWriter ? KErrNone : KErrNoMemory; |
|
35 } |
|
36 |
|
37 void CHttpDataReceiver::DataAvailable() |
|
38 { |
|
39 if(iDynamicSink) |
|
40 { |
|
41 THttpContentSinkOp op(*this); |
|
42 iDynamicSink->OnData(op); |
|
43 } |
|
44 else |
|
45 { |
|
46 Store(); |
|
47 } |
|
48 } |
|
49 |
|
50 TBool CHttpDataReceiver::GetData(TPtrC8& aData) |
|
51 { |
|
52 return iDataSupplier->GetNextDataPart(aData); |
|
53 } |
|
54 |
|
55 void CHttpDataReceiver::Store() |
|
56 { |
|
57 if(iFileWriter) |
|
58 { |
|
59 TPtrC8 ptr; |
|
60 iDataSupplier->GetNextDataPart(ptr); |
|
61 iFileWriter->Write(ptr); |
|
62 if(!iDynamicSink) |
|
63 { |
|
64 iTransfferedDataSize += ptr.Length(); |
|
65 iClientTrans.OnTransferProgress(iTransaction.Response().Body()->OverallDataSize(), iTransfferedDataSize); |
|
66 } |
|
67 } |
|
68 else |
|
69 { |
|
70 Release(); |
|
71 } |
|
72 } |
|
73 |
|
74 void CHttpDataReceiver::Release() |
|
75 { |
|
76 iDataSupplier->ReleaseData(); |
|
77 } |
|
78 |
|
79 |
|
80 void CHttpDataReceiver::Error(TInt aError) |
|
81 { |
|
82 THTTPEvent evt(aError); |
|
83 iTransaction.SendEvent(evt, THTTPEvent::EIncoming, THTTPFilterHandle::EClient); |
|
84 } |