|
1 // Copyright (c) 2008-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 // @file |
|
15 // @internalComponent |
|
16 // |
|
17 // |
|
18 |
|
19 #ifndef __CTRANSACTION_H_ |
|
20 #define __CTRANSACTION_H_ |
|
21 |
|
22 // System Includes |
|
23 #include <http/framework/cheadercodec.h> |
|
24 #include <rmemchunk.h> |
|
25 |
|
26 // Local Includes |
|
27 #include "CRequest.h" |
|
28 #include "CResponse.h" |
|
29 |
|
30 |
|
31 class CTransaction : public CBase |
|
32 { |
|
33 public: |
|
34 static CTransaction* NewL ( CHeaderCodec& aCodec, RStringPool& aStringPool ); |
|
35 virtual ~CTransaction ( ); |
|
36 |
|
37 CRequest* Request ( ) const; |
|
38 CResponse* Response ( ) const; |
|
39 |
|
40 inline void AddBodyPart ( RMBufChain& aData ) |
|
41 { |
|
42 if ( !aData.IsEmpty () ) |
|
43 iBodyParts.Append ( aData ); |
|
44 } |
|
45 |
|
46 inline void AddBodyPart ( RMemChunk& aMemChunk ) |
|
47 { |
|
48 if ( !aMemChunk.IsEmpty () ) |
|
49 iMemParts.Append ( aMemChunk ); |
|
50 } |
|
51 |
|
52 inline void FreeMemChunk ( ) |
|
53 { |
|
54 if ( !iMemParts.IsEmpty () ) |
|
55 iMemParts.Free(); |
|
56 } |
|
57 |
|
58 inline void RemoveAllBodyParts ( ) |
|
59 { |
|
60 if ( iBodyParts.IsEmpty ( ) ) |
|
61 { |
|
62 return; |
|
63 } |
|
64 |
|
65 while ( iBodyParts.NumBufs ( ) > 0 ) |
|
66 { |
|
67 iBodyParts.Remove ( ); |
|
68 if ( iBodyParts.IsEmpty ( ) ) |
|
69 { |
|
70 break; |
|
71 } |
|
72 } |
|
73 } |
|
74 |
|
75 inline RMBufChain& BodyParts ( ) |
|
76 { |
|
77 return iBodyParts; |
|
78 } |
|
79 |
|
80 inline RMemChunk& MemParts ( ) |
|
81 { |
|
82 return iMemParts; |
|
83 } |
|
84 |
|
85 inline void RemoveBodyPart () |
|
86 { |
|
87 RMBuf* mBuf = iBodyParts.Remove (); // Remove the first body part |
|
88 __ASSERT_DEBUG ( mBuf, User::Invariant() ); |
|
89 if ( iDataLeft != KErrUnknown ) |
|
90 iDataLeft -= mBuf->Length (); |
|
91 } |
|
92 |
|
93 inline void GetBodyPart ( TPtrC8& aData ) |
|
94 { |
|
95 RMBuf* buf = iBodyParts.First (); |
|
96 aData.Set ( buf->Ptr (), buf->Length () ); |
|
97 } |
|
98 |
|
99 inline TBool IsLastBodyPart () const |
|
100 { |
|
101 if ( iDataLeft != KErrUnknown ) |
|
102 { |
|
103 return ( ( iDataLeft - iBodyParts.First()->Length() ) == 0) ? ETrue : EFalse; |
|
104 } |
|
105 return Complete(); |
|
106 } |
|
107 |
|
108 inline void SetDataLeft ( TInt aDataLeft ) |
|
109 { |
|
110 iDataLeft = aDataLeft; |
|
111 } |
|
112 |
|
113 inline void SetComplete () |
|
114 { |
|
115 iComplete = ETrue; |
|
116 } |
|
117 |
|
118 inline TBool Complete() const |
|
119 { |
|
120 return iComplete; |
|
121 } |
|
122 |
|
123 inline TInt DataLeft () const |
|
124 { |
|
125 return iDataLeft; |
|
126 } |
|
127 |
|
128 inline void Reset () |
|
129 { |
|
130 iDataLeft = KErrUnknown; |
|
131 iRequest->Reset (); |
|
132 iResponse->Reset (); |
|
133 if ( !iBodyParts.IsEmpty () ) |
|
134 iBodyParts.Free (); |
|
135 iComplete = EFalse; |
|
136 } |
|
137 |
|
138 inline TBool CloseNeeded () const |
|
139 { |
|
140 if ( iDataLeft != KErrUnknown ) |
|
141 { |
|
142 if ( iBodyParts.IsEmpty () ) |
|
143 { |
|
144 return iDataLeft != 0 ? ETrue : EFalse; |
|
145 } |
|
146 else |
|
147 { |
|
148 return ( ( iDataLeft - iBodyParts.Length() ) != 0 ) ? ETrue : EFalse; |
|
149 } |
|
150 } |
|
151 |
|
152 return !Complete (); |
|
153 } |
|
154 |
|
155 protected: |
|
156 CTransaction ( ); |
|
157 void ConstructL ( CHeaderCodec& aCodec, RStringPool& aStringPool ); |
|
158 |
|
159 protected: |
|
160 TInt iDataLeft; |
|
161 CRequest* iRequest; |
|
162 CResponse* iResponse; |
|
163 RMBufChain iBodyParts; |
|
164 RMemChunk iMemParts; |
|
165 TBool iComplete : 1; |
|
166 }; |
|
167 |
|
168 |
|
169 #endif // CTRANSACTION_H |
|
170 |