1 // Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of "Eclipse Public License v1.0" |
4 // under the terms of "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
13 // Description: |
13 // Description: |
14 // |
14 // |
15 |
15 |
16 #include <e32base.h> |
16 #include <e32base.h> |
17 #include "IPCBuf.h" |
17 #include "IPCBuf.h" |
18 #include "SqlAssert.h" |
18 #include "SqlPanic.h" |
19 #include "SqlDbSession.h" |
19 #include "SqlDbSession.h" |
20 #include "OstTraceDefinitions.h" |
|
21 #ifdef OST_TRACE_COMPILER_IN_USE |
|
22 #include "IPCBufTraces.h" |
|
23 #endif |
|
24 #include "SqlTraceDef.h" |
|
25 |
20 |
26 /** |
21 /** |
27 Standard, phase-one HIpcBuf factory method. |
22 Standard, phase-one HIpcBuf factory method. |
28 Created HIpcBuf instance will be used for transfering large text or binary objects from/to SQL server. |
23 Created HIpcBuf instance will be used for transfering large text or binary objects from/to SQL server. |
29 The created HIpcBuf instance will be placed in the cleanup stack. |
24 The created HIpcBuf instance will be placed in the cleanup stack. |
78 void HIpcBuf::ConstructL(TInt aFunction, TIpcArgs& aArgs) |
73 void HIpcBuf::ConstructL(TInt aFunction, TIpcArgs& aArgs) |
79 { |
74 { |
80 TPckg<TIpcStreamBuf> pckg(iBuf); |
75 TPckg<TIpcStreamBuf> pckg(iBuf); |
81 aArgs.Set(2, &pckg); |
76 aArgs.Set(2, &pckg); |
82 __SQLLEAVE_IF_ERROR(iHandle = iSession.SendReceive(aFunction, aArgs)); |
77 __SQLLEAVE_IF_ERROR(iHandle = iSession.SendReceive(aFunction, aArgs)); |
83 SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, HIPCBUF_CONSTRUCTL, "0x%X;HIpcBuf::ConstructL;iHandle=%d", (TUint)this, iHandle)); |
|
84 TUint8* base = iBuf.iData; |
78 TUint8* base = iBuf.iData; |
85 // if reading we already have one buffer-full of data |
79 // if reading we already have one buffer-full of data |
86 TInt avail = Max(0, Min(iBuf.iExt, KIpcBufSize)); |
80 TInt avail = Max(0, Min(iBuf.iExt, KIpcBufSize)); |
87 SetBuf(ERead, base, base + avail); |
81 SetBuf(ERead, base, base + avail); |
88 SetPos(ERead, avail); |
82 SetPos(ERead, avail); |
121 // when handle is null there is no data to read from server |
114 // when handle is null there is no data to read from server |
122 if(!iHandle) |
115 if(!iHandle) |
123 { |
116 { |
124 return 0; |
117 return 0; |
125 } |
118 } |
126 __ASSERT_DEBUG(Avail(ERead) == 0, __SQLPANIC(ESqlPanicInternalError)); |
119 __SQLASSERT(Avail(ERead) == 0, ESqlPanicInternalError); |
127 TUint8* base=iBuf.iData; |
120 TUint8* base=iBuf.iData; |
128 IpcWriteL(base,Lag(EWrite)); |
121 IpcWriteL(base,Lag(EWrite)); |
129 SetBuf(EWrite,base,base); |
122 SetBuf(EWrite,base,base); |
130 |
123 |
131 TInt len=IpcReadL(base,iBuf.ESize); |
124 TInt len=IpcReadL(base,iBuf.ESize); |
136 /** |
129 /** |
137 Set up the buffer's write area. |
130 Set up the buffer's write area. |
138 */ |
131 */ |
139 void HIpcBuf::OverflowL() |
132 void HIpcBuf::OverflowL() |
140 { |
133 { |
141 __ASSERT_DEBUG(Avail(EWrite) == 0, __SQLPANIC(ESqlPanicInternalError)); |
134 __SQLASSERT(Avail(EWrite) == 0, ESqlPanicInternalError); |
142 |
135 |
143 TUint8* base = iBuf.iData; |
136 TUint8* base = iBuf.iData; |
144 MovePos(ERead, Lag(ERead)); |
137 MovePos(ERead, Lag(ERead)); |
145 SetBuf(ERead, base, base); |
138 SetBuf(ERead, base, base); |
146 |
139 |
173 /** |
166 /** |
174 Read direct from ipc if asked to transfer more than a bufferful. |
167 Read direct from ipc if asked to transfer more than a bufferful. |
175 */ |
168 */ |
176 TInt HIpcBuf::DoReadL(TAny* aPtr, TInt aMaxLength) |
169 TInt HIpcBuf::DoReadL(TAny* aPtr, TInt aMaxLength) |
177 { |
170 { |
178 __ASSERT_DEBUG(aMaxLength > 0, __SQLPANIC(ESqlPanicInternalError)); |
171 __SQLASSERT(aMaxLength > 0, ESqlPanicInternalError); |
179 TInt avail = Avail(ERead); |
172 TInt avail = Avail(ERead); |
180 __ASSERT_DEBUG(avail >= 0 && Avail(EWrite) >= 0, __SQLPANIC(ESqlPanicInternalError)); |
173 __SQLASSERT(avail >= 0 && Avail(EWrite) >= 0, ESqlPanicInternalError); |
181 if(avail > 0) |
174 if(avail > 0) |
182 { |
175 { |
183 TInt len = Min(aMaxLength, avail); |
176 TInt len = Min(aMaxLength, avail); |
184 TUint8* ptr = Ptr(ERead); |
177 TUint8* ptr = Ptr(ERead); |
185 aPtr = Mem::Copy(aPtr, ptr, len); |
178 aPtr = Mem::Copy(aPtr, ptr, len); |
186 SetPtr(ERead, ptr + len); |
179 SetPtr(ERead, ptr + len); |
187 aMaxLength -= len; |
180 aMaxLength -= len; |
188 if(aMaxLength == 0) |
181 if(aMaxLength == 0) |
189 return len; // that's it |
182 return len; // that's it |
190 } |
183 } |
191 __ASSERT_DEBUG(Avail(ERead) == 0, __SQLPANIC(ESqlPanicInternalError)); |
184 __SQLASSERT(Avail(ERead) == 0, ESqlPanicInternalError); |
192 if(aMaxLength < iBuf.ESize) |
185 if(aMaxLength < iBuf.ESize) |
193 return avail + TStreamBuf::DoReadL(aPtr, aMaxLength); |
186 return avail + TStreamBuf::DoReadL(aPtr, aMaxLength); |
194 |
187 |
195 // when handle is null there is no more data to read from server |
188 // when handle is null there is no more data to read from server |
196 if(!iHandle) |
189 if(!iHandle) |
207 /** |
200 /** |
208 Write direct to ipc if asked to transfer more than a bufferful. |
201 Write direct to ipc if asked to transfer more than a bufferful. |
209 */ |
202 */ |
210 void HIpcBuf::DoWriteL(const TAny* aPtr,TInt aLength) |
203 void HIpcBuf::DoWriteL(const TAny* aPtr,TInt aLength) |
211 { |
204 { |
212 __ASSERT_DEBUG(aLength > 0, __SQLPANIC(ESqlPanicInternalError)); |
205 __SQLASSERT(aLength > 0, ESqlPanicInternalError); |
213 TInt avail = Avail(EWrite); |
206 TInt avail = Avail(EWrite); |
214 __ASSERT_DEBUG(Avail(ERead) >= 0 && avail >= 0, __SQLPANIC(ESqlPanicInternalError)); |
207 __SQLASSERT(Avail(ERead) >= 0 && avail >= 0, ESqlPanicInternalError); |
215 if(avail > 0) |
208 if(avail > 0) |
216 { |
209 { |
217 TInt len = Min(aLength, avail); |
210 TInt len = Min(aLength, avail); |
218 SetPtr(EWrite, Mem::Copy(Ptr(EWrite), aPtr, len)); |
211 SetPtr(EWrite, Mem::Copy(Ptr(EWrite), aPtr, len)); |
219 aLength -= len; |
212 aLength -= len; |
220 if(aLength == 0) |
213 if(aLength == 0) |
221 return; // done |
214 return; // done |
222 |
215 |
223 aPtr = (TUint8*)aPtr + len; |
216 aPtr = (TUint8*)aPtr + len; |
224 } |
217 } |
225 __ASSERT_DEBUG(Avail(EWrite) == 0, __SQLPANIC(ESqlPanicInternalError)); |
218 __SQLASSERT(Avail(EWrite) == 0, ESqlPanicInternalError); |
226 if(aLength < iBuf.ESize) |
219 if(aLength < iBuf.ESize) |
227 TStreamBuf::DoWriteL(aPtr, aLength); |
220 TStreamBuf::DoWriteL(aPtr, aLength); |
228 else |
221 else |
229 { |
222 { |
230 TUint8* base = iBuf.iData; |
223 TUint8* base = iBuf.iData; |
278 { |
271 { |
279 aOffset = end; |
272 aOffset = end; |
280 r = KErrEof; |
273 r = KErrEof; |
281 } |
274 } |
282 |
275 |
283 __ASSERT_ALWAYS(!(aMark & ~(ERead | EWrite)), __SQLPANIC(ESqlPanicStreamMarkInvalid)); |
276 __SQLASSERT_ALWAYS(!(aMark & ~(ERead | EWrite)), ESqlPanicStreamMarkInvalid); |
284 if(aMark & ERead) |
277 if(aMark & ERead) |
285 { |
278 { |
286 TInt lag = aOffset - Pos(ERead); |
279 TInt lag = aOffset - Pos(ERead); |
287 if(lag >= base - End(ERead) && lag <= 0) |
280 if(lag >= base - End(ERead) && lag <= 0) |
288 SetPtr(ERead, End(ERead) + lag); |
281 SetPtr(ERead, End(ERead) + lag); |
309 Arg 2: [in/out] IPC buffer |
302 Arg 2: [in/out] IPC buffer |
310 Arg 3: [out] max length of the requested data |
303 Arg 3: [out] max length of the requested data |
311 */ |
304 */ |
312 TInt HIpcBuf::IpcReadL(TAny* aPtr, TInt aMaxLength) |
305 TInt HIpcBuf::IpcReadL(TAny* aPtr, TInt aMaxLength) |
313 { |
306 { |
314 __ASSERT_DEBUG(aMaxLength >= 0, __SQLPANIC(ESqlPanicInternalError)); |
307 __SQLASSERT(aMaxLength >= 0, ESqlPanicInternalError); |
315 if(aMaxLength == 0) |
308 if(aMaxLength == 0) |
316 return 0; |
309 return 0; |
317 |
310 |
318 TPtr8 des((TUint8*)aPtr, aMaxLength); |
311 TPtr8 des((TUint8*)aPtr, aMaxLength); |
319 TInt pos = Pos(ERead); |
312 TInt pos = Pos(ERead); |
332 Arg 1: [out] from which position to write |
325 Arg 1: [out] from which position to write |
333 Arg 2: [in/out] IPC buffer |
326 Arg 2: [in/out] IPC buffer |
334 */ |
327 */ |
335 void HIpcBuf::IpcWriteL(const TAny* aPtr, TInt aLength) |
328 void HIpcBuf::IpcWriteL(const TAny* aPtr, TInt aLength) |
336 { |
329 { |
337 __ASSERT_DEBUG(aLength >= 0, __SQLPANIC(ESqlPanicInternalError)); |
330 __SQLASSERT(aLength >= 0, ESqlPanicInternalError); |
338 if(aLength == 0) |
331 if(aLength == 0) |
339 return; |
332 return; |
340 |
333 |
341 TPtrC8 ptr((TUint8*)aPtr, aLength); |
334 TPtrC8 ptr((TUint8*)aPtr, aLength); |
342 TInt ext = iBuf.iExt; |
335 TInt ext = iBuf.iExt; |