|
1 // Copyright (c) 2001-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 // System includes |
|
17 #include <wapcli.h> |
|
18 |
|
19 // Local includes |
|
20 #include "tnwsswsptrhndpanic.h" |
|
21 #include "testoom.h" |
|
22 |
|
23 // Class signature |
|
24 #include "cnwsswsptrhnddatasupplier.h" |
|
25 |
|
26 // Constants used in this file |
|
27 #define LOGDIR "http" |
|
28 #define LOGFILE "nwsswsptrhnd.txt" |
|
29 |
|
30 CNwssWspTrHndDataSupplier* CNwssWspTrHndDataSupplier::NewL(RWSPCOTrans& aStackTrans, MNwssOomHandler& aOomHandler) |
|
31 { |
|
32 CNwssWspTrHndDataSupplier* me = new(ELeave)CNwssWspTrHndDataSupplier(aStackTrans, aOomHandler); |
|
33 CleanupStack::PushL(me); |
|
34 me->ConstructL(); |
|
35 CleanupStack::Pop(me); |
|
36 return me; |
|
37 } |
|
38 |
|
39 CNwssWspTrHndDataSupplier::~CNwssWspTrHndDataSupplier() |
|
40 { |
|
41 __CLOSELOG |
|
42 } |
|
43 |
|
44 TBool CNwssWspTrHndDataSupplier::GetNextDataPart(TPtrC8& aDataPart) |
|
45 { |
|
46 // Set the data buffer |
|
47 aDataPart.Set(iBuffer); |
|
48 |
|
49 return (iRemainingBytes == 0); |
|
50 } |
|
51 |
|
52 void CNwssWspTrHndDataSupplier::ReleaseData() |
|
53 { |
|
54 // If more data is expected, then extract the next chunk from the WAP Stack |
|
55 if (iRemainingBytes > 0) |
|
56 { |
|
57 // Extract the next chunk of data from the transaction, handling OOM appropriately |
|
58 // should it occur |
|
59 if (ExtractBodyData() == KErrNoMemory) |
|
60 { |
|
61 // Ensure the buffer is empty (should the client call again to GetNextDataPart after |
|
62 // releasing), then mimic a method abort. No stack abort to occur since this can |
|
63 // only execute following a MethodResult-ind |
|
64 iBuffer.Zero(); |
|
65 iRemainingBytes = 0; |
|
66 iOomHandler.SendOomMethodAbort(iStackTransId, EFalse); |
|
67 } |
|
68 } |
|
69 } |
|
70 |
|
71 TInt CNwssWspTrHndDataSupplier::OverallDataSize() |
|
72 { |
|
73 return iOverallDataSize; |
|
74 } |
|
75 |
|
76 TInt CNwssWspTrHndDataSupplier::Reset() |
|
77 { |
|
78 return KErrNotSupported; |
|
79 } |
|
80 |
|
81 CNwssWspTrHndDataSupplier::CNwssWspTrHndDataSupplier(RWSPCOTrans& aStackTrans, MNwssOomHandler& aOomHandler) |
|
82 : iStackTrans(aStackTrans), iOomHandler(aOomHandler) |
|
83 { |
|
84 __OPENLOG(LOGDIR, LOGFILE) |
|
85 } |
|
86 |
|
87 void CNwssWspTrHndDataSupplier::ConstructL() |
|
88 { |
|
89 // Store the transaction ID for later |
|
90 __TESTOOMD(stkErr, iStackTrans.Id(iStackTransId)); |
|
91 __LOG1("--RWSPCOTrans::Id() returned %d", stkErr) |
|
92 User::LeaveIfError(stkErr); |
|
93 |
|
94 // Extract the first chunk of data from the transaction. |
|
95 User::LeaveIfError( ExtractBodyData() ); |
|
96 |
|
97 // Calculate the overall data size |
|
98 iOverallDataSize = iBuffer.Length() + iRemainingBytes; |
|
99 |
|
100 __LOG1("--Overall data size is %d", iOverallDataSize) |
|
101 } |
|
102 |
|
103 TInt CNwssWspTrHndDataSupplier::ExtractBodyData() |
|
104 { |
|
105 __TESTOOMD(stkErr, iStackTrans.GetData(iBuffer, RWSPCOTrans::EResultBody, &iRemainingBytes)); |
|
106 __LOG1("--RWSPCOTrans::GetData(EResultBody) returned %d", stkErr) |
|
107 if ((stkErr != KErrNone) && (stkErr != RWAPConn::EMoreData)) |
|
108 return stkErr; |
|
109 |
|
110 __LOG("--Result Body is:") |
|
111 __DUMP("--", "--", iBuffer) |
|
112 __LOG1("--Remaining bytes to extract is %d", iRemainingBytes) |
|
113 return KErrNone; |
|
114 } |