|
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 "chttpdatasender.h" |
|
17 #include "chttpcontentreader.h" |
|
18 #include "chttpclienttransaction.h" |
|
19 #include <thttpevent.h> |
|
20 |
|
21 CHttpDataSender* CHttpDataSender::New(RHTTPTransaction aTrans, CHttpClientTransaction& aClientTrans, MHttpContentSource* aSource) |
|
22 { |
|
23 return new CHttpDataSender(aTrans, aClientTrans, aSource); |
|
24 } |
|
25 |
|
26 CHttpDataSender* CHttpDataSender::New(RHTTPTransaction aTrans, CHttpClientTransaction& aClientTrans, RFile& aFile) |
|
27 { |
|
28 CHttpDataSender* self = new CHttpDataSender(aTrans, aClientTrans); |
|
29 if(self) |
|
30 { |
|
31 if(self->Construct(aFile) != KErrNone) |
|
32 { |
|
33 delete self; |
|
34 self = NULL; |
|
35 } |
|
36 } |
|
37 return self; |
|
38 } |
|
39 |
|
40 |
|
41 CHttpDataSender::CHttpDataSender(RHTTPTransaction aTrans, CHttpClientTransaction& aClientTrans) |
|
42 : iTransaction(aTrans),iClientTrans(aClientTrans), |
|
43 iDynamicContentLen(KErrNotFound) |
|
44 { |
|
45 } |
|
46 |
|
47 CHttpDataSender::CHttpDataSender(RHTTPTransaction aTrans, CHttpClientTransaction& aClientTrans, MHttpContentSource* aSource) |
|
48 : iTransaction(aTrans),iDynamicSource(aSource), |
|
49 iClientTrans(aClientTrans) |
|
50 { |
|
51 |
|
52 } |
|
53 |
|
54 CHttpDataSender::~CHttpDataSender() |
|
55 { |
|
56 delete iFileReader; |
|
57 } |
|
58 |
|
59 TInt CHttpDataSender::Construct(RFile& aFile) |
|
60 { |
|
61 iFileReader = CHttpFileReader::New(aFile, *this); |
|
62 return iFileReader ? KErrNone : KErrNoMemory; |
|
63 } |
|
64 |
|
65 // From MHttpDataSender |
|
66 void CHttpDataSender::Notify(const TDesC8& aData, TBool aLast) |
|
67 { |
|
68 __ASSERT_DEBUG(iDataPtr.Length() == 0, User::Invariant()); |
|
69 iDataPtr.Set(aData.Ptr(), aData.Length()); |
|
70 iLastPart = aLast; |
|
71 if(!iInCallback) |
|
72 { |
|
73 iTransaction.SendEvent(THTTPEvent::ENotifyNewRequestBodyPart, THTTPEvent::EOutgoing, THTTPFilterHandle::EClient); |
|
74 } |
|
75 } |
|
76 |
|
77 void CHttpDataSender::Error(TInt aError) |
|
78 { |
|
79 THTTPEvent evt(aError); |
|
80 iTransaction.SendEvent(evt, THTTPEvent::EIncoming, THTTPFilterHandle::EClient); |
|
81 } |
|
82 |
|
83 // From MHTTPDataSupplier |
|
84 TBool CHttpDataSender::GetNextDataPart(TPtrC8& aDataPart) |
|
85 { |
|
86 aDataPart.Set(KNullDesC8()); |
|
87 iInCallback = ETrue; |
|
88 if(iDataPtr.Length() == 0) |
|
89 { |
|
90 RequestData(); |
|
91 } |
|
92 |
|
93 if(iDataPtr.Length() > 0) |
|
94 { |
|
95 iTransfferedDataSize += iDataPtr.Length(); |
|
96 iClientTrans.OnTransferProgress(iTransaction.Request().Body()->OverallDataSize(), iTransfferedDataSize); |
|
97 aDataPart.Set(iDataPtr); |
|
98 iWaitingForRelease = ETrue; |
|
99 } |
|
100 iInCallback = EFalse; |
|
101 return iLastPart; |
|
102 } |
|
103 |
|
104 void CHttpDataSender::ReleaseData() |
|
105 { |
|
106 if(iWaitingForRelease) |
|
107 { |
|
108 iDataPtr.Set(NULL, 0); |
|
109 if(!iLastPart) |
|
110 RequestData(); |
|
111 iWaitingForRelease = EFalse; |
|
112 } |
|
113 } |
|
114 |
|
115 TInt CHttpDataSender::OverallDataSize() |
|
116 { |
|
117 if(iFileReader) |
|
118 return iFileReader->Size(); |
|
119 return iDynamicContentLen; |
|
120 } |
|
121 |
|
122 TInt CHttpDataSender::Reset() |
|
123 { |
|
124 return KErrNone; |
|
125 } |
|
126 |
|
127 void CHttpDataSender::RequestData() |
|
128 { |
|
129 if(iDynamicSource) |
|
130 { |
|
131 THttpContentSourceOp op(this); |
|
132 iDynamicSource->OnData(op); |
|
133 } |
|
134 else if(iFileReader) |
|
135 { |
|
136 iFileReader->Read(); |
|
137 } |
|
138 } |
|
139 |
|
140 void CHttpDataSender::SetDynamicContentLen(TInt aLen) |
|
141 { |
|
142 iDynamicContentLen = aLen; |
|
143 } |