|
1 // Copyright (c) 2008-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 // |
|
15 |
|
16 #include "cupnpregisternotify.h" |
|
17 #include "pnputils.h" |
|
18 #include <upnp/upnpconstants.h> |
|
19 |
|
20 _LIT8(KSsdpAll,"ssdp:all"); |
|
21 |
|
22 CUPnPRegisterNotify::CUPnPRegisterNotify( RSubConnection& aSubConnection ) |
|
23 : iSubConnection( aSubConnection ) |
|
24 { |
|
25 } |
|
26 |
|
27 CUPnPRegisterNotify::~CUPnPRegisterNotify() |
|
28 { |
|
29 delete iElementArray; |
|
30 } |
|
31 /* Submits a request to the network to register for announcements of a specific type. |
|
32 @param aBundle Parameter bundle containing list of uris to be registered |
|
33 */ |
|
34 void CUPnPRegisterNotify::SubmitRequestL( const RPnPParameterBundle& aBundle ) |
|
35 { |
|
36 RParameterFamily family = const_cast<RPnPParameterBundle&>(aBundle).FindFamily ( EUPnPRegisterAnnouncementParamSet ); |
|
37 // Iterate through all the param sets in the passed bundle |
|
38 |
|
39 CUPnPRegisterAnnouncementParamSet* paramSet = NULL; |
|
40 |
|
41 TUint count = family.CountParameterSets ( RParameterFamily::ERequested ) ; |
|
42 // Perform the first iteration in which validation of all the uris |
|
43 // contained in the bundle will be done |
|
44 |
|
45 for ( TInt paramIndex = count - 1; paramIndex >= 0; paramIndex-- ) |
|
46 { |
|
47 paramSet = static_cast<CUPnPRegisterAnnouncementParamSet*> ( family.GetParameterSetAtIndex ( paramIndex, RParameterFamily::ERequested ) ); |
|
48 const TDesC8& uri = paramSet->Uri(); |
|
49 if( !iElementArray ) |
|
50 { |
|
51 iElementArray = new (ELeave) CUPnPElementArray ; |
|
52 if (uri.CompareF(KSsdpAll) != NULL) |
|
53 User::LeaveIfError(CUPnPUtils::GenericUriValidity( uri, CUPnPUtils::EAny )); |
|
54 iElementArray->InsertElementL( aBundle.PnPObserver() , uri ); |
|
55 } |
|
56 else |
|
57 { |
|
58 if ( iElementArray->MatchElement( uri ) || iElementArray->MatchElement( KSsdpAll )) |
|
59 { |
|
60 reinterpret_cast<RUPnPParameterFamily*>(&family)->DeleteParamSetL ( paramIndex ); |
|
61 continue; |
|
62 } |
|
63 if (uri.CompareF( KSsdpAll) == NULL) |
|
64 { |
|
65 iElementArray->SsdpAllModificationL( aBundle.PnPObserver() ); |
|
66 for(TInt i=family.CountParameterSets(RParameterFamily::ERequested)-1; i>=0 ; i--) |
|
67 { |
|
68 if( i != paramIndex ) |
|
69 reinterpret_cast<RUPnPParameterFamily*>(&family)->DeleteParamSetL ( i ); |
|
70 } |
|
71 break; |
|
72 } |
|
73 |
|
74 User::LeaveIfError( CUPnPUtils::GenericUriValidity( uri, CUPnPUtils::EAny ) ); |
|
75 iElementArray->InsertElementL( aBundle.PnPObserver() , uri ); |
|
76 } |
|
77 } |
|
78 User::LeaveIfError(iSubConnection.SetParameters(aBundle)); |
|
79 } |
|
80 |
|
81 /* Used to cancel registration request |
|
82 @param aServiceInfo Bundle containing list of uris whose registraion for |
|
83 advertisements have to be cancelled |
|
84 */ |
|
85 void CUPnPRegisterNotify::CancelNotifyAnnouncementL( const RPnPParameterBundle& aServiceInfo ) |
|
86 { |
|
87 RParameterFamily family = const_cast<RPnPParameterBundle&>(aServiceInfo).FindFamily ( EUPnPCancelRegisterNotifyParamSet ); |
|
88 // Iterate through all the param sets in the passed bundle |
|
89 CUPnPCancelRegisterNotifyParamSet* paramSet = NULL; |
|
90 TUint count = family.CountParameterSets ( RParameterFamily::ERequested ) ; |
|
91 |
|
92 for ( TInt paramIndex = count - 1; paramIndex >= 0; paramIndex-- ) |
|
93 { |
|
94 paramSet = static_cast<CUPnPCancelRegisterNotifyParamSet*> ( family.GetParameterSetAtIndex ( paramIndex, RParameterFamily::ERequested) ); |
|
95 |
|
96 if ( !(iElementArray->MatchElement(paramSet->Uri()))) |
|
97 { |
|
98 reinterpret_cast<RUPnPParameterFamily*>(&family)->DeleteParamSetL ( paramIndex ); |
|
99 continue; |
|
100 } |
|
101 else |
|
102 iElementArray->RemoveElement( paramSet->Uri() ); |
|
103 // Removes the uri entry from the array if exists |
|
104 } |
|
105 |
|
106 User::LeaveIfError(iSubConnection.SetParameters( aServiceInfo )); |
|
107 } |
|
108 |
|
109 /* Sends the notification to the client according to the advertisement received. |
|
110 Advertisements can be for both presence (ssdp:alive) or absence (ssdp:bye-bye) |
|
111 |
|
112 @param aFamily Indicates whether the advertisement is presence or absence |
|
113 */ |
|
114 void CUPnPRegisterNotify::NotifyResultsL(TUint32 aFamily, RPnPParameterBundleBase& aBundle) |
|
115 { |
|
116 MPnPObserver* observer = NULL; |
|
117 |
|
118 CUPnPPresenceAnnouncementParamSet* presenceParamSet = NULL; |
|
119 CUPnPAbsenceAnnouncementParamSet* absenceParamSet = NULL; |
|
120 RParameterFamily family ; |
|
121 switch(aFamily) |
|
122 { |
|
123 case EUPnPPresenceAnnouncementParamSet: |
|
124 { |
|
125 family = aBundle.FindFamily(EUPnPPresenceAnnouncementParamSet); |
|
126 __ASSERT_DEBUG(!family.IsNull (), User::Panic(KUPnPInvalidFamily,KUPnPErrInvalidFamily)); |
|
127 __ASSERT_DEBUG( family.CountParameterSets(RParameterFamily::ERequested) > 0, User::Panic(KUPnPNoParamSet,KUPnPErrNoParamSet)); |
|
128 TUint count = family.CountParameterSets ( RParameterFamily::ERequested ) ; |
|
129 presenceParamSet = static_cast<CUPnPPresenceAnnouncementParamSet*> ( family.GetParameterSetAtIndex ( count - 1, RParameterFamily::ERequested ) ); |
|
130 |
|
131 observer = iElementArray->MatchElement( presenceParamSet->Uri () ); |
|
132 if ( !observer ) |
|
133 { |
|
134 observer = iElementArray->MatchElement( KSsdpAll ); |
|
135 User::LeaveIfNull(observer); |
|
136 } |
|
137 break; |
|
138 } |
|
139 |
|
140 case EUPnPAbsenceAnnouncementParamSet: |
|
141 { |
|
142 // Remove the uri from the element array as the service |
|
143 // point is no more in the network |
|
144 family = aBundle.FindFamily(EUPnPAbsenceAnnouncementParamSet); |
|
145 __ASSERT_DEBUG(!family.IsNull (), User::Panic(KUPnPInvalidFamily,KUPnPErrInvalidFamily)); |
|
146 __ASSERT_DEBUG( family.CountParameterSets(RParameterFamily::ERequested) > 0, User::Panic(KUPnPNoParamSet,KUPnPErrNoParamSet)); |
|
147 TUint count = family.CountParameterSets ( RParameterFamily::ERequested ) ; |
|
148 absenceParamSet = static_cast<CUPnPAbsenceAnnouncementParamSet*> ( family.GetParameterSetAtIndex ( count - 1, RParameterFamily::ERequested ) ); |
|
149 |
|
150 observer = iElementArray->MatchElement( absenceParamSet->Uri () ); |
|
151 if ( !observer ) |
|
152 { |
|
153 observer = iElementArray->MatchElement( KSsdpAll ); |
|
154 User::LeaveIfNull(observer); |
|
155 } |
|
156 break; |
|
157 } |
|
158 |
|
159 default: |
|
160 __ASSERT_DEBUG(0, User::Panic(KUPnPInvalidFamily,KUPnPErrInvalidFamily)); |
|
161 } |
|
162 |
|
163 observer->OnPnPEventL( aBundle ) ; |
|
164 } |