|
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: Message dispatcher |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32svr.h> |
|
21 #include "upnpdispatcher.pan" |
|
22 #include "upnpdispatcher.h" |
|
23 #include "upnpdiscoveryobserver.h" |
|
24 #include "upnpdispatcherengine.h" |
|
25 #include "upnpstring.h" |
|
26 #include "upnpsettings.h" |
|
27 #include "upnpcustomlog.h" |
|
28 |
|
29 #ifdef _DEBUG |
|
30 #define KLogFile _L("UPnPStack.txt") |
|
31 #endif |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CUpnpDispatcher::CUpnpDispatcher |
|
37 // C++ default constructor can NOT contain any code, that |
|
38 // might leave. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CUpnpDispatcher::CUpnpDispatcher( MUpnpDiscoveryObserver* aParent) |
|
42 : iParent( aParent ) |
|
43 { |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CUpnpDispatcher::ConstructL |
|
48 // Symbian 2nd phase constructor can leave. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 void CUpnpDispatcher::ConstructL( ) |
|
52 { |
|
53 // LOGSH(iHandle, "Dispatcher::ConstructL"); |
|
54 |
|
55 iEngine = CUpnpDispatcherEngine::NewL( *this ); |
|
56 iUpdateId = 0; |
|
57 |
|
58 iEngine->UpdateDevicesL(iUpdateId); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CUpnpDispatcher::NewL |
|
63 // Two-phased constructor. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 EXPORT_C CUpnpDispatcher* CUpnpDispatcher::NewL( MUpnpDiscoveryObserver* aParent ) |
|
67 { |
|
68 CUpnpDispatcher* self = NewLC( aParent ); |
|
69 CleanupStack::Pop( self ); |
|
70 return( self ); |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CUpnpDispatcher::NewLC |
|
75 // Two-phased constructor. |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 EXPORT_C CUpnpDispatcher* CUpnpDispatcher::NewLC( MUpnpDiscoveryObserver* aParent ) |
|
79 { |
|
80 CUpnpDispatcher* self = new (ELeave) CUpnpDispatcher( aParent ); |
|
81 CleanupStack::PushL( self ); |
|
82 self->ConstructL(); |
|
83 |
|
84 if( aParent ) |
|
85 { |
|
86 self->StartHttpServerL( EFalse , KRandomPort ); |
|
87 } |
|
88 return self; |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CUpnpDispatcher::~CUpnpDispatcher |
|
93 // Destructor. |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 EXPORT_C CUpnpDispatcher::~CUpnpDispatcher() |
|
97 { |
|
98 delete iEngine; |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CUpnpDispatcher::DeviceListReceivedL |
|
103 // |
|
104 // (other items were commented in a header). |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 void CUpnpDispatcher::DeviceListReceivedL(TInt aUpdateId) |
|
108 { |
|
109 //LOGSH( iHandle, "Dispatcher DeviceListReceived"); |
|
110 UpdateDevicesL(aUpdateId); |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CUpnpDispatcher::AddCustomer |
|
115 // Adds a customer to this Dispatcher. |
|
116 // (other items were commented in a header). |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 EXPORT_C void CUpnpDispatcher::AddCustomer( const MUpnpDispatcherCustomer& aCustomer ) |
|
120 { |
|
121 //LOGSH( iHandle, "Dispatcher AddCustomer"); |
|
122 TRAP_IGNORE(AddCustomerL(aCustomer, ETrue )); |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CUpnpDispatcher::RemoveCustomer |
|
127 // Removes a customer from Dispatcher. |
|
128 // (other items were commented in a header). |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 EXPORT_C void CUpnpDispatcher::RemoveCustomer( const MUpnpDispatcherCustomer& aCustomer ) |
|
132 { |
|
133 RemoveCustomer(aCustomer, ETrue); |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CUpnpDispatcher::AddCustomer |
|
138 // Adds a customer to this Dispatcher. |
|
139 // (other items were commented in a header). |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 EXPORT_C void CUpnpDispatcher::AddCustomerL( const MUpnpDispatcherCustomer& aCustomer, TBool aIsCP) |
|
143 { |
|
144 //LOGSH( iHandle, "Dispatcher AddCustomer"); |
|
145 iEngine->AddCustomer( aCustomer ); |
|
146 if (aIsCP) |
|
147 { |
|
148 iEngine->AddControlPointClientL( ); |
|
149 } |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CUpnpDispatcher::RemoveCustomer |
|
154 // Removes a customer from Dispatcher. |
|
155 // (other items were commented in a header). |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 EXPORT_C void CUpnpDispatcher::RemoveCustomer( const MUpnpDispatcherCustomer& aCustomer, |
|
159 TBool aIsCP) |
|
160 { |
|
161 LOGS1("CUpnpDispatcher::RemoveCustomer 0x%x", &aCustomer); |
|
162 iEngine->RemoveCustomer( aCustomer ); |
|
163 if ( aIsCP ) |
|
164 { |
|
165 TRAP_IGNORE(iEngine->RemoveControlPointClientL( )); |
|
166 } |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CUpnpDispatcher::SendMessageL |
|
171 // Sends a message using Engine's HTTP server, |
|
172 // if device is local (third param), used local sending feature, type of message has to be EAction |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 EXPORT_C void CUpnpDispatcher::SendMessageL( CUpnpHttpMessage* aMessage, |
|
176 MUpnpDispatcherCustomer& aCustomer , |
|
177 TBool /*aIsLocal*/ ) |
|
178 { |
|
179 //LOGSH( iHandle, "Dispatcher SendMessageL"); |
|
180 |
|
181 TPtrC8 path(0,0); |
|
182 if (iParent != NULL) |
|
183 { |
|
184 path.Set(iParent->Path()); |
|
185 } |
|
186 |
|
187 |
|
188 HBufC8* wholePath = HBufC8::NewLC( path.Length() |
|
189 + 1 |
|
190 + aCustomer.Path().Length() ); |
|
191 TPtr8 ptr = wholePath->Des(); |
|
192 ptr.Append( path ); |
|
193 ptr.Append( UpnpString::KSlash() ); |
|
194 ptr.Append( aCustomer.Path() ); |
|
195 |
|
196 if ( aMessage ) |
|
197 { |
|
198 aMessage->SetSenderPathL( *wholePath ); |
|
199 iEngine->SendMessageL( aMessage ); |
|
200 } |
|
201 |
|
202 CleanupStack::PopAndDestroy(wholePath); |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CUpnpDispatcher::UpdateDevicesL |
|
207 // |
|
208 // (other items were commented in a header). |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 EXPORT_C void CUpnpDispatcher::UpdateDevicesL( TInt aNewId ) |
|
212 { |
|
213 |
|
214 //LOGSH( iHandle, "Dispatcher UpdateDevicesL"); |
|
215 if ( iUpdateId != aNewId ) |
|
216 { |
|
217 // Go through the new devices and add them inform |
|
218 // the Control Point of the new devices? |
|
219 const RPointerArray<CUpnpDevice>& newDevices = iEngine->NewDevices(); |
|
220 for ( TInt i = 0; i < newDevices.Count(); i++ ) |
|
221 { |
|
222 CUpnpDevice* dev = newDevices[i]; |
|
223 |
|
224 if ( iParent != NULL ) |
|
225 { |
|
226 |
|
227 if ( dev->Alive() ) |
|
228 { |
|
229 iParent->DeviceFoundL( *dev ); |
|
230 } |
|
231 else |
|
232 { |
|
233 iParent->DeviceLostL( *dev ); |
|
234 } |
|
235 } |
|
236 |
|
237 } |
|
238 iEngine->RemoveDevices(); |
|
239 |
|
240 iUpdateId = aNewId; |
|
241 } |
|
242 } |
|
243 |
|
244 // ----------------------------------------------------------------------------- |
|
245 // CUpnpDispatcher::AddLocalDeviceL |
|
246 // |
|
247 // (other items were commented in a header). |
|
248 // ----------------------------------------------------------------------------- |
|
249 // |
|
250 EXPORT_C void CUpnpDispatcher::AddLocalDeviceL( const TDesC8& aUuid, |
|
251 const TDesC8& aDeviceType, |
|
252 const TDesC8& aDescriptionPath, |
|
253 const CDesC8Array& aServices, |
|
254 const TBool aIsRootDevice ) |
|
255 { |
|
256 //LOGSH( iHandle, "Dispatcher AddLocalDeviceL"); |
|
257 iEngine->AddLocalDeviceL( aUuid, aDeviceType, aDescriptionPath, aServices, aIsRootDevice ); |
|
258 } |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // CUpnpDispatcher::RemoveLocalDeviceL |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 void CUpnpDispatcher::RemoveLocalDeviceL( const TDesC8& aUuid, TBool aSilent ) |
|
265 { |
|
266 //LOGSH( iHandle, "Dispatcher RemoveLocalDeviceL"); |
|
267 iEngine->RemoveLocalDeviceL( aUuid, aSilent ); |
|
268 } |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CUpnpDispatcher::SearchL |
|
272 // Sends a SSDP search with given string. |
|
273 // (other items were commented in a header). |
|
274 // ----------------------------------------------------------------------------- |
|
275 // |
|
276 EXPORT_C void CUpnpDispatcher::SearchL( const TDesC8& aSearchString ) |
|
277 { |
|
278 iEngine->SsdpSearchL( aSearchString ); |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CUpnpDispatcher::StopFilteringL |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 EXPORT_C void CUpnpDispatcher::StopFilteringL( const TDesC8& aUuids ) |
|
286 { |
|
287 iEngine->SsdpStopFilteringL( aUuids ); |
|
288 } |
|
289 |
|
290 // ----------------------------------------------------------------------------- |
|
291 // CUpnpDispatcher::SearchL |
|
292 // |
|
293 // (other items were commented in a header). |
|
294 // ----------------------------------------------------------------------------- |
|
295 // |
|
296 EXPORT_C void CUpnpDispatcher::SearchL( const TDesC16& aSearchString ) |
|
297 { |
|
298 //LOGSH( iHandle, "Dispatcher SearchL"); |
|
299 HBufC8* buf = UpnpString::FromUnicodeL( aSearchString ); |
|
300 SearchL( *buf ); |
|
301 delete buf; |
|
302 } |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // CUpnpDispatcher::HttpServerAddressL |
|
306 // Returns the HTTP servers IP address. |
|
307 // (other items were commented in a header). |
|
308 // ----------------------------------------------------------------------------- |
|
309 // |
|
310 EXPORT_C TInetAddr CUpnpDispatcher::HttpServerAddress() |
|
311 { |
|
312 return iEngine->HttpServerAddress(); |
|
313 } |
|
314 |
|
315 // ----------------------------------------------------------------------------- |
|
316 // CUpnpDispatcher::MacAddressL |
|
317 // Returns the MAC address of HTTP server. |
|
318 // (other items were commented in a header). |
|
319 // ----------------------------------------------------------------------------- |
|
320 // |
|
321 const HBufC8* CUpnpDispatcher::MacAddressL() |
|
322 { |
|
323 //LOGSH( iHandle, "Dispatcher MacAddressL"); |
|
324 return iEngine->MacAddressL(); |
|
325 } |
|
326 |
|
327 // ----------------------------------------------------------------------------- |
|
328 // CUpnpDispatcher::SetTransactionCreator |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 void CUpnpDispatcher::SetTransactionCreator( |
|
332 MUpnpHttpServerTransactionCreator* aTransactionCreator ) |
|
333 { |
|
334 iEngine->SetTransactionCreator( aTransactionCreator ); |
|
335 } |
|
336 |
|
337 // ----------------------------------------------------------------------------- |
|
338 // CUpnpDispatcher::StartHttpServerL |
|
339 // ----------------------------------------------------------------------------- |
|
340 // |
|
341 EXPORT_C void CUpnpDispatcher::StartHttpServerL( TBool aRegister , const TInt aPort ) |
|
342 { |
|
343 iEngine->StartHttpServerL( aRegister , aPort ); |
|
344 } |
|
345 |
|
346 // ----------------------------------------------------------------------------- |
|
347 // CUpnpDispatcher::StopHttpServerL |
|
348 // (other items were commented in a header). |
|
349 // ----------------------------------------------------------------------------- |
|
350 // |
|
351 EXPORT_C void CUpnpDispatcher::StopHttpServer() |
|
352 { |
|
353 iEngine->StopHttpServer(); |
|
354 } |
|
355 |
|
356 EXPORT_C void CUpnpDispatcher::StartIPFilteringL( ) |
|
357 { |
|
358 #ifdef RD_UPNP_REMOTE_ACCESS |
|
359 iEngine->HttpServer()->StartIPFilteringL(); |
|
360 #endif |
|
361 } |
|
362 |
|
363 EXPORT_C void CUpnpDispatcher::StopIPFiltering( ) |
|
364 { |
|
365 #ifdef RD_UPNP_REMOTE_ACCESS |
|
366 iEngine->HttpServer()->StopIPFiltering( ); |
|
367 #endif |
|
368 } |
|
369 |
|
370 // End of File |