|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Header of TransferBuffer. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __MMFFILEPRIV_H_ |
|
20 #define __MMFFILEPRIV_H_ |
|
21 |
|
22 #include <f32file.h> |
|
23 |
|
24 #include <mmf/server/mmfclip.h> |
|
25 #include <mmf/server/mmfdatabuffer.h> |
|
26 |
|
27 /** |
|
28 * @publishedAll |
|
29 * |
|
30 * Represents a copy of a KUidMmfTransferBuffer used for reading/writting to the file server |
|
31 */ |
|
32 |
|
33 class CTransferBufferCopy : public CBase |
|
34 { |
|
35 public: |
|
36 static CTransferBufferCopy* NewL(TInt aMaxLength); |
|
37 |
|
38 virtual ~CTransferBufferCopy() |
|
39 {delete iBuffer;} |
|
40 |
|
41 |
|
42 TDes8& Des() {return iBufferDes;} |
|
43 |
|
44 TInt MaxLength() {return iBufferDes.MaxLength();} |
|
45 |
|
46 void ReUse(TInt aMaxLength) {iBufferDes.Set(iBuffer,0, Min(aMaxLength, iMaxLength));} |
|
47 |
|
48 TBool InUse() {return iInUse;} |
|
49 |
|
50 void SetInUse(TBool aInUse) {iInUse=aInUse;} |
|
51 |
|
52 private: |
|
53 CTransferBufferCopy(TInt aMaxLength) : CBase(), iMaxLength(aMaxLength), iBufferDes(0,0,0), iInUse(EFalse){} |
|
54 |
|
55 void ConstructL(); |
|
56 |
|
57 private: |
|
58 TUint8* iBuffer; |
|
59 |
|
60 //Holds the original MaxLength when class constructed. |
|
61 //May be larger than MaxLength of iBufferDes |
|
62 TInt iMaxLength; |
|
63 |
|
64 TPtr8 iBufferDes; |
|
65 |
|
66 TBool iInUse; |
|
67 }; |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 /** |
|
73 * @internalComponent |
|
74 * |
|
75 * A request is created when an external object requests or supplies data. Calls to the File Server are |
|
76 * made asynchronously and a CReadWriteRequest created to notify the caller on completion. |
|
77 * |
|
78 * CReadWriteRequest is an abstract class. Concrete instances are of CReadRequest & CWriteRequest. |
|
79 * Concrete instances need to know whether to call MDataSink::BufferFilledL() or MDataSource::BufferEmptiedL() |
|
80 */ |
|
81 class CReadWriteRequest : public CActive |
|
82 { |
|
83 public: |
|
84 CReadWriteRequest(TAny* aSinkOrSource, CMMFBuffer* aBuffer,TBool aSourceType) |
|
85 : CActive(EPriorityStandard), |
|
86 iSinkOrSource(aSinkOrSource), |
|
87 iBuffer(aBuffer), |
|
88 iSourceType(aSourceType) |
|
89 { |
|
90 CActiveScheduler::Add( this ); |
|
91 } |
|
92 |
|
93 CReadWriteRequest(TAny* aSinkOrSource, CMMFBuffer* aBuffer, CTransferBufferCopy* aOptionalDataBuffer,TBool aSourceType) |
|
94 : CActive(EPriorityStandard), |
|
95 iSinkOrSource(aSinkOrSource), |
|
96 iBuffer(aBuffer), |
|
97 iSourceType(aSourceType), |
|
98 iTransferBufferCopy(aOptionalDataBuffer) |
|
99 { |
|
100 CActiveScheduler::Add( this ); |
|
101 iTransferBufferCopy->SetInUse(ETrue); |
|
102 } |
|
103 |
|
104 CReadWriteRequest(CReadWriteRequest& aRequest) |
|
105 : CActive(EPriorityStandard), |
|
106 iSinkOrSource(aRequest.iSinkOrSource), |
|
107 iBuffer(aRequest.iBuffer), |
|
108 iSourceType(aRequest.iSourceType), |
|
109 iTransferBufferCopy(aRequest.iTransferBufferCopy) |
|
110 { |
|
111 CActiveScheduler::Add( this ); |
|
112 iTransferBufferCopy->SetInUse(ETrue); |
|
113 } |
|
114 |
|
115 |
|
116 inline TBool Processing() const { return iState == EProcessing; } |
|
117 inline TBool Completed() const { return iState == ECompleted; } |
|
118 TDes8& BufferDes() ; |
|
119 TBool SourceType(); |
|
120 const TDesC8& BufferDesC() ; |
|
121 CMMFBuffer* Buffer(); |
|
122 TAny* GetSinkOrSource(); |
|
123 ~CReadWriteRequest() ; |
|
124 |
|
125 |
|
126 // CActive functions. |
|
127 // |
|
128 void SetActive() ; |
|
129 void DoCancel() ; |
|
130 virtual void RunL() = 0 ; |
|
131 virtual TInt RunError( TInt aError ) ; |
|
132 |
|
133 |
|
134 protected : |
|
135 TAny* iSinkOrSource; |
|
136 CMMFBuffer* iBuffer; |
|
137 TBool iSourceType; |
|
138 CTransferBufferCopy* iTransferBufferCopy; |
|
139 |
|
140 TDes8* iBufferDes ; |
|
141 TInt iError ; |
|
142 TBool iUseTransferBuffer ; |
|
143 void SetTransferBuffer (TBool aTBuffer) ; |
|
144 TBool CanUseTransferBuffer () ; |
|
145 enum TState |
|
146 { |
|
147 EActive, |
|
148 EProcessing, |
|
149 ECompleted |
|
150 }; |
|
151 |
|
152 TState iState; |
|
153 } ; |
|
154 |
|
155 /** |
|
156 * @internalComponent |
|
157 */ |
|
158 class CReadRequest : public CReadWriteRequest |
|
159 { |
|
160 public : |
|
161 CReadRequest(TAny* aParent,TAny* aSinkOrSource, CMMFBuffer* aBuffer, TUint aPosition, TUint aFileSize,TBool aSourceType) |
|
162 : CReadWriteRequest(aSinkOrSource, aBuffer,aSourceType), |
|
163 iPosition(aPosition), iFileSize(aFileSize),iParent(aParent) |
|
164 { } |
|
165 |
|
166 CReadRequest(TAny* aParent,TAny* aSinkOrSource, CMMFBuffer* aBuffer, CTransferBufferCopy* aOptionalDataBuffer, TUint aPosition, TUint aFileSize,TBool aSourceType) |
|
167 : CReadWriteRequest(aSinkOrSource, aBuffer, aOptionalDataBuffer,aSourceType), |
|
168 iPosition(aPosition), iFileSize(aFileSize),iParent(aParent) |
|
169 { } |
|
170 |
|
171 void RunL(); |
|
172 private: |
|
173 TUint iPosition; |
|
174 TUint iFileSize; |
|
175 TAny* iParent; |
|
176 }; |
|
177 |
|
178 #endif |
|
179 |