|
1 // Copyright (c) 2003-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 // Name : SdpFmtAttributeField.h |
|
15 // Part of : SDP Codec |
|
16 // Version : 1.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include <s32mem.h> |
|
22 #include "SdpFmtAttributeField.h" |
|
23 #include "SdpAttributeField.h" |
|
24 #include "SdpRtpmapValue.h" |
|
25 #include "SdpUtil.h" |
|
26 #include "SdpCodecConstants.h" |
|
27 #include "SdpCodecStringPool.h" |
|
28 #include "SdpCodecErr.h" |
|
29 #include "SDPCodec.pan" |
|
30 #include "_sdpdefs.h" |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS =============================== |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CSdpFmtAttributeField::CSdpFmtAttributeField |
|
36 // C++ default constructor can NOT contain any code, that |
|
37 // might leave. |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 CSdpFmtAttributeField::CSdpFmtAttributeField() |
|
41 : iFormat ( KNullDesC8() ), iValuePart( KNullDesC8() ) |
|
42 { |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CSdpFmtAttributeField::ConstructL |
|
47 // Symbian 2nd phase constructor can leave. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 void CSdpFmtAttributeField::ConstructL( |
|
51 const TDesC8& aText ) |
|
52 { |
|
53 iPool = SdpCodecStringPool::StringPoolL(); |
|
54 |
|
55 iAttributeField = CSdpAttributeField::DecodeL( aText ); |
|
56 FormatValueParamsL( iAttributeField ); |
|
57 __TEST_INVARIANT; |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CSdpFmtAttributeField::ConstructL |
|
62 // Symbian 2nd phase constructor can leave. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 void CSdpFmtAttributeField::ConstructL( RStringF aAttribute, |
|
66 const TDesC8& aFormat, |
|
67 const TDesC8& aValue ) |
|
68 { |
|
69 iPool = SdpCodecStringPool::StringPoolL(); |
|
70 |
|
71 TInt length = aFormat.Length() + aValue.Length() + KSPStr().Length(); |
|
72 HBufC8* text = HBufC8::NewLC( length ); |
|
73 text->Des().Copy( aFormat ); |
|
74 if ( aValue.Length() > 0 ) |
|
75 { |
|
76 text->Des().Append( KSPStr ); |
|
77 text->Des().Append( aValue ); |
|
78 } |
|
79 |
|
80 iAttributeField = CSdpAttributeField::NewL( aAttribute, *text ); |
|
81 CleanupStack::PopAndDestroy(); //text |
|
82 |
|
83 FormatValueParamsL( iAttributeField ); |
|
84 __TEST_INVARIANT; |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CSdpFmtAttributeField::DecodeL |
|
89 // Two-phased constructor |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 EXPORT_C CSdpFmtAttributeField* CSdpFmtAttributeField::DecodeL( |
|
93 const TDesC8& aText ) |
|
94 { |
|
95 CSdpFmtAttributeField* field = |
|
96 CSdpFmtAttributeField::DecodeLC( aText ); |
|
97 CleanupStack::Pop(); // field |
|
98 return field; |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CSdpFmtAttributeField::DecodeLC |
|
103 // Two-phased constructor |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 EXPORT_C CSdpFmtAttributeField* CSdpFmtAttributeField::DecodeLC( |
|
107 const TDesC8& aText ) |
|
108 { |
|
109 CSdpFmtAttributeField* field = new ( ELeave ) CSdpFmtAttributeField; |
|
110 CleanupStack::PushL( field ); |
|
111 field->ConstructL( aText ); |
|
112 return field; |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CSdpFmtAttributeField::NewL |
|
117 // Two-phased constructor |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 EXPORT_C CSdpFmtAttributeField* CSdpFmtAttributeField::NewL( |
|
121 RStringF aAttribute, |
|
122 const TDesC8& aFormat, |
|
123 const TDesC8& aValue ) |
|
124 { |
|
125 CSdpFmtAttributeField* field = |
|
126 CSdpFmtAttributeField::NewLC( aAttribute, aFormat, aValue ); |
|
127 CleanupStack::Pop(); // field |
|
128 return field; |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CSdpFmtAttributeField::NewLC |
|
133 // Two-phased constructor |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 EXPORT_C CSdpFmtAttributeField* CSdpFmtAttributeField::NewLC( |
|
137 RStringF aAttribute, |
|
138 const TDesC8& aFormat, |
|
139 const TDesC8& aValue ) |
|
140 { |
|
141 CSdpFmtAttributeField* field = new ( ELeave ) CSdpFmtAttributeField; |
|
142 CleanupStack::PushL( field ); |
|
143 field->ConstructL( aAttribute, aFormat, aValue ); |
|
144 return field; |
|
145 } |
|
146 |
|
147 // Destructor |
|
148 EXPORT_C CSdpFmtAttributeField::~CSdpFmtAttributeField() |
|
149 { |
|
150 delete iAttributeField; |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CSdpFmtAttributeField::EncodeL |
|
155 // Encodes the string to a proper message format |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 EXPORT_C void CSdpFmtAttributeField::EncodeL( RWriteStream& aStream ) const |
|
159 { |
|
160 __TEST_INVARIANT; |
|
161 iAttributeField->EncodeL( aStream ); |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CSdpFmtAttributeField::CloneL |
|
166 // Creates an exact copy of the object |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 EXPORT_C CSdpFmtAttributeField* CSdpFmtAttributeField::CloneL() const |
|
170 { |
|
171 __TEST_INVARIANT; |
|
172 |
|
173 CSdpFmtAttributeField* obj = |
|
174 CSdpFmtAttributeField::NewL( iAttributeField->Attribute(), |
|
175 Format(), Value() ); |
|
176 |
|
177 __ASSERT_DEBUG( *obj == *this, |
|
178 User::Panic( KSdpCodecPanicCat, KSdpCodecPanicInternal ) ); |
|
179 |
|
180 return obj; |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CSdpFmtAttributeField::operator== |
|
185 // Creates an exact copy of the object |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 EXPORT_C TBool CSdpFmtAttributeField::operator==( |
|
189 const CSdpFmtAttributeField& aObj ) const |
|
190 { |
|
191 __TEST_INVARIANT; |
|
192 |
|
193 return ( *iAttributeField == *(aObj.AttributeField()) |
|
194 && iFormat.Compare(aObj.Format()) == 0 |
|
195 && iValuePart.Compare(aObj.Value()) == 0); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CSdpFmtAttributeField::Attribute |
|
200 // Returns attribute field |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 EXPORT_C RStringF CSdpFmtAttributeField::Attribute() const |
|
204 { |
|
205 __TEST_INVARIANT; |
|
206 return iAttributeField->Attribute(); |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CSdpFmtAttributeField::Format |
|
211 // Returns Format |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 EXPORT_C const TDesC8& CSdpFmtAttributeField::Format() const |
|
215 { |
|
216 __TEST_INVARIANT; |
|
217 |
|
218 return iFormat; |
|
219 } |
|
220 |
|
221 // ----------------------------------------------------------------------------- |
|
222 // CSdpFmtAttributeField::Value |
|
223 // Returns Format value |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 EXPORT_C const TDesC8& CSdpFmtAttributeField::Value() const |
|
227 { |
|
228 __TEST_INVARIANT; |
|
229 return iValuePart; |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CSdpFmtAttributeField::SetL |
|
234 // Sets new format attribute |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 EXPORT_C void CSdpFmtAttributeField::SetL( RStringF aAttribute, |
|
238 const TDesC8& aFormat, |
|
239 const TDesC8& aValue ) |
|
240 { |
|
241 __TEST_INVARIANT; |
|
242 |
|
243 TInt length = aFormat.Length() + aValue.Length() + KSPStr().Length(); |
|
244 HBufC8* txt = HBufC8::NewLC( length ); |
|
245 txt->Des().Copy( aFormat ); |
|
246 if ( aValue.Length() > 0 ) |
|
247 { |
|
248 txt->Des().Append( KSPStr ); |
|
249 txt->Des().Append( aValue ); |
|
250 } |
|
251 |
|
252 CSdpAttributeField* attrFld = CSdpAttributeField::NewL(aAttribute, *txt); |
|
253 CleanupStack::PopAndDestroy(); //txt |
|
254 |
|
255 delete iAttributeField; |
|
256 iAttributeField = attrFld; |
|
257 |
|
258 FormatValueParamsL( iAttributeField ); |
|
259 |
|
260 __TEST_INVARIANT; |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CSdpFmtAttributeField::ExternalizeL |
|
265 // Externalizes object to stream |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 void CSdpFmtAttributeField::ExternalizeL( RWriteStream& aStream ) const |
|
269 { |
|
270 __TEST_INVARIANT; |
|
271 |
|
272 iAttributeField->ExternalizeL( aStream ); |
|
273 } |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // CSdpFmtAttributeField::InternalizeL |
|
277 // Internalizes object from stream |
|
278 // ----------------------------------------------------------------------------- |
|
279 // |
|
280 CSdpFmtAttributeField* CSdpFmtAttributeField::InternalizeL( |
|
281 RReadStream& aStream ) |
|
282 { |
|
283 CSdpFmtAttributeField* obj = new ( ELeave ) CSdpFmtAttributeField(); |
|
284 CleanupStack::PushL( obj ); |
|
285 obj->DoInternalizeL( aStream ); |
|
286 CleanupStack::Pop(); |
|
287 |
|
288 return obj; |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // CSdpFmtAttributeField::DoInternalizeL |
|
293 // Does the "2nd phase construction" of internalization |
|
294 // ----------------------------------------------------------------------------- |
|
295 // |
|
296 void CSdpFmtAttributeField::DoInternalizeL( RReadStream& aStream ) |
|
297 { |
|
298 iPool = SdpCodecStringPool::StringPoolL(); |
|
299 iAttributeField = CSdpAttributeField::InternalizeL( aStream ); |
|
300 FormatValueParamsL( iAttributeField ); |
|
301 } |
|
302 |
|
303 // ----------------------------------------------------------------------------- |
|
304 // CSdpFmtAttributeField::AttributeField |
|
305 // Returns attribute field |
|
306 // ----------------------------------------------------------------------------- |
|
307 // |
|
308 const CSdpAttributeField* CSdpFmtAttributeField::AttributeField() const |
|
309 { |
|
310 __TEST_INVARIANT; |
|
311 return iAttributeField; |
|
312 } |
|
313 |
|
314 // ----------------------------------------------------------------------------- |
|
315 // CSdpFmtAttributeField::FormatValueParamsL |
|
316 // Formats value parameters |
|
317 // ----------------------------------------------------------------------------- |
|
318 // |
|
319 void CSdpFmtAttributeField::FormatValueParamsL( CSdpAttributeField* aField ) |
|
320 { |
|
321 __ASSERT_ALWAYS (aField->Attribute() == |
|
322 iPool.StringF( SdpCodecStringConstants::EAttributeFmtp, |
|
323 SdpCodecStringConstants::Table ) |
|
324 || aField->Attribute() == |
|
325 iPool.StringF( SdpCodecStringConstants::EAttributeRtpmap, |
|
326 SdpCodecStringConstants::Table ), |
|
327 User::Leave( KErrSdpCodecMediaAttributeField )); |
|
328 DecodeFormatL( aField->Value() ); |
|
329 if ( iValuePart.Length() == 0 && |
|
330 aField->Attribute() == |
|
331 iPool.StringF( SdpCodecStringConstants::EAttributeRtpmap, |
|
332 SdpCodecStringConstants::Table )) |
|
333 { |
|
334 User::Leave( KErrSdpCodecMediaAttributeField ); |
|
335 } |
|
336 } |
|
337 |
|
338 |
|
339 // ----------------------------------------------------------------------------- |
|
340 // CSdpFmtAttributeField::DecodeFormatL |
|
341 // Decodes format parameter from string |
|
342 // ----------------------------------------------------------------------------- |
|
343 // |
|
344 void CSdpFmtAttributeField::DecodeFormatL( const TDesC8& aText ) |
|
345 { |
|
346 __ASSERT_ALWAYS( aText.Length() > 0, |
|
347 User::Leave( KErrSdpCodecAttributeField ) ); |
|
348 |
|
349 TInt pos = aText.Locate( KSPChar ); |
|
350 |
|
351 if ( pos == 0 ) |
|
352 { |
|
353 User::Leave( KErrSdpCodecAttributeField ); |
|
354 } |
|
355 |
|
356 if ( pos > 0 ) |
|
357 { |
|
358 iFormat.Set( aText.Left( pos ) ); |
|
359 |
|
360 TPtrC8 formatParameters( aText.Right( aText.Length() - pos - 1 ) ); |
|
361 |
|
362 if ( formatParameters.Length() > 0 ) |
|
363 { |
|
364 iValuePart.Set( formatParameters ); |
|
365 } |
|
366 else |
|
367 { |
|
368 iValuePart.Set( KNullDesC8 ); |
|
369 } |
|
370 } |
|
371 else |
|
372 { |
|
373 // No format parameters |
|
374 iFormat.Set( aText ); |
|
375 iValuePart.Set( KNullDesC8 ); |
|
376 } |
|
377 } |
|
378 |
|
379 // For DEBUG builds |
|
380 // ----------------------------------------------------------------------------- |
|
381 // CSdpFmtAttributeField::__DbgTestInvariant |
|
382 // Test invariant |
|
383 // ----------------------------------------------------------------------------- |
|
384 // |
|
385 void CSdpFmtAttributeField::__DbgTestInvariant() const |
|
386 { |
|
387 TBool invariant = iAttributeField != NULL; |
|
388 |
|
389 if ( !invariant ) |
|
390 { |
|
391 User::Invariant(); |
|
392 } |
|
393 } |