|
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 "cmessagedatasupplier.h" |
|
17 |
|
18 #include "mdatasupplierobserver.h" |
|
19 |
|
20 CMessageDataSupplier* CMessageDataSupplier::NewL(MDataSupplierObserver& aObserver, const TDesC8& aData, TInt aBufferSize) |
|
21 { |
|
22 CMessageDataSupplier* self = new(ELeave) CMessageDataSupplier(aObserver, aData, aBufferSize); |
|
23 CleanupStack::PushL(self); |
|
24 self->ConstructL(); |
|
25 CleanupStack::Pop(self); |
|
26 return self; |
|
27 } |
|
28 |
|
29 CMessageDataSupplier::~CMessageDataSupplier() |
|
30 { |
|
31 Cancel(); |
|
32 |
|
33 delete iBuffer; |
|
34 } |
|
35 |
|
36 CMessageDataSupplier::CMessageDataSupplier(MDataSupplierObserver& aObserver, const TDesC8& aData, TInt aBufferSize) |
|
37 : CActive(CActive::EPriorityStandard), iObserver(aObserver), iRemainingData(aData), iBufferSize(aBufferSize) |
|
38 { |
|
39 CActiveScheduler::Add(this); |
|
40 } |
|
41 |
|
42 void CMessageDataSupplier::ConstructL() |
|
43 { |
|
44 iBuffer = HBufC8::NewL(iBufferSize); |
|
45 |
|
46 SetData(); |
|
47 } |
|
48 |
|
49 |
|
50 TBool CMessageDataSupplier::GetData(TPtrC8& aData) |
|
51 { |
|
52 aData.Set(*iBuffer); |
|
53 |
|
54 return iLast; |
|
55 } |
|
56 |
|
57 void CMessageDataSupplier::ReleaseData() |
|
58 { |
|
59 iBuffer->Des().Zero(); |
|
60 |
|
61 if( !iLast ) |
|
62 CompleteSelf(); |
|
63 } |
|
64 |
|
65 void CMessageDataSupplier::CompleteSelf() |
|
66 { |
|
67 TRequestStatus* pStat = &iStatus; |
|
68 User::RequestComplete(pStat, KErrNone); |
|
69 SetActive(); |
|
70 } |
|
71 |
|
72 void CMessageDataSupplier::SetData() |
|
73 { |
|
74 // Need to set the new data... |
|
75 TInt dataLength = iBufferSize; |
|
76 |
|
77 if( dataLength > iRemainingData.Length() ) |
|
78 { |
|
79 dataLength = iRemainingData.Length(); |
|
80 } |
|
81 // Copy the data... |
|
82 iBuffer->Des().Copy(iRemainingData.Left(dataLength)); |
|
83 |
|
84 // Update the remaining data |
|
85 iRemainingData.Set(iRemainingData.Mid(dataLength)); |
|
86 |
|
87 // Is this the last part? |
|
88 iLast = iRemainingData.Length() == 0; |
|
89 } |
|
90 |
|
91 /* |
|
92 * Methods from CActive |
|
93 */ |
|
94 |
|
95 void CMessageDataSupplier::RunL() |
|
96 { |
|
97 // Set the data... |
|
98 SetData(); |
|
99 |
|
100 // Notify the observer that the data is ready |
|
101 iObserver.DataReady(); |
|
102 } |
|
103 |
|
104 void CMessageDataSupplier::DoCancel() |
|
105 { |
|
106 // Do nothing... |
|
107 } |
|
108 |
|
109 |