31
|
1 |
// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// $Workfile: obexSendOp_normal.cpp $
|
|
15 |
// $Author: Stevep $
|
|
16 |
// $Revision: 20 $
|
|
17 |
// $Date: 25/03/02 10:53 $
|
|
18 |
//
|
|
19 |
//
|
|
20 |
|
|
21 |
//class include
|
|
22 |
#include <obexsendop.h>
|
|
23 |
|
|
24 |
#ifndef __OBEX_SEND_OP_FILE_DEBUG_MODE__
|
|
25 |
|
|
26 |
//System includes
|
|
27 |
#include <msvids.h>
|
|
28 |
#include <msventry.h> //CMsvServerEntry
|
|
29 |
#include <btmsgtypeuid.h> //KUidMsgTypeBt
|
|
30 |
#include <irmsgtypeuid.h> //KUidMsgTypeIr
|
|
31 |
#include <obexclientmtm.h>
|
|
32 |
//#include <obexpindlguid.h> //KObexPinNotifierUid
|
|
33 |
#include <obexconstantsinternal.h>
|
|
34 |
|
|
35 |
//user includes
|
|
36 |
#define KObexPinNotifierUid 0 //STP TEMPORARY!
|
|
37 |
|
|
38 |
// error resolver compatible error numbers - Now taken from obex.h
|
|
39 |
//const TInt KErrIrObexClientNoDevicesFound = -5501;
|
|
40 |
//const TInt KErrIrObexClientPutPeerAborted = -5503;
|
|
41 |
|
|
42 |
// Following are named KErrIrObexClientXXXXX because they are using the irobex.dll (which
|
|
43 |
// should really be called obex.dll now that it supports more than IR)
|
|
44 |
const TInt KErrIrObexClientFirstPutFailed = -5510;
|
|
45 |
|
|
46 |
// Obex Send Operation specific constants
|
|
47 |
_LIT8(KObexClientLocalWho,"Epoc device");
|
|
48 |
|
|
49 |
//
|
|
50 |
// CObexServerSendOperation.... CMsvOperation derived op that is intended to be owned by a CMsvReporterOperation or similar.
|
|
51 |
// When this completes, the CMsvReporterOperation completes too
|
|
52 |
//
|
|
53 |
|
|
54 |
void CObexServerSendOperation::BuildSpecificConstructL()
|
|
55 |
/**
|
|
56 |
* Normal second phase constructor.
|
|
57 |
*/
|
|
58 |
{
|
|
59 |
}
|
|
60 |
|
|
61 |
void CObexServerSendOperation::BuildSpecificDestructor()
|
|
62 |
/**
|
|
63 |
* Destructor. Cancel()s, deletes owned objects and Close()s the connection to the FileServer.
|
|
64 |
*/
|
|
65 |
{
|
|
66 |
}
|
|
67 |
|
|
68 |
EXPORT_C const TDesC8& CObexServerSendOperation::ProgressL()
|
|
69 |
/**
|
|
70 |
* Returns current progress information.
|
|
71 |
*
|
|
72 |
* @return A reference to a TPckgC<TObexMtmProgress> package pointer descriptor containing progress information on this send operation.
|
|
73 |
* @leave KErrXXX system wide error codes
|
|
74 |
*/
|
|
75 |
{
|
|
76 |
// State operation type (and progress).
|
|
77 |
TObexMtmProgress progress;
|
|
78 |
|
|
79 |
//cases are due to inconsistencies between S60 and Sym Obex TObexMtmProgress
|
|
80 |
switch(iSendState)
|
|
81 |
{
|
|
82 |
case TObexMtmProgress::EInitialised:
|
|
83 |
progress.iSendState = TObexMtmProgress::EInitialise;
|
|
84 |
break;
|
|
85 |
case TObexMtmProgress::EMovedToSent:
|
|
86 |
progress.iSendState = TObexMtmProgress::ESendComplete;
|
|
87 |
break;
|
|
88 |
default:
|
|
89 |
progress.iSendState = iSendState;
|
|
90 |
break;
|
|
91 |
}
|
|
92 |
|
|
93 |
progress.iTotalEntryCount = iAttachmentEntryCount;
|
|
94 |
progress.iEntriesDone = progress.iTotalEntryCount - (iNextAttachment+1);
|
|
95 |
progress.iCurrentEntrySize = iObexObject? iObexObject->Length() : 0;
|
|
96 |
progress.iCurrentBytesTrans = iObexObject? iObexObject->BytesSent() : 0;
|
|
97 |
|
|
98 |
if (progress.iSendState == TObexMtmProgress::EUserCancelled)
|
|
99 |
{
|
|
100 |
progress.iError = KErrCancel;
|
|
101 |
}
|
|
102 |
else
|
|
103 |
{
|
|
104 |
progress.iError = iStatus.Int();
|
|
105 |
}
|
|
106 |
|
|
107 |
// prepate package buffer for return value, we copy it to a data member so progress
|
|
108 |
// data isn't destroyed when we go out of scope
|
|
109 |
TPckgC<TObexMtmProgress> progressDes(progress);
|
|
110 |
iProgressPckg.Copy(progressDes); //important to use copy() not set(), set() just points to our local descriptor
|
|
111 |
return iProgressPckg;
|
|
112 |
}
|
|
113 |
|
|
114 |
void CObexServerSendOperation::RealRunL()
|
|
115 |
/**
|
|
116 |
* Implementation of the send operation state machine. Progresses as:
|
|
117 |
* Initialise-->Connect-->ConnectAttemptComplete-->SendObject-->(SendNextObject-->)SendComplete-->Disconnected
|
|
118 |
* The SendNextObject state is repeated for each attachment in excess of one.
|
|
119 |
* Also handles UserCancelled and SendError states by CompleteObserver()ing with appropriate error codes.
|
|
120 |
* Leaves will be passed back to RunL and handled there.
|
|
121 |
*
|
|
122 |
* @leave KErrXXX system wide error codes
|
|
123 |
*/
|
|
124 |
{
|
|
125 |
const TInt status=iStatus.Int();
|
|
126 |
|
|
127 |
switch(iSendState)
|
|
128 |
{
|
|
129 |
case TObexMtmProgress::EInitialise:
|
|
130 |
{
|
|
131 |
// Initialise Obex client object.
|
|
132 |
InitialiseObexClientL(); //to be implemented by derived classes and this is transport specific
|
|
133 |
|
|
134 |
if(!iAsyncInit)
|
|
135 |
{
|
|
136 |
iSendState = TObexMtmProgress::EInitialised;
|
|
137 |
SetActive();
|
|
138 |
CompleteSelf(KErrNone);
|
|
139 |
}
|
|
140 |
else
|
|
141 |
{
|
|
142 |
iSendState = TObexMtmProgress::EInitialised;
|
|
143 |
iStatus = KRequestPending;
|
|
144 |
SetActive();
|
|
145 |
}
|
|
146 |
break;
|
|
147 |
}
|
|
148 |
|
|
149 |
case TObexMtmProgress::EInitialised:
|
|
150 |
{
|
|
151 |
// any work to be done in the second phase of initialisation can be done here by derived classes.
|
|
152 |
SecondPhaseObexClientInitL();
|
|
153 |
|
|
154 |
iObexClient->SetLocalWho(KObexClientLocalWho);
|
|
155 |
|
|
156 |
// Set up call back for authentication challenge. If the server sends an
|
|
157 |
// an authentication challenge GetUserPasswordL() will be called in this class
|
|
158 |
iObexClient->SetCallBack(*this);
|
|
159 |
|
|
160 |
// We do this here so that we can re-enter the connect phase until this timeout
|
|
161 |
// expires in the case where there is no device present.
|
|
162 |
|
|
163 |
// Timeout for repeatedly trying to connect to remote OBEX device
|
|
164 |
if(iTimeoutTimer->IsActive())
|
|
165 |
iTimeoutTimer->Cancel();
|
|
166 |
|
|
167 |
if(iConnectTimeout)
|
|
168 |
iTimeoutTimer->After(iConnectTimeout);
|
|
169 |
|
|
170 |
// move to connect phase
|
|
171 |
iSendState = TObexMtmProgress::EConnect;
|
|
172 |
SetActive();
|
|
173 |
CompleteSelf(KErrNone);
|
|
174 |
break;
|
|
175 |
}
|
|
176 |
|
|
177 |
case TObexMtmProgress::EConnect:
|
|
178 |
{
|
|
179 |
PreConnectOperations();
|
|
180 |
|
|
181 |
// Attempt an OBEX connect.
|
|
182 |
// If Connect is not successful (see TObexMtmProgress::EConnectAttemptComplete
|
|
183 |
// below) then we will return to this state and try to connect again, this will
|
|
184 |
// continue until we successfully connect or iConnectTimeout expires.
|
|
185 |
iSendState=TObexMtmProgress::EConnectAttemptComplete;
|
|
186 |
iStatus=KRequestPending;
|
|
187 |
SetActive();
|
|
188 |
|
|
189 |
// Pass this active objects iStatus to OBEX Connect Request, so that when
|
|
190 |
// Connect completes our RunL() will be called
|
|
191 |
if (iConnectPassword)
|
|
192 |
{
|
|
193 |
//Only use password if its length > 0
|
|
194 |
if (iConnectPassword->Length() > 0)
|
|
195 |
{
|
|
196 |
// connect with a normal authentication challenge for the remote obex server
|
|
197 |
iObexClient->ConnectL(*iConnectPassword,iStatus);
|
|
198 |
}
|
|
199 |
else
|
|
200 |
{
|
|
201 |
// no authentication challenge
|
|
202 |
iObexClient->Connect(iStatus);
|
|
203 |
}
|
|
204 |
}
|
|
205 |
else
|
|
206 |
{
|
|
207 |
// no authentication challenge
|
|
208 |
iObexClient->Connect(iStatus);
|
|
209 |
}
|
|
210 |
break;
|
|
211 |
}
|
|
212 |
|
|
213 |
case TObexMtmProgress::EConnectAttemptComplete:
|
|
214 |
{
|
|
215 |
// A connection _attempt_ has completed - see if it was sucessful.
|
|
216 |
if (status == KErrNone)
|
|
217 |
{
|
|
218 |
// Ok - remote Obex device found and connected to
|
|
219 |
if(iTimeoutTimer->IsActive())
|
|
220 |
iTimeoutTimer->Cancel(); //cancel connect timeout
|
|
221 |
iSendState=TObexMtmProgress::ESendObject; //Go to send state
|
|
222 |
CompleteSelf(KErrNone);
|
|
223 |
}
|
|
224 |
else if( (status == KErrNotFound) || (status == KErrTimedOut) || (status == KErrIrObexClientNoDevicesFound) )
|
|
225 |
{
|
|
226 |
// We need to determine if we should retry.
|
|
227 |
// As long as we have our own timeout set, we should continue to retry indefinitely -
|
|
228 |
// the timout will guard us and we'll drop into the next case.
|
|
229 |
if(iTimeoutTimer->IsActive())
|
|
230 |
{
|
|
231 |
// Connect failed. No remote device was found so we try again.
|
|
232 |
// (KErrIrObexClientNoDevicesFound is an OBEX specific error)
|
|
233 |
iSendState=TObexMtmProgress::EConnect; //return to connect state above
|
|
234 |
CompleteSelf(KErrNone);
|
|
235 |
}
|
|
236 |
else
|
|
237 |
{
|
|
238 |
// We could not connect to any remote devices. We had no local timeout
|
|
239 |
// available, so we will not try again.
|
|
240 |
iSendState=TObexMtmProgress::ESendError;
|
|
241 |
CompleteSelf(KErrIrObexClientNoDevicesFound);
|
|
242 |
}
|
|
243 |
}
|
|
244 |
else
|
|
245 |
{
|
|
246 |
// KErrDisconnected = Found obex machine but had "Obex" IAS query failure.
|
|
247 |
// status>0 means that 'status' obex machines have been found.
|
|
248 |
if(iTimeoutTimer->IsActive())
|
|
249 |
iTimeoutTimer->Cancel();
|
|
250 |
iSendState=TObexMtmProgress::ESendError;
|
|
251 |
CompleteSelf(status);
|
|
252 |
}
|
|
253 |
|
|
254 |
PostConnectOperations();
|
|
255 |
|
|
256 |
SetActive();
|
|
257 |
break;
|
|
258 |
}
|
|
259 |
|
|
260 |
case TObexMtmProgress::ESendObject:
|
|
261 |
{
|
|
262 |
// As this is the first object to send, perform any pre send operations required
|
|
263 |
PreSendOperations();
|
|
264 |
|
|
265 |
// Fall through to next state to do the send
|
|
266 |
}
|
|
267 |
|
|
268 |
case TObexMtmProgress::ESendNextObject: // Multiple object support.
|
|
269 |
{
|
|
270 |
if(iTimeoutTimer->IsActive())
|
|
271 |
iTimeoutTimer->Cancel(); // Cancel last timeout.
|
|
272 |
|
|
273 |
// For multiObject, check success of previous put. (Single objects won't be affected).
|
|
274 |
if(!CheckStatusOfLastObject (status, iSendState))
|
|
275 |
{
|
|
276 |
//Last message failed - CheckStatusOfLastObject has taken the necessary steps to notify
|
|
277 |
break;
|
|
278 |
}
|
|
279 |
|
|
280 |
//Get the next object ready to send
|
|
281 |
TInt err = PrepareCurrentObjectAndSetStateL();
|
|
282 |
|
|
283 |
//Check the status of preparation
|
|
284 |
if (err == KErrNone)
|
|
285 |
{
|
|
286 |
if(iPutTimeout)
|
|
287 |
iTimeoutTimer->After(iPutTimeout); // Start a new one.
|
|
288 |
|
|
289 |
// **** SEND THE OBJECT *****
|
|
290 |
// Pass this active objects iStatus to OBEX Put Request, so that when
|
|
291 |
// Put completes this RunL() will be called again
|
|
292 |
iStatus = KRequestPending;
|
|
293 |
|
|
294 |
// added to mimic minimal header behaviour from 7.0 irmtm for Win98.
|
|
295 |
if(iLastSendAttempt)
|
|
296 |
iObexObject->SetHeaderMask( KObexHdrName | KObexHdrLength);
|
|
297 |
|
|
298 |
iObexClient->Put(*iObexObject, iStatus);
|
|
299 |
}
|
|
300 |
else
|
|
301 |
{
|
|
302 |
//Unsuccessful--report the error
|
|
303 |
CompleteSelf(err);
|
|
304 |
}
|
|
305 |
|
|
306 |
SetActive();
|
|
307 |
break;
|
|
308 |
}
|
|
309 |
|
|
310 |
case TObexMtmProgress::ESendComplete:
|
|
311 |
{
|
|
312 |
if(iTimeoutTimer->IsActive())
|
|
313 |
iTimeoutTimer->Cancel(); //cancel iPutTimeout
|
|
314 |
|
|
315 |
// Perform any post send operations required
|
|
316 |
PostSendOperations();
|
|
317 |
|
|
318 |
// Object "send(s)" have completed but latest might have completed with an error
|
|
319 |
if(status != KErrNone)
|
|
320 |
{
|
|
321 |
// Pass error code onto the owner of this messaging operation
|
|
322 |
if( (status==KErrInUse) || (status==KErrArgument) )
|
|
323 |
{
|
|
324 |
// Have connected OK but couldn't send, so receiver might be dealing with
|
|
325 |
// a previous connection
|
|
326 |
CompleteSelf(KErrIrObexClientFirstPutFailed); //different to EMultiObjectSendError
|
|
327 |
}
|
|
328 |
else
|
|
329 |
{
|
|
330 |
CompleteSelf(status); // General error.
|
|
331 |
}
|
|
332 |
|
|
333 |
SetActive();
|
|
334 |
iSendState=TObexMtmProgress::ESendError;
|
|
335 |
return;
|
|
336 |
}
|
|
337 |
|
|
338 |
// we have to clean up the obex object to release the file lock.
|
|
339 |
delete iObexObject;
|
|
340 |
iObexObject = NULL;
|
|
341 |
|
|
342 |
//Now attempt to move the successfully sent message to the sent folder
|
|
343 |
iMoveEntrySelection = new (ELeave) CMsvEntrySelection;
|
|
344 |
iMoveEntrySelection->AppendL(iMsvSendParent.Entry().Id()); //i.e. just the sent message
|
|
345 |
#ifdef MOVE_MESSAGE_TO_SENT
|
|
346 |
User::LeaveIfError(iMsvSendParent.SetEntry(iMsvSendParent.Entry().Parent())); //Move to the parent
|
|
347 |
// move entry selection. The method is asynchronous and iStatus must be checked when
|
|
348 |
// the request completes (in case TObexMtmProgress::EMovedToSent)
|
|
349 |
iMsvSendParent.MoveEntriesL(*iMoveEntrySelection, KMsvSentEntryId, iStatus);
|
|
350 |
iSendState = TObexMtmProgress::EMovedToSent;
|
|
351 |
SetActive();
|
|
352 |
#else
|
|
353 |
// Don't delete the entry here because the entry must be deleted even if the
|
|
354 |
// operation fails or is cancelled.
|
|
355 |
// The message will be deleted in the CompleteObserver function.
|
|
356 |
iSendState = TObexMtmProgress::EMovedToSent;
|
|
357 |
SetActive();
|
|
358 |
// We need to kick ourselves into the next state because we're not waiting on anything.
|
|
359 |
CompleteSelf(KErrNone);
|
|
360 |
#endif
|
|
361 |
break;
|
|
362 |
}
|
|
363 |
|
|
364 |
case TObexMtmProgress::EMovedToSent:
|
|
365 |
{
|
|
366 |
#ifdef MOVE_MESSAGE_TO_SENT
|
|
367 |
// first check result of asynchronous MoveEntriesL, leave if not KErrNone
|
|
368 |
User::LeaveIfError(iStatus.Int());
|
|
369 |
iMsvSendParent.SetEntry(iMoveEntrySelection->At(0)); //Switch back to actual message
|
|
370 |
TMsvEntry entry = iMsvSendParent.Entry();
|
|
371 |
entry.SetVisible(ETrue); // Moved OK. Make the entry visible and flag it as complete.
|
|
372 |
entry.SetInPreparation(EFalse);
|
|
373 |
User::LeaveIfError(iMsvSendParent.ChangeEntry(entry)); //Commit changes
|
|
374 |
User::LeaveIfError(iMsvSendParent.SetEntry(KMsvNullIndexEntryId)); //Unlock the entry
|
|
375 |
#endif
|
|
376 |
if(iTimeoutTimer->IsActive())
|
|
377 |
iTimeoutTimer->Cancel();
|
|
378 |
|
|
379 |
iStatus=KRequestPending;
|
|
380 |
iObexClient->Disconnect(iStatus);
|
|
381 |
|
|
382 |
// test code
|
|
383 |
// User::WaitForRequest(iStatus);
|
|
384 |
|
|
385 |
iSendState=TObexMtmProgress::EDisconnected;
|
|
386 |
SetActive(); // Will call back when have completed disconnection.
|
|
387 |
|
|
388 |
// Unfortunately, it is possible for this call to never complete if you send
|
|
389 |
// a file that the peer does not understand. This occurs because some peers
|
|
390 |
// (i.e. Palm) don't seem able to handle this scenario correctly and don't
|
|
391 |
// drop the transport when they should. So we restart the 'connect' timeout to
|
|
392 |
// catch this error
|
|
393 |
if(iConnectTimeout)
|
|
394 |
iTimeoutTimer->After(iConnectTimeout);
|
|
395 |
}
|
|
396 |
break;
|
|
397 |
|
|
398 |
case TObexMtmProgress::EDisconnected:
|
|
399 |
{
|
|
400 |
if(iTimeoutTimer->IsActive())
|
|
401 |
iTimeoutTimer->Cancel();
|
|
402 |
if(status != KErrNone)
|
|
403 |
{
|
|
404 |
// Pass error code onto the owner of this messaging operation
|
|
405 |
iSendState=TObexMtmProgress::ESendError;
|
|
406 |
SetActive();
|
|
407 |
CompleteSelf(status);
|
|
408 |
}
|
|
409 |
else
|
|
410 |
{
|
|
411 |
// Completed OK -
|
|
412 |
// Signal MS that the CMsvOperation has ended, and clean up.
|
|
413 |
CompleteObserverL();
|
|
414 |
}
|
|
415 |
break;
|
|
416 |
}
|
|
417 |
|
|
418 |
case TObexMtmProgress::EUserCancelled:
|
|
419 |
{
|
|
420 |
// Signal that the CMsvOperation has been cancelled by the user.
|
|
421 |
TObexMtmProgress& progress = iProgressPckg();
|
|
422 |
progress.iError = KErrCancel;
|
|
423 |
if(iTimeoutTimer->IsActive())
|
|
424 |
iTimeoutTimer->Cancel();
|
|
425 |
CompleteObserverL();
|
|
426 |
break;
|
|
427 |
}
|
|
428 |
|
|
429 |
case TObexMtmProgress::ESendError:
|
|
430 |
{
|
|
431 |
// General error handling stage.
|
|
432 |
if(iTimeoutTimer->IsActive())
|
|
433 |
iTimeoutTimer->Cancel();
|
|
434 |
CompleteObserverL();
|
|
435 |
break;
|
|
436 |
}
|
|
437 |
|
|
438 |
|
|
439 |
default:
|
|
440 |
Panic(EObexSendOperationUnknownSendState);
|
|
441 |
}
|
|
442 |
}
|
|
443 |
|
|
444 |
#endif //__OBEX_SEND_OP_FILE_DEBUG_MODE__
|