|
1 // Copyright (c) 2001-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 // $Workfile: obexinternalutils.cpp $ |
|
15 // $Author: Stevep $ |
|
16 // $Revision: 3 $ |
|
17 // $Date: 19/11/01 15:55 $ |
|
18 // |
|
19 // |
|
20 |
|
21 //class include |
|
22 #include <obexinternalutils.h> |
|
23 |
|
24 //system includes |
|
25 #include <s32strm.h> //RReadStream, RWriteStream |
|
26 |
|
27 EXPORT_C void ObexInternalUtils::InternalizeL(HBufC*& aBuf, RReadStream& aStream) |
|
28 /** |
|
29 * Internalizes a HBufC from a stream. |
|
30 * |
|
31 * @param aBuf The HBufC to be internalized |
|
32 * @param aStream The stream to be read from |
|
33 * @leave KErrXXX Leaves with standard EPOC stream and memory allocation leave codes |
|
34 */ |
|
35 { |
|
36 TInt length = aStream.ReadInt32L(); |
|
37 delete aBuf; |
|
38 aBuf = NULL; |
|
39 aBuf = HBufC::NewL(aStream, length); |
|
40 } |
|
41 |
|
42 EXPORT_C void ObexInternalUtils::ExternalizeL(const HBufC* aBuf, RWriteStream& aStream) |
|
43 /** |
|
44 * Externalizes a HBufC to a stream. |
|
45 * |
|
46 * @param aBuf The HBufC to be externalized |
|
47 * @param aStream The stream to be written to |
|
48 * @leave KErrXXX Leaves with standard EPOC stream leave codes |
|
49 */ |
|
50 { |
|
51 aStream.WriteInt32L(aBuf->Length()); |
|
52 aStream << *aBuf; |
|
53 } |
|
54 |
|
55 |
|
56 EXPORT_C void ObexInternalUtils::InternalizeL(HBufC8*& aBuf, RReadStream& aStream) |
|
57 /** |
|
58 * Internalizes a HBufC8 from a stream. |
|
59 * |
|
60 * @param aBuf The HBufC8 to be internalized |
|
61 * @param aStream The stream to be read from |
|
62 * @leave KErrXXX Leaves with standard EPOC stream and memory allocation leave codes |
|
63 */ |
|
64 { |
|
65 TInt length = aStream.ReadInt32L(); |
|
66 delete aBuf; |
|
67 aBuf = NULL; |
|
68 aBuf = HBufC8::NewL(aStream, length); |
|
69 } |
|
70 |
|
71 EXPORT_C void ObexInternalUtils::ExternalizeL(const HBufC8* aBuf, RWriteStream& aStream) |
|
72 /** |
|
73 * Externalizes a HBufC8 to a stream. |
|
74 * |
|
75 * @param aBuf The HBufC8 to be externalized |
|
76 * @param aStream The stream to be written to |
|
77 * @leave KErrXXX Leaves with standard EPOC stream leave codes |
|
78 */ |
|
79 { |
|
80 aStream.WriteInt32L(aBuf->Length()); |
|
81 aStream << *aBuf; |
|
82 } |
|
83 |
|
84 |
|
85 EXPORT_C void ObexInternalUtils::InternalizeL(TDes& aDes, RReadStream& aStream) |
|
86 /** |
|
87 * Internalizes a TDes from a stream. |
|
88 * |
|
89 * @param aDes The TDes to be internalized |
|
90 * @param aStream The stream to be read from |
|
91 * @leave KErrXXX Leaves with standard EPOC stream and memory allocation leave codes |
|
92 * @leave KErrOverflow if the incoming data is too big for the TBuf provided |
|
93 */ |
|
94 { |
|
95 //read a HBufC from the stream |
|
96 TInt length = aStream.ReadInt32L(); |
|
97 HBufC* buf = HBufC::NewL(aStream, length); |
|
98 CleanupStack::PushL(buf); |
|
99 |
|
100 //check it'll fit into aBuf |
|
101 if (length <= aDes.MaxLength()) |
|
102 { |
|
103 //copy it into aDes |
|
104 aDes.Copy(*buf); |
|
105 } |
|
106 else |
|
107 { |
|
108 //Doesn't fit so leave |
|
109 User::Leave(KErrOverflow); |
|
110 } |
|
111 |
|
112 CleanupStack::PopAndDestroy(); //buf |
|
113 } |
|
114 |
|
115 EXPORT_C void ObexInternalUtils::ExternalizeL(const TDes& aDes, RWriteStream& aStream) |
|
116 /** |
|
117 * Externalizes a TDes to a stream. |
|
118 * |
|
119 * @param aBuf The TDes to be externalized |
|
120 * @param aStream The stream to be written to |
|
121 * @leave KErrXXX Leaves with standard EPOC stream leave codes |
|
122 */ |
|
123 { |
|
124 aStream.WriteInt32L(aDes.Length()); |
|
125 aStream << aDes; |
|
126 } |
|
127 |
|
128 |
|
129 EXPORT_C void ObexInternalUtils::InternalizeL(TDes8& aDes, RReadStream& aStream) |
|
130 /** |
|
131 * Internalizes a TDes8 from a stream. |
|
132 * |
|
133 * @param aBuf The TDes8 to be internalized |
|
134 * @param aStream The stream to be read from |
|
135 * @leave KErrXXX Leaves with standard EPOC stream and memory allocation leave codes |
|
136 * @leave KErrOverflow if the incoming data is too big for the TBuf provided |
|
137 */ |
|
138 { |
|
139 //read a HBufC from the stream |
|
140 TInt length = aStream.ReadInt32L(); |
|
141 HBufC8* buf = HBufC8::NewL(aStream, length); |
|
142 CleanupStack::PushL(buf); |
|
143 |
|
144 //check it'll fit into aBuf |
|
145 if (length <= aDes.MaxLength()) |
|
146 { |
|
147 //copy it into aDes |
|
148 aDes.Copy(*buf); |
|
149 } |
|
150 else |
|
151 { |
|
152 //Doesn't fit so leave |
|
153 User::Leave(KErrOverflow); |
|
154 } |
|
155 |
|
156 CleanupStack::PopAndDestroy(); //buf |
|
157 } |
|
158 |
|
159 EXPORT_C void ObexInternalUtils::ExternalizeL(const TDes8& aDes, RWriteStream& aStream) |
|
160 /** |
|
161 * Externalizes a TDes8 to a stream. |
|
162 * |
|
163 * @param aBuf The TDes8 to be externalized |
|
164 * @param aStream The stream to be written to |
|
165 * @leave KErrXXX Leaves with standard EPOC stream leave codes |
|
166 */ |
|
167 { |
|
168 aStream.WriteInt32L(aDes.Length()); |
|
169 aStream << aDes; |
|
170 } |
|
171 |
|
172 EXPORT_C void ObexInternalUtils::Panic(ObexInternalUtils::TObexInternalUtilsPanic aPanic) |
|
173 /** |
|
174 * Indicates Panic originates from Obex MTM |
|
175 * |
|
176 * @param aPanic The type of TObexInternalUtilsPanic which has taken place |
|
177 */ |
|
178 { |
|
179 _LIT(KPanicCategory, "ObexMTM"); |
|
180 User::Panic(KPanicCategory, aPanic); |
|
181 } |