|
1 /* |
|
2 * Copyright (c) 2007-2009 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 the License "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: |
|
15 * Library to add s32strm support for IPC (ie. stream via multiple IPC read/writes instead of |
|
16 * copying to a buffer and streaming to/from there. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 /** |
|
22 @file |
|
23 */ |
|
24 #include "ipcbuf.h" |
|
25 |
|
26 |
|
27 EXPORT_C void RIpcBuf::Open(const RMessagePtr2& aMessage, TInt aMessageSlot) |
|
28 { |
|
29 iMessage = aMessage; |
|
30 iMessageSlot = aMessageSlot; |
|
31 iReadPos = 0; |
|
32 iWritePos = 0; |
|
33 } |
|
34 |
|
35 EXPORT_C TStreamPos RIpcBuf::DoSeekL(TMark aMark, TStreamLocation aLocation, TInt anOffset) |
|
36 { |
|
37 |
|
38 TInt size = iMessage.GetDesLengthL(iMessageSlot); |
|
39 |
|
40 switch (aLocation) |
|
41 { |
|
42 case EStreamBeginning: |
|
43 // do nothing |
|
44 break; |
|
45 |
|
46 case EStreamMark: |
|
47 if (aMark&ERead) |
|
48 { |
|
49 anOffset += iReadPos; |
|
50 } |
|
51 else if (aMark&EWrite) |
|
52 { |
|
53 anOffset += iWritePos; |
|
54 } |
|
55 break; |
|
56 |
|
57 case EStreamEnd: |
|
58 anOffset += size; |
|
59 break; |
|
60 |
|
61 default: |
|
62 User::Panic(KIpcBufPanic, EIpcBufSeekUnknownLocation); |
|
63 break; |
|
64 } |
|
65 |
|
66 // offset can't be negative or greater than size |
|
67 if (anOffset > size || anOffset < 0) |
|
68 { |
|
69 User::Panic(KIpcBufPanic, EIpcBufSeekBadOffset); |
|
70 } |
|
71 |
|
72 if (aMark&ERead) |
|
73 { |
|
74 iReadPos = anOffset; |
|
75 } |
|
76 else if (aMark&EWrite) |
|
77 { |
|
78 iWritePos = anOffset; |
|
79 } |
|
80 |
|
81 return TStreamPos(anOffset); |
|
82 } |
|
83 |
|
84 EXPORT_C TInt RIpcBuf::DoReadL(TAny *aPtr, TInt aMaxLength) |
|
85 { |
|
86 TPtr8 ptr((TUint8*)aPtr, aMaxLength); |
|
87 iMessage.ReadL(iMessageSlot, ptr, iReadPos); |
|
88 TInt len = ptr.Length(); |
|
89 iReadPos += len; |
|
90 return len; |
|
91 } |
|
92 |
|
93 EXPORT_C void RIpcBuf::DoWriteL(const TAny* aPtr,TInt aLength) |
|
94 { |
|
95 TPtr8 ptr((TUint8*)aPtr, aLength, aLength); |
|
96 iMessage.WriteL(iMessageSlot, ptr, iWritePos); |
|
97 iWritePos += aLength; |
|
98 } |