|
1 /* |
|
2 * Copyright (c) 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: Class definition of CDiagResultDetailBasicItem |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // SYSTEM INCLUDE FILES |
|
20 #include <s32strm.h> // RReadStream, RWriteStream |
|
21 |
|
22 // USER INCLUDE FILES |
|
23 #include "diagresultdetailbasicitem.h" |
|
24 |
|
25 // CONSTANTS |
|
26 const TInt KDiagResultDetailBasicMaxNameLen = 50; |
|
27 const TInt KDiagResultDetailBasicMaxFieldValueLen = 1024; |
|
28 |
|
29 // ======== MEMBER FUNCTIONS ======== |
|
30 // --------------------------------------------------------------------------- |
|
31 // CDiagResultDetailBasicItem::NewL |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CDiagResultDetailBasicItem* CDiagResultDetailBasicItem::NewL( |
|
35 TInt aFieldId, |
|
36 const TDesC8& aFieldName, |
|
37 TInt aValue ) |
|
38 { |
|
39 CDiagResultDetailBasicItem* self = new( ELeave ) |
|
40 CDiagResultDetailBasicItem(); |
|
41 CleanupStack::PushL( self ); |
|
42 |
|
43 self->iFieldId = aFieldId; |
|
44 self->iFieldName = aFieldName.AllocL(); |
|
45 self->iFieldType = ETypeInt; |
|
46 self->iValue.iInt = aValue; |
|
47 |
|
48 CleanupStack::Pop( self ); |
|
49 return self; |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // CDiagResultDetailBasicItem::NewL |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CDiagResultDetailBasicItem* CDiagResultDetailBasicItem::NewL( |
|
57 TInt aFieldId, |
|
58 const TDesC8& aFieldName, |
|
59 const TDesC8& aValue ) |
|
60 { |
|
61 CDiagResultDetailBasicItem* self = new( ELeave ) |
|
62 CDiagResultDetailBasicItem(); |
|
63 CleanupStack::PushL( self ); |
|
64 |
|
65 self->iFieldId = aFieldId; |
|
66 self->iFieldName = aFieldName.AllocL(); |
|
67 self->iFieldType = ETypeDes8; |
|
68 self->iValue.iBuffer8 = aValue.AllocL(); |
|
69 |
|
70 CleanupStack::Pop( self ); |
|
71 return self; |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // CDiagResultDetailBasicItem::NewL |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 CDiagResultDetailBasicItem* CDiagResultDetailBasicItem::NewL( |
|
79 TInt aFieldId, |
|
80 const TDesC8& aFieldName, |
|
81 const TDesC16& aValue ) |
|
82 { |
|
83 CDiagResultDetailBasicItem* self = new( ELeave ) |
|
84 CDiagResultDetailBasicItem(); |
|
85 CleanupStack::PushL( self ); |
|
86 |
|
87 self->iFieldId = aFieldId; |
|
88 self->iFieldName = aFieldName.AllocL(); |
|
89 self->iFieldType = ETypeDes16; |
|
90 self->iValue.iBuffer16 = aValue.AllocL(); |
|
91 |
|
92 CleanupStack::Pop( self ); |
|
93 return self; |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // CDiagResultDetailBasicItem::NewL |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 CDiagResultDetailBasicItem* CDiagResultDetailBasicItem::NewL( |
|
101 RReadStream& aReadStream ) |
|
102 { |
|
103 CDiagResultDetailBasicItem* self = new( ELeave ) |
|
104 CDiagResultDetailBasicItem(); |
|
105 CleanupStack::PushL( self ); |
|
106 |
|
107 self->InternalizeL( aReadStream ); |
|
108 |
|
109 CleanupStack::Pop( self ); |
|
110 return self; |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // CDiagResultDetailBasicItem::CDiagResultDetailBasicItem |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 CDiagResultDetailBasicItem::CDiagResultDetailBasicItem() |
|
118 { |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // CDiagResultDetailBasicItem::~CDiagResultDetailBasicItem |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 CDiagResultDetailBasicItem::~CDiagResultDetailBasicItem() |
|
126 { |
|
127 delete iFieldName; |
|
128 iFieldName = NULL; |
|
129 |
|
130 switch ( Type() ) |
|
131 { |
|
132 case ETypeDes16: |
|
133 delete iValue.iBuffer16; |
|
134 iValue.iBuffer16 = NULL; |
|
135 break; |
|
136 case ETypeDes8: |
|
137 delete iValue.iBuffer8; |
|
138 iValue.iBuffer8 = NULL; |
|
139 break; |
|
140 default: |
|
141 // do nothing |
|
142 break; |
|
143 } |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // CDiagResultDetailBasicItem::FieldId |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 TInt CDiagResultDetailBasicItem::FieldId() const |
|
151 { |
|
152 return iFieldId; |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // CDiagResultDetailBasicItem::FieldName |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 const TDesC8& CDiagResultDetailBasicItem::FieldName() const |
|
160 { |
|
161 return *iFieldName; |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // CDiagResultDetailBasicItem::Type |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 CDiagResultDetailBasicItem::TFieldType CDiagResultDetailBasicItem::Type() const |
|
169 { |
|
170 return iFieldType; |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // CDiagResultDetailBasicItem::GetValue |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 TInt CDiagResultDetailBasicItem::GetValue( TInt& aValue ) const |
|
178 { |
|
179 if ( Type() != ETypeInt ) |
|
180 return KErrArgument; |
|
181 |
|
182 aValue = iValue.iInt; |
|
183 return KErrNone; |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // CDiagResultDetailBasicItem::GetValue |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 TInt CDiagResultDetailBasicItem::GetValue( TPtrC8& aValue ) const |
|
191 { |
|
192 if ( Type() != ETypeDes8 ) |
|
193 return KErrArgument; |
|
194 |
|
195 aValue.Set( iValue.iBuffer8->Des() ); |
|
196 return KErrNone; |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // CDiagResultDetailBasicItem::GetValue |
|
201 // --------------------------------------------------------------------------- |
|
202 // |
|
203 TInt CDiagResultDetailBasicItem::GetValue( TPtrC16& aValue ) const |
|
204 { |
|
205 if ( Type() != ETypeDes16 ) |
|
206 return KErrArgument; |
|
207 |
|
208 |
|
209 aValue.Set( iValue.iBuffer16->Des() ); |
|
210 return KErrNone; |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // CDiagResultDetailBasicItem::InternalizeL |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 void CDiagResultDetailBasicItem::InternalizeL( RReadStream& aReadStream ) |
|
218 { |
|
219 // first read id |
|
220 iFieldId = aReadStream.ReadInt32L(); |
|
221 |
|
222 // read field Type |
|
223 iFieldType = ( TFieldType ) aReadStream.ReadUint32L(); |
|
224 |
|
225 // read field name |
|
226 iFieldName = HBufC8::NewL( aReadStream, KDiagResultDetailBasicMaxNameLen ); |
|
227 |
|
228 switch ( Type() ) |
|
229 { |
|
230 case ETypeInt: |
|
231 iValue.iInt = aReadStream.ReadInt32L(); |
|
232 break; |
|
233 case ETypeDes16: |
|
234 iValue.iBuffer16 = HBufC16::NewL( aReadStream, |
|
235 KDiagResultDetailBasicMaxFieldValueLen ); |
|
236 break; |
|
237 case ETypeDes8: |
|
238 iValue.iBuffer8 = HBufC8::NewL( aReadStream, |
|
239 KDiagResultDetailBasicMaxFieldValueLen ); |
|
240 break; |
|
241 default: |
|
242 User::Leave( KErrCorrupt ); |
|
243 } |
|
244 } |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // CDiagResultDetailBasicItem::ExternalizeL |
|
248 // --------------------------------------------------------------------------- |
|
249 // |
|
250 void CDiagResultDetailBasicItem::ExternalizeL( RWriteStream& aWriteStream ) const |
|
251 { |
|
252 // first field id |
|
253 aWriteStream.WriteInt32L( iFieldId ); |
|
254 |
|
255 // write field Type |
|
256 aWriteStream.WriteUint32L( ( TUint )Type() ); |
|
257 |
|
258 // write field name |
|
259 aWriteStream << FieldName(); |
|
260 |
|
261 switch ( Type() ) |
|
262 { |
|
263 case ETypeInt: |
|
264 aWriteStream.WriteInt32L( iValue.iInt ); |
|
265 break; |
|
266 case ETypeDes16: |
|
267 aWriteStream << *( iValue.iBuffer16 ); |
|
268 break; |
|
269 case ETypeDes8: |
|
270 aWriteStream << *( iValue.iBuffer8 ); |
|
271 break; |
|
272 default: |
|
273 User::Leave( KErrCorrupt ); |
|
274 } |
|
275 } |
|
276 |
|
277 // End of File |
|
278 |