|
1 /* |
|
2 * Copyright (c) 2006 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: Light weight version of UpnpObject |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 #include "upnpobjectlite.h" |
|
24 |
|
25 const TInt KDelimeter = 46; |
|
26 const TInt KRound1 = 1; |
|
27 const TInt KRound2 = 2; |
|
28 const TInt KRound3 = 3; |
|
29 const TInt KRound4 = 4; |
|
30 |
|
31 const TInt KMask1 = 0xFF000000; |
|
32 const TInt KMask2 = 0x00FF0000; |
|
33 |
|
34 _LIT8( KObject, "object" ); |
|
35 _LIT8( KItem, "item" ); |
|
36 _LIT8( KContainer,"container" ); |
|
37 |
|
38 _LIT8( KImageItem, "imageItem" ); |
|
39 _LIT8( KAudioItem, "audioItem" ); |
|
40 _LIT8( KVideoItem, "videoItem" ); |
|
41 _LIT8( KPlaylistItem, "playlistItem" ); |
|
42 _LIT8( KStorageFolder, "storageFolder" ); |
|
43 _LIT8( KPlaylistContainer, "playlistContainer" ); |
|
44 |
|
45 _LIT8( KMusicTrack,"musicTrack" ); |
|
46 _LIT8( KPhoto,"photo" ); |
|
47 _LIT8( KVideo,"video" ); |
|
48 _LIT8( KMusicAlbum,"musicAlbum" ); |
|
49 |
|
50 |
|
51 // -------------------------------------------------------------------------- |
|
52 // CUpnpObjectLite::CUpnpObjectLite |
|
53 // See upnpobjectlite.h |
|
54 // -------------------------------------------------------------------------- |
|
55 CUpnpObjectLite::CUpnpObjectLite() |
|
56 { |
|
57 } |
|
58 |
|
59 // -------------------------------------------------------------------------- |
|
60 // CUpnpObjectLite::~CUpnpObjectLite |
|
61 // See upnpobjectlite.h |
|
62 // -------------------------------------------------------------------------- |
|
63 EXPORT_C CUpnpObjectLite::~CUpnpObjectLite() |
|
64 { |
|
65 delete iObjectId; |
|
66 delete iTitle; |
|
67 } |
|
68 |
|
69 // -------------------------------------------------------------------------- |
|
70 // CUpnpObjectLite::NewL |
|
71 // See upnpobjectlite.h |
|
72 // -------------------------------------------------------------------------- |
|
73 void CUpnpObjectLite::ConstructL() |
|
74 { |
|
75 |
|
76 } |
|
77 |
|
78 // -------------------------------------------------------------------------- |
|
79 // CUpnpObjectLite::NewL |
|
80 // See upnpobjectlite.h |
|
81 // -------------------------------------------------------------------------- |
|
82 EXPORT_C CUpnpObjectLite* CUpnpObjectLite::NewL() |
|
83 { |
|
84 CUpnpObjectLite* self = new (ELeave) CUpnpObjectLite(); |
|
85 CleanupStack::PushL(self); |
|
86 self->ConstructL(); |
|
87 CleanupStack::Pop( self ); |
|
88 return self; |
|
89 } |
|
90 |
|
91 // -------------------------------------------------------------------------- |
|
92 // CUpnpObjectLite::SetObjectIdL |
|
93 // See upnpobjectlite.h |
|
94 // -------------------------------------------------------------------------- |
|
95 EXPORT_C void CUpnpObjectLite::SetObjectIdL( const TDesC8& aObjectId ) |
|
96 { |
|
97 HBufC8* tmp = aObjectId.AllocL(); |
|
98 delete iObjectId; |
|
99 iObjectId = tmp; |
|
100 } |
|
101 |
|
102 |
|
103 // -------------------------------------------------------------------------- |
|
104 // CUpnpObjectLite::SetObjectIdL |
|
105 // See upnpobjectlite.h |
|
106 // -------------------------------------------------------------------------- |
|
107 EXPORT_C void CUpnpObjectLite::SetObjectIdL( HBufC8* aObjectId ) |
|
108 { |
|
109 if( aObjectId ) |
|
110 { |
|
111 delete iObjectId; |
|
112 iObjectId = aObjectId; |
|
113 } |
|
114 else |
|
115 { |
|
116 User::Leave( KErrArgument ); |
|
117 } |
|
118 } |
|
119 |
|
120 // -------------------------------------------------------------------------- |
|
121 // CUpnpObjectLite::ObjectId |
|
122 // See upnpobjectlite.h |
|
123 // -------------------------------------------------------------------------- |
|
124 EXPORT_C const TDesC8& CUpnpObjectLite::ObjectId() const |
|
125 { |
|
126 if( iObjectId ) |
|
127 { |
|
128 return *iObjectId; |
|
129 } |
|
130 else |
|
131 { |
|
132 return KNullDesC8; |
|
133 } |
|
134 } |
|
135 |
|
136 // -------------------------------------------------------------------------- |
|
137 // CUpnpObjectLite::SetTitleL |
|
138 // See upnpobjectlite.h |
|
139 // -------------------------------------------------------------------------- |
|
140 EXPORT_C void CUpnpObjectLite::SetTitleL( const TDesC& aTitle ) |
|
141 { |
|
142 HBufC* tmp = aTitle.AllocL(); |
|
143 delete iTitle; |
|
144 iTitle = tmp; |
|
145 } |
|
146 |
|
147 // -------------------------------------------------------------------------- |
|
148 // CUpnpObjectLite::SetTitleL |
|
149 // See upnpobjectlite.h |
|
150 // -------------------------------------------------------------------------- |
|
151 EXPORT_C void CUpnpObjectLite::SetTitleL( HBufC* aTitle ) |
|
152 { |
|
153 if( aTitle ) |
|
154 { |
|
155 delete iTitle; |
|
156 iTitle = aTitle; |
|
157 } |
|
158 else |
|
159 { |
|
160 User::Leave( KErrArgument ); |
|
161 } |
|
162 } |
|
163 |
|
164 // -------------------------------------------------------------------------- |
|
165 // CUpnpObjectLite::Title |
|
166 // See upnpobjectlite.h |
|
167 // -------------------------------------------------------------------------- |
|
168 EXPORT_C const TDesC& CUpnpObjectLite::Title() const |
|
169 { |
|
170 if( iTitle ) |
|
171 { |
|
172 return *iTitle; |
|
173 } |
|
174 else |
|
175 { |
|
176 return KNullDesC; |
|
177 } |
|
178 } |
|
179 |
|
180 // -------------------------------------------------------------------------- |
|
181 // CUpnpObjectLite::SetObjectClass |
|
182 // See upnpobjectlite.h |
|
183 // -------------------------------------------------------------------------- |
|
184 EXPORT_C void CUpnpObjectLite::SetObjectClass( const TDesC8& aObjectClass ) |
|
185 { |
|
186 iObjectClass = 0; |
|
187 TInt round = 0; |
|
188 |
|
189 TLex8 input( aObjectClass ); |
|
190 while( !input.Eos() ) |
|
191 { |
|
192 round++; |
|
193 ParseToDelimeter( input, TChar( KDelimeter ) ); |
|
194 |
|
195 HandleRound( round, input.MarkedToken() ); |
|
196 |
|
197 if( !input.Eos() ) |
|
198 { |
|
199 input.SkipAndMark( 1 ); // Skip the delimeter |
|
200 } |
|
201 } |
|
202 |
|
203 } |
|
204 |
|
205 // -------------------------------------------------------------------------- |
|
206 // CUpnpObjectLite::IsTypeOf |
|
207 // See upnpobjectlite.h |
|
208 // -------------------------------------------------------------------------- |
|
209 EXPORT_C TBool CUpnpObjectLite::IsTypeOf( TObjectType aType ) const |
|
210 { |
|
211 TBool retVal = EFalse; |
|
212 switch( aType ) |
|
213 { |
|
214 case EItem: |
|
215 { |
|
216 if( ( iObjectClass & KMask1 ) == EBaseItem ) |
|
217 { |
|
218 retVal = ETrue; |
|
219 } |
|
220 } |
|
221 break; |
|
222 case EContainer: |
|
223 { |
|
224 if( ( iObjectClass & KMask1 ) == EBaseContainer ) |
|
225 { |
|
226 retVal = ETrue; |
|
227 } |
|
228 } |
|
229 break; |
|
230 case EMusicItem: |
|
231 { |
|
232 if( ( iObjectClass & KMask2 ) == EBaseMusicItem ) |
|
233 { |
|
234 retVal = ETrue; |
|
235 } |
|
236 } |
|
237 break; |
|
238 case EImageItem: |
|
239 { |
|
240 if( ( iObjectClass & KMask2 ) == EBaseImageItem ) |
|
241 { |
|
242 retVal = ETrue; |
|
243 } |
|
244 } |
|
245 break; |
|
246 case EVideoItem: |
|
247 { |
|
248 if( ( iObjectClass & KMask2 ) == EBaseVideoItem ) |
|
249 { |
|
250 retVal = ETrue; |
|
251 } |
|
252 } |
|
253 break; |
|
254 default: |
|
255 { |
|
256 retVal = EFalse; |
|
257 } |
|
258 break; |
|
259 } |
|
260 |
|
261 return retVal; |
|
262 } |
|
263 |
|
264 // -------------------------------------------------------------------------- |
|
265 // CUpnpObjectLite::ParseToDelimeter |
|
266 // See upnpobjectlite.h |
|
267 // -------------------------------------------------------------------------- |
|
268 void CUpnpObjectLite::ParseToDelimeter( TLex8& aLex, TChar aDelimeter ) const |
|
269 { |
|
270 aLex.Mark(); |
|
271 while( (aLex.Peek() != aDelimeter) && (!aLex.Eos()) ) |
|
272 { |
|
273 aLex.Inc(); |
|
274 } |
|
275 } |
|
276 |
|
277 // -------------------------------------------------------------------------- |
|
278 // CUpnpObjectLite::HandleRound |
|
279 // See upnpobjectlite.h |
|
280 // -------------------------------------------------------------------------- |
|
281 void CUpnpObjectLite::HandleRound( TInt aRound, TPtrC8 aString ) |
|
282 { |
|
283 switch( aRound ) |
|
284 { |
|
285 case KRound1: |
|
286 { |
|
287 Round1( aString ); |
|
288 break; |
|
289 } |
|
290 case KRound2: |
|
291 { |
|
292 Round2( aString ); |
|
293 break; |
|
294 } |
|
295 case KRound3: |
|
296 { |
|
297 Round3( aString ); |
|
298 break; |
|
299 } |
|
300 case KRound4: |
|
301 { |
|
302 Round4( aString ); |
|
303 break; |
|
304 } |
|
305 |
|
306 default: |
|
307 { |
|
308 |
|
309 break; |
|
310 } |
|
311 } |
|
312 } |
|
313 |
|
314 void CUpnpObjectLite::Round1( TPtrC8 aString ) |
|
315 { |
|
316 if( aString.Compare( KObject ) != 0 ) |
|
317 { |
|
318 // Not an object |
|
319 iObjectClass |= EBaseUnknown; |
|
320 } |
|
321 } |
|
322 |
|
323 void CUpnpObjectLite::Round2( TPtrC8 aString ) |
|
324 { |
|
325 if( aString.Compare( KItem ) == 0 ) |
|
326 { |
|
327 iObjectClass |= EBaseItem; |
|
328 } |
|
329 else if( aString.Compare( KContainer ) == 0 ) |
|
330 { |
|
331 iObjectClass |= EBaseContainer; |
|
332 } |
|
333 else |
|
334 { |
|
335 iObjectClass |= EBaseUnknown; |
|
336 } |
|
337 } |
|
338 |
|
339 void CUpnpObjectLite::Round3( TPtrC8 aString ) |
|
340 { |
|
341 if( aString.Compare( KImageItem ) == 0 ) |
|
342 { |
|
343 iObjectClass |= EBaseImageItem; |
|
344 } |
|
345 else if( aString.Compare( KAudioItem ) == 0 ) |
|
346 { |
|
347 iObjectClass |= EBaseMusicItem; |
|
348 } |
|
349 else if( aString.Compare( KVideoItem ) == 0 ) |
|
350 { |
|
351 iObjectClass |= EBaseVideoItem; |
|
352 } |
|
353 else if( aString.Compare( KPlaylistItem ) == 0 ) |
|
354 { |
|
355 iObjectClass |= EBasePlaylistItem; |
|
356 } |
|
357 else if( aString.Compare( KStorageFolder ) == 0 ) |
|
358 { |
|
359 iObjectClass |= EStorageFolder; |
|
360 } |
|
361 else if( aString.Compare( KPlaylistContainer ) == 0 ) |
|
362 { |
|
363 iObjectClass |= EPlaylistContainer; |
|
364 } |
|
365 else |
|
366 { |
|
367 |
|
368 } |
|
369 } |
|
370 |
|
371 void CUpnpObjectLite::Round4( TPtrC8 aString ) |
|
372 { |
|
373 if( aString.Compare( KMusicTrack ) == 0 ) |
|
374 { |
|
375 iObjectClass |= EMusicTrack; |
|
376 } |
|
377 else if( aString.Compare( KPhoto ) == 0 ) |
|
378 { |
|
379 iObjectClass |= EPhoto; |
|
380 } |
|
381 else if( aString.Compare( KVideo ) == 0 ) |
|
382 { |
|
383 iObjectClass |= EMovie; |
|
384 } |
|
385 else if( aString.Compare( KMusicAlbum ) == 0 ) |
|
386 { |
|
387 iObjectClass |= EMusicAlbum; |
|
388 } |
|
389 else |
|
390 { |
|
391 |
|
392 } |
|
393 } |
|
394 |
|
395 // end of file |
|
396 |
|
397 |