|
1 /** @file |
|
2 * Copyright (c) 2005-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: Defines the CUpnpDevice class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include <e32math.h> |
|
23 |
|
24 #include "upnpfileutils.h" |
|
25 #include "upnpicon.h" |
|
26 #include "upnpdevice.h" |
|
27 #include "upnpcommonstructs.h" |
|
28 #include "upnpstring.h" |
|
29 #include "upnpdispatcher.h" |
|
30 #include "upnpcons.h" |
|
31 #include "upnpcommonupnplits.h" |
|
32 #include "upnpcustomlog.h" |
|
33 #include "upnpserviceimplementation.h" |
|
34 #include "upnpdevicecontenthandler.h" |
|
35 |
|
36 #define KLogFile _L("UPnPStack.txt") |
|
37 |
|
38 // ============================= LOCAL FUNCTIONS =============================== |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CUpnpDevice::SetUuidL |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 void CUpnpDevice::SetUuidL( const TDesC8& aUUID ) |
|
45 { |
|
46 HBufC8* tmp = aUUID.AllocL(); |
|
47 delete iUUID; |
|
48 iUUID = tmp; |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CUpnpDevice::AddDeviceL |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 void CUpnpDevice::AddDeviceL( CUpnpDevice* device ) |
|
56 { |
|
57 device->SetRootDevice( EFalse ); |
|
58 iDeviceList.AppendL( device ); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CUpnpDevice::CUpnpDevice |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CUpnpDevice::CUpnpDevice() : |
|
66 iExpired(ETrue), iNetworkType(EHomeNetwork), iIsRootDevice(ETrue) |
|
67 { |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CUpnpDevice::ConstructL |
|
72 // Symbian 2nd phase constructor can leave. |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 void CUpnpDevice::ConstructL( const TUpnpDevice* aDevice, |
|
76 const RPointerArray<TUpnpService>& aServices ) |
|
77 { |
|
78 Init(); |
|
79 |
|
80 if ( aDevice ) |
|
81 { |
|
82 iUUID = aDevice->iUUID.AllocL(); |
|
83 iDeviceType = aDevice->iDeviceType.AllocL(); |
|
84 iDescriptionURL = aDevice->iDescriptionURL.AllocL(); |
|
85 iDomain = aDevice->iDomain.AllocL(); |
|
86 iExpired = aDevice->iExpired; |
|
87 iAlive = aDevice->iAlive; |
|
88 |
|
89 if ( aDevice->iLocal ) |
|
90 { |
|
91 iNetworkType = ELocalDevice; |
|
92 } |
|
93 else if ( aDevice->iRemote ) |
|
94 { |
|
95 iNetworkType = ERemoteDevice; |
|
96 } |
|
97 else |
|
98 { |
|
99 iNetworkType = EHomeNetwork; |
|
100 } |
|
101 |
|
102 iServiceTypes = new (ELeave) CDesC8ArrayFlat( aServices.Count() |
|
103 == 0 ? 1 : aServices.Count() ); |
|
104 |
|
105 for ( TInt i = 0; i < aServices.Count(); i++ ) |
|
106 { |
|
107 iServiceTypes->AppendL( aServices[i]->iServiceType ); |
|
108 } |
|
109 } |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CUpnpDevice::NewL |
|
114 // Two-phased constructor. |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 EXPORT_C CUpnpDevice* CUpnpDevice::NewL( const TUpnpDevice* aDevice, |
|
118 const RPointerArray<TUpnpService> & aServices |
|
119 ) |
|
120 { |
|
121 CUpnpDevice* self = new (ELeave) CUpnpDevice(); |
|
122 |
|
123 CleanupStack::PushL( self ); |
|
124 self->ConstructL( aDevice, aServices ); |
|
125 CleanupStack::Pop( self ); |
|
126 |
|
127 return self; |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CUpnpDevice::~CUpnpDevice |
|
132 // Destructor. |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 CUpnpDevice::~CUpnpDevice() |
|
136 { |
|
137 iServiceDescriptionSessionIds.Reset(); |
|
138 iServiceDescriptionSessionIds.Close(); |
|
139 |
|
140 if ( iServiceTypes ) |
|
141 { |
|
142 iServiceTypes->Reset(); |
|
143 delete iServiceTypes; |
|
144 } |
|
145 if ( iServicesId ) |
|
146 { |
|
147 iServicesId->Reset(); |
|
148 delete iServicesId; |
|
149 } |
|
150 |
|
151 delete iUUID; |
|
152 delete iDeviceType; |
|
153 delete iDescriptionURL; |
|
154 delete iDomain; |
|
155 |
|
156 CleanupServiceArray(); |
|
157 |
|
158 // destroy embedded devices |
|
159 iDeviceList.ResetAndDestroy(); |
|
160 iDeviceList.Close(); |
|
161 |
|
162 delete iClockSeq; |
|
163 |
|
164 iIcons.ResetAndDestroy(); |
|
165 iIcons.Close(); |
|
166 |
|
167 iServiceDescriptionSessionIds.Reset(); |
|
168 iServiceDescriptionSessionIds.Close(); |
|
169 iIconSessionIds.Reset(); |
|
170 iIconSessionIds.Close(); |
|
171 |
|
172 delete iUrlBase; |
|
173 |
|
174 iProperties.ResetAndDestroy(); |
|
175 iProperties.Close(); |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CUpnpDevice::Init |
|
180 // Initialisation. |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 void CUpnpDevice::Init() |
|
184 { |
|
185 iAddress = TInetAddr( INET_ADDR( 0,0,0,0 ), 0 ); |
|
186 iIconReceiveState = EAllIconsAdded; |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CUpnpDevice::CleanupServiceArray |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 void CUpnpDevice::CleanupServiceArray() |
|
194 { |
|
195 for ( TInt i = iServiceList.Count() - 1; i >= 0; --i ) |
|
196 { |
|
197 delete iServiceList[ i ]; |
|
198 iServiceList[ i ] = NULL; |
|
199 } |
|
200 iServiceList.Close(); |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CUpnpDevice::DescriptionUrl |
|
205 // Return description URL. |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 EXPORT_C const TDesC8& CUpnpDevice::DescriptionUrl() const |
|
209 { |
|
210 if ( iDescriptionURL ) |
|
211 { |
|
212 return *iDescriptionURL; |
|
213 } |
|
214 else |
|
215 { |
|
216 return KNullDesC8(); |
|
217 } |
|
218 } |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CUpnpDevice::SetDescriptionUrlL |
|
222 // Return description URL. |
|
223 // ----------------------------------------------------------------------------- |
|
224 // |
|
225 void CUpnpDevice::SetDescriptionUrlL( const TDesC8& aDescriptionUrl ) |
|
226 { |
|
227 HBufC8* tmp = aDescriptionUrl.AllocL(); |
|
228 delete iDescriptionURL; |
|
229 iDescriptionURL = tmp; |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CUpnpDevice::SetAlive |
|
234 // Set alive. |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 EXPORT_C void CUpnpDevice::SetAlive( TBool aAlive ) |
|
238 { |
|
239 iAlive = aAlive; |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // CUpnpDevice::Expired |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 EXPORT_C TBool CUpnpDevice::Expired() const |
|
247 { |
|
248 return iExpired; |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // CUpnpDevice::SetExpired |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 EXPORT_C void CUpnpDevice::SetExpired( TBool aExpired ) |
|
256 { |
|
257 iExpired = aExpired; |
|
258 } |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // CUpnpDevice::DeviceType |
|
262 // Return device type. |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 EXPORT_C const TPtrC8 CUpnpDevice::DeviceType() |
|
266 { |
|
267 if ( iDeviceType ) |
|
268 { |
|
269 return TPtrC8( iDeviceType->Des() ); |
|
270 } |
|
271 else |
|
272 { |
|
273 return KNullDesC8(); |
|
274 } |
|
275 } |
|
276 |
|
277 // ----------------------------------------------------------------------------- |
|
278 // CUpnpDevice::Uuid |
|
279 // Return UUID. |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 EXPORT_C const TPtrC8 CUpnpDevice::Uuid() |
|
283 { |
|
284 if ( iUUID ) |
|
285 { |
|
286 return TPtrC8( iUUID->Des() ); |
|
287 } |
|
288 else |
|
289 { |
|
290 return KNullDesC8(); |
|
291 } |
|
292 } |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // CUpnpDevice::Alive |
|
296 // Return iAlive. |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 EXPORT_C TBool CUpnpDevice::Alive() const |
|
300 { |
|
301 return iAlive; |
|
302 } |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // CUpnpDevice::DescriptionUrlAddressL |
|
306 // Return description URL address. |
|
307 // ----------------------------------------------------------------------------- |
|
308 // |
|
309 EXPORT_C TInetAddr CUpnpDevice::DescriptionUrlAddressL() const |
|
310 { |
|
311 if ( iAddress == TInetAddr( INET_ADDR( 0,0,0,0 ), 0) ) |
|
312 { |
|
313 |
|
314 const TDesC8& url = DescriptionUrl(); |
|
315 |
|
316 if ( url.Length()> KHttp().Length() ) |
|
317 { |
|
318 TPtrC8 addrAndPath = url.Right( url.Length() - KHttp().Length() ); |
|
319 |
|
320 TInt index = addrAndPath.Find( KSepar() ); |
|
321 |
|
322 if ( index == KErrNotFound ) |
|
323 { |
|
324 index = addrAndPath.Find( KSlash8() ); |
|
325 } |
|
326 |
|
327 if ( index == KErrNotFound ) |
|
328 { |
|
329 return TInetAddr( INET_ADDR( 0,0,0,0 ), 0 ); |
|
330 } |
|
331 |
|
332 TPtrC8 addr = addrAndPath.Left( index ); |
|
333 |
|
334 TInetAddr address; |
|
335 |
|
336 HBufC* addrBuf = HBufC::NewLC(addr.Length()); |
|
337 addrBuf->Des().Copy(addr); |
|
338 address.Input(*addrBuf); |
|
339 CleanupStack::PopAndDestroy(addrBuf); |
|
340 |
|
341 return address; |
|
342 } |
|
343 |
|
344 return TInetAddr(INET_ADDR( 0,0,0,0 ), 0 ); |
|
345 } |
|
346 |
|
347 return iAddress; |
|
348 } |
|
349 |
|
350 // ----------------------------------------------------------------------------- |
|
351 // CUpnpDevice::DescriptionUrlPath |
|
352 // Return description URL path. |
|
353 // ----------------------------------------------------------------------------- |
|
354 // |
|
355 EXPORT_C const TPtrC8 CUpnpDevice::DescriptionUrlPath() const |
|
356 { |
|
357 |
|
358 const TDesC8& url = DescriptionUrl(); |
|
359 |
|
360 if ( url.Length()> KHttp().Length() ) |
|
361 { |
|
362 TPtrC8 addrAndPath = url.Right( url.Length() - KHttp().Length() ); |
|
363 |
|
364 TInt index = addrAndPath.Find( KSlash8() ); |
|
365 |
|
366 if ( index != KErrNotFound ) |
|
367 { |
|
368 TPtrC8 addr = addrAndPath.Right( addrAndPath.Length() - index ); |
|
369 return addr; |
|
370 } |
|
371 } |
|
372 return TPtrC8( KNullDesC8 ); |
|
373 } |
|
374 |
|
375 // ----------------------------------------------------------------------------- |
|
376 // CUpnpDevice::DescriptionUrlPort |
|
377 // Retrun description URL port. |
|
378 // ----------------------------------------------------------------------------- |
|
379 // |
|
380 EXPORT_C TInt CUpnpDevice::DescriptionUrlPort() const |
|
381 { |
|
382 if ( iAddress != TInetAddr( INET_ADDR( 0,0,0,0 ), 0) ) |
|
383 { |
|
384 return iAddress.Port(); |
|
385 } |
|
386 |
|
387 const TDesC8& url = DescriptionUrl(); |
|
388 |
|
389 if ( url.Length()> KHttp().Length() ) |
|
390 { |
|
391 TPtrC8 addrAndPath = url.Right( url.Length() - KHttp().Length() ); |
|
392 |
|
393 TInt separIndex = addrAndPath.Find( KSepar() ); |
|
394 |
|
395 if ( separIndex == KErrNotFound ) |
|
396 { |
|
397 return KDefaultDescriptionUrlPort; |
|
398 } |
|
399 |
|
400 TInt slashIndex = addrAndPath.Find( KSlash8() ); |
|
401 |
|
402 if ( slashIndex != KErrNotFound ) |
|
403 { |
|
404 TPtrC8 port = addrAndPath.Mid( |
|
405 separIndex + 1, slashIndex - separIndex |
|
406 ); |
|
407 |
|
408 TLex8 lex( port ); |
|
409 TInt prt; |
|
410 TInt err = lex.Val( prt ); |
|
411 if( KErrNone != err ) |
|
412 { |
|
413 return KErrNotFound; |
|
414 } |
|
415 |
|
416 return prt; |
|
417 } |
|
418 else |
|
419 { |
|
420 TPtrC8 port = addrAndPath.Right( |
|
421 addrAndPath.Length() - ( separIndex + 1 ) |
|
422 ); |
|
423 |
|
424 TLex8 lex( port ); |
|
425 TInt prt; |
|
426 TInt err = lex.Val( prt ); |
|
427 if( KErrNone != err ) |
|
428 { |
|
429 return KErrNotFound; |
|
430 } |
|
431 |
|
432 return prt; |
|
433 } |
|
434 } |
|
435 |
|
436 return KDefaultDescriptionUrlPort; |
|
437 } |
|
438 |
|
439 // ----------------------------------------------------------------------------- |
|
440 // CUpnpDevice::ServiceTypesL |
|
441 // Return service types. |
|
442 // ----------------------------------------------------------------------------- |
|
443 // |
|
444 EXPORT_C CDesC8Array& CUpnpDevice::ServiceTypesL() |
|
445 { |
|
446 if ( !iServiceTypes ) |
|
447 { |
|
448 iServiceTypes = new (ELeave) CDesC8ArrayFlat( 2 ); |
|
449 } |
|
450 return *iServiceTypes; |
|
451 |
|
452 } |
|
453 |
|
454 // ----------------------------------------------------------------------------- |
|
455 // CUpnpDevice::FriendlyName |
|
456 // Return friendly name. |
|
457 // ----------------------------------------------------------------------------- |
|
458 // |
|
459 EXPORT_C const TPtrC8 CUpnpDevice::DescriptionProperty( const TDesC8& aPropertyName ) |
|
460 { |
|
461 TInt index = 0; |
|
462 |
|
463 while ( index < iProperties.Count() ) |
|
464 { |
|
465 CUpnpDescriptionProperty* var = iProperties[index]; |
|
466 |
|
467 if ( aPropertyName.Compare( var->Name() ) == KErrNone ) |
|
468 { |
|
469 return var->Value(); |
|
470 } |
|
471 |
|
472 index++; |
|
473 } |
|
474 |
|
475 return KNullDesC8(); |
|
476 |
|
477 } |
|
478 |
|
479 // ----------------------------------------------------------------------------- |
|
480 // CUpnpDevice::ServiceId |
|
481 // Return service ID. |
|
482 // ----------------------------------------------------------------------------- |
|
483 // |
|
484 EXPORT_C const TPtrC8 CUpnpDevice::ServiceId( const TDesC8 &aServiceType ) |
|
485 { |
|
486 //return Content( KServiceId(), aServiceType ); |
|
487 for( TInt i(0); i < iServiceTypes->Count(); i++) |
|
488 { |
|
489 TInt pos =(*iServiceTypes)[i].Find( aServiceType ); |
|
490 if( pos != KErrNotFound ) |
|
491 return TPtrC8( ( *iServicesId )[i] ); |
|
492 |
|
493 } |
|
494 |
|
495 return TPtrC8( (TUint8*)"", 0); |
|
496 } |
|
497 |
|
498 // ----------------------------------------------------------------------------- |
|
499 // CUpnpDevice::ServiceDescriptionUrl |
|
500 // Return service description URL. |
|
501 // ----------------------------------------------------------------------------- |
|
502 // |
|
503 EXPORT_C const TPtrC8 CUpnpDevice::ServiceDescriptionUrl( const TDesC8 &aServiceType ) |
|
504 { |
|
505 |
|
506 for (TInt i=0;i<iServiceList.Count();i++) |
|
507 { |
|
508 if (!iServiceList[i]->ServiceType().Compare(aServiceType)) |
|
509 { |
|
510 return iServiceList[i]->ServiceDescriptionUrl(); |
|
511 } |
|
512 } |
|
513 return TPtrC8( (TUint8*)"", 0 );; |
|
514 |
|
515 } |
|
516 |
|
517 // ----------------------------------------------------------------------------- |
|
518 // CUpnpDevice::ServiceList |
|
519 // Return service list. |
|
520 // ----------------------------------------------------------------------------- |
|
521 // |
|
522 EXPORT_C RPointerArray<CUpnpService>& CUpnpDevice::ServiceList() |
|
523 { |
|
524 return iServiceList; |
|
525 } |
|
526 |
|
527 // ----------------------------------------------------------------------------- |
|
528 // CUpnpDevice::DeviceList |
|
529 // Return service list. |
|
530 // ----------------------------------------------------------------------------- |
|
531 // |
|
532 EXPORT_C RPointerArray<CUpnpDevice>& CUpnpDevice::DeviceList() |
|
533 { |
|
534 return iDeviceList; |
|
535 } |
|
536 |
|
537 // ----------------------------------------------------------------------------- |
|
538 // CUpnpDevice::DeviceList |
|
539 // Return service list. |
|
540 // ----------------------------------------------------------------------------- |
|
541 // |
|
542 EXPORT_C void CUpnpDevice::GetAllDevices( RPointerArray<CUpnpDevice>& aDevices ) |
|
543 { |
|
544 |
|
545 for (TInt i = 0; i < iDeviceList.Count(); i++ ) |
|
546 { |
|
547 aDevices.Append( iDeviceList[i] ); |
|
548 iDeviceList[i]->GetAllDevices(aDevices); |
|
549 } |
|
550 |
|
551 } |
|
552 |
|
553 // ----------------------------------------------------------------------------- |
|
554 // CUpnpDevice::AttachService |
|
555 // Attach to service. |
|
556 // ----------------------------------------------------------------------------- |
|
557 // |
|
558 void CUpnpDevice::AttachServiceL( CUpnpService *aService ) |
|
559 { |
|
560 if ( aService ) |
|
561 { |
|
562 if ( !aService->IsAdded() ) |
|
563 { |
|
564 TInt servCount = aService->Device().ServiceList().Count(); |
|
565 CUpnpService* service= NULL; |
|
566 TInt i(0); |
|
567 |
|
568 do |
|
569 { |
|
570 service = aService->Device().ServiceList()[i]; |
|
571 i++; |
|
572 } while ( service->IsAdded() ); |
|
573 |
|
574 aService->SetServiceTypeL( service->ServiceType() ); |
|
575 aService->SetPathL( service->Path() ); |
|
576 |
|
577 aService->SetControlUrl( ConcatWithUrlBaseL( service->ControlUrl() ) ); |
|
578 aService->SetSubscriptionUrl( ConcatWithUrlBaseL( service->SubscriptionUrl() ) ); |
|
579 aService->SetServiceDescriptionUrl( service->ServiceDescriptionUrl().AllocL() ); |
|
580 |
|
581 ServiceList().Remove( i-1 ); |
|
582 ServiceList().Insert( aService, i-1 ); |
|
583 delete service; |
|
584 } |
|
585 |
|
586 aService->Added(); |
|
587 } |
|
588 } |
|
589 |
|
590 // ----------------------------------------------------------------------------- |
|
591 // CUpnpDevice::DetachService |
|
592 // ----------------------------------------------------------------------------- |
|
593 // |
|
594 void CUpnpDevice::DetachService( CUpnpService *aService ) |
|
595 { |
|
596 for ( TInt i = ServiceList().Count() - 1; i >= 0; --i ) |
|
597 { |
|
598 if ( ServiceList()[ i ] == aService ) |
|
599 { |
|
600 ServiceList().Remove( i ); |
|
601 break; |
|
602 } |
|
603 } |
|
604 } |
|
605 |
|
606 // ----------------------------------------------------------------------------- |
|
607 // CUpnpDevice::WaitServiceDescriptionL |
|
608 // Wait service description. |
|
609 // ----------------------------------------------------------------------------- |
|
610 // |
|
611 EXPORT_C void CUpnpDevice::WaitServiceDescriptionL( TInt aSessionId ) |
|
612 { |
|
613 User::LeaveIfError( iServiceDescriptionSessionIds.Append( aSessionId ) ); |
|
614 } |
|
615 |
|
616 // ----------------------------------------------------------------------------- |
|
617 // CUpnpDevice::WaitServiceDescriptionCount |
|
618 // Wait service description count. |
|
619 // ----------------------------------------------------------------------------- |
|
620 // |
|
621 EXPORT_C TInt CUpnpDevice::WaitServiceDescriptionCount() |
|
622 { |
|
623 return iServiceDescriptionSessionIds.Count(); |
|
624 } |
|
625 |
|
626 // ----------------------------------------------------------------------------- |
|
627 // CUpnpDevice::WaitServiceDescriptionSessionId |
|
628 // Wait service description session ID. |
|
629 // ----------------------------------------------------------------------------- |
|
630 // |
|
631 EXPORT_C TInt CUpnpDevice::WaitServiceDescriptionSessionId(TInt aIndex) |
|
632 { |
|
633 if(iServiceDescriptionSessionIds.Count()> aIndex) |
|
634 { |
|
635 return iServiceDescriptionSessionIds[aIndex]; |
|
636 } |
|
637 return KErrGeneral; |
|
638 } |
|
639 |
|
640 // ----------------------------------------------------------------------------- |
|
641 // CUpnpDevice::WaitServiceDescriptionRemoveSessionId |
|
642 // Wait service description remove session ID. |
|
643 // ----------------------------------------------------------------------------- |
|
644 // |
|
645 EXPORT_C void CUpnpDevice::WaitServiceDescriptionRemoveSessionId( TInt aIndex ) |
|
646 { |
|
647 if(iServiceDescriptionSessionIds.Count()> aIndex) |
|
648 { |
|
649 iServiceDescriptionSessionIds.Remove(aIndex); |
|
650 iServiceDescriptionSessionIds.Compress(); |
|
651 } |
|
652 } |
|
653 |
|
654 // ----------------------------------------------------------------------------- |
|
655 // CUpnpDevice::AddServiceL |
|
656 // Add service. |
|
657 // ----------------------------------------------------------------------------- |
|
658 // |
|
659 EXPORT_C CUpnpDevice::TServiceAdd CUpnpDevice::AddServiceL( |
|
660 TInt aSessionId, |
|
661 CUpnpService* aService ) |
|
662 { |
|
663 TInt idx = iServiceDescriptionSessionIds.Find( aSessionId ); |
|
664 if ( idx != KErrNotFound ) |
|
665 { // received Service Description for service of this device |
|
666 iServiceDescriptionSessionIds[idx] = KErrNotFound; |
|
667 |
|
668 AttachServiceL(aService); |
|
669 |
|
670 TInt count = iServiceDescriptionSessionIds.Count(); |
|
671 TInt i; |
|
672 for ( i = 0; i < count && iServiceDescriptionSessionIds[i] == KErrNotFound; i++ ) |
|
673 { |
|
674 } |
|
675 |
|
676 // We have retrieved all services only when i == iServices.Count(). |
|
677 // is there some reason why this was ( i == count ) |
|
678 if ( i == iServiceList.Count() ) |
|
679 |
|
680 { // All Service Descriptions for this device arrived |
|
681 iServiceDescriptionSessionIds.Reset(); |
|
682 iServiceDescriptionReceiveState = EAllServicesAdded; |
|
683 return EAllServicesAdded; |
|
684 } |
|
685 else |
|
686 { |
|
687 return EServiceAdded; |
|
688 } |
|
689 } |
|
690 return ENotServiceAdded; |
|
691 } |
|
692 |
|
693 // ----------------------------------------------------------------------------- |
|
694 // CUpnpDevice::WaitIconL |
|
695 // Wait icon. |
|
696 // ----------------------------------------------------------------------------- |
|
697 // |
|
698 EXPORT_C void CUpnpDevice::WaitIconL( TInt aSessionId ) |
|
699 { |
|
700 User::LeaveIfError( iIconSessionIds.Append( aSessionId ) ); |
|
701 iIconReceiveState = ENotIconAdded; |
|
702 } |
|
703 |
|
704 // ----------------------------------------------------------------------------- |
|
705 // CUpnpDevice::AddIcon |
|
706 // Add icon. |
|
707 // ----------------------------------------------------------------------------- |
|
708 // |
|
709 EXPORT_C CUpnpDevice::TIconAdd CUpnpDevice::AddIcon( TInt aSessionId ) |
|
710 { |
|
711 TInt idx = iIconSessionIds.Find( aSessionId ); |
|
712 if ( idx != KErrNotFound ) |
|
713 { // received Icon Description for service of this device |
|
714 iIconSessionIds[idx] = -1; |
|
715 |
|
716 TInt count = iIconSessionIds.Count(); |
|
717 TInt i; |
|
718 for (i = 0; i < count && iIconSessionIds[i] == -1; i++ ) |
|
719 { |
|
720 } |
|
721 |
|
722 if ( i == count ) |
|
723 |
|
724 { // All Icon Descriptions for this device arrived |
|
725 iIconSessionIds.Reset(); |
|
726 iIconReceiveState = EAllIconsAdded; |
|
727 return EAllIconsAdded; |
|
728 } |
|
729 else |
|
730 { |
|
731 return EIconAdded; |
|
732 } |
|
733 } |
|
734 return ENotIconAdded; |
|
735 } |
|
736 |
|
737 // ----------------------------------------------------------------------------- |
|
738 // CUpnpDevice::Address |
|
739 // Return IP address. |
|
740 // ----------------------------------------------------------------------------- |
|
741 // |
|
742 EXPORT_C TInetAddr CUpnpDevice::Address() |
|
743 { |
|
744 return iAddress; |
|
745 } |
|
746 |
|
747 // ----------------------------------------------------------------------------- |
|
748 // CUpnpDevice::SetAddress |
|
749 // Set IP address. |
|
750 // ----------------------------------------------------------------------------- |
|
751 // |
|
752 EXPORT_C void CUpnpDevice::SetAddress( const TInetAddr& aAddr ) |
|
753 { |
|
754 iAddress = aAddr; |
|
755 } |
|
756 |
|
757 // ----------------------------------------------------------------------------- |
|
758 // CUpnpDevice::Icons |
|
759 // Return iIcons. |
|
760 // ----------------------------------------------------------------------------- |
|
761 // |
|
762 EXPORT_C RPointerArray<CUpnpIcon>& CUpnpDevice::Icons() |
|
763 { |
|
764 return iIcons; |
|
765 } |
|
766 |
|
767 // ----------------------------------------------------------------------------- |
|
768 // CUpnpDevice::Local |
|
769 // Return iLocal. |
|
770 // ----------------------------------------------------------------------------- |
|
771 // |
|
772 EXPORT_C TBool CUpnpDevice::Local() const |
|
773 { |
|
774 return iNetworkType == ELocalDevice; |
|
775 } |
|
776 |
|
777 // ----------------------------------------------------------------------------- |
|
778 // CUpnpDevice::SetLocal |
|
779 // Set local. |
|
780 // ----------------------------------------------------------------------------- |
|
781 // |
|
782 EXPORT_C void CUpnpDevice::SetLocal( TBool aLocal ) |
|
783 { |
|
784 if(aLocal) |
|
785 { |
|
786 iNetworkType = ELocalDevice; |
|
787 } |
|
788 } |
|
789 |
|
790 // ----------------------------------------------------------------------------- |
|
791 // CUpnpDevice::Local |
|
792 // Return iLocal. |
|
793 // ----------------------------------------------------------------------------- |
|
794 // |
|
795 EXPORT_C TBool CUpnpDevice::Remote() const |
|
796 { |
|
797 return iNetworkType == ERemoteDevice; |
|
798 } |
|
799 |
|
800 // ----------------------------------------------------------------------------- |
|
801 // CUpnpDevice::DeviceNetwork |
|
802 // Get device network type. |
|
803 // ----------------------------------------------------------------------------- |
|
804 // |
|
805 EXPORT_C CUpnpDevice::TUpnpDeviceNetwork CUpnpDevice::DeviceNetwork() const |
|
806 { |
|
807 return iNetworkType; |
|
808 } |
|
809 |
|
810 // ----------------------------------------------------------------------------- |
|
811 // CUpnpDevice::SetDeviceNetwork |
|
812 // Set device network type. |
|
813 // ----------------------------------------------------------------------------- |
|
814 // |
|
815 EXPORT_C void CUpnpDevice::SetDeviceNetwork( CUpnpDevice::TUpnpDeviceNetwork aNetworkType ) |
|
816 { |
|
817 iNetworkType = aNetworkType; |
|
818 } |
|
819 |
|
820 // ----------------------------------------------------------------------------- |
|
821 // CUpnpDevice::RemoveIpAddress |
|
822 // Removes IP address in front of the url leaving only path to file. |
|
823 // (12.34.56.78/folder/file.ext -> /folder/file ) |
|
824 // ----------------------------------------------------------------------------- |
|
825 // |
|
826 TPtrC8 CUpnpDevice::RemoveIpAddress( const TDesC8 &aAddress ) |
|
827 { |
|
828 if ( aAddress.Length() > KHttp().Length() ) |
|
829 { |
|
830 if ( aAddress.Left( KHttp().Length() ) == KHttp() ) |
|
831 { |
|
832 TPtrC8 newContent = aAddress.Mid( KHttp().Length() ); |
|
833 |
|
834 TInt slashIndex = newContent.Find( UpnpString::KSlash() ); |
|
835 |
|
836 if ( slashIndex != KErrNotFound ) |
|
837 { |
|
838 return newContent.Mid( slashIndex ); |
|
839 } |
|
840 } |
|
841 } |
|
842 return TPtrC8( aAddress ); |
|
843 } |
|
844 |
|
845 // ----------------------------------------------------------------------------- |
|
846 // CUpnpDevice::ChangeIconSessionId |
|
847 // This function is used for removing old icon request session id from list |
|
848 // and adding a new one. |
|
849 // ----------------------------------------------------------------------------- |
|
850 // |
|
851 TInt CUpnpDevice::ChangeIconSessionIdL( const TInt aOldSessionId, |
|
852 const TInt aNewSessionId ) |
|
853 { |
|
854 |
|
855 // remove old sessionid from list |
|
856 TInt idx = iIconSessionIds.Find( aOldSessionId ); |
|
857 if ( idx != KErrNotFound ) |
|
858 { |
|
859 iIconSessionIds.Remove( idx ); |
|
860 } |
|
861 |
|
862 // add new to list |
|
863 User::LeaveIfError( iIconSessionIds.Append( aNewSessionId ) ); |
|
864 |
|
865 return KErrNone; |
|
866 } |
|
867 |
|
868 // ----------------------------------------------------------------------------- |
|
869 // CUpnpDevice::CheckIconSessionIdExist |
|
870 // Checking if given session id is listed in this device's iconSessionId list. |
|
871 // ----------------------------------------------------------------------------- |
|
872 // |
|
873 TInt CUpnpDevice::CheckIconSessionIdExist( const TInt aSessionId ) |
|
874 { |
|
875 return iIconSessionIds.Find( aSessionId ); |
|
876 } |
|
877 |
|
878 // ----------------------------------------------------------------------------- |
|
879 // CUpnpDevice::GetUrlBase |
|
880 // Return URLBase content. |
|
881 // ----------------------------------------------------------------------------- |
|
882 // |
|
883 EXPORT_C const TPtrC8 CUpnpDevice::UrlBase() |
|
884 { |
|
885 if( iUrlBase ) |
|
886 { |
|
887 return iUrlBase->Des(); |
|
888 } |
|
889 else |
|
890 { |
|
891 return KNullDesC8(); |
|
892 } |
|
893 } |
|
894 |
|
895 // ----------------------------------------------------------------------------- |
|
896 // CUpnpDevice::PresentationUrl |
|
897 // Return presentation URL. |
|
898 // ----------------------------------------------------------------------------- |
|
899 // |
|
900 EXPORT_C const TPtrC8 CUpnpDevice::PresentationUrl() |
|
901 { |
|
902 TInt index = 0; |
|
903 |
|
904 while ( index < iProperties.Count() ) |
|
905 { |
|
906 CUpnpDescriptionProperty* var = iProperties[index]; |
|
907 |
|
908 if ( KPresentationUrl().Compare( var->Name() ) == KErrNone ) |
|
909 { |
|
910 return var->Value(); |
|
911 } |
|
912 |
|
913 index++; |
|
914 } |
|
915 |
|
916 return KNullDesC8();//return Content( KPresentationUrl() ); |
|
917 } |
|
918 |
|
919 // ----------------------------------------------------------------------------- |
|
920 // CUpnpDevice::PresentationUrl |
|
921 // Return presentation URL. |
|
922 // ----------------------------------------------------------------------------- |
|
923 // |
|
924 EXPORT_C void CUpnpDevice::SetUrlBaseL(const TDesC8& aUrlBase) |
|
925 { |
|
926 if( iUrlBase ) |
|
927 { |
|
928 delete iUrlBase; |
|
929 iUrlBase = NULL; |
|
930 } |
|
931 iUrlBase = aUrlBase.AllocL(); |
|
932 } |
|
933 |
|
934 // ----------------------------------------------------------------------------- |
|
935 // CUpnpDevice::ConcatWithUrlBase |
|
936 // ----------------------------------------------------------------------------- |
|
937 // |
|
938 EXPORT_C HBufC8* CUpnpDevice::ConcatWithUrlBaseL(const TDesC8& aUrl) |
|
939 { |
|
940 TPtrC8 baseUrl( UrlBase() ); |
|
941 |
|
942 if( baseUrl.Length() == 0 || |
|
943 aUrl.Length() == 0 || |
|
944 aUrl.Find( KHttp ) == 0 || |
|
945 ( aUrl[0] == KSlash8()[0] && !( baseUrl.Find( KHttp ) == 0 ) ) ) |
|
946 |
|
947 { |
|
948 return aUrl.AllocL(); |
|
949 } |
|
950 |
|
951 HBufC8* result( NULL ); |
|
952 TBool slashInBase( baseUrl[baseUrl.Length() - 1] == KSlash8()[0] ); |
|
953 TBool slashInUrl( aUrl[0] == KSlash8()[0] ); |
|
954 TInt length( 0 ); |
|
955 |
|
956 if( slashInBase && slashInUrl ) |
|
957 { |
|
958 length = baseUrl.Length() + aUrl.Length() - 1; |
|
959 result = HBufC8::NewL( length ); |
|
960 TPtr8 resultPtr( result->Des() ); |
|
961 resultPtr.Append( baseUrl.Left( baseUrl.Length() - 1 )); |
|
962 } |
|
963 else if( slashInBase != slashInUrl ) |
|
964 { |
|
965 length = baseUrl.Length() + aUrl.Length(); |
|
966 result = HBufC8::NewL( length ); |
|
967 TPtr8 resultPtr( result->Des() ); |
|
968 resultPtr.Append( baseUrl ); |
|
969 } |
|
970 else |
|
971 { |
|
972 length = baseUrl.Length() + aUrl.Length() + 1; |
|
973 result = HBufC8::NewL( length ); |
|
974 TPtr8 resultPtr( result->Des() ); |
|
975 resultPtr.Append( baseUrl ); |
|
976 resultPtr.Append( '/' ); |
|
977 } |
|
978 |
|
979 result->Des().Append( aUrl ); |
|
980 return result; |
|
981 } |
|
982 |
|
983 // ----------------------------------------------------------------------------- |
|
984 // CUpnpDevice::SetTypeL |
|
985 // ----------------------------------------------------------------------------- |
|
986 // |
|
987 void CUpnpDevice::SetTypeL( const TDesC8& aType ) |
|
988 { |
|
989 HBufC8* tmp = aType.AllocL(); |
|
990 delete iDeviceType; |
|
991 iDeviceType = tmp; |
|
992 } |
|
993 |
|
994 // ----------------------------------------------------------------------------- |
|
995 // CUpnpDevice::AddDevicePropertyL |
|
996 // ----------------------------------------------------------------------------- |
|
997 // |
|
998 void CUpnpDevice::AddDevicePropertyL( |
|
999 CUpnpDescriptionProperty* aDeviceProperty ) |
|
1000 { |
|
1001 iProperties.AppendL( aDeviceProperty ); |
|
1002 } |
|
1003 |
|
1004 // ----------------------------------------------------------------------------- |
|
1005 // CUpnpDevice::SetRootDevice |
|
1006 // ----------------------------------------------------------------------------- |
|
1007 // |
|
1008 void CUpnpDevice::SetRootDevice( TBool aIsRoot ) |
|
1009 { |
|
1010 iIsRootDevice = aIsRoot; |
|
1011 } |
|
1012 |
|
1013 // ----------------------------------------------------------------------------- |
|
1014 // CUpnpDevice::GetProperty |
|
1015 // Get information from device description. |
|
1016 // ----------------------------------------------------------------------------- |
|
1017 // |
|
1018 EXPORT_C TPtrC8 CUpnpDevice::GetProperty(const TDesC8& aProperty) |
|
1019 { |
|
1020 TInt index = 0; |
|
1021 |
|
1022 while ( index < iProperties.Count() ) |
|
1023 { |
|
1024 CUpnpDescriptionProperty* var = iProperties[index]; |
|
1025 if ( aProperty.Compare( var->Name() ) == KErrNone ) |
|
1026 { |
|
1027 return var->Value(); |
|
1028 } |
|
1029 |
|
1030 index++; |
|
1031 } |
|
1032 |
|
1033 return KNullDesC8(); |
|
1034 //return Content( aProperty ); |
|
1035 } |
|
1036 |
|
1037 // ----------------------------------------------------------------------------- |
|
1038 // CUpnpDevice::AddIconL |
|
1039 // ----------------------------------------------------------------------------- |
|
1040 // |
|
1041 EXPORT_C void CUpnpDevice::AddIconL( CUpnpIcon* aIcon) |
|
1042 { |
|
1043 if( aIcon ) |
|
1044 iIcons.AppendL( aIcon); |
|
1045 |
|
1046 } |
|
1047 |
|
1048 // ----------------------------------------------------------------------------- |
|
1049 // CUpnpDevice::ServiceIdL |
|
1050 // Get information about service IDs. |
|
1051 // ----------------------------------------------------------------------------- |
|
1052 // |
|
1053 EXPORT_C CDesC8Array& CUpnpDevice::ServiceIdL() |
|
1054 { |
|
1055 if ( !iServicesId ) |
|
1056 { |
|
1057 iServicesId = new (ELeave) CDesC8ArrayFlat( 2 ); |
|
1058 } |
|
1059 return *iServicesId; |
|
1060 } |
|
1061 |
|
1062 // ----------------------------------------------------------------------------- |
|
1063 // CUpnpDevice::IsEmbeddDevice |
|
1064 // ----------------------------------------------------------------------------- |
|
1065 // |
|
1066 EXPORT_C TBool CUpnpDevice::IsEmbeddDevice() |
|
1067 { |
|
1068 return !(iIsRootDevice); |
|
1069 } |
|
1070 |
|
1071 // ----------------------------------------------------------------------------- |
|
1072 // CUpnpDevice::CloneL |
|
1073 // ----------------------------------------------------------------------------- |
|
1074 // |
|
1075 EXPORT_C CUpnpDevice* CUpnpDevice::CloneL() |
|
1076 { |
|
1077 CUpnpDevice* device = new (ELeave) CUpnpDevice(); |
|
1078 CleanupStack::PushL( device ); |
|
1079 Init(); |
|
1080 if(!this->iUUID || !this->iDeviceType || !this->iDescriptionURL) |
|
1081 { |
|
1082 CleanupStack::PopAndDestroy(device); |
|
1083 User::Leave(KErrGeneral); |
|
1084 } |
|
1085 |
|
1086 device->SetUuidL( *this->iUUID ); |
|
1087 device->SetTypeL( *this->iDeviceType); |
|
1088 device->SetDescriptionUrlL( *this->iDescriptionURL ); |
|
1089 device->SetDeviceNetwork( this->iNetworkType ); |
|
1090 device->SetAddress( this->iAddress ); |
|
1091 device->SetAlive( this->iAlive ); |
|
1092 device->SetExpired( this->iExpired ); |
|
1093 |
|
1094 CleanupStack::Pop( device ); |
|
1095 return device; |
|
1096 } |
|
1097 |
|
1098 // End of File |