|
1 /* |
|
2 * Copyright (c) 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: Source file for CUpnpCopyTask class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 // System |
|
21 #include <utf.h> // ConvertToUnicodeFromUtf8L |
|
22 |
|
23 // upnp stack api |
|
24 #include <upnpitem.h> // CUpnpItem |
|
25 #include <upnpobject.h> // CUpnpObject (cast) |
|
26 |
|
27 // upnp framework / avcontroller api |
|
28 #include "upnpavcontroller.h" // MUPnPAVController |
|
29 #include "upnpavcontrollerfactory.h" // UPnPAVControllerFactory |
|
30 #include "upnpavbrowsingsession.h" // MUPnPAVBrowsingSession |
|
31 #include "upnpavsessionbase.h" // ReserveLocalMSServicesCompleted() |
|
32 #include "upnpavdevice.h" // CUpnpAVDevice |
|
33 |
|
34 // upnp framework / commonutils api |
|
35 #include "upnpcommonutils.h" // TUPnPItemType |
|
36 #include "upnpmetadatafetcher.h" // UPnPMetadataFetcher |
|
37 |
|
38 // upnp framework / filetransferengine api |
|
39 #include "upnpfiletransferengine.h" // CUpnpFileTransferEngine |
|
40 |
|
41 // upnp framework / command internal |
|
42 #include "upnpfilepipe.h" // CUpnpFilePipe |
|
43 #include "upnpcommandparameters.h" // CUpnpCommandParameters |
|
44 #include "upnptaskhandler.h" // MUpnpTaskHandler |
|
45 #include "upnpnotehandler.h" // CUpnpNoteHandler |
|
46 #include "upnpcopytask.h" |
|
47 #include "upnpcommand.h" |
|
48 #include "upnptaskresourceallocator.h" // CUpnpTaskResourceAllocator |
|
49 |
|
50 _LIT( KComponentLogfile, "upnpcommand.log"); |
|
51 #include "upnplog.h" |
|
52 |
|
53 // -------------------------------------------------------------------------- |
|
54 // CUpnpCopyTask::NewL |
|
55 // Creates an instance of the implementation. |
|
56 // -------------------------------------------------------------------------- |
|
57 // |
|
58 CUpnpTask* CUpnpCopyTask::NewL() |
|
59 { |
|
60 __LOG( "[UpnpCommand]\t CUpnpCopyTask::NewL" ); |
|
61 |
|
62 // Create instance |
|
63 CUpnpCopyTask* self = new (ELeave) CUpnpCopyTask(); |
|
64 CleanupStack::PushL( self ); |
|
65 self->ConstructL(); |
|
66 CleanupStack::Pop( self ); |
|
67 return self; |
|
68 } |
|
69 |
|
70 // -------------------------------------------------------------------------- |
|
71 // CUpnpCopyTask::CUpnpCopyTask |
|
72 // First phase construction. |
|
73 // -------------------------------------------------------------------------- |
|
74 // |
|
75 CUpnpCopyTask::CUpnpCopyTask() |
|
76 : CUpnpFileTransferBaseTask() |
|
77 { |
|
78 __LOG( "[UpnpCommand]\t CUpnpCopyTask::Constructor" ); |
|
79 } |
|
80 |
|
81 // -------------------------------------------------------------------------- |
|
82 // Destructor. |
|
83 // -------------------------------------------------------------------------- |
|
84 // |
|
85 CUpnpCopyTask::~CUpnpCopyTask() |
|
86 { |
|
87 __LOG( "[UpnpCommand]\t CUpnpCopyTask::Destructor" ); |
|
88 } |
|
89 |
|
90 // -------------------------------------------------------------------------- |
|
91 // CUpnpCopyTask::ConstructL |
|
92 // Perform the second phase of two phase construction. Reserves the Upnp Fw |
|
93 // resources (they are released when the task is destroyed). |
|
94 // -------------------------------------------------------------------------- |
|
95 // |
|
96 void CUpnpCopyTask::ConstructL() |
|
97 { |
|
98 __LOG( "[UpnpCommand]\t CUpnpCopyTask::ConstructL" ); |
|
99 } |
|
100 |
|
101 // -------------------------------------------------------------------------- |
|
102 // CUpnpCopyTask::AllocateResourcesL |
|
103 // Allocates the Upnp Fw resources. |
|
104 // -------------------------------------------------------------------------- |
|
105 // |
|
106 void CUpnpCopyTask::AllocateResourcesL() |
|
107 { |
|
108 __LOG( "[UpnpCommand]\t CUpnpCopyTask::AllocateResourcesL" ); |
|
109 |
|
110 AllocateFileTransferResourcesL( |
|
111 CUpnpTaskResourceAllocator::EResourceAvController | |
|
112 CUpnpTaskResourceAllocator::EResourceSelectCopyServer ); |
|
113 } |
|
114 |
|
115 // -------------------------------------------------------------------------- |
|
116 // CUpnpCopyTask::ExecuteL |
|
117 // Executes the task. |
|
118 // -------------------------------------------------------------------------- |
|
119 // |
|
120 void CUpnpCopyTask::ExecuteL() |
|
121 { |
|
122 __LOG( "[UpnpCommand]\t CUpnpCopyTask::ExecuteL" ); |
|
123 |
|
124 if( !ResourceAllocator() ) |
|
125 { |
|
126 __LOG( "[UpnpCommand]\t CUpnpCopyTask::ExecuteL \ |
|
127 resources not allocated, leave" ); |
|
128 User::Leave( KErrNotReady ); |
|
129 } |
|
130 |
|
131 TInt transferredFiles = 0; |
|
132 |
|
133 TRAPD( status, ExecuteFileTransferL |
|
134 ( EFalse, transferredFiles ) ); |
|
135 __LOG1( "[UpnpCommand]\t CUpnpCopyTask::ExecuteL done status %d", status ); |
|
136 |
|
137 // inform user |
|
138 if( status == KErrNone ) |
|
139 { |
|
140 HBufC* deviceString = CnvUtfConverter::ConvertToUnicodeFromUtf8L( |
|
141 ResourceAllocator()->SelectedDevice().FriendlyName() ); |
|
142 CleanupStack::PushL( deviceString ); |
|
143 NoteHandler()->ShowCopyInfoNoteL( |
|
144 transferredFiles, *deviceString ); |
|
145 CleanupStack::PopAndDestroy( deviceString ); |
|
146 } |
|
147 else if( status == KErrDisconnected || status == KErrSessionClosed |
|
148 || status == KErrCouldNotConnect ) |
|
149 { |
|
150 // check if wlan is active |
|
151 // note shown only in device disappeared cases |
|
152 if( IsWlanActive() ) |
|
153 { |
|
154 NoteHandler()->ShowCopyDisconnectionErrorNoteL(); |
|
155 } |
|
156 } |
|
157 else if( status != KErrCancel ) |
|
158 { |
|
159 // some other generic error EXCEPT cancel |
|
160 NoteHandler()->ShowCopyErrorNoteL(); |
|
161 } |
|
162 |
|
163 // If there was an error, leave |
|
164 if( status != KErrNone ) |
|
165 { |
|
166 User::Leave( status ); |
|
167 } |
|
168 } |
|
169 |
|
170 |
|
171 // End of File |