|
1 // Copyright (c) 1998-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 "US_STD.H" |
|
17 |
|
18 EXPORT_C RShareBuf::RShareBuf() |
|
19 : iHost(NULL) |
|
20 /** Constructs an empty shared stream buffer object. |
|
21 |
|
22 Call one of the Open() functions to prepare the stream. */ |
|
23 {} |
|
24 |
|
25 EXPORT_C void RShareBuf::Open(TStreamExchange& aHost,TStreamPos aPos,TInt aMode) |
|
26 /** Prepares the shared stream buffer for streaming. |
|
27 |
|
28 The function sets the read mark and/or the write mark to the specified position |
|
29 within the host stream. |
|
30 |
|
31 @param aHost The object that manages shared streaming. |
|
32 @param aPos The position within the host stream. |
|
33 @param aMode The streaming mode. This can be read and/or write, as indicated |
|
34 by the ERead and EWrite bits. |
|
35 @see MStreamBuf::TRead |
|
36 @see MStreamBuf::TWrite */ |
|
37 { |
|
38 iHost=&aHost; |
|
39 if (aMode&ERead) |
|
40 iRMark=aPos; |
|
41 else |
|
42 iRMark.Clear(); |
|
43 if (aMode&EWrite) |
|
44 iWMark=aPos; |
|
45 else |
|
46 iWMark.Clear(); |
|
47 } |
|
48 |
|
49 EXPORT_C void RShareBuf::DoRelease() |
|
50 // |
|
51 // Withdraw this stream buffer's marks. |
|
52 // |
|
53 { |
|
54 if (iHost!=NULL) |
|
55 { |
|
56 TStreamExchange& host=*iHost; |
|
57 iRMark.Withdraw(host); |
|
58 iWMark.Withdraw(host); |
|
59 iHost=NULL; |
|
60 } |
|
61 } |
|
62 |
|
63 EXPORT_C TInt RShareBuf::DoReadL(TAny* aPtr,TInt aMaxLength) |
|
64 // |
|
65 // Read up to aMaxLength bytes. |
|
66 // |
|
67 { |
|
68 return iRMark.ReadL(Host(),aPtr,aMaxLength); |
|
69 } |
|
70 |
|
71 EXPORT_C TInt RShareBuf::DoReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus) |
|
72 // |
|
73 // Read up to aMaxLength bytes asynchronously. |
|
74 // |
|
75 { |
|
76 return iRMark.ReadL(Host(),aDes,aMaxLength,aStatus); |
|
77 } |
|
78 |
|
79 EXPORT_C TStreamTransfer RShareBuf::DoReadL(MStreamInput& anInput,TStreamTransfer aTransfer) |
|
80 // |
|
81 // Push up to aTransfer bytes into anInput. |
|
82 // |
|
83 { |
|
84 return iRMark.ReadL(Host(),anInput,aTransfer); |
|
85 } |
|
86 |
|
87 EXPORT_C void RShareBuf::DoWriteL(const TAny* aPtr,TInt aLength) |
|
88 // |
|
89 // Write aLength bytes. |
|
90 // |
|
91 { |
|
92 iWMark.WriteL(Host(),aPtr,aLength); |
|
93 } |
|
94 |
|
95 EXPORT_C TInt RShareBuf::DoWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus) |
|
96 // |
|
97 // Write up to aMaxLength bytes asynchronously. |
|
98 // |
|
99 { |
|
100 return iWMark.WriteL(Host(),aDes,aMaxLength,aStatus); |
|
101 } |
|
102 |
|
103 EXPORT_C TStreamTransfer RShareBuf::DoWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer) |
|
104 // |
|
105 // Pull up to aTransfer bytes from anOutput. |
|
106 // |
|
107 { |
|
108 return iWMark.WriteL(Host(),anOutput,aTransfer); |
|
109 } |
|
110 |
|
111 EXPORT_C TStreamPos RShareBuf::DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset) |
|
112 // |
|
113 // Position the mark(s) indicated by aMark at anOffset from aLocation. |
|
114 // |
|
115 { |
|
116 TStreamExchange& host=Host(); |
|
117 if (!aMark) |
|
118 { |
|
119 TStreamMark mark; |
|
120 return mark.SeekL(host,aLocation,anOffset); |
|
121 } |
|
122 // |
|
123 __ASSERT_ALWAYS(!(aMark&~(ERead|EWrite)),Panic(EStreamMarkInvalid)); |
|
124 TStreamPos pos(0); |
|
125 if (aMark&ERead) |
|
126 { |
|
127 __ASSERT_ALWAYS(aLocation!=EStreamMark||aMark==ERead,Panic(EStreamMarkInvalid)); |
|
128 if (!iRMark.RelatesTo(host)) |
|
129 __LEAVE(KErrNotReady); |
|
130 // |
|
131 pos=iRMark.SeekL(host,aLocation,anOffset); |
|
132 } |
|
133 if (aMark&EWrite) |
|
134 { |
|
135 if (!iWMark.RelatesTo(host)) |
|
136 __LEAVE(KErrNotReady); |
|
137 // |
|
138 TStreamPos p=iWMark.SeekL(host,aLocation,anOffset); |
|
139 __ASSERT_DEBUG(aMark==EWrite||p==pos,User::Invariant()); |
|
140 return p; |
|
141 } |
|
142 // |
|
143 return pos; |
|
144 } |
|
145 |
|
146 EXPORT_C RShareReadStream::RShareReadStream(TStreamExchange& aHost,TStreamPos aPos) |
|
147 /** Constructs the shared read stream object and prepares the shared stream for |
|
148 reading. |
|
149 |
|
150 @param aHost The object that manages shared streaming. |
|
151 @param aPos The position of the stream within the host stream. Defaults to |
|
152 the beginning of the host stream, if not explicitly specified. |
|
153 @see KStreamBeginning */ |
|
154 { |
|
155 Open(aHost,aPos); |
|
156 } |
|
157 |
|
158 EXPORT_C void RShareReadStream::Open(TStreamExchange& aHost,TStreamPos aPos) |
|
159 /** Prepares the shared stream for reading. |
|
160 |
|
161 @param aHost The object that manages shared streaming. |
|
162 @param aPos The position of the stream within the host stream. Defaults to |
|
163 the beginning of the host stream, if not explicitly specified. */ |
|
164 { |
|
165 iSource.Open(aHost,aPos,iSource.ERead); |
|
166 RReadStream::Attach(&iSource); |
|
167 } |
|
168 |
|
169 EXPORT_C RShareWriteStream::RShareWriteStream(TStreamExchange& aHost,TStreamPos aPos) |
|
170 /** Constructs the shared write stream object and prepares the shared stream for |
|
171 writing. |
|
172 |
|
173 @param aHost The object that manages shared streaming. |
|
174 @param aPos The position of the stream within the host stream. Defaults to |
|
175 the beginning of the host stream, if not explicitly specified. |
|
176 @see KStreamBeginning */ |
|
177 { |
|
178 Open(aHost,aPos); |
|
179 } |
|
180 |
|
181 EXPORT_C void RShareWriteStream::Open(TStreamExchange& aHost,TStreamPos aPos) |
|
182 /** Prepares the shared stream for writing. |
|
183 |
|
184 @param aHost The object that manages shared streaming. |
|
185 @param aPos The position of the stream within the host stream. Defaults to |
|
186 the beginning of the host stream, if not explicitly specified. */ |
|
187 { |
|
188 iSink.Open(aHost,aPos,iSink.EWrite); |
|
189 RWriteStream::Attach(&iSink); |
|
190 } |
|
191 |