|
1 /* |
|
2 * Copyright (c) 2006-2007 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: CUPnPFileSharingEngine class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 // Include Files |
|
24 #include <upnpcontainer.h> |
|
25 #include <f32file.h> |
|
26 #include <upnpstring.h> |
|
27 #include <s32file.h> |
|
28 |
|
29 #include <upnpmediaserverclient.h> |
|
30 #include "upnpfilesharingengine.h" |
|
31 #include "upnpfilesharingengineao.h" |
|
32 #include "upnpcontentrequestao.h" |
|
33 #include "upnpcontentshareao.h" |
|
34 #include "upnpcontentserverclient.h" |
|
35 #include "upnpsettingsengine.h" |
|
36 #include "upnpprogresswatcher.h" |
|
37 #include "upnpcommonutils.h" |
|
38 #include "upnpdownloaditemresolver.h" |
|
39 #include "upnpcontentshareao.h" |
|
40 #include "upnpconnectionmonitor.h" |
|
41 #include "upnpiconconfigurator.h" |
|
42 |
|
43 _LIT( KComponentLogfile, "applicationengine.txt"); |
|
44 #include "upnplog.h" |
|
45 |
|
46 // ============================ MEMBER FUNCTIONS ============================= |
|
47 |
|
48 // -------------------------------------------------------------------------- |
|
49 // CUPnPFileSharingEngine::CUPnPFileSharingEngine |
|
50 // C++ default constructor can NOT contain any code, that |
|
51 // might leave. |
|
52 // -------------------------------------------------------------------------- |
|
53 // |
|
54 CUPnPFileSharingEngine::CUPnPFileSharingEngine() |
|
55 { |
|
56 iShareFileState = EFalse; |
|
57 } |
|
58 |
|
59 // -------------------------------------------------------------------------- |
|
60 // CUPnPFileSharingEngine::ConstructL |
|
61 // Symbian 2nd phase constructor can leave. |
|
62 // -------------------------------------------------------------------------- |
|
63 // |
|
64 void CUPnPFileSharingEngine::ConstructL() |
|
65 { |
|
66 iContentServer.OpenL(); |
|
67 iAO = new (ELeave) CUPnPFileSharingEngineAO( *this, iContentServer ); |
|
68 iContentSharer = CUpnpContentShareAO::NewL( *this, iContentServer ); |
|
69 UPnPCommonUtils::DeleteTempFilesL(); |
|
70 CUPnPDownloadItemResolver::DeleteTempDownloadFilesL(); |
|
71 iContentRequestor = new (ELeave) CUpnpContentRequestAO( |
|
72 *this, iContentServer ); |
|
73 |
|
74 // create connection monitor, so we can receive wlan lost notifications |
|
75 // immideatly and observe connection if application was restarted |
|
76 CUPnPSettingsEngine* settings = CUPnPSettingsEngine::NewLC(); |
|
77 TInt iap( 0 ); |
|
78 User::LeaveIfError( settings->GetAccessPoint( iap ) ); |
|
79 CleanupStack::PopAndDestroy( settings ); |
|
80 iConnMon = CUPnPConnectionMonitor::NewL( *this, iap ); |
|
81 |
|
82 //set flag that icons hasn't been set |
|
83 CUPnPIconConfigurator::MarkIconsAddedL( EFalse ); |
|
84 } |
|
85 |
|
86 // -------------------------------------------------------------------------- |
|
87 // CUPnPFileSharingEngine::NewL |
|
88 // Two-phased constructor. |
|
89 // -------------------------------------------------------------------------- |
|
90 // |
|
91 EXPORT_C CUPnPFileSharingEngine* CUPnPFileSharingEngine::NewL() |
|
92 { |
|
93 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::NewL begin"); |
|
94 CUPnPFileSharingEngine* self = CUPnPFileSharingEngine::NewLC(); |
|
95 CleanupStack::Pop( self ); |
|
96 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::NewL end"); |
|
97 return self; |
|
98 } |
|
99 |
|
100 // -------------------------------------------------------------------------- |
|
101 // CUPnPFileSharingEngine::NewLC |
|
102 // Two-phased constructor. |
|
103 // -------------------------------------------------------------------------- |
|
104 // |
|
105 EXPORT_C CUPnPFileSharingEngine* CUPnPFileSharingEngine::NewLC() |
|
106 { |
|
107 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::NewLC begin"); |
|
108 CUPnPFileSharingEngine* self = new (ELeave) CUPnPFileSharingEngine; |
|
109 CleanupStack::PushL( self ); |
|
110 self->ConstructL(); |
|
111 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::NewLC end"); |
|
112 return self; |
|
113 } |
|
114 |
|
115 // -------------------------------------------------------------------------- |
|
116 // CUPnPFileSharingEngine::~CUPnPFileSharingEngine |
|
117 // Destructor |
|
118 // -------------------------------------------------------------------------- |
|
119 // |
|
120 EXPORT_C CUPnPFileSharingEngine::~CUPnPFileSharingEngine() |
|
121 { |
|
122 __LOG("[UPNP_ENGINE]\tCUPnPFileSharingEngine::~CUPnPFileSharingEngine\ |
|
123 begin"); |
|
124 |
|
125 delete iConnMon; |
|
126 delete iAO; |
|
127 delete iContentSharer; |
|
128 |
|
129 delete iImageSelections; |
|
130 delete iMusicSelections; |
|
131 delete iContentRequestor; |
|
132 |
|
133 |
|
134 iContentServer.Close(); |
|
135 delete iProgress; |
|
136 |
|
137 __LOG("[UPNP_ENGINE]\tCUPnPFileSharingEngine::~CUPnPFileSharingEngine\ |
|
138 end"); |
|
139 } |
|
140 |
|
141 // -------------------------------------------------------------------------- |
|
142 // CUPnPFileSharingEngine::SetObserver |
|
143 // Set observer |
|
144 // -------------------------------------------------------------------------- |
|
145 // |
|
146 EXPORT_C void CUPnPFileSharingEngine::SetObserver( |
|
147 MUPnPFileSharingEngineObserver* aObserver ) |
|
148 { |
|
149 iObserver = aObserver; |
|
150 if ( !iObserver ) |
|
151 { |
|
152 if ( iProgress ) |
|
153 { |
|
154 iProgress->Stop(); |
|
155 } |
|
156 } |
|
157 } |
|
158 |
|
159 // -------------------------------------------------------------------------- |
|
160 // CUPnPFileSharingEngine::Observer |
|
161 // ( other items are commented in header ) |
|
162 // -------------------------------------------------------------------------- |
|
163 // |
|
164 EXPORT_C MUPnPFileSharingEngineObserver* CUPnPFileSharingEngine::Observer() |
|
165 { |
|
166 return iObserver; |
|
167 } |
|
168 |
|
169 // -------------------------------------------------------------------------- |
|
170 // CUPnPFileSharingEngine::SetSharingState |
|
171 // Starts/Stops file sharing using UPnP Media server API |
|
172 // -------------------------------------------------------------------------- |
|
173 // |
|
174 EXPORT_C void CUPnPFileSharingEngine::SetSharingStateL( TBool aState ) |
|
175 { |
|
176 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::SetSharingState \ |
|
177 begin"); |
|
178 if ( iProgress && iShareFileState ) |
|
179 { |
|
180 iProgress->Stop(); |
|
181 } |
|
182 iAO->SetSharingStateL( aState ); |
|
183 |
|
184 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::SetSharingState \ |
|
185 end"); |
|
186 } |
|
187 |
|
188 // -------------------------------------------------------------------------- |
|
189 // CUPnPFileSharingEngine::SharingState |
|
190 // Gets file sharing status. |
|
191 // -------------------------------------------------------------------------- |
|
192 // |
|
193 EXPORT_C TBool CUPnPFileSharingEngine::SharingStateL() |
|
194 { |
|
195 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::SharingState \ |
|
196 begin"); |
|
197 |
|
198 TBool status( EFalse ); |
|
199 if ( iAO ) |
|
200 { |
|
201 status = iAO->SharingStateL(); |
|
202 } |
|
203 |
|
204 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::SharingState \ |
|
205 end"); |
|
206 return status; |
|
207 } |
|
208 |
|
209 // -------------------------------------------------------------------------- |
|
210 // CUPnPFileSharingEngine::ShareMediaL |
|
211 // Starts sharing process |
|
212 // -------------------------------------------------------------------------- |
|
213 // |
|
214 EXPORT_C void CUPnPFileSharingEngine::ShareMediaL( |
|
215 THomeConnectMediaType aType ) |
|
216 { |
|
217 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::ShareMediaL begin"); |
|
218 |
|
219 switch ( aType ) |
|
220 { |
|
221 case EImageAndVideo : |
|
222 { |
|
223 iContentSharer->ChangeSharedContentL( |
|
224 UpnpContentServer::TUpnpMediaType( aType ), |
|
225 *iImageSelections ); |
|
226 } |
|
227 break; |
|
228 case EPlaylist: |
|
229 { |
|
230 iContentSharer->ChangeSharedContentL( |
|
231 UpnpContentServer::TUpnpMediaType( aType ), |
|
232 *iMusicSelections ); |
|
233 } |
|
234 break; |
|
235 default : |
|
236 User::Leave( KErrArgument ); |
|
237 break; |
|
238 } |
|
239 |
|
240 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::ShareMediaL end"); |
|
241 } |
|
242 |
|
243 // -------------------------------------------------------------------------- |
|
244 // CUPnPFileSharingEngine::RefreshSharedMediaL |
|
245 // Updates shared objects |
|
246 // -------------------------------------------------------------------------- |
|
247 // |
|
248 EXPORT_C void CUPnPFileSharingEngine::RefreshSharedMediaL( |
|
249 THomeConnectMediaType aType ) |
|
250 { |
|
251 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::RefreshSharedMediaL\ |
|
252 begin"); |
|
253 |
|
254 // clear UI cache |
|
255 delete iImageSelections; |
|
256 iImageSelections = NULL; |
|
257 delete iMusicSelections; |
|
258 iMusicSelections = NULL; |
|
259 |
|
260 |
|
261 iContentSharer->RefreshSharedContentL( |
|
262 UpnpContentServer::TUpnpMediaType( aType ) ); |
|
263 RequestSharingProgressL(); |
|
264 |
|
265 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::RefreshSharedMediaL\ |
|
266 end"); |
|
267 } |
|
268 |
|
269 // -------------------------------------------------------------------------- |
|
270 // CUPnPFileSharingEngine::RequestSelectionIndexesL |
|
271 // Gets the selected albums/playlist indexes |
|
272 // -------------------------------------------------------------------------- |
|
273 // |
|
274 EXPORT_C void CUPnPFileSharingEngine::RequestSelectionIndexesL( |
|
275 THomeConnectMediaType aType ) const |
|
276 { |
|
277 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::RequestSelectionIndexesL\ |
|
278 begin"); |
|
279 |
|
280 iContentRequestor->RequestSelectionIndexesL( |
|
281 UpnpContentServer::TUpnpMediaType( aType ) ); |
|
282 |
|
283 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::RequestSelectionIndexesL\ |
|
284 end"); |
|
285 } |
|
286 |
|
287 // -------------------------------------------------------------------------- |
|
288 // CUPnPFileSharingEngine::GetSelectionIndexes |
|
289 // Gets the selected albums/playlist indexes |
|
290 // -------------------------------------------------------------------------- |
|
291 // |
|
292 EXPORT_C void CUPnPFileSharingEngine::GetSelectionIndexesL( |
|
293 CArrayFix<TInt>& aMarkedItems ) const |
|
294 { |
|
295 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::GetSelectionIndexesL\ |
|
296 begin"); |
|
297 |
|
298 iContentRequestor->GetSelectionIndexesL( aMarkedItems ); |
|
299 |
|
300 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::GetSelectionIndexesL\ |
|
301 end"); |
|
302 } |
|
303 |
|
304 // -------------------------------------------------------------------------- |
|
305 // CUPnPFileSharingEngine::SetSelectionIndexes |
|
306 // Sets the user selections |
|
307 // -------------------------------------------------------------------------- |
|
308 // |
|
309 EXPORT_C void CUPnPFileSharingEngine::SetSelectionIndexesL( |
|
310 THomeConnectMediaType aType, |
|
311 const CArrayFix<TInt>& aMarkedItems ) |
|
312 { |
|
313 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::SetSelectionIndexesL\ |
|
314 begin"); |
|
315 |
|
316 switch ( aType ) |
|
317 { |
|
318 case EImageAndVideo: |
|
319 { |
|
320 delete iImageSelections; |
|
321 iImageSelections = NULL; |
|
322 iImageSelections = new (ELeave) CArrayFixFlat<TInt> |
|
323 (aMarkedItems.Count()); |
|
324 CopyTintArrayL( aMarkedItems, *iImageSelections ); |
|
325 } |
|
326 break; |
|
327 case EPlaylist: |
|
328 { |
|
329 delete iMusicSelections; |
|
330 iMusicSelections = NULL; |
|
331 iMusicSelections = new (ELeave) CArrayFixFlat<TInt> |
|
332 (aMarkedItems.Count()); |
|
333 CopyTintArrayL( aMarkedItems, *iMusicSelections ); |
|
334 |
|
335 } |
|
336 break; |
|
337 default: |
|
338 User::Leave( KErrArgument ); |
|
339 break; |
|
340 } |
|
341 |
|
342 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::SetSelectionIndexesL\ |
|
343 end"); |
|
344 } |
|
345 |
|
346 // -------------------------------------------------------------------------- |
|
347 // CUPnPFileSharingEngine::RequestSelectionContentL |
|
348 // Requests the album /playlist names |
|
349 // -------------------------------------------------------------------------- |
|
350 // |
|
351 EXPORT_C void CUPnPFileSharingEngine::RequestSelectionContentL( |
|
352 THomeConnectMediaType aType ) |
|
353 { |
|
354 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::RequestSelectionContentL\ |
|
355 begin"); |
|
356 |
|
357 iContentRequestor->RequestSelectionContentL( |
|
358 UpnpContentServer::TUpnpMediaType( aType ) ); |
|
359 |
|
360 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::RequestSelectionContentL\ |
|
361 begin"); |
|
362 } |
|
363 |
|
364 // -------------------------------------------------------------------------- |
|
365 // CUPnPFileSharingEngine::GetSelectionContentL |
|
366 // Get all albums/playlists identifiers from Media gallery |
|
367 // -------------------------------------------------------------------------- |
|
368 // |
|
369 EXPORT_C void CUPnPFileSharingEngine::GetSelectionContentL( |
|
370 CDesCArray& aArray ) const |
|
371 { |
|
372 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine:: \ |
|
373 GetSelectionContentL begin"); |
|
374 |
|
375 iContentRequestor->GetSelectionContentL( aArray ); |
|
376 |
|
377 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine:: \ |
|
378 GetSelectionContentL end"); |
|
379 } |
|
380 |
|
381 // -------------------------------------------------------------------------- |
|
382 // CUPnPFileSharingEngine::RequestSharingProgressL |
|
383 // ( other items are commented in header ) |
|
384 // -------------------------------------------------------------------------- |
|
385 // |
|
386 EXPORT_C void CUPnPFileSharingEngine::RequestSharingProgressL() |
|
387 { |
|
388 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::\ |
|
389 RequestSharingProgressL begin"); |
|
390 if( !iProgress ) |
|
391 { |
|
392 iProgress = CUpnpProgressWatcher::NewL( *this ); |
|
393 } |
|
394 iProgress->StartL(); |
|
395 |
|
396 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::\ |
|
397 RequestSharingProgressL end"); |
|
398 } |
|
399 |
|
400 // -------------------------------------------------------------------------- |
|
401 // CUPnPFileSharingEngine::StartUploadListenerL |
|
402 // ( other items are commented in header ) |
|
403 // -------------------------------------------------------------------------- |
|
404 // |
|
405 EXPORT_C void CUPnPFileSharingEngine::StartUploadListenerL() |
|
406 { |
|
407 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::\ |
|
408 StartUploadListenerL begin"); |
|
409 iContentServer.StartUploadListenerL(); |
|
410 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::\ |
|
411 StartUploadListenerL end"); |
|
412 } |
|
413 |
|
414 // -------------------------------------------------------------------------- |
|
415 // CUPnPFileSharingEngine::StopUploadListenerL |
|
416 // ( other items are commented in header ) |
|
417 // -------------------------------------------------------------------------- |
|
418 // |
|
419 EXPORT_C void CUPnPFileSharingEngine::StopUploadListenerL() |
|
420 { |
|
421 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::\ |
|
422 StopUploadListenerL begin"); |
|
423 iContentServer.StopUploadListenerL(); |
|
424 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::\ |
|
425 StopUploadListenerL end"); |
|
426 } |
|
427 |
|
428 // -------------------------------------------------------------------------- |
|
429 // CUPnPFileSharingEngine::SetConMonState |
|
430 // ( other items are commented in header ) |
|
431 // -------------------------------------------------------------------------- |
|
432 // |
|
433 void CUPnPFileSharingEngine::SetConMonStateL( |
|
434 TBool aState, TRequestStatus& aStatus ) |
|
435 { |
|
436 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::\ |
|
437 SetConMonState begin"); |
|
438 |
|
439 delete iConnMon; |
|
440 iConnMon = NULL; |
|
441 |
|
442 if ( aState ) |
|
443 { |
|
444 // (Re)Start |
|
445 CUPnPSettingsEngine* settings = CUPnPSettingsEngine::NewLC(); |
|
446 TInt iap( KErrNotFound ); |
|
447 User::LeaveIfError( settings->GetAccessPoint( iap ) ); |
|
448 iConnMon = CUPnPConnectionMonitor::NewL( *this, iap ); |
|
449 CleanupStack::PopAndDestroy( settings ); |
|
450 iContentServer.StartConnectionMonitorL( iap, aStatus ); |
|
451 } |
|
452 else |
|
453 { |
|
454 iContentServer.StopConnectionMonitorL( aStatus ); |
|
455 } |
|
456 |
|
457 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::\ |
|
458 SetConMonState end"); |
|
459 } |
|
460 |
|
461 // -------------------------------------------------------------------------- |
|
462 // CUPnPFileSharingEngine::ConnectionLost |
|
463 // ( other items are commented in header ) |
|
464 // -------------------------------------------------------------------------- |
|
465 // |
|
466 void CUPnPFileSharingEngine::ConnectionLost() |
|
467 { |
|
468 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::\ |
|
469 ConnectionLost begin"); |
|
470 if( iAO->SharingStateL() ) |
|
471 { |
|
472 iAO->ConnectionLost(); |
|
473 if ( iObserver ) |
|
474 { |
|
475 iObserver->HandleSharingConnectionLost( *this ); |
|
476 } |
|
477 } |
|
478 __LOG("[UPNP_ENGINE]\t CUPnPFileSharingEngine::\ |
|
479 ConnectionLost end"); |
|
480 } |
|
481 |
|
482 // -------------------------------------------------------------------------- |
|
483 // CUPnPFileSharingEngine::CopyTintArrayL |
|
484 // ( other items are commented in header ) |
|
485 // -------------------------------------------------------------------------- |
|
486 // |
|
487 void CUPnPFileSharingEngine::CopyTintArrayL( const CArrayFix<TInt>& aSrc, |
|
488 CArrayFix<TInt>& aDst ) const |
|
489 { |
|
490 for ( TInt i(0); i<aSrc.Count();i++ ) |
|
491 { |
|
492 aDst.AppendL(aSrc.At(i)); |
|
493 } |
|
494 } |
|
495 |
|
496 // -------------------------------------------------------------------------- |
|
497 // CUPnPFileSharingEngine::CopyCdescArray |
|
498 // ( other items are commented in header ) |
|
499 // -------------------------------------------------------------------------- |
|
500 // |
|
501 void CUPnPFileSharingEngine::CopyCdescArrayL( |
|
502 const CDesCArray& aSrc, |
|
503 CDesCArray& aDst ) const |
|
504 { |
|
505 for ( TInt i(0); i<aSrc.Count();i++ ) |
|
506 { |
|
507 aDst.AppendL( aSrc[ i ] ); |
|
508 } |
|
509 } |
|
510 |
|
511 // -------------------------------------------------------------------------- |
|
512 // CUPnPFileSharingEngine::SetShareFileComplete |
|
513 // ( other items are commented in header ) |
|
514 // -------------------------------------------------------------------------- |
|
515 // |
|
516 void CUPnPFileSharingEngine::SetShareFileComplete( |
|
517 TBool aShareState ) |
|
518 { |
|
519 iShareFileState = aShareState; |
|
520 } |
|
521 |
|
522 // End of file |