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