|
1 // Copyright (c) 2010 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 // Name : SdpBandwidthField.h |
|
15 // Part of : Local SDP Codec |
|
16 // Version : 1.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include <s32strm.h> |
|
22 #include "sdpbandwidthfield.h" |
|
23 #include "sdpcodec.pan" |
|
24 #include "_sdpdefs.h" |
|
25 #include "sdpcodecstringconstants.h" |
|
26 #include "sdputil.h" |
|
27 #include "sdpcodecconstants.h" |
|
28 #include "sdpcodecerr.h" |
|
29 #include "sdpcodecstringpool.h" |
|
30 |
|
31 // LOCAL CONSTANTS |
|
32 const TInt KLines = 1; |
|
33 const TInt KElements = 3; |
|
34 const TUint KMaxTInt64Digits = 30; |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CSdpBandwidthField::DecodeL |
|
38 // Decodes bandwidth field from TDesC |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 EXPORT_C CSdpBandwidthField* CSdpBandwidthField::DecodeL(const TDesC8& aText) |
|
42 { |
|
43 CSdpBandwidthField* obj = DecodeLC(aText); |
|
44 CleanupStack::Pop(); |
|
45 return obj; |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CSdpBandwidthField::DecodeLC |
|
50 // Decodes bandwidth field from TDesC |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 EXPORT_C CSdpBandwidthField* CSdpBandwidthField::DecodeLC(const TDesC8& aText) |
|
54 { |
|
55 CSdpBandwidthField* obj = new (ELeave) CSdpBandwidthField(); |
|
56 CleanupStack::PushL(obj); |
|
57 obj->ConstructL(aText); |
|
58 return obj; |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CSdpBandwidthField::NewL |
|
63 // Two-phased constructor |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 EXPORT_C CSdpBandwidthField* CSdpBandwidthField::NewL(RStringF aModifier, |
|
67 TUint32 aValue) |
|
68 { |
|
69 CSdpBandwidthField* obj = NewLC(aModifier, aValue); |
|
70 CleanupStack::Pop(); |
|
71 return obj; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CSdpBandwidthField::NewLC |
|
76 // Two-phased constructor |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 EXPORT_C CSdpBandwidthField* CSdpBandwidthField::NewLC(RStringF aModifier, |
|
80 TUint32 aValue) |
|
81 { |
|
82 CSdpBandwidthField* obj = new (ELeave) CSdpBandwidthField(); |
|
83 CleanupStack::PushL(obj); |
|
84 obj->ConstructL(aModifier, aValue); |
|
85 return obj; |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CSdpBandwidthField::~CSdpBandwidthField |
|
90 // Destructor |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 EXPORT_C CSdpBandwidthField::~CSdpBandwidthField() |
|
94 { |
|
95 iModifier.Close(); |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CSdpBandwidthField::EncodeL |
|
100 // Writes attributes in proper format to the stream |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 EXPORT_C void CSdpBandwidthField::EncodeL(RWriteStream& aStream) const |
|
104 { |
|
105 RStringF header = iModifier.Pool().StringF( |
|
106 SdpCodecStringConstants::EBandwidth, |
|
107 SdpCodecStringConstants::Table ); |
|
108 aStream.WriteL( header.DesC() ); |
|
109 |
|
110 aStream.WriteL( iModifier.DesC() ); |
|
111 aStream.WriteL( KColonStr ); |
|
112 |
|
113 TBuf8<KMaxTInt64Digits> number; |
|
114 number.Format( _L8("%u"), iValue ); |
|
115 aStream.WriteL( number ); |
|
116 |
|
117 aStream.WriteL( KCRLFStr ); |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CSdpBandwidthField::CloneL |
|
122 // Creates an exact copy of the bandwidth field |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 EXPORT_C CSdpBandwidthField * CSdpBandwidthField::CloneL() const |
|
126 { |
|
127 CSdpBandwidthField* obj = NewL(iModifier, iValue); |
|
128 __ASSERT_DEBUG(*this == *obj, User::Panic(KSdpCodecPanicCat, |
|
129 KSdpCodecPanicInternal)); |
|
130 return obj; |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CSdpBandwidthField::operator == |
|
135 // Checks if two bandwidth fields are equal |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 EXPORT_C TBool CSdpBandwidthField::operator == (const CSdpBandwidthField& aObj) |
|
139 const |
|
140 { |
|
141 return iModifier == aObj.iModifier && iValue == aObj.iValue; |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CSdpBandwidthField::Modifier |
|
146 // Returns bandwidth modifier |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 EXPORT_C RStringF CSdpBandwidthField::Modifier() const |
|
150 { |
|
151 return iModifier; |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CSdpBandwidthField::SetModifier |
|
156 // Set new bandwidth modifier |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 EXPORT_C void CSdpBandwidthField::SetModifier(RStringF aModifier) |
|
160 { |
|
161 iModifier.Close(); |
|
162 iModifier = aModifier.Copy(); |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CSdpBandwidthField::Value |
|
167 // Returns bandwidth value |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 EXPORT_C TUint32 CSdpBandwidthField::Value() const |
|
171 { |
|
172 return iValue; |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CSdpBandwidthField::SetValue |
|
177 // Set new bandwidth value |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 EXPORT_C void CSdpBandwidthField::SetValue(TUint32 aValue) |
|
181 { |
|
182 iValue = aValue; |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CSdpBandwidthField::ExternalizeL |
|
187 // Externalizes the object to stream |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 void CSdpBandwidthField::ExternalizeL(RWriteStream& aStream) const |
|
191 { |
|
192 aStream.WriteUint32L(iModifier.DesC().Length()); |
|
193 aStream.WriteL(iModifier.DesC(), iModifier.DesC().Length()); |
|
194 aStream.WriteUint32L(iValue); |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CSdpBandwidthField::InternalizeL |
|
199 // Internalizes the object from stream |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 CSdpBandwidthField* CSdpBandwidthField::InternalizeL(RReadStream& aStream) |
|
203 { |
|
204 TUint32 length = aStream.ReadUint32L(); |
|
205 HBufC8* modifier = HBufC8::NewLC(length); |
|
206 TPtr8 ptr(modifier->Des()); |
|
207 aStream.ReadL(ptr, length); |
|
208 |
|
209 TUint32 value = aStream.ReadUint32L(); |
|
210 |
|
211 CSdpBandwidthField* obj = new (ELeave) CSdpBandwidthField(); |
|
212 CleanupStack::PushL(obj); |
|
213 obj->ConstructL(*modifier, value); |
|
214 |
|
215 CleanupStack::PopAndDestroy(); // modifier |
|
216 CleanupStack::Pop(obj); |
|
217 return obj; |
|
218 } |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CSdpBandwidthField::CSdpBandwidthField |
|
222 // Constructor |
|
223 // ----------------------------------------------------------------------------- |
|
224 // |
|
225 CSdpBandwidthField::CSdpBandwidthField() |
|
226 { |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CSdpBandwidthField::ConstructL |
|
231 // Symbian 2nd phase constructor can leave. |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 void CSdpBandwidthField::ConstructL(const TDesC8& aText) |
|
235 { |
|
236 iStringPool = SdpCodecStringPool::StringPoolL(); |
|
237 RArray <TPtrC8> lines; |
|
238 lines = SdpUtil::DivideToLinesL(aText, KErrSdpCodecBandwidthField); |
|
239 CleanupClosePushL(lines); |
|
240 RArray<TPtrC8> bwArray; |
|
241 bwArray = SdpUtil::GetElementsFromLineL(lines[0], KColonChar, |
|
242 KErrSdpCodecBandwidthField); |
|
243 CleanupClosePushL(bwArray); |
|
244 const TDesC8& bwName = iStringPool.StringF( |
|
245 SdpCodecStringConstants::EBandwidth, |
|
246 SdpCodecStringConstants::Table).DesC(); |
|
247 |
|
248 __ASSERT_ALWAYS(lines.Count() == KLines |
|
249 && bwArray.Count() == KElements |
|
250 && bwArray[0].Find(bwName) != KErrNotFound, |
|
251 User::Leave(KErrSdpCodecBandwidthField)); |
|
252 |
|
253 CopyModifierL(bwArray[1]); |
|
254 TLex8 lexer(bwArray[2]); |
|
255 lexer.Val(iValue, EDecimal); |
|
256 |
|
257 CleanupStack::PopAndDestroy(2); //lines, bwArray |
|
258 } |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // CSdpBandwidthField::ConstructL |
|
262 // Symbian 2nd phase constructor can leave. |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 void CSdpBandwidthField::ConstructL(RStringF aModifier, TUint32 aValue) |
|
266 { |
|
267 iStringPool = SdpCodecStringPool::StringPoolL(); |
|
268 iModifier = aModifier.Copy(); |
|
269 iValue = aValue; |
|
270 } |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CSdpBandwidthField::ConstructL |
|
274 // Symbian 2nd phase constructor can leave. |
|
275 // ----------------------------------------------------------------------------- |
|
276 // |
|
277 void CSdpBandwidthField::ConstructL(const TDesC8& aModifier, TUint32 aValue) |
|
278 { |
|
279 iStringPool = SdpCodecStringPool::StringPoolL(); |
|
280 CopyModifierL(aModifier); |
|
281 iValue = aValue; |
|
282 } |
|
283 |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CSdpBandwidthField::CopyModifierL |
|
287 // Copies modifier to object after check |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 void CSdpBandwidthField::CopyModifierL(const TDesC8& aModifier) |
|
291 { |
|
292 RStringF modifierCT = iStringPool.StringF( |
|
293 SdpCodecStringConstants::EModifierCT, |
|
294 SdpCodecStringConstants::Table ); |
|
295 RStringF modifierAS = iStringPool.StringF( |
|
296 SdpCodecStringConstants::EModifierAS, |
|
297 SdpCodecStringConstants::Table ); |
|
298 |
|
299 if (modifierCT.DesC().CompareF(aModifier) == 0) |
|
300 { |
|
301 iModifier.Close(); |
|
302 iModifier = modifierCT.Copy(); |
|
303 } |
|
304 else if ( modifierAS.DesC().CompareF(aModifier) == 0) |
|
305 { |
|
306 iModifier.Close(); |
|
307 iModifier = modifierAS.Copy(); |
|
308 } |
|
309 else |
|
310 { |
|
311 iModifier.Close(); |
|
312 iModifier = iStringPool.OpenFStringL(aModifier); |
|
313 } |
|
314 } |
|
315 |
|
316 |