|
1 /* |
|
2 * Copyright (c) 2005-2007 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: Implements Phonebook 2 generic IPC package. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Phonebook 2 |
|
20 #include "Pbk2IPCPackage.h" |
|
21 |
|
22 // System includes |
|
23 #include <barsread.h> |
|
24 #include <s32mem.h> |
|
25 |
|
26 // -------------------------------------------------------------------------- |
|
27 // Package syntax |
|
28 // 1. Bit enumeration (EBuffer8Bit or EBuffer16Bit) |
|
29 // 2. Length of the buffer |
|
30 // 3. Data |
|
31 // -------------------------------------------------------------------------- |
|
32 |
|
33 /// Unnamed namespace for local definitions |
|
34 namespace { |
|
35 |
|
36 const TInt KFormatSlotSize( 4 + 4 ); |
|
37 const TInt KConvert16To8 = 2; |
|
38 |
|
39 enum TPanicCode |
|
40 { |
|
41 EInvalidArgument |
|
42 }; |
|
43 |
|
44 void Panic(TPanicCode aReason) |
|
45 { |
|
46 _LIT( KPanicText, "Pbk2IPCPackage" ); |
|
47 User::Panic( KPanicText, aReason ); |
|
48 } |
|
49 |
|
50 } /// namespace |
|
51 |
|
52 // -------------------------------------------------------------------------- |
|
53 // Pbk2IPCPackage::ExternalizeL |
|
54 // -------------------------------------------------------------------------- |
|
55 // |
|
56 EXPORT_C void Pbk2IPCPackage::ExternalizeL |
|
57 ( HBufC8*& aBuffer, RDesWriteStream& aWriteStream ) |
|
58 { |
|
59 if ( aBuffer ) |
|
60 { |
|
61 aWriteStream.WriteUint32L( EBuffer8Bit ); |
|
62 aWriteStream.WriteUint32L( aBuffer->Length() ); |
|
63 aWriteStream.WriteL( *aBuffer ); |
|
64 } |
|
65 else |
|
66 { |
|
67 aWriteStream.WriteUint32L( EBuffer8Bit ); |
|
68 aWriteStream.WriteUint32L( 0 ); |
|
69 } |
|
70 } |
|
71 |
|
72 // -------------------------------------------------------------------------- |
|
73 // Pbk2IPCPackage::ExternalizeL |
|
74 // -------------------------------------------------------------------------- |
|
75 // |
|
76 EXPORT_C void Pbk2IPCPackage::ExternalizeL |
|
77 ( HBufC*& aBuffer, RDesWriteStream& aWriteStream ) |
|
78 { |
|
79 if ( aBuffer ) |
|
80 { |
|
81 aWriteStream.WriteUint32L( EBuffer16Bit ); |
|
82 aWriteStream.WriteUint32L( aBuffer->Length() ); |
|
83 aWriteStream.WriteL( *aBuffer ); |
|
84 } |
|
85 else |
|
86 { |
|
87 aWriteStream.WriteUint32L( EBuffer16Bit ); |
|
88 aWriteStream.WriteUint32L( 0 ); |
|
89 } |
|
90 } |
|
91 |
|
92 // -------------------------------------------------------------------------- |
|
93 // Pbk2IPCPackage::InternalizeL |
|
94 // -------------------------------------------------------------------------- |
|
95 // |
|
96 EXPORT_C void Pbk2IPCPackage::InternalizeL |
|
97 ( HBufC8*& aBuffer, RDesReadStream& aReadStream ) |
|
98 { |
|
99 delete aBuffer; |
|
100 aBuffer = NULL; |
|
101 |
|
102 // Need to read, even we don't needed |
|
103 TInt bit( aReadStream.ReadUint32L() ); |
|
104 TInt length( aReadStream.ReadUint32L() ); |
|
105 if ( length > 0 ) |
|
106 { |
|
107 aBuffer = HBufC8::NewL( length ); |
|
108 TPtr8 ptr = aBuffer->Des(); |
|
109 aReadStream.ReadL( ptr, length ); |
|
110 } |
|
111 } |
|
112 |
|
113 // -------------------------------------------------------------------------- |
|
114 // Pbk2IPCPackage::InternalizeL |
|
115 // -------------------------------------------------------------------------- |
|
116 // |
|
117 EXPORT_C void Pbk2IPCPackage::InternalizeL |
|
118 ( HBufC*& aBuffer, RDesReadStream& aReadStream ) |
|
119 { |
|
120 delete aBuffer; |
|
121 aBuffer = NULL; |
|
122 |
|
123 // Need to read, even we don't needed |
|
124 TInt bit( aReadStream.ReadUint32L() ); |
|
125 TInt length( aReadStream.ReadUint32L() ); |
|
126 if ( length > 0 ) |
|
127 { |
|
128 aBuffer = HBufC::NewL( length ); |
|
129 TPtr ptr = aBuffer->Des(); |
|
130 aReadStream.ReadL( ptr ,length ); |
|
131 } |
|
132 } |
|
133 |
|
134 // -------------------------------------------------------------------------- |
|
135 // Pbk2IPCPackage::InternalizeL |
|
136 // -------------------------------------------------------------------------- |
|
137 // |
|
138 EXPORT_C void Pbk2IPCPackage::InternalizeL |
|
139 ( HBufC8*& aBuffer, RDesReadStream& aReadStream, |
|
140 const TInt aPosition ) |
|
141 { |
|
142 delete aBuffer; |
|
143 aBuffer = NULL; |
|
144 |
|
145 // Read the non relevant parts of the package |
|
146 FindPositionL( aReadStream, aPosition ); |
|
147 |
|
148 // Need to read, even we don't needed |
|
149 TInt bit( aReadStream.ReadUint32L() ); |
|
150 TInt length( aReadStream.ReadUint32L() ); |
|
151 if ( length > 0 ) |
|
152 { |
|
153 aBuffer = HBufC8::NewL( length ); |
|
154 TPtr8 ptr = aBuffer->Des(); |
|
155 aReadStream.ReadL( ptr, length ); |
|
156 } |
|
157 } |
|
158 |
|
159 // -------------------------------------------------------------------------- |
|
160 // Pbk2IPCPackage::InternalizeL |
|
161 // -------------------------------------------------------------------------- |
|
162 // |
|
163 EXPORT_C void Pbk2IPCPackage::InternalizeL |
|
164 ( HBufC*& aBuffer, RDesReadStream& aReadStream, |
|
165 const TInt aPosition ) |
|
166 { |
|
167 delete aBuffer; |
|
168 aBuffer = NULL; |
|
169 |
|
170 // Read the non relevant parts of the package |
|
171 FindPositionL( aReadStream, aPosition ); |
|
172 |
|
173 // Need to read, even we don't needed |
|
174 TInt bit( aReadStream.ReadUint32L() ); |
|
175 TInt length( aReadStream.ReadUint32L() ); |
|
176 if ( length > 0 ) |
|
177 { |
|
178 aBuffer = HBufC::NewL( length ); |
|
179 TPtr ptr = aBuffer->Des(); |
|
180 aReadStream.ReadL( ptr ,length ); |
|
181 } |
|
182 } |
|
183 |
|
184 // -------------------------------------------------------------------------- |
|
185 // Pbk2IPCPackage::CountPackageSize |
|
186 // -------------------------------------------------------------------------- |
|
187 // |
|
188 EXPORT_C TInt Pbk2IPCPackage::CountPackageSize( HBufC8* aBuffer ) |
|
189 { |
|
190 TInt ret = KFormatSlotSize; |
|
191 |
|
192 if ( aBuffer ) |
|
193 { |
|
194 // See package syntax |
|
195 ret = aBuffer->Length() + KFormatSlotSize; |
|
196 } |
|
197 return ret; |
|
198 } |
|
199 |
|
200 // -------------------------------------------------------------------------- |
|
201 // Pbk2IPCPackage::CountPackageSize |
|
202 // -------------------------------------------------------------------------- |
|
203 // |
|
204 EXPORT_C TInt Pbk2IPCPackage::CountPackageSize( HBufC* aBuffer ) |
|
205 { |
|
206 TInt ret = KFormatSlotSize; |
|
207 if ( aBuffer ) |
|
208 { |
|
209 // See package syntax |
|
210 ret = aBuffer->Length()*KConvert16To8 + KFormatSlotSize; |
|
211 } |
|
212 return ret; |
|
213 } |
|
214 |
|
215 // -------------------------------------------------------------------------- |
|
216 // Pbk2IPCPackage::FindPositionL |
|
217 // Reads the non relevant parts of the package. |
|
218 // @param aReadStream The stream to read from. |
|
219 // @param aPosition The position where to read. |
|
220 // -------------------------------------------------------------------------- |
|
221 // |
|
222 void Pbk2IPCPackage::FindPositionL |
|
223 ( RDesReadStream& aReadStream, const TInt aPosition ) |
|
224 { |
|
225 for ( TInt i=0; i < aPosition; ++i ) |
|
226 { |
|
227 TInt bit = aReadStream.ReadUint32L(); |
|
228 switch ( bit ) |
|
229 { |
|
230 case EBuffer8Bit: |
|
231 { |
|
232 TInt dummyLength = aReadStream.ReadUint32L(); |
|
233 aReadStream.ReadL(dummyLength); |
|
234 break; |
|
235 } |
|
236 case EBuffer16Bit: |
|
237 { |
|
238 TInt dummyLength = aReadStream.ReadUint32L()*KConvert16To8; |
|
239 aReadStream.ReadL(dummyLength); |
|
240 break; |
|
241 } |
|
242 default: |
|
243 { |
|
244 Panic( EInvalidArgument ); |
|
245 } |
|
246 }; |
|
247 } |
|
248 } |
|
249 |
|
250 // End of File |