|
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 // cupnpservicediscoveryimpl.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <connpref.h> |
|
19 #include "cupnpservicediscoveryimpl.h" |
|
20 #include <upnp/upnpconstants.h> |
|
21 |
|
22 CUPnPServiceDiscoveryImpl::CUPnPServiceDiscoveryImpl () |
|
23 { |
|
24 } |
|
25 CUPnPServiceDiscoveryImpl* CUPnPServiceDiscoveryImpl::NewL() |
|
26 { |
|
27 CUPnPServiceDiscoveryImpl* self = new (ELeave) CUPnPServiceDiscoveryImpl; |
|
28 return self; |
|
29 } |
|
30 CUPnPServiceDiscoveryImpl::~CUPnPServiceDiscoveryImpl () |
|
31 { |
|
32 |
|
33 delete iEventNotifier; |
|
34 delete iUPnPSearch; |
|
35 delete iUPnPDescribe; |
|
36 delete iUPnPSubscribe; |
|
37 delete iUPnPRegister; |
|
38 |
|
39 iHostResolver.Close(); |
|
40 iSubConnection.Close(); |
|
41 iConnection.Close(); |
|
42 iSocketServer.Close(); |
|
43 } |
|
44 |
|
45 // Explicitly start the connection |
|
46 TInt CUPnPServiceDiscoveryImpl::Construct( TUint aTierId ) |
|
47 { |
|
48 TInt err; |
|
49 //Connect the Socket Server |
|
50 if((err = iSocketServer.Connect()) != KErrNone) |
|
51 return err; |
|
52 |
|
53 //const TUint KUPnPTierId = 0x2000D054; |
|
54 // Open the connection passing the socket server and the tier Id |
|
55 if((err = iConnection.Open( iSocketServer, aTierId )) != KErrNone) |
|
56 return err; |
|
57 |
|
58 //Start the connection using the given preferences |
|
59 TConnSnapPref prefs ( KDiscoveryConnPref ); |
|
60 if((err = iConnection.Start( prefs )) != KErrNone) |
|
61 return err; |
|
62 |
|
63 //Create a new sub-connection on the started connection |
|
64 err = iSubConnection.Open(iSocketServer, RSubConnection::ECreateNew, iConnection); |
|
65 if ( err != KErrNone ) |
|
66 return err; |
|
67 |
|
68 err = iHostResolver.Open( iSocketServer, KAfInet , KProtocolInetTcp);// , iConnection); |
|
69 if (err != KErrNone ) |
|
70 return err; |
|
71 |
|
72 iEventNotifier = new CUPnPEventNotifier ( *this , iSubConnection ); |
|
73 if( !iEventNotifier ) |
|
74 return KErrNoMemory ; |
|
75 |
|
76 iEventNotifier->Notify(); |
|
77 return KErrNone; |
|
78 } |
|
79 |
|
80 // Sends the M-SEARCH request |
|
81 void CUPnPServiceDiscoveryImpl::Discover ( const RPnPParameterBundle& aServiceInfo ) |
|
82 { |
|
83 TRAPD( err, DiscoverL( aServiceInfo )); |
|
84 if(err != KErrNone ) |
|
85 aServiceInfo.PnPObserver()->OnPnPError(err); |
|
86 } |
|
87 |
|
88 void CUPnPServiceDiscoveryImpl::DiscoverL ( const RPnPParameterBundle& aServiceInfo ) |
|
89 { |
|
90 if( !iUPnPSearch ) |
|
91 iUPnPSearch = CUPnPSearch::NewL( iSubConnection ); |
|
92 |
|
93 __ASSERT_DEBUG( iUPnPSearch->DiscoverInProgress()== EFalse,User::Panic(KUPnPDiscoveryInProgress,KUPnPErrDiscoveryInProgress) ); |
|
94 iUPnPSearch->SubmitRequestL( aServiceInfo ); |
|
95 } |
|
96 |
|
97 |
|
98 void CUPnPServiceDiscoveryImpl::Describe( const RPnPParameterBundle& aServiceInfo ) |
|
99 { |
|
100 TRAPD( err, DescribeL( aServiceInfo )); |
|
101 if(err != KErrNone ) |
|
102 aServiceInfo.PnPObserver()->OnPnPError(err); |
|
103 } |
|
104 // Sends the Describe request |
|
105 void CUPnPServiceDiscoveryImpl::DescribeL ( const RPnPParameterBundle& aServiceInfo ) |
|
106 { |
|
107 if( !iUPnPDescribe ) |
|
108 iUPnPDescribe = new (ELeave) CUPnPDescribe(iSubConnection ,iHostResolver); |
|
109 iUPnPDescribe->SubmitRequestL(aServiceInfo); |
|
110 } |
|
111 //Sends the Subscribe request |
|
112 void CUPnPServiceDiscoveryImpl::Subscribe ( const RPnPParameterBundle& aServiceInfo ) |
|
113 { |
|
114 TRAPD( err, SubscribeL( aServiceInfo )); |
|
115 if(err != KErrNone ) |
|
116 aServiceInfo.PnPObserver()->OnPnPError(err); |
|
117 } |
|
118 |
|
119 void CUPnPServiceDiscoveryImpl::SubscribeL ( const RPnPParameterBundle& aServiceInfo ) |
|
120 { |
|
121 if( !iUPnPSubscribe ) |
|
122 iUPnPSubscribe = CUPnPSubscribe::NewL( iSubConnection, iHostResolver ); |
|
123 |
|
124 iUPnPSubscribe->SubmitRequestL( aServiceInfo ); |
|
125 } |
|
126 |
|
127 void CUPnPServiceDiscoveryImpl::RegisterNotify( const RPnPParameterBundle& aServiceInfo )//done |
|
128 { |
|
129 TRAPD( err, RegisterNotifyL( aServiceInfo )); |
|
130 if(err != KErrNone ) |
|
131 aServiceInfo.PnPObserver()->OnPnPError(err); |
|
132 } |
|
133 // Used to register for advertisements of specific service type or ssdp:all |
|
134 void CUPnPServiceDiscoveryImpl::RegisterNotifyL ( const RPnPParameterBundle& aServiceInfo )//done |
|
135 { |
|
136 if( !iUPnPRegister ) |
|
137 iUPnPRegister = new (ELeave) CUPnPRegisterNotify(iSubConnection ); |
|
138 iUPnPRegister->SubmitRequestL(aServiceInfo); |
|
139 } |
|
140 |
|
141 /* Used to cancel previous requests of control point */ |
|
142 void CUPnPServiceDiscoveryImpl::Cancel ( const RPnPParameterBundle& aServiceInfo )//done |
|
143 { |
|
144 //Ignore the error. |
|
145 TRAP_IGNORE(ProcessCancelL(aServiceInfo)); |
|
146 } |
|
147 |
|
148 /* Used to call the NotifyResults method (which sends the responses back to the |
|
149 callback of the respective classes. In case , responses are coming for requests |
|
150 then they're ignored as they'll mostly be acknowlegements. |
|
151 @param afamilyId The family according to which NotifyResults of respective class |
|
152 is called |
|
153 */ |
|
154 void CUPnPServiceDiscoveryImpl::OnNotificationL (TUint32 afamilyId) |
|
155 { |
|
156 RPnPParameterBundleBase pnpBundle; |
|
157 CleanupClosePushL(pnpBundle); |
|
158 // Get the subcon parameters |
|
159 User::LeaveIfError(iSubConnection.GetParameters(pnpBundle)); |
|
160 |
|
161 // Send a clear request |
|
162 RPnPParameterBundleBase pBundle; |
|
163 User::LeaveIfError(pBundle.Open()); |
|
164 CleanupClosePushL(pBundle); |
|
165 RParameterFamily family = pBundle.CreateFamilyL(EUPnPClearParamSet); |
|
166 User::LeaveIfError ( iSubConnection.SetParameters(pBundle) ); |
|
167 CleanupStack::PopAndDestroy(&pBundle); |
|
168 CleanupStack::Pop(&pnpBundle); |
|
169 |
|
170 switch(afamilyId) |
|
171 { |
|
172 case EUPnPDiscoverResponseParamSet: |
|
173 iUPnPSearch->NotifyResultsL(pnpBundle); |
|
174 break; |
|
175 |
|
176 case EUPnPDescribeResponseParamSet: |
|
177 iUPnPDescribe->NotifyResultsL(pnpBundle); |
|
178 break; |
|
179 |
|
180 case EUPnPPresenceAnnouncementParamSet: |
|
181 case EUPnPAbsenceAnnouncementParamSet: |
|
182 iUPnPRegister->NotifyResultsL(afamilyId, pnpBundle); |
|
183 break; |
|
184 |
|
185 case EUPnPSubscribeResponseParamSet: |
|
186 case EUPnPNotifyEventParamSet: |
|
187 iUPnPSubscribe->NotifyResultsL(afamilyId, pnpBundle); |
|
188 break; |
|
189 |
|
190 default: |
|
191 __ASSERT_DEBUG(0, User::Panic(KUPnPInvalidFamily,KUPnPErrInvalidFamily)); |
|
192 break; |
|
193 } |
|
194 } |
|
195 |
|
196 TInt CUPnPServiceDiscoveryImpl::InitiateControl ( RControlChannel& /*aControlChannel*/, const TDesC8& aUri ) |
|
197 { |
|
198 TInetAddr addr; |
|
199 TRAPD ( err, CUPnPUtils::ResolveHostAddressL ( iHostResolver, aUri, addr ) ); |
|
200 |
|
201 if ( err == KErrNone ) |
|
202 { |
|
203 TConnectionDetails connDetails ( &addr, aUri ); |
|
204 //err = aControlChannel.Open ( iSocketServer, iSubConnection, KAfInet, EFalse, KProtocolInetTcp, connDetails ); |
|
205 } |
|
206 |
|
207 return err; |
|
208 } |
|
209 |
|
210 void CUPnPServiceDiscoveryImpl::ProcessCancelL( const RPnPParameterBundle& aServiceInfo) |
|
211 { |
|
212 RParameterFamily family=const_cast<RPnPParameterBundle&>(aServiceInfo).GetFamilyAtIndex(0); |
|
213 |
|
214 switch(family.Id()) |
|
215 { |
|
216 case EUPnPCancelDiscoverParamSet: |
|
217 if( iUPnPSearch ) |
|
218 iUPnPSearch->CancelSearchL( aServiceInfo ); |
|
219 break; |
|
220 |
|
221 case EUPnPCancelDescribeParamSet: |
|
222 if ( iUPnPDescribe ) |
|
223 iUPnPDescribe->CancelDescribeL( aServiceInfo ); |
|
224 break; |
|
225 |
|
226 case EUPnPCancelRegisterNotifyParamSet: |
|
227 if( iUPnPRegister ) |
|
228 iUPnPRegister->CancelNotifyAnnouncementL( aServiceInfo ); |
|
229 break; |
|
230 |
|
231 case EUPnPCancelSubscribeParamSet: |
|
232 if ( iUPnPSubscribe ) |
|
233 iUPnPSubscribe->CancelSubscribeL( aServiceInfo ); |
|
234 break; |
|
235 |
|
236 default: |
|
237 __ASSERT_DEBUG(0, User::Panic(KUPnPInvalidFamily,KUPnPErrInvalidFamily)); |
|
238 break; |
|
239 } |
|
240 } |