|
1 // Copyright (c) 2002-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 "cbodydatasupplier.h" |
|
17 |
|
18 #include "mbodydatasupplierobserver.h" |
|
19 |
|
20 const TInt KGranularity = 5; |
|
21 |
|
22 CBodyDataSupplier* CBodyDataSupplier::NewL(MBodyDataSupplierObserver& aObserver) |
|
23 { |
|
24 CBodyDataSupplier* self = new (ELeave) CBodyDataSupplier(aObserver); |
|
25 CleanupStack::PushL(self); |
|
26 self->ConstructL(); |
|
27 CleanupStack::Pop(self); |
|
28 return self; |
|
29 } |
|
30 |
|
31 CBodyDataSupplier::~CBodyDataSupplier() |
|
32 { |
|
33 if( iBodyParts ) |
|
34 iBodyParts->Reset(); |
|
35 delete iBodyParts; |
|
36 } |
|
37 |
|
38 CBodyDataSupplier::CBodyDataSupplier(MBodyDataSupplierObserver& aObserver) |
|
39 : CActive(CActive::EPriorityStandard), iObserver(aObserver) |
|
40 { |
|
41 CActiveScheduler::Add(this); |
|
42 } |
|
43 |
|
44 void CBodyDataSupplier::ConstructL() |
|
45 { |
|
46 iBodyParts = new (ELeave) CDesC8ArrayFlat(KGranularity); |
|
47 } |
|
48 |
|
49 void CBodyDataSupplier::AddBodyPartL(const TDesC8& aData) |
|
50 { |
|
51 iBodyParts->AppendL(aData); |
|
52 |
|
53 if( iState == EIdle ) |
|
54 { |
|
55 iState = EPendingRelease; |
|
56 } |
|
57 } |
|
58 |
|
59 void CBodyDataSupplier::SetBodySize(TInt aSize) |
|
60 { |
|
61 iOverallDataSize = aSize; |
|
62 } |
|
63 |
|
64 TBool CBodyDataSupplier::IsChunked() const |
|
65 { |
|
66 return iOverallDataSize == KErrNotFound; |
|
67 } |
|
68 |
|
69 void CBodyDataSupplier::CompleteSelf() |
|
70 { |
|
71 TRequestStatus* pStat = &iStatus; |
|
72 User::RequestComplete(pStat, KErrNone); |
|
73 SetActive(); |
|
74 } |
|
75 |
|
76 void CBodyDataSupplier::ResetSupplier() |
|
77 { |
|
78 Cancel(); |
|
79 iState = EPendingRelease; |
|
80 iIndex = 0; |
|
81 } |
|
82 |
|
83 /* |
|
84 * Methods from CActive |
|
85 */ |
|
86 |
|
87 void CBodyDataSupplier::RunL() |
|
88 { |
|
89 // Move to the EPendingRelease state. |
|
90 iState = EPendingRelease; |
|
91 |
|
92 // Notify the observer |
|
93 iObserver.NotifyMoreData(); |
|
94 } |
|
95 |
|
96 void CBodyDataSupplier::DoCancel() |
|
97 { |
|
98 // Do nothing... |
|
99 } |
|
100 |
|
101 /* |
|
102 * Methods from MHTTPDataSupplier |
|
103 */ |
|
104 |
|
105 TBool CBodyDataSupplier::GetNextDataPart(TPtrC8& aDataPart) |
|
106 { |
|
107 __ASSERT_DEBUG( iState == EPendingRelease, User::Invariant() ); |
|
108 |
|
109 aDataPart.Set(iBodyParts->MdcaPoint(iIndex)); |
|
110 |
|
111 return ( iIndex == iBodyParts->MdcaCount()-1 ); |
|
112 } |
|
113 |
|
114 void CBodyDataSupplier::ReleaseData() |
|
115 { |
|
116 // Move onto the next part |
|
117 ++iIndex; |
|
118 |
|
119 // Have all the parts been released? |
|
120 if( iIndex < iBodyParts->MdcaCount() ) |
|
121 { |
|
122 // More to go - self-complete to notify observer and move to the |
|
123 // EPendingNotify state. |
|
124 iState = EPendingNotify; |
|
125 CompleteSelf(); |
|
126 } |
|
127 else |
|
128 { |
|
129 // All done - move to EDone state |
|
130 iState = EDone; |
|
131 } |
|
132 } |
|
133 |
|
134 TInt CBodyDataSupplier::OverallDataSize() |
|
135 { |
|
136 if( iIsChunked ) |
|
137 return KErrNotFound; |
|
138 else |
|
139 return iOverallDataSize; |
|
140 } |
|
141 |
|
142 TInt CBodyDataSupplier::Reset() |
|
143 { |
|
144 return KErrNotFound; |
|
145 } |
|
146 |
|
147 |