|
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: Media Server Session |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "upnpmediaserversession.h" |
|
21 #include "upnpmediaservereventhandler.h" |
|
22 #include "upnpmediaserver.pan" |
|
23 #include "upnpitem.h" |
|
24 #include "upnpicon.h" |
|
25 #include "upnpcontainer.h" |
|
26 #include "upnpitemlist.h" |
|
27 #include "upnpcontainerlist.h" |
|
28 #include "upnpbrowsecriteria.h" |
|
29 #include "upnpmediaserverclient.h" |
|
30 #include <xml/xmlparsererrors.h> |
|
31 #include <s32mem.h> |
|
32 |
|
33 |
|
34 |
|
35 // ================= MEMBER FUNCTIONS ======================= |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CUpnpMediaServerSession::CUpnpMediaServerSession |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CUpnpMediaServerSession::CUpnpMediaServerSession(CUpnpMediaServer* aServer) |
|
42 : CSession2(), iRespLengthPkg(iRespLength), iRespExecStatusPkg(iRespExecStatus) |
|
43 { |
|
44 iMediaServer = aServer; |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CUpnpMediaServerSession::ConstructL |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 void CUpnpMediaServerSession::ConstructL() |
|
52 { |
|
53 iEventHandler = CUpnpMediaServerEventHandler::NewL(this->iMediaServer); |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CUpnpMediaServerSession::~CUpnpMediaServerSession |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CUpnpMediaServerSession::~CUpnpMediaServerSession() |
|
61 { |
|
62 delete iResponseBuffer; |
|
63 delete iEventHandler; |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CUpnpMediaServerSession::ServiceL |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void CUpnpMediaServerSession::ServiceL( const RMessage2& aMessage ) |
|
71 { |
|
72 // first of all server must be started |
|
73 if( iMediaServer->Status() == RUpnpMediaServerClient::EStopped && |
|
74 aMessage.Function() != EMediaServerStatus && |
|
75 aMessage.Function() != EMediaServerStart && |
|
76 aMessage.Function() != EMediaServerStartOffline && |
|
77 aMessage.Function() != EMediaServerSubscribeEvents && |
|
78 aMessage.Function() != EMediaServerUnsubscribeEvents && |
|
79 aMessage.Function() != EMediaServerListenTransferEvent && |
|
80 aMessage.Function() != EMediaServerGetTransferEventBody && |
|
81 aMessage.Function() != EMediaServerStatusChange && |
|
82 aMessage.Function() != EMediaServerStatusChangeCancel && |
|
83 aMessage.Function() != EMediaServerAddIcon && |
|
84 aMessage.Function() != EMediaServerRemoveIcon && |
|
85 aMessage.Function() != EMediaServerRemoveIcons && |
|
86 aMessage.Function() != EMediaServerUpdateIcon |
|
87 ) |
|
88 { |
|
89 User::Leave( KErrNotReady ); |
|
90 } |
|
91 |
|
92 switch ( aMessage.Function() ) |
|
93 { |
|
94 case EMediaServerStatus: |
|
95 EventMediaServerStatusL( aMessage ); |
|
96 break; |
|
97 case EMediaServerStartOffline: |
|
98 EventMediaServerStartOfflineL(aMessage); |
|
99 break; |
|
100 case EMediaServerStart: |
|
101 EventMediaServerStartL( aMessage ); |
|
102 break; |
|
103 case EMediaServerStop: |
|
104 EventMediaServerStop( aMessage ); |
|
105 break; |
|
106 case EMediaServerStopSilent: |
|
107 EventMediaServerStopSilent( aMessage ); |
|
108 break; |
|
109 case EMediaServerRestart: |
|
110 EventMediaServerRestartL( aMessage ); |
|
111 break; |
|
112 case EMediaServerShareItem: |
|
113 EventMediaServerShareItemL( aMessage ); |
|
114 break; |
|
115 case EMediaServerShareItemResult: |
|
116 EventMediaServerGetShareItemResultL( aMessage ); |
|
117 break; |
|
118 case EMediaServerShareContainer: |
|
119 EventMediaServerShareContainerL( aMessage ); |
|
120 break; |
|
121 case EMediaServerShareContainerResult: |
|
122 EventMediaServerGetShareContainerResultL(aMessage); |
|
123 break; |
|
124 case EMediaServerShareItemList: |
|
125 EventMediaServerShareItemListL( aMessage ); |
|
126 break; |
|
127 case EMediaServerShareItemListResult: |
|
128 EventMediaServerGetShareItemListResultL( aMessage ); |
|
129 break; |
|
130 case EMediaServerUnshareItem: |
|
131 EventMediaServerUnshareItemL( aMessage ); |
|
132 break; |
|
133 case EMediaServerUnshareRoot: |
|
134 EventMediaServerUnshareRootL( aMessage ); |
|
135 break; |
|
136 case EMediaServerUnshareContainer: |
|
137 EventMediaServerUnshareContainerL( aMessage ); |
|
138 break; |
|
139 case EMediaServerGetSharedItem: |
|
140 EventMediaServerGetSharedItemL( aMessage ); |
|
141 break; |
|
142 case EMediaServerGetSharedItemResult: |
|
143 EventMediaServerGetGetSharedItemResultL( aMessage ); |
|
144 break; |
|
145 case EMediaServerGetSharedContainer: |
|
146 EventMediaServerGetSharedContainerL( aMessage ); |
|
147 break; |
|
148 case EMediaServerGetSharedContainerResult: |
|
149 EventMediaServerGetGetSharedContainerResultL( aMessage ); |
|
150 break; |
|
151 case EMediaServerUnshareItemList: |
|
152 EventMediaServerUnshareItemListL( aMessage ); |
|
153 break; |
|
154 case EMediaServerGetSharedItemList: |
|
155 EventMediaServerGetSharedItemListL(aMessage); |
|
156 break; |
|
157 case EMediaServerGetSharedItemListResult: |
|
158 EventMediaServerGetGetSharedItemListResultL(aMessage); |
|
159 break; |
|
160 case EMediaServerGetSharedContainerList: |
|
161 EventMediaServerGetSharedContainerListL(aMessage); |
|
162 break; |
|
163 case EMediaServerGetSharedContainerListResult: |
|
164 EventMediaServerGetGetSharedContainerListResultL(aMessage); |
|
165 break; |
|
166 case EMediaServerSubscribeEvents: |
|
167 iEventHandler->EventMediaServerSubscribeEvents(aMessage); |
|
168 break; |
|
169 case EMediaServerUnsubscribeEvents: |
|
170 iEventHandler->EventMediaServerUnsubscribeEvents(aMessage); |
|
171 break; |
|
172 case EMediaServerListenTransferEvent: |
|
173 iEventHandler->EventMediaServerServerListenTransferEventL(aMessage); |
|
174 break; |
|
175 case EMediaServerGetTransferEventBody: |
|
176 iEventHandler->EventMediaServerGetTransferEventBodyL(aMessage); |
|
177 break; |
|
178 case EMediaServerGetIpAndPort: |
|
179 EventMediaServerGetIpAndPortL(aMessage); |
|
180 break; |
|
181 case EMediaServerSetUploadDirectory: |
|
182 EventSetUploadDirectoryL( aMessage ); |
|
183 break; |
|
184 case EMediaServerAddIcon: |
|
185 EventAddIconL( aMessage ); |
|
186 break; |
|
187 case EMediaServerRemoveIcon: |
|
188 EventRemoveIconL( aMessage ); |
|
189 break; |
|
190 case EMediaServerRemoveIcons: |
|
191 EventRemoveIconsL( aMessage ); |
|
192 break; |
|
193 case EMediaServerUpdateIcon: |
|
194 EventUpdateIconL( aMessage ); |
|
195 break; |
|
196 case EMediaServerShareReference: |
|
197 EventMediaServerShareReferenceL( aMessage ); |
|
198 break; |
|
199 case EMediaServerShareReferenceList: |
|
200 EventMediaServerShareReferenceListL( aMessage ); |
|
201 break; |
|
202 case EMediaServerStatusChange: |
|
203 EventMediaServerStatusChange( aMessage ); |
|
204 break; |
|
205 case EMediaServerStatusChangeCancel: |
|
206 EventMediaServerStatusChangeCancel( aMessage ); |
|
207 break; |
|
208 default : |
|
209 PanicClient( aMessage, EMediaServerBadRequest ); |
|
210 break; |
|
211 } |
|
212 } |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // CUpnpMediaServerSession::PanicClient |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 void CUpnpMediaServerSession::PanicClient( const RMessage2 &aMessage, TInt aPanic ) const |
|
219 { |
|
220 static_cast<const CUpnpSymbianServerBase*>( Server() )->PanicClient( aMessage, aPanic ); |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // CUpnpMediaServerSession::NewL |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 CUpnpMediaServerSession* CUpnpMediaServerSession::NewL(CUpnpMediaServer* aServer) |
|
228 { |
|
229 CUpnpMediaServerSession* self = CUpnpMediaServerSession::NewLC(aServer); |
|
230 CleanupStack::Pop( self ) ; |
|
231 return self ; |
|
232 } |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // CUpnpMediaServerSession::NewLC |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 CUpnpMediaServerSession* CUpnpMediaServerSession::NewLC(CUpnpMediaServer* aServer) |
|
239 { |
|
240 CUpnpMediaServerSession* self = new (ELeave) CUpnpMediaServerSession(aServer); |
|
241 CleanupStack::PushL( self ); |
|
242 self->ConstructL() ; |
|
243 return self ; |
|
244 } |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // CUpnpMediaServerSession::EventMediaServerStartL |
|
248 // ----------------------------------------------------------------------------- |
|
249 // |
|
250 void CUpnpMediaServerSession::EventMediaServerStatusL( const RMessage2& aMessage ) |
|
251 { |
|
252 TPckgBuf<TInt> status( iMediaServer->Status() ); |
|
253 aMessage.WriteL( 0, status ); |
|
254 aMessage.Complete( KErrNone ); |
|
255 } |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // CUpnpMediaServerSession::EventMediaServerStartL |
|
259 // ----------------------------------------------------------------------------- |
|
260 // |
|
261 void CUpnpMediaServerSession::EventMediaServerStartL( const RMessage2& aMessage ) |
|
262 { |
|
263 iMediaServer->CancelAVMediaServerStop();//if stop was scheduled - cancel it |
|
264 |
|
265 if ( iMediaServer->Status() != RUpnpMediaServerClient::EStartedOnline ) |
|
266 { |
|
267 TRAPD( err, iMediaServer->StartAVMediaServerL() ); |
|
268 |
|
269 if ( err == KErrNotFound // files not found |
|
270 || err == KErrArgument // empty or improper one of description files |
|
271 || (err >= EXmlParserError && err <= EXmlFeatureLockedWhileParsing) // description malformed |
|
272 || err == KErrNoMemory // problem with start because of memory usage |
|
273 ) |
|
274 { |
|
275 iMediaServer->InitializeL( ETrue ); |
|
276 iMediaServer->RestartAVMediaServerL(); |
|
277 iMediaServer->StartAVMediaServerL(); |
|
278 } |
|
279 else if (err == KErrCorrupt || err == KErrEof || err == KErrNotSupported) |
|
280 { |
|
281 iMediaServer->ResetDbL(); |
|
282 iMediaServer->StartAVMediaServerL(); |
|
283 } |
|
284 else |
|
285 { |
|
286 User::LeaveIfError(err); |
|
287 } |
|
288 } |
|
289 |
|
290 if ( !aMessage.IsNull() ) |
|
291 { |
|
292 aMessage.Complete( KErrNone ); |
|
293 } |
|
294 } |
|
295 |
|
296 // ----------------------------------------------------------------------------- |
|
297 // CUpnpMediaServerSession::EventMediaServerStartOfflineL |
|
298 // ----------------------------------------------------------------------------- |
|
299 // |
|
300 void CUpnpMediaServerSession::EventMediaServerStartOfflineL( const RMessage2& aMessage ) |
|
301 { |
|
302 iMediaServer->CancelAVMediaServerStop();//if stop was scheduled cancel it |
|
303 if( iMediaServer->Status() != RUpnpMediaServerClient::EStartedOffline ) |
|
304 { |
|
305 TRAPD(err, iMediaServer->StartAVMediaServerOfflineL()); |
|
306 if ( err == KErrNotFound // files not found |
|
307 || err == KErrArgument // empty or improper one of description files |
|
308 || (err >= EXmlParserError && err <= EXmlFeatureLockedWhileParsing) // description malformed |
|
309 || err == KErrNoMemory // problem with start because of memory usage |
|
310 ) |
|
311 { |
|
312 iMediaServer->InitializeL( ETrue ); |
|
313 iMediaServer->StartAVMediaServerOfflineL(); |
|
314 } |
|
315 else if (err == KErrCorrupt || err == KErrEof) |
|
316 { |
|
317 iMediaServer->ResetDbL(); |
|
318 iMediaServer->StartAVMediaServerOfflineL(); |
|
319 } |
|
320 else |
|
321 { |
|
322 User::LeaveIfError(err); |
|
323 } |
|
324 |
|
325 } |
|
326 aMessage.Complete( KErrNone ); |
|
327 } |
|
328 |
|
329 // ----------------------------------------------------------------------------- |
|
330 // CUpnpMediaServerSession::EventMediaServerStop |
|
331 // ----------------------------------------------------------------------------- |
|
332 // |
|
333 void CUpnpMediaServerSession::EventMediaServerStop( const RMessage2& aMessage ) |
|
334 { |
|
335 if ( iMediaServer->Status() != RUpnpMediaServerClient::EStopped ) |
|
336 { |
|
337 iMediaServer->StopAVMediaServer(EFalse); |
|
338 } |
|
339 aMessage.Complete( KErrNone ); |
|
340 } |
|
341 |
|
342 // ----------------------------------------------------------------------------- |
|
343 // CUpnpMediaServerSession::EventMediaServerStopSilent |
|
344 // ----------------------------------------------------------------------------- |
|
345 // |
|
346 void CUpnpMediaServerSession::EventMediaServerStopSilent( const RMessage2& aMessage ) |
|
347 { |
|
348 if ( iMediaServer->Status() != RUpnpMediaServerClient::EStopped ) |
|
349 { |
|
350 iMediaServer->StopAVMediaServer(ETrue); |
|
351 } |
|
352 aMessage.Complete( KErrNone ); |
|
353 } |
|
354 |
|
355 // ----------------------------------------------------------------------------- |
|
356 // CUpnpMediaServerSession::EventMediaServerRestartL |
|
357 // ----------------------------------------------------------------------------- |
|
358 // |
|
359 void CUpnpMediaServerSession::EventMediaServerRestartL( const RMessage2& aMessage ) |
|
360 { |
|
361 iMediaServer->RestartAVMediaServerL(); |
|
362 aMessage.Complete( KErrNone ); |
|
363 } |
|
364 |
|
365 // ----------------------------------------------------------------------------- |
|
366 // CUpnpMediaServerSession::EventMediaServerGetShareItemResultL |
|
367 // ----------------------------------------------------------------------------- |
|
368 // |
|
369 void CUpnpMediaServerSession::EventMediaServerGetShareItemResultL( const RMessage2& aMessage ) |
|
370 { |
|
371 ASSERT(aMessage.GetDesMaxLength(0) >= iRespLength); |
|
372 |
|
373 // Write result back to client |
|
374 aMessage.WriteL( 0, *iResponseBuffer ); |
|
375 aMessage.Complete( KErrNone ); |
|
376 |
|
377 // clean up |
|
378 delete iResponseBuffer; |
|
379 iResponseBuffer = NULL; |
|
380 } |
|
381 |
|
382 // ----------------------------------------------------------------------------- |
|
383 // CUpnpMediaServerSession::EventMediaServerGetShareContainerResultL |
|
384 // ----------------------------------------------------------------------------- |
|
385 // |
|
386 void CUpnpMediaServerSession::EventMediaServerGetShareContainerResultL( const RMessage2& aMessage ) |
|
387 { |
|
388 ASSERT(aMessage.GetDesMaxLength(0) >= iRespLength); |
|
389 |
|
390 // Write result back to client |
|
391 aMessage.WriteL( 0, *iResponseBuffer ); |
|
392 aMessage.Complete( KErrNone ); |
|
393 |
|
394 // clean up |
|
395 delete iResponseBuffer; |
|
396 iResponseBuffer = NULL; |
|
397 } |
|
398 |
|
399 // ----------------------------------------------------------------------------- |
|
400 // CUpnpMediaServerSession::EventMediaServerShareItemL |
|
401 // Stops the server. |
|
402 // ----------------------------------------------------------------------------- |
|
403 // |
|
404 void CUpnpMediaServerSession::EventMediaServerShareItemL( const RMessage2& aMessage ) |
|
405 { |
|
406 // get object from message |
|
407 CUpnpItem* item = CUpnpItem::NewL(); |
|
408 CleanupStack::PushL(item); |
|
409 ReadObjFromMessageL(aMessage, 0, item); |
|
410 |
|
411 // perform action |
|
412 iMediaServer->ShareObjectL(item); |
|
413 |
|
414 // prepare response |
|
415 iResponseBuffer = item->ToDes8L(); |
|
416 iRespLength = iResponseBuffer->Length(); |
|
417 aMessage.WriteL(1, iRespLengthPkg); |
|
418 aMessage.Complete( KErrNone ); |
|
419 |
|
420 // clean up |
|
421 CleanupStack::PopAndDestroy(item); |
|
422 } |
|
423 |
|
424 // ----------------------------------------------------------------------------- |
|
425 // CUpnpMediaServerSession::EventMediaServerGetSharedItemL |
|
426 // Stops the server. |
|
427 // ----------------------------------------------------------------------------- |
|
428 // |
|
429 void CUpnpMediaServerSession::EventMediaServerGetSharedItemL( |
|
430 const RMessage2& aMessage ) |
|
431 { |
|
432 // perform action |
|
433 CUpnpItem* item = iMediaServer->GetSharedItemL(aMessage.Int0()); |
|
434 CleanupStack::PushL(item); |
|
435 |
|
436 // prepare response |
|
437 iResponseBuffer = item->ToDes8L(); |
|
438 iRespLength = iResponseBuffer->Length(); |
|
439 aMessage.WriteL(1, iRespLengthPkg); |
|
440 aMessage.Complete( KErrNone ); |
|
441 |
|
442 // clean up |
|
443 CleanupStack::PopAndDestroy(item); |
|
444 } |
|
445 |
|
446 // ----------------------------------------------------------------------------- |
|
447 // CUpnpMediaServerSession::EventMediaServerGetGetSharedItemResultL |
|
448 // Stops the server. |
|
449 // ----------------------------------------------------------------------------- |
|
450 // |
|
451 void CUpnpMediaServerSession::EventMediaServerGetGetSharedItemResultL( |
|
452 const RMessage2& aMessage ) |
|
453 { |
|
454 ASSERT(aMessage.GetDesMaxLength(0) >= iRespLength); |
|
455 |
|
456 // Write result back to client |
|
457 aMessage.WriteL( 0, *iResponseBuffer ); |
|
458 aMessage.Complete( KErrNone ); |
|
459 |
|
460 // clean up |
|
461 delete iResponseBuffer; |
|
462 iResponseBuffer = NULL; |
|
463 } |
|
464 |
|
465 // ----------------------------------------------------------------------------- |
|
466 // CUpnpMediaServerSession::EventMediaServerGetSharedContainerL |
|
467 // Stops the server. |
|
468 // ----------------------------------------------------------------------------- |
|
469 // |
|
470 void CUpnpMediaServerSession::EventMediaServerGetSharedContainerL( |
|
471 const RMessage2& aMessage ) |
|
472 { |
|
473 // perform action |
|
474 CUpnpContainer* cont = iMediaServer->GetSingleContainerL(aMessage.Int0()); |
|
475 CleanupStack::PushL(cont); |
|
476 |
|
477 // prepare response |
|
478 iResponseBuffer = cont->ToDes8L(); |
|
479 iRespLength = iResponseBuffer->Length(); |
|
480 aMessage.WriteL(1, iRespLengthPkg); |
|
481 aMessage.Complete( KErrNone ); |
|
482 |
|
483 // clean up |
|
484 CleanupStack::PopAndDestroy(cont); |
|
485 } |
|
486 |
|
487 // ----------------------------------------------------------------------------- |
|
488 // CUpnpMediaServerSession::EventMediaServerGetShareContainerListResultL |
|
489 // Stops the server. |
|
490 // ----------------------------------------------------------------------------- |
|
491 // |
|
492 void CUpnpMediaServerSession::EventMediaServerGetGetSharedContainerResultL( |
|
493 const RMessage2& aMessage ) |
|
494 { |
|
495 ASSERT(aMessage.GetDesMaxLength(0) >= iRespLength); |
|
496 |
|
497 // Write result back to client |
|
498 aMessage.WriteL( 0, *iResponseBuffer ); |
|
499 aMessage.Complete( KErrNone ); |
|
500 |
|
501 // clean up |
|
502 delete iResponseBuffer; |
|
503 iResponseBuffer = NULL; |
|
504 } |
|
505 |
|
506 // ----------------------------------------------------------------------------- |
|
507 // CUpnpMediaServerSession::EventMediaServerShareContainerL |
|
508 // Stops the server. |
|
509 // ----------------------------------------------------------------------------- |
|
510 // |
|
511 void CUpnpMediaServerSession::EventMediaServerShareContainerL( |
|
512 const RMessage2& aMessage ) |
|
513 { |
|
514 // get object from message |
|
515 CUpnpContainer* cont = CUpnpContainer::NewL(); |
|
516 CleanupStack::PushL(cont); |
|
517 ReadObjFromMessageL(aMessage, 0, cont); |
|
518 |
|
519 // perform action |
|
520 iMediaServer->ShareObjectL(cont); |
|
521 |
|
522 // prepare response |
|
523 iResponseBuffer = cont->ToDes8L(); |
|
524 iRespLength = iResponseBuffer->Length(); |
|
525 aMessage.WriteL(1, iRespLengthPkg); |
|
526 aMessage.Complete( KErrNone ); |
|
527 |
|
528 // clean up |
|
529 CleanupStack::PopAndDestroy(cont); |
|
530 } |
|
531 |
|
532 // ----------------------------------------------------------------------------- |
|
533 // CUpnpMediaServerSession::EventMediaServerGetShareItemListResultL |
|
534 // ----------------------------------------------------------------------------- |
|
535 // |
|
536 void CUpnpMediaServerSession::EventMediaServerGetGetSharedItemListResultL( |
|
537 const RMessage2& aMessage ) |
|
538 { |
|
539 ASSERT(aMessage.GetDesMaxLength(0) >= iRespLength); |
|
540 |
|
541 // Write result back to client |
|
542 aMessage.WriteL( 0, *iResponseBuffer ); |
|
543 aMessage.WriteL( 1, iRespExecStatusPkg ); |
|
544 aMessage.Complete( KErrNone ); |
|
545 |
|
546 // clean up |
|
547 delete iResponseBuffer; |
|
548 iResponseBuffer = NULL; |
|
549 } |
|
550 |
|
551 // ----------------------------------------------------------------------------- |
|
552 // CUpnpMediaServerSession::EventMediaServerGetGetSharedContainerListResultL |
|
553 // ----------------------------------------------------------------------------- |
|
554 // |
|
555 void CUpnpMediaServerSession::EventMediaServerGetGetSharedContainerListResultL( |
|
556 const RMessage2& aMessage ) |
|
557 { |
|
558 ASSERT(aMessage.GetDesMaxLength(0) >= iRespLength); |
|
559 |
|
560 // Write result back to client |
|
561 aMessage.WriteL( 0, *iResponseBuffer ); |
|
562 aMessage.WriteL( 1, iRespExecStatusPkg ); |
|
563 aMessage.Complete( KErrNone ); |
|
564 |
|
565 // clean up |
|
566 delete iResponseBuffer; |
|
567 iResponseBuffer = NULL; |
|
568 } |
|
569 |
|
570 // ----------------------------------------------------------------------------- |
|
571 // CUpnpMediaServerSession::EventMediaServerGetShareItemListResultL |
|
572 // ----------------------------------------------------------------------------- |
|
573 // |
|
574 void CUpnpMediaServerSession::EventMediaServerGetShareItemListResultL( const RMessage2& aMessage ) |
|
575 { |
|
576 ASSERT(aMessage.GetDesMaxLength(0) >= iRespLength); |
|
577 |
|
578 // Write result back to client |
|
579 aMessage.WriteL( 0, *iResponseBuffer ); |
|
580 aMessage.WriteL( 1, iRespExecStatusPkg ); |
|
581 aMessage.Complete( KErrNone ); |
|
582 |
|
583 // clean up |
|
584 delete iResponseBuffer; |
|
585 iResponseBuffer = NULL; |
|
586 } |
|
587 // ----------------------------------------------------------------------------- |
|
588 // CUpnpMediaServerSession::EventMediaServerUnshareRootL |
|
589 // ----------------------------------------------------------------------------- |
|
590 // |
|
591 void CUpnpMediaServerSession::EventMediaServerUnshareRootL( |
|
592 const RMessage2& aMessage ) |
|
593 { |
|
594 iMediaServer->UnshareRootL(); |
|
595 aMessage.Complete( KErrNone ); |
|
596 } |
|
597 // ----------------------------------------------------------------------------- |
|
598 // CUpnpMediaServerSession::EventMediaServerUnshareItemL |
|
599 // ----------------------------------------------------------------------------- |
|
600 // |
|
601 void CUpnpMediaServerSession::EventMediaServerUnshareItemL( |
|
602 const RMessage2& aMessage ) |
|
603 { |
|
604 iMediaServer->UnshareItemL(aMessage.Int0()); |
|
605 aMessage.Complete( KErrNone ); |
|
606 } |
|
607 |
|
608 // ----------------------------------------------------------------------------- |
|
609 // CUpnpMediaServerSession::EventMediaServerUnshareContainerL |
|
610 // ----------------------------------------------------------------------------- |
|
611 // |
|
612 void CUpnpMediaServerSession::EventMediaServerUnshareContainerL( |
|
613 const RMessage2& aMessage ) |
|
614 { |
|
615 iMediaServer->UnshareContainerL(aMessage.Int0()); |
|
616 aMessage.Complete( KErrNone ); |
|
617 } |
|
618 |
|
619 // ----------------------------------------------------------------------------- |
|
620 // CUpnpMediaServerSession::EventMediaServerGetSharedItemListL |
|
621 // ----------------------------------------------------------------------------- |
|
622 // |
|
623 void CUpnpMediaServerSession::EventMediaServerGetSharedItemListL( |
|
624 const RMessage2& aMessage ) |
|
625 { |
|
626 // get object from message |
|
627 CUpnpBrowseCriteria* bc = CUpnpBrowseCriteria::NewL(); |
|
628 CleanupStack::PushL(bc); |
|
629 ReadObjFromMessageL(aMessage, 1, bc); |
|
630 |
|
631 // item list |
|
632 CUpnpItemList* il = CUpnpItemList::NewL(); |
|
633 CleanupStack::PushL(il); |
|
634 |
|
635 // perform action |
|
636 iMediaServer->GetSharedItemListL(aMessage.Int0(), bc, &iRespExecStatus, il); |
|
637 |
|
638 // prepare response |
|
639 iResponseBuffer = il->ToDes8L(); |
|
640 iRespLength = iResponseBuffer->Length(); |
|
641 aMessage.WriteL(2, iRespLengthPkg); |
|
642 aMessage.Complete( KErrNone ); |
|
643 |
|
644 // clean up |
|
645 CleanupStack::PopAndDestroy(il); |
|
646 CleanupStack::PopAndDestroy(bc); |
|
647 } |
|
648 |
|
649 // ----------------------------------------------------------------------------- |
|
650 // CUpnpMediaServerSession::EventMediaServerGetSharedContainerListL |
|
651 // ----------------------------------------------------------------------------- |
|
652 // |
|
653 void CUpnpMediaServerSession::EventMediaServerGetSharedContainerListL( |
|
654 const RMessage2& aMessage ) |
|
655 { |
|
656 // get object from message |
|
657 CUpnpBrowseCriteria* bc = CUpnpBrowseCriteria::NewL(); |
|
658 CleanupStack::PushL(bc); |
|
659 ReadObjFromMessageL(aMessage, 1, bc); |
|
660 |
|
661 // item list |
|
662 CUpnpContainerList* cl = CUpnpContainerList::NewL(); |
|
663 CleanupStack::PushL(cl); |
|
664 |
|
665 // perform action |
|
666 iMediaServer->GetSharedContainerListL(aMessage.Int0(), |
|
667 bc, &iRespExecStatus, cl); |
|
668 |
|
669 // prepare response |
|
670 iResponseBuffer = cl->ToDes8L(); |
|
671 iRespLength = iResponseBuffer->Length(); |
|
672 aMessage.WriteL(2, iRespLengthPkg); |
|
673 aMessage.Complete( KErrNone ); |
|
674 |
|
675 // clean up |
|
676 CleanupStack::PopAndDestroy(cl); |
|
677 CleanupStack::PopAndDestroy(bc); |
|
678 } |
|
679 |
|
680 // ----------------------------------------------------------------------------- |
|
681 // CUpnpMediaServerSession::EventMediaServerShareItemListL |
|
682 // ----------------------------------------------------------------------------- |
|
683 // |
|
684 void CUpnpMediaServerSession::EventMediaServerShareItemListL( |
|
685 const RMessage2& aMessage ) |
|
686 { |
|
687 // get object from message |
|
688 CUpnpItemList* il = CUpnpItemList::NewL(); |
|
689 CleanupStack::PushL(il); |
|
690 ReadObjFromMessageL(aMessage, 0, il); |
|
691 |
|
692 // perform action |
|
693 iMediaServer->ShareItemListL(il, &iRespExecStatus); |
|
694 |
|
695 // prepare response |
|
696 iResponseBuffer = il->ToDes8L(); |
|
697 iRespLength = iResponseBuffer->Length(); |
|
698 aMessage.WriteL(1, iRespLengthPkg); |
|
699 aMessage.Complete( KErrNone ); |
|
700 |
|
701 // clean up |
|
702 CleanupStack::PopAndDestroy(il); |
|
703 } |
|
704 |
|
705 // ----------------------------------------------------------------------------- |
|
706 // CUpnpMediaServerSession::EventMediaServerUnshareItemListL |
|
707 // ----------------------------------------------------------------------------- |
|
708 // |
|
709 void CUpnpMediaServerSession::EventMediaServerUnshareItemListL( |
|
710 const RMessage2& aMessage ) |
|
711 { |
|
712 // get ids from message |
|
713 RArray<TInt> il; |
|
714 CleanupClosePushL(il); |
|
715 ReadIdsFromMessageL(aMessage, 0, il); |
|
716 |
|
717 // perform action |
|
718 iMediaServer->UnshareItemListL(il, &iRespExecStatus); |
|
719 |
|
720 // prepare response |
|
721 aMessage.WriteL( 1, iRespExecStatusPkg ); |
|
722 aMessage.Complete( KErrNone ); |
|
723 |
|
724 // clean up |
|
725 CleanupStack::PopAndDestroy(&il); |
|
726 } |
|
727 |
|
728 // ----------------------------------------------------------------------------- |
|
729 // CUpnpMediaServerSession::EventMediaServerGetIpAndPortL |
|
730 // ----------------------------------------------------------------------------- |
|
731 // |
|
732 void CUpnpMediaServerSession::EventMediaServerGetIpAndPortL( |
|
733 const RMessage2& aMessage ) |
|
734 { |
|
735 // response |
|
736 TInetAddr address = iMediaServer->GetAddress(); |
|
737 if (address.Match(TInetAddr(INET_ADDR(0, 0, 0, 0)))) |
|
738 { |
|
739 User::Leave( KErrNotReady ); |
|
740 } |
|
741 aMessage.WriteL( 0, TPckgBuf<TInetAddr>( address ) ); |
|
742 aMessage.Complete( KErrNone ); |
|
743 } |
|
744 |
|
745 // ----------------------------------------------------------------------------- |
|
746 // CUpnpMediaServerSession::EventSetUploadDirectoryL |
|
747 // ----------------------------------------------------------------------------- |
|
748 // |
|
749 void CUpnpMediaServerSession::EventSetUploadDirectoryL( const RMessage2& aMessage ) |
|
750 { |
|
751 HBufC* buf = HBufC::NewLC( aMessage.GetDesLength( 0 ) ); |
|
752 TPtr ptr( buf->Des() ); |
|
753 User::LeaveIfError( aMessage.Read( 0, ptr ) ); |
|
754 iMediaServer->SetUploadDirToCDL( ptr ); |
|
755 CleanupStack::PopAndDestroy(buf); |
|
756 aMessage.Complete( KErrNone ); |
|
757 } |
|
758 // ----------------------------------------------------------------------------- |
|
759 // CUpnpMediaServerSession::EventAddIcon |
|
760 // ----------------------------------------------------------------------------- |
|
761 // |
|
762 void CUpnpMediaServerSession::EventAddIconL( const RMessage2& aMessage) |
|
763 { |
|
764 HBufC8* buf = HBufC8::NewLC( aMessage.GetDesLength( 0 ) ); |
|
765 TPtr8 ptr( buf->Des() ); |
|
766 User::LeaveIfError( aMessage.Read( 0, ptr ) ); |
|
767 |
|
768 iMediaServer->AddIconL(ptr); |
|
769 CleanupStack::PopAndDestroy(buf); |
|
770 aMessage.Complete( KErrNone ); |
|
771 } |
|
772 |
|
773 // ----------------------------------------------------------------------------- |
|
774 // CUpnpMediaServerSession::EventUpdateIcon |
|
775 // ----------------------------------------------------------------------------- |
|
776 // |
|
777 void CUpnpMediaServerSession::EventUpdateIconL( const RMessage2& aMessage) |
|
778 { |
|
779 HBufC8* buf0 = HBufC8::NewLC( aMessage.GetDesLength( 0 ) ); |
|
780 TPtr8 ptr0( buf0->Des() ); |
|
781 User::LeaveIfError( aMessage.Read( 0, ptr0 ) ); |
|
782 |
|
783 HBufC8* buf1 = HBufC8::NewLC( aMessage.GetDesLength( 1 ) ); |
|
784 TPtr8 ptr1( buf1->Des() ); |
|
785 User::LeaveIfError( aMessage.Read( 1, ptr1 ) ); |
|
786 |
|
787 iMediaServer->UpdateIconL(ptr0, ptr1); |
|
788 |
|
789 CleanupStack::PopAndDestroy(buf1); |
|
790 CleanupStack::PopAndDestroy(buf0); |
|
791 |
|
792 aMessage.Complete( KErrNone ); |
|
793 } |
|
794 |
|
795 // ----------------------------------------------------------------------------- |
|
796 // CUpnpMediaServerSession::EventRemoveIcon |
|
797 // ----------------------------------------------------------------------------- |
|
798 // |
|
799 void CUpnpMediaServerSession::EventRemoveIconL( const RMessage2& aMessage) |
|
800 { |
|
801 //Remove icon |
|
802 HBufC8* buf = HBufC8::NewLC( aMessage.GetDesLength( 0 ) ); |
|
803 TPtr8 ptr( buf->Des() ); |
|
804 User::LeaveIfError( aMessage.Read( 0, ptr ) ); |
|
805 |
|
806 iMediaServer->RemoveIconL(ptr); |
|
807 CleanupStack::PopAndDestroy(buf); |
|
808 |
|
809 aMessage.Complete( KErrNone ); |
|
810 } |
|
811 // ----------------------------------------------------------------------------- |
|
812 // CUpnpMediaServerSession::EventRemoveIcons |
|
813 // ----------------------------------------------------------------------------- |
|
814 // |
|
815 void CUpnpMediaServerSession::EventRemoveIconsL( const RMessage2& aMessage ) |
|
816 { |
|
817 iMediaServer->RemoveIconsL(); |
|
818 aMessage.Complete( KErrNone ); |
|
819 } |
|
820 |
|
821 // ----------------------------------------------------------------------------- |
|
822 // CUpnpMediaServerSession::ObjFromMessageL |
|
823 // ----------------------------------------------------------------------------- |
|
824 // |
|
825 void CUpnpMediaServerSession::ReadIdsFromMessageL( const RMessage2& aMessage, |
|
826 TInt aSlot, RArray<TInt>& aObjIds ) |
|
827 { |
|
828 // create buffer |
|
829 TInt len = aMessage.GetDesMaxLength(aSlot); |
|
830 HBufC8* buf = HBufC8::NewLC(len); |
|
831 TPtr8 ptr(buf->Des()); |
|
832 User::LeaveIfError(aMessage.Read(aSlot, ptr)); |
|
833 |
|
834 // read stream |
|
835 RDesReadStream stream(*buf); |
|
836 CleanupClosePushL(stream); |
|
837 |
|
838 // number of elements |
|
839 TInt n = stream.ReadInt32L(); |
|
840 |
|
841 // variables used to retrieve integers |
|
842 HBufC8* tmpId; |
|
843 TLex8 lex; |
|
844 TInt tmpIdNum; |
|
845 // read elements |
|
846 while( n-- ) |
|
847 { |
|
848 tmpId = HBufC8::NewLC(stream, KMaxUpnpObjStringLen); |
|
849 if ( tmpId->Des() == KNullDesC8() ) |
|
850 { |
|
851 User::Leave( KErrNotFound ); |
|
852 } |
|
853 lex.Assign(tmpId->Des()); |
|
854 if( lex.Val( tmpIdNum ) < KErrNone ) |
|
855 { |
|
856 User::Leave( KErrNotFound ); |
|
857 } |
|
858 aObjIds.AppendL( tmpIdNum); |
|
859 CleanupStack::PopAndDestroy(tmpId); |
|
860 } |
|
861 |
|
862 // clean up |
|
863 CleanupStack::PopAndDestroy(&stream); |
|
864 CleanupStack::PopAndDestroy(buf); |
|
865 } |
|
866 // ----------------------------------------------------------------------------- |
|
867 // CUpnpMediaServerSession::ObjFromMessageL |
|
868 // ----------------------------------------------------------------------------- |
|
869 // |
|
870 void CUpnpMediaServerSession::ReadObjFromMessageL( const RMessage2& aMessage, |
|
871 TInt aSlot, CUpnpObject* aObj ) |
|
872 { |
|
873 // create buffer |
|
874 TInt len = aMessage.GetDesMaxLength(aSlot); |
|
875 HBufC8* buf = HBufC8::NewLC(len); |
|
876 TPtr8 ptr(buf->Des()); |
|
877 User::LeaveIfError(aMessage.Read(aSlot, ptr)); |
|
878 |
|
879 // read stream |
|
880 RDesReadStream stream(*buf); |
|
881 CleanupClosePushL(stream); |
|
882 |
|
883 // internalize object |
|
884 stream >> *aObj; |
|
885 |
|
886 // clean up |
|
887 CleanupStack::PopAndDestroy(&stream); |
|
888 CleanupStack::PopAndDestroy(buf); |
|
889 } |
|
890 |
|
891 // ----------------------------------------------------------------------------- |
|
892 // CUpnpMediaServerSession::ReadItemFromMessageL |
|
893 // ----------------------------------------------------------------------------- |
|
894 // |
|
895 void CUpnpMediaServerSession::ReadItemFromMessageL( const RMessage2& aMessage, |
|
896 TInt aSlot, CUpnpItem* aItem ) |
|
897 { |
|
898 // create buffer |
|
899 TInt len = aMessage.GetDesMaxLength(aSlot); |
|
900 HBufC8* buf = HBufC8::NewLC(len); |
|
901 TPtr8 ptr(buf->Des()); |
|
902 User::LeaveIfError(aMessage.Read(aSlot, ptr)); |
|
903 |
|
904 // read stream |
|
905 RDesReadStream stream(*buf); |
|
906 CleanupClosePushL(stream); |
|
907 |
|
908 // internalize object |
|
909 stream >> *aItem; |
|
910 |
|
911 // clean up |
|
912 CleanupStack::PopAndDestroy(&stream); |
|
913 CleanupStack::PopAndDestroy(buf); |
|
914 } |
|
915 |
|
916 // ----------------------------------------------------------------------------- |
|
917 // CUpnpMediaServerSession::ReadObjFromMessageL |
|
918 // ----------------------------------------------------------------------------- |
|
919 // |
|
920 void CUpnpMediaServerSession::ReadObjFromMessageL( const RMessage2& aMessage, |
|
921 TInt aSlot, CUpnpItemList* aItemList ) |
|
922 { |
|
923 // create buffer |
|
924 TInt len = aMessage.GetDesMaxLength(aSlot); |
|
925 HBufC8* buf = HBufC8::NewLC(len); |
|
926 TPtr8 ptr(buf->Des()); |
|
927 User::LeaveIfError(aMessage.Read(aSlot, ptr)); |
|
928 |
|
929 // read stream |
|
930 RDesReadStream stream(*buf); |
|
931 CleanupClosePushL(stream); |
|
932 |
|
933 // internalize object |
|
934 stream >> *aItemList; |
|
935 |
|
936 // clean up |
|
937 CleanupStack::PopAndDestroy(&stream); |
|
938 CleanupStack::PopAndDestroy(buf); |
|
939 } |
|
940 |
|
941 // ----------------------------------------------------------------------------- |
|
942 // CUpnpMediaServerSession::ReadObjFromMessageL |
|
943 // ----------------------------------------------------------------------------- |
|
944 // |
|
945 void CUpnpMediaServerSession::ReadObjFromMessageL( const RMessage2& aMessage, |
|
946 TInt aSlot, CUpnpBrowseCriteria* aBrowseCriteria ) |
|
947 { |
|
948 // create buffer |
|
949 TInt len = aMessage.GetDesMaxLength(aSlot); |
|
950 HBufC8* buf = HBufC8::NewLC(len); |
|
951 TPtr8 ptr(buf->Des()); |
|
952 User::LeaveIfError(aMessage.Read(aSlot, ptr)); |
|
953 |
|
954 // read stream |
|
955 RDesReadStream stream(*buf); |
|
956 CleanupClosePushL(stream); |
|
957 |
|
958 // internalize object |
|
959 stream >> *aBrowseCriteria; |
|
960 |
|
961 // clean up |
|
962 CleanupStack::PopAndDestroy(&stream); |
|
963 CleanupStack::PopAndDestroy(buf); |
|
964 } |
|
965 |
|
966 // ----------------------------------------------------------------------------- |
|
967 // CUpnpMediaServerSession::EventMediaServerShareReferenceL |
|
968 // ----------------------------------------------------------------------------- |
|
969 // |
|
970 void CUpnpMediaServerSession::EventMediaServerShareReferenceL( const RMessage2& aMessage ) |
|
971 { |
|
972 // get 'reference object' from message |
|
973 CUpnpItem* ref = CUpnpItem::NewL(); |
|
974 CleanupStack::PushL(ref); |
|
975 ReadItemFromMessageL(aMessage, 0, ref); |
|
976 |
|
977 // perform sharing |
|
978 iMediaServer->ShareReferenceL(ref); |
|
979 |
|
980 // prepare response |
|
981 iResponseBuffer = ref->ToDes8L(); |
|
982 iRespLength = iResponseBuffer->Length(); |
|
983 aMessage.WriteL(1, iRespLengthPkg); |
|
984 aMessage.Complete( KErrNone ); |
|
985 |
|
986 // clean up |
|
987 CleanupStack::PopAndDestroy(ref); |
|
988 } |
|
989 |
|
990 // ----------------------------------------------------------------------------- |
|
991 // CUpnpMediaServerSession::EventMediaServerShareReferenceListL |
|
992 // ----------------------------------------------------------------------------- |
|
993 // |
|
994 void CUpnpMediaServerSession::EventMediaServerShareReferenceListL( const RMessage2& aMessage ) |
|
995 { |
|
996 // get 'reference item' list from message |
|
997 CUpnpItemList* refList = CUpnpItemList::NewL(); |
|
998 CleanupStack::PushL(refList); |
|
999 ReadObjFromMessageL(aMessage, 0, refList); |
|
1000 |
|
1001 // perform sharing |
|
1002 iMediaServer->ShareReferenceListL(refList, &iRespExecStatus); |
|
1003 |
|
1004 // prepare response |
|
1005 iResponseBuffer = refList->ToDes8L(); |
|
1006 iRespLength = iResponseBuffer->Length(); |
|
1007 aMessage.WriteL(1, iRespLengthPkg); |
|
1008 aMessage.Complete( KErrNone ); |
|
1009 |
|
1010 // clean up |
|
1011 CleanupStack::PopAndDestroy(refList); |
|
1012 } |
|
1013 |
|
1014 // ----------------------------------------------------------------------------- |
|
1015 // CUpnpMediaServerSession::EventMediaServerStatusChangeL |
|
1016 // ----------------------------------------------------------------------------- |
|
1017 // |
|
1018 void CUpnpMediaServerSession::EventMediaServerStatusChange( const RMessage2& aMessage ) |
|
1019 { |
|
1020 if ( !iStatusMessage.IsNull() ) |
|
1021 { |
|
1022 aMessage.Complete( KErrInUse ); |
|
1023 } |
|
1024 else |
|
1025 { |
|
1026 iStatusMessage = aMessage; |
|
1027 } |
|
1028 } |
|
1029 |
|
1030 // ----------------------------------------------------------------------------- |
|
1031 // CUpnpMediaServerSession::EventMediaServerStatusChangeCancelL |
|
1032 // ----------------------------------------------------------------------------- |
|
1033 // |
|
1034 void CUpnpMediaServerSession::EventMediaServerStatusChangeCancel( const RMessage2& aMessage ) |
|
1035 { |
|
1036 if ( !iStatusMessage.IsNull() ) |
|
1037 { |
|
1038 iStatusMessage.Complete( KErrCancel ); |
|
1039 } |
|
1040 aMessage.Complete( KErrNone ); |
|
1041 } |
|
1042 |
|
1043 // ----------------------------------------------------------------------------- |
|
1044 // CUpnpMediaServerSession::StatusChanged |
|
1045 // ----------------------------------------------------------------------------- |
|
1046 // |
|
1047 void CUpnpMediaServerSession::StatusChanged() |
|
1048 { |
|
1049 if ( !iStatusMessage.IsNull() ) |
|
1050 { |
|
1051 iStatusMessage.Complete( KErrNone ); |
|
1052 } |
|
1053 } |
|
1054 |
|
1055 // End of File |