|
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 : SdpRepeatField.h |
|
15 // Part of : Local SDP Codec |
|
16 // Version : 1.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include <s32strm.h> |
|
22 #include "sdprepeatfield.h" |
|
23 #include "sdputil.h" |
|
24 #include "sdpcodec.pan" |
|
25 #include "_sdpdefs.h" |
|
26 #include "sdpcodecstringconstants.h" |
|
27 #include "sdpdocument.h" |
|
28 #include "sdpcodecConstants.h" |
|
29 #include "sdpcodecErr.h" |
|
30 #include "sdpcodecStringPool.h" |
|
31 |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CSdpRepeatField::DecodeL |
|
35 // Decodes bandwidth field from TDesC |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 EXPORT_C CSdpRepeatField* CSdpRepeatField::DecodeL(const TDesC8& aText) |
|
39 { |
|
40 CSdpRepeatField* obj = DecodeLC(aText); |
|
41 CleanupStack::Pop(); |
|
42 return obj; |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CSdpRepeatField::DecodeLC |
|
47 // Decodes bandwidth field from TDesC |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 EXPORT_C CSdpRepeatField* CSdpRepeatField::DecodeLC(const TDesC8& aText) |
|
51 { |
|
52 CSdpRepeatField* obj = new (ELeave) CSdpRepeatField(); |
|
53 CleanupStack::PushL(obj); |
|
54 obj->ConstructL(aText); |
|
55 return obj; |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CSdpRepeatField::NewL |
|
60 // Two-phased constructor |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 EXPORT_C CSdpRepeatField* CSdpRepeatField::NewL( |
|
64 const TSdpTypedTime aRepeatInterval, |
|
65 const TSdpTypedTime aActiveDuration, |
|
66 const RArray<TSdpTypedTime>& aOffsets) |
|
67 { |
|
68 CSdpRepeatField* obj = NewLC(aRepeatInterval, aActiveDuration, aOffsets); |
|
69 CleanupStack::Pop(); |
|
70 return obj; |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CSdpRepeatField::NewLC |
|
75 // Two-phased constructor |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 EXPORT_C CSdpRepeatField* CSdpRepeatField::NewLC( |
|
79 const TSdpTypedTime aRepeatInterval, |
|
80 const TSdpTypedTime aActiveDuration, |
|
81 const RArray<TSdpTypedTime>& aOffsets) |
|
82 { |
|
83 CSdpRepeatField* obj = new (ELeave) CSdpRepeatField(aRepeatInterval, |
|
84 aActiveDuration); |
|
85 CleanupStack::PushL(obj); |
|
86 obj->ConstructL(aOffsets); |
|
87 return obj; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CSdpRepeatField::~CSdpRepeatField |
|
92 // Destructor |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 EXPORT_C CSdpRepeatField::~CSdpRepeatField() |
|
96 { |
|
97 iTimeOffsets.Close(); |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CSdpRepeatField::EncodeL |
|
102 // Writes attributes in proper format to the stream |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 EXPORT_C void CSdpRepeatField::EncodeL(RWriteStream& aStream) const |
|
106 { |
|
107 const TDesC8& repeatName = iPool.StringF(SdpCodecStringConstants::ERepeat, |
|
108 SdpCodecStringConstants::Table).DesC(); |
|
109 aStream.WriteL(repeatName); |
|
110 iRepeatInterval.EncodeL(aStream); |
|
111 aStream.WriteL(KSPStr); |
|
112 iActiveDuration.EncodeL(aStream); |
|
113 for (TInt i = 0; i < iTimeOffsets.Count(); i++) |
|
114 { |
|
115 aStream.WriteL(KSPStr); |
|
116 (iTimeOffsets)[i].EncodeL(aStream); |
|
117 } |
|
118 aStream.WriteL(KCRLFStr); |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CSdpRepeatField::CloneL |
|
123 // Creates an exact copy of the repeat field |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 EXPORT_C CSdpRepeatField* CSdpRepeatField::CloneL() const |
|
127 { |
|
128 __TEST_INVARIANT; |
|
129 CSdpRepeatField* obj = NewL(iRepeatInterval, iActiveDuration, |
|
130 iTimeOffsets); |
|
131 __ASSERT_DEBUG(*this == *obj, User::Panic(KSdpCodecPanicCat, |
|
132 KSdpCodecPanicInternal)); |
|
133 return obj; |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CSdpRepeatField::operator == |
|
138 // Checks if two repeat fields are equal |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 EXPORT_C TBool CSdpRepeatField::operator == (const CSdpRepeatField & aObj) |
|
142 const |
|
143 { |
|
144 __TEST_INVARIANT; |
|
145 TBool result = iRepeatInterval == aObj.iRepeatInterval |
|
146 && iActiveDuration == aObj.iActiveDuration |
|
147 && iTimeOffsets.Count() == (aObj.iTimeOffsets).Count(); |
|
148 if (result) |
|
149 { |
|
150 int i = 0; |
|
151 while (result && i < iTimeOffsets.Count()) |
|
152 { |
|
153 result = (iTimeOffsets)[i] == (aObj.iTimeOffsets)[i]; |
|
154 i++; |
|
155 } |
|
156 } |
|
157 return result; |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CSdpRepeatField::RepeatInterval |
|
162 // Return repeat interval value |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 EXPORT_C const TSdpTypedTime CSdpRepeatField::RepeatInterval() const |
|
166 { |
|
167 __TEST_INVARIANT; |
|
168 return iRepeatInterval; |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CSdpRepeatField::SetRepeatIntervalL |
|
173 // Sets repeat interval to one of predefined values |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 EXPORT_C void CSdpRepeatField::SetRepeatIntervalL(const TSdpTypedTime aValue) |
|
177 { |
|
178 __TEST_INVARIANT; |
|
179 __ASSERT_ALWAYS(aValue.iValue > 0, User::Leave(KErrSdpCodecRepeatField)); |
|
180 iRepeatInterval = aValue; |
|
181 __TEST_INVARIANT; |
|
182 } |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CSdpRepeatField::ActiveDuration |
|
186 // Returns active duration value |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 EXPORT_C const TSdpTypedTime CSdpRepeatField::ActiveDuration() const |
|
190 { |
|
191 __TEST_INVARIANT; |
|
192 return iActiveDuration; |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CSdpRepeatField::SetActiveDuration |
|
197 // Sets new active duration value |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 EXPORT_C void CSdpRepeatField::SetActiveDuration(const TSdpTypedTime aValue) |
|
201 { |
|
202 __TEST_INVARIANT; |
|
203 iActiveDuration = aValue; |
|
204 __TEST_INVARIANT; |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CSdpRepeatField::TimeOffsets |
|
209 // CReturns timeoffsets |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 EXPORT_C const RArray<TSdpTypedTime>& CSdpRepeatField::TimeOffsets() const |
|
213 { |
|
214 __TEST_INVARIANT; |
|
215 return iTimeOffsets; |
|
216 } |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // CSdpRepeatField::SetTimeOffsetsL |
|
220 // Sets timeoffsets |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 EXPORT_C void CSdpRepeatField::SetTimeOffsetsL( |
|
224 const RArray<TSdpTypedTime>& aValue) |
|
225 { |
|
226 RArray<TSdpTypedTime> tempOffsets; |
|
227 if (aValue.Count() > 0) |
|
228 { |
|
229 CleanupClosePushL( tempOffsets ); |
|
230 for (TInt i = 0; i < aValue.Count(); i++) |
|
231 { |
|
232 User::LeaveIfError(tempOffsets.Append(aValue[i])); |
|
233 } |
|
234 CleanupStack::Pop(); // tempOffsets |
|
235 iTimeOffsets.Close(); |
|
236 iTimeOffsets = tempOffsets; |
|
237 } |
|
238 else |
|
239 { |
|
240 // remove old timeoffsets |
|
241 iTimeOffsets.Reset(); |
|
242 } |
|
243 } |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CSdpRepeatField::ExternalizeL |
|
247 // Externalizes the object to stream |
|
248 // ----------------------------------------------------------------------------- |
|
249 // |
|
250 void CSdpRepeatField::ExternalizeL(RWriteStream& aStream) const |
|
251 { |
|
252 iRepeatInterval.ExternalizeL(aStream); |
|
253 iActiveDuration.ExternalizeL(aStream); |
|
254 aStream.WriteUint32L(iTimeOffsets.Count()); |
|
255 for (TInt i = 0; i < iTimeOffsets.Count(); i++) |
|
256 { |
|
257 (iTimeOffsets)[i].ExternalizeL(aStream); |
|
258 } |
|
259 } |
|
260 |
|
261 // ----------------------------------------------------------------------------- |
|
262 // CSdpRepeatField::InternalizeL |
|
263 // Internalizes the object from stream |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 CSdpRepeatField* CSdpRepeatField::InternalizeL(RReadStream& aStream) |
|
267 { |
|
268 const TSdpTypedTime repeatInterval = TSdpTypedTime::InternalizeL(aStream); |
|
269 TSdpTypedTime activeDuration = TSdpTypedTime::InternalizeL(aStream); |
|
270 TUint32 offsetsCount = aStream.ReadUint32L(); |
|
271 RArray<TSdpTypedTime> offsets; |
|
272 CleanupClosePushL(offsets); |
|
273 |
|
274 if (offsetsCount > 0) |
|
275 { |
|
276 for (TUint i = 0; i < offsetsCount; i++) |
|
277 { |
|
278 User::LeaveIfError(offsets.Append( |
|
279 TSdpTypedTime::InternalizeL(aStream))); |
|
280 } |
|
281 |
|
282 } |
|
283 |
|
284 CSdpRepeatField* obj = CSdpRepeatField::NewL(repeatInterval, |
|
285 activeDuration, offsets); |
|
286 |
|
287 CleanupStack::PopAndDestroy(); // offsets |
|
288 return obj; |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // CSdpRepeatField::CSdpRepeatField |
|
293 // Constructor |
|
294 // ----------------------------------------------------------------------------- |
|
295 // |
|
296 CSdpRepeatField::CSdpRepeatField(const TSdpTypedTime aRepeatInterval, |
|
297 const TSdpTypedTime aActiveDuration) |
|
298 : iRepeatInterval(aRepeatInterval), iActiveDuration(aActiveDuration) |
|
299 { |
|
300 } |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CSdpRepeatField::CSdpRepeatField |
|
304 // Constructor |
|
305 // ----------------------------------------------------------------------------- |
|
306 // |
|
307 CSdpRepeatField::CSdpRepeatField() |
|
308 { |
|
309 } |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CSdpRepeatField::ConstructL |
|
313 // Symbian 2nd phase constructor can leave. |
|
314 // ----------------------------------------------------------------------------- |
|
315 // |
|
316 void CSdpRepeatField::ConstructL(const TDesC8& aText) |
|
317 { |
|
318 iPool = SdpCodecStringPool::StringPoolL(); |
|
319 RArray <TPtrC8> lines; |
|
320 lines = SdpUtil::DivideToLinesL(aText, KErrSdpCodecRepeatField); |
|
321 CleanupClosePushL(lines); |
|
322 RArray<TPtrC8> repeatArray; |
|
323 repeatArray = SdpUtil::GetElementsFromLineL(lines[0], |
|
324 KErrSdpCodecRepeatField); |
|
325 CleanupClosePushL(repeatArray); |
|
326 const TDesC8& repeatName = iPool.StringF(SdpCodecStringConstants::ERepeat, |
|
327 SdpCodecStringConstants::Table).DesC(); |
|
328 __ASSERT_ALWAYS(lines.Count() == 1 |
|
329 && repeatArray.Count() >= 3 |
|
330 && repeatName.CompareF(repeatArray[0]) == 0, |
|
331 User::Leave(KErrSdpCodecRepeatField)); |
|
332 |
|
333 // repeat interval |
|
334 __ASSERT_ALWAYS(TLex8(repeatArray[1]).Peek() != '0', |
|
335 User::Leave(KErrSdpCodecRepeatField)); |
|
336 iRepeatInterval = TSdpTypedTime::DecodeL(repeatArray[1]); |
|
337 |
|
338 // active duration |
|
339 iActiveDuration = TSdpTypedTime::DecodeL(repeatArray[2]); |
|
340 |
|
341 if (repeatArray.Count() > 3) |
|
342 { |
|
343 for (TInt i = 3; i < repeatArray.Count(); i++) |
|
344 { |
|
345 User::LeaveIfError(iTimeOffsets.Append( |
|
346 TSdpTypedTime::DecodeL(repeatArray[i]))); |
|
347 } |
|
348 } |
|
349 CleanupStack::PopAndDestroy(2); // lines, repeatArray |
|
350 __TEST_INVARIANT; |
|
351 } |
|
352 |
|
353 // ----------------------------------------------------------------------------- |
|
354 // CSdpRepeatField::ConstructL |
|
355 // Symbian 2nd phase constructor can leave. |
|
356 // ----------------------------------------------------------------------------- |
|
357 // |
|
358 void CSdpRepeatField::ConstructL(const RArray<TSdpTypedTime>& aOffsets) |
|
359 { |
|
360 __ASSERT_ALWAYS(iRepeatInterval.iValue > 0, |
|
361 User::Leave(KErrSdpCodecRepeatField)); |
|
362 iPool = SdpCodecStringPool::StringPoolL(); |
|
363 if (aOffsets.Count() > 0) |
|
364 { |
|
365 for (TInt i = 0; i < aOffsets.Count(); i++) |
|
366 { |
|
367 User::LeaveIfError(iTimeOffsets.Append(aOffsets[i])); |
|
368 } |
|
369 } |
|
370 __TEST_INVARIANT; |
|
371 } |
|
372 |
|
373 // ----------------------------------------------------------------------------- |
|
374 // CSdpRepeatField::__DbgTestInvariant |
|
375 // Test invariant |
|
376 // ----------------------------------------------------------------------------- |
|
377 // |
|
378 void CSdpRepeatField::__DbgTestInvariant() const |
|
379 { |
|
380 TBool invariant = iRepeatInterval.iValue > 0; |
|
381 if (!invariant) |
|
382 User::Invariant(); |
|
383 } |
|
384 |
|
385 |