|
1 /* |
|
2 * Copyright (c) 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: implements upload session |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 // INTERNAL INCLUDES |
|
24 // upnpframework / avcontroller api |
|
25 #include "upnpavdevice.h" |
|
26 #include "upnpfiletransfersessionobserver.h" |
|
27 |
|
28 // avcontroller internal |
|
29 #include "upnpfileuploadsessionimpl.h" |
|
30 #include "upnpavcontrollerclient.h" |
|
31 #include "upnpfiletransferitem.h" |
|
32 |
|
33 _LIT( KComponentLogfile, "upnpavcontrollerclient.txt"); |
|
34 #include "upnplog.h" |
|
35 |
|
36 // ======== MEMBER FUNCTIONS ======== |
|
37 |
|
38 // -------------------------------------------------------------------------- |
|
39 // CUPnPFileUploadSessionImpl::NewL |
|
40 // Two-phase construction |
|
41 // -------------------------------------------------------------------------- |
|
42 CUPnPFileUploadSessionImpl* CUPnPFileUploadSessionImpl::NewL( |
|
43 RUPnPAVControllerClient& aServer, const CUpnpAVDevice& aDevice ) |
|
44 { |
|
45 __LOG( "CUPnPFileUploadSessionImpl::NewL" ); |
|
46 |
|
47 CUPnPFileUploadSessionImpl* self = new (ELeave) |
|
48 CUPnPFileUploadSessionImpl( aServer ); |
|
49 CleanupStack::PushL( self ); |
|
50 self->iDevice = CUpnpAVDevice::NewL( aDevice ); |
|
51 self->ConstructL(); |
|
52 CleanupStack::Pop( self ); |
|
53 return self; |
|
54 } |
|
55 |
|
56 // -------------------------------------------------------------------------- |
|
57 // CUPnPFileUploadSessionImpl::CUPnPFileUploadSessionImpl |
|
58 // Constructor |
|
59 // -------------------------------------------------------------------------- |
|
60 CUPnPFileUploadSessionImpl::CUPnPFileUploadSessionImpl( |
|
61 RUPnPAVControllerClient& aServer ) : |
|
62 CActive( EPriorityStandard ), |
|
63 iServer( aServer ), |
|
64 iBufferPtr( 0, 0 ), |
|
65 iAlive( ETrue ), |
|
66 iEventPkg( iEvent ) |
|
67 { |
|
68 __LOG( "CUPnPFileUploadSessionImpl::NewL" ); |
|
69 |
|
70 CActiveScheduler::Add( this ); |
|
71 } |
|
72 |
|
73 // -------------------------------------------------------------------------- |
|
74 // CUPnPFileUploadSessionImpl::~CUPnPFileUploadSessionImpl |
|
75 // Destructor |
|
76 // -------------------------------------------------------------------------- |
|
77 CUPnPFileUploadSessionImpl::~CUPnPFileUploadSessionImpl() |
|
78 { |
|
79 __LOG( "CUPnPFileUploadSessionImpl::~CUPnPFileUploadSessionImpl" ); |
|
80 |
|
81 CancelAllTransfers(); |
|
82 |
|
83 Cancel(); |
|
84 iServer.DestroyUploadSession( (TInt)this ); |
|
85 |
|
86 delete iDevice; |
|
87 delete iBuffer; |
|
88 } |
|
89 |
|
90 // -------------------------------------------------------------------------- |
|
91 // CUPnPFileUploadSessionImpl::ConstructL |
|
92 // Two-phase construction |
|
93 // -------------------------------------------------------------------------- |
|
94 void CUPnPFileUploadSessionImpl::ConstructL() |
|
95 { |
|
96 __LOG( "CUPnPFileUploadSessionImpl::ConstructL" ); |
|
97 |
|
98 iBuffer = iDevice->Uuid().AllocL(); |
|
99 iBufferPtr.Set( iBuffer->Des() ); |
|
100 User::LeaveIfError( iServer.CreateUploadSession( |
|
101 (TInt)this , iBufferPtr ) ); |
|
102 |
|
103 iServer.GetUploadEvent( (TInt)this, iEventPkg, iStatus ); |
|
104 SetActive(); |
|
105 } |
|
106 |
|
107 // -------------------------------------------------------------------------- |
|
108 // CUPnPFileUploadSessionImpl::ConstructL |
|
109 // Two-phase construction |
|
110 // -------------------------------------------------------------------------- |
|
111 void CUPnPFileUploadSessionImpl::RunL() |
|
112 { |
|
113 __LOG( "CUPnPFileUploadSessionImpl::RunL" ); |
|
114 |
|
115 TUpnpFileTransferEvent event = iEvent; |
|
116 |
|
117 if( iStatus.Int() == KErrNone ) |
|
118 { |
|
119 iServer.GetUploadEvent( (TInt)this, iEventPkg, iStatus ); |
|
120 SetActive(); |
|
121 } |
|
122 else |
|
123 { |
|
124 __LOG1( "RunL - %d", iStatus.Int() ); |
|
125 } |
|
126 |
|
127 // Handle event and activate again |
|
128 switch( event.iEvent ) |
|
129 { |
|
130 case TUpnpFileTransferEvent::ETransferStarted: |
|
131 { |
|
132 if( iObserver ) |
|
133 { |
|
134 __LOG2( "RunL - ETransferStarted, key = %d, status = %d", |
|
135 event.iKey, event.iStatus ); |
|
136 |
|
137 // iKey - 1 since it's incremented when we request the upload |
|
138 // the reason behind of this is the fact that httptransfer |
|
139 // does not accept value 0 which is legal from the API point |
|
140 // of view |
|
141 iObserver->TransferStarted( event.iKey - 1, |
|
142 event.iStatus ); |
|
143 } |
|
144 break; |
|
145 } |
|
146 |
|
147 case TUpnpFileTransferEvent::ETransferCompleted: |
|
148 { |
|
149 if( iObserver ) |
|
150 { |
|
151 __LOG2( "RunL - ETransferCompleted,key = %d, status = %d", |
|
152 event.iKey, event.iStatus ); |
|
153 |
|
154 iObserver->TransferCompleted( event.iKey - 1, |
|
155 event.iStatus, KNullDesC ); |
|
156 } |
|
157 break; |
|
158 } |
|
159 |
|
160 case TUpnpFileTransferEvent::ETransferProgress: |
|
161 { |
|
162 if( iObserver ) |
|
163 { |
|
164 __LOG1( "RunL - ETransferProgress, status = %d", |
|
165 event.iStatus ); |
|
166 |
|
167 iObserver->TransferProgress( event.iKey - 1, |
|
168 event.iParam1, event.iParam2 ); |
|
169 } |
|
170 break; |
|
171 } |
|
172 |
|
173 case TUpnpFileTransferEvent::EDeviceDisconnected: |
|
174 { |
|
175 __LOG( "RunL - EDeviceDisconnected" ); |
|
176 |
|
177 CUpnpAVDevice* tmpDev = NULL; |
|
178 UPnPDeviceDisappeared( *tmpDev ); |
|
179 } |
|
180 break; |
|
181 |
|
182 default: |
|
183 { |
|
184 __LOG( "RunL - default!" ); |
|
185 break; |
|
186 } |
|
187 } |
|
188 } |
|
189 |
|
190 // -------------------------------------------------------------------------- |
|
191 // CUPnPFileUploadSessionImpl::ConstructL |
|
192 // See upnpfileuploadsessionimpl.h |
|
193 // -------------------------------------------------------------------------- |
|
194 void CUPnPFileUploadSessionImpl::StartUploadL( const TDesC& aFilePath, |
|
195 TInt aKey ) |
|
196 { |
|
197 __LOG( "CUPnPFileUploadSessionImpl::StartUploadL" ); |
|
198 |
|
199 ResetL(); |
|
200 |
|
201 CUpnpFileTransferItem* item = CUpnpFileTransferItem::NewLC(); |
|
202 // aKey + 1 |
|
203 // the reason behind of this is the fact that httptransfer |
|
204 // does not accept value 0 which is legal from the API point |
|
205 // of view. |
|
206 item->SetKey( aKey + 1 ); |
|
207 item->SetPathL( aFilePath ); |
|
208 |
|
209 iBuffer = item->ToDes8L(); |
|
210 iBufferPtr.Set( iBuffer->Des() ); |
|
211 |
|
212 CleanupStack::PopAndDestroy( item ); |
|
213 |
|
214 User::LeaveIfError( iServer.StartUpload( (TInt)this, iBufferPtr ) ); |
|
215 } |
|
216 |
|
217 // -------------------------------------------------------------------------- |
|
218 // CUPnPFileUploadSessionImpl::DoCancel |
|
219 // From CActive |
|
220 // -------------------------------------------------------------------------- |
|
221 void CUPnPFileUploadSessionImpl::DoCancel() |
|
222 { |
|
223 __LOG( "CUPnPFileUploadSessionImpl::DoCancel" ); |
|
224 |
|
225 iServer.CancelUploadEvent( (TInt)this ); |
|
226 |
|
227 __LOG( "CUPnPFileUploadSessionImpl::DoCancel - end" ); |
|
228 } |
|
229 |
|
230 // -------------------------------------------------------------------------- |
|
231 // CUPnPFileUploadSessionImpl::RunError |
|
232 // From CActive |
|
233 // -------------------------------------------------------------------------- |
|
234 TInt CUPnPFileUploadSessionImpl::RunError( TInt /*aError*/ ) |
|
235 { |
|
236 __LOG( "CUPnPFileUploadSessionImpl::RunError" ); |
|
237 |
|
238 return KErrNone; |
|
239 } |
|
240 |
|
241 |
|
242 // -------------------------------------------------------------------------- |
|
243 // CUPnPFileUploadSessionImpl::SetObserver |
|
244 // See upnpfileuploadsessionimpl.h |
|
245 // -------------------------------------------------------------------------- |
|
246 void CUPnPFileUploadSessionImpl::SetObserver( |
|
247 MUPnPFileTransferSessionObserver& aObserver ) |
|
248 { |
|
249 __LOG( "CUPnPFileUploadSessionImpl::SetObserver" ); |
|
250 |
|
251 iObserver = &aObserver; |
|
252 } |
|
253 |
|
254 // -------------------------------------------------------------------------- |
|
255 // CUPnPFileUploadSessionImpl::RemoveObserver |
|
256 // See upnpfileuploadsessionimpl.h |
|
257 // -------------------------------------------------------------------------- |
|
258 void CUPnPFileUploadSessionImpl::RemoveObserver() |
|
259 { |
|
260 __LOG( "CUPnPFileUploadSessionImpl::RemoveObserver" ); |
|
261 |
|
262 iObserver = NULL; |
|
263 } |
|
264 |
|
265 // -------------------------------------------------------------------------- |
|
266 // CUPnPFileUploadSessionImpl::Observer |
|
267 // See upnpfileuploadsessionimpl.h |
|
268 // -------------------------------------------------------------------------- |
|
269 MUPnPFileTransferSessionObserver* |
|
270 CUPnPFileUploadSessionImpl::Observer() const |
|
271 { |
|
272 return iObserver; |
|
273 } |
|
274 |
|
275 // -------------------------------------------------------------------------- |
|
276 // CUPnPFileUploadSessionImpl::StartTrackingProgressL |
|
277 // See upnpfileuploadsessionimpl.h |
|
278 // -------------------------------------------------------------------------- |
|
279 void CUPnPFileUploadSessionImpl::StartTrackingProgressL( TInt aKey ) |
|
280 { |
|
281 __LOG( "CUPnPFileUploadSessionImpl::StartTrackingProgressL" ); |
|
282 |
|
283 ResetL(); |
|
284 User::LeaveIfError( iServer.StartTrackingUploadProgress( |
|
285 (TInt)this, aKey + 1 ) ); |
|
286 } |
|
287 |
|
288 // -------------------------------------------------------------------------- |
|
289 // CUPnPFileUploadSessionImpl::CancelTransfer |
|
290 // See upnpfileuploadsessionimpl.h |
|
291 // -------------------------------------------------------------------------- |
|
292 void CUPnPFileUploadSessionImpl::CancelTransfer( TInt aKey ) |
|
293 { |
|
294 __LOG( "CUPnPFileUploadSessionImpl::CancelTransfer" ); |
|
295 |
|
296 iServer.CancelUpload( (TInt)this, aKey + 1 ); // Ignore error |
|
297 } |
|
298 |
|
299 // -------------------------------------------------------------------------- |
|
300 // CUPnPFileUploadSessionImpl::CancelAllTransfers |
|
301 // See upnpfileuploadsessionimpl.h |
|
302 // -------------------------------------------------------------------------- |
|
303 void CUPnPFileUploadSessionImpl::CancelAllTransfers() |
|
304 { |
|
305 __LOG( "CUPnPFileUploadSessionImpl::CancelAllTransfers" ); |
|
306 |
|
307 iServer.CancelAllUploads( (TInt)this ); // Ignore error |
|
308 } |
|
309 |
|
310 // -------------------------------------------------------------------------- |
|
311 // CUPnPFileUploadSessionImpl::UPnPDeviceDiscovered |
|
312 // Device discovered |
|
313 // -------------------------------------------------------------------------- |
|
314 void CUPnPFileUploadSessionImpl::UPnPDeviceDiscovered( |
|
315 const CUpnpAVDevice& /*aDevice*/ ) |
|
316 { |
|
317 // No implementation needed |
|
318 } |
|
319 |
|
320 |
|
321 // -------------------------------------------------------------------------- |
|
322 // CUPnPFileUploadSessionImpl::UPnPDeviceDisappeared |
|
323 // Device disappeared |
|
324 // -------------------------------------------------------------------------- |
|
325 void CUPnPFileUploadSessionImpl::UPnPDeviceDisappeared( |
|
326 const CUpnpAVDevice& /*aDevice*/ ) |
|
327 { |
|
328 __LOG( "CUPnPAVBrowsingSessionImpl::UPnPDeviceDisappeared" ); |
|
329 |
|
330 iAlive = EFalse; |
|
331 if( iObserver ) |
|
332 { |
|
333 iObserver->MediaServerDisappeared( |
|
334 MUPnPAVSessionObserverBase::EDisconnected ); |
|
335 } |
|
336 } |
|
337 |
|
338 // -------------------------------------------------------------------------- |
|
339 // CUPnPFileUploadSessionImpl::WLANConnectionLost |
|
340 // Connection lost |
|
341 // -------------------------------------------------------------------------- |
|
342 void CUPnPFileUploadSessionImpl::WLANConnectionLost() |
|
343 { |
|
344 __LOG( "CUPnPAVBrowsingSessionImpl::WLANConnectionLost" ); |
|
345 |
|
346 iAlive = EFalse; |
|
347 if( iObserver ) |
|
348 { |
|
349 iObserver->MediaServerDisappeared( |
|
350 MUPnPAVSessionObserverBase::EWLANLost ); |
|
351 } |
|
352 } |
|
353 |
|
354 // -------------------------------------------------------------------------- |
|
355 // CUPnPFileUploadSessionImpl::Device |
|
356 // Returns used device |
|
357 // -------------------------------------------------------------------------- |
|
358 const CUpnpAVDevice& CUPnPFileUploadSessionImpl::Device() const |
|
359 { |
|
360 return *iDevice; |
|
361 } |
|
362 |
|
363 // -------------------------------------------------------------------------- |
|
364 // CUPnPFileUploadSessionImpl::ResetL |
|
365 // Reset |
|
366 // -------------------------------------------------------------------------- |
|
367 void CUPnPFileUploadSessionImpl::ResetL() |
|
368 { |
|
369 __LOG( "CUPnPFileUploadSessionImpl::ResetL" ); |
|
370 |
|
371 if( !iAlive ) |
|
372 { |
|
373 User::Leave( KErrDisconnected ); |
|
374 } |
|
375 |
|
376 delete iBuffer; iBuffer = NULL; |
|
377 } |
|
378 |
|
379 // end of file |
|
380 |