williamr@2: // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@2: // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members williamr@2: // which accompanies this distribution, and is available williamr@2: // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // williamr@2: williamr@2: williamr@2: #ifndef __OBEXSENDOP_H__ williamr@2: #define __OBEXSENDOP_H__ williamr@2: williamr@2: williamr@2: williamr@2: //#define __OBEX_SEND_OP_FILE_DEBUG_MODE__ williamr@2: williamr@2: #include williamr@2: #include // CDesCArray williamr@2: #include williamr@2: #include //TObexMtmProgress williamr@2: williamr@2: williamr@2: class CObexHeaderList; williamr@2: williamr@2: williamr@2: /////////////////////////////////////////////////////////////////////////////////// williamr@2: // Panic Code williamr@2: /////////////////////////////////////////////////////////////////////////////////// williamr@2: williamr@2: ///Obex Send Operation Panics williamr@2: enum TObexSendOperationPanic williamr@2: { williamr@2: EObexSendOperationAlreadyActive, ///< The current Obex send operation is already active williamr@2: EObexSendOperationUnknownJob, ///< williamr@2: EObexSendOperationUnknownSendState, ///< The current value of the Obex send state of the send operation is not found in TObexMtmProgress::TSendState williamr@2: EObexSendOperationUnexpectedTimeout ///< Panic if send has timeout unexpectedly williamr@2: }; williamr@2: williamr@2: GLDEF_C void Panic(TObexSendOperationPanic aPanic); williamr@2: williamr@2: williamr@2: williamr@2: /////////////////////////////////////////////////////////////////////////////////// williamr@2: // CObexServerSendOperation williamr@2: /////////////////////////////////////////////////////////////////////////////////// williamr@2: class CObexSendOpTimeout; williamr@2: class CObexPasswordGetter; williamr@2: williamr@2: class CObexServerSendOperation : public CActive, public MObexAuthChallengeHandler williamr@2: /** williamr@2: class CObexServerSendOperation williamr@2: williamr@2: Obex Server Send Operation: williamr@2: williamr@2: Base class for Send operations using Obex protocol. williamr@2: williamr@2: Implements a state machine with the following states: williamr@2: Initialise-->Connect-->ConnectAttemptComplete-->SendObject-->(SendNextObject-->)SendComplete-->MovedToSent-->Disconnected williamr@2: williamr@2: The pure virtual function InitialiseObexClientL() must be overridden in the base class to initialise the williamr@2: iObexClient member to use the desired Obex transport mechanism (e.g. infrared, Bluetooth). williamr@2: williamr@2: In order to allow asynchronous transport initialisations (for example BT's SDP Query) williamr@2: implementations of this function must set iAsyncInit and provide a mechanism to williamr@2: complete a request. See the bluetooth server mtm code for implementation details. williamr@2: williamr@2: @internalTechnology williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: williamr@2: /** williamr@2: * Destructor. Cancel()s, deletes owned objects and Close()s the connection to the FileServer. williamr@2: */ williamr@2: williamr@2: virtual IMPORT_C ~CObexServerSendOperation(); williamr@2: williamr@2: /// Must be implemented in the derived class to initialise the iObexClient member to use the desired Obex transport mechanism williamr@2: virtual void InitialiseObexClientL() =0; williamr@2: williamr@2: /** williamr@2: * This is not required to do anything in the base implementation. williamr@2: */ williamr@2: williamr@2: IMPORT_C virtual void SecondPhaseObexClientInitL(); // may be overridden to do anything required in a second phase. default implementation is blank. williamr@2: williamr@2: /** williamr@2: * Operations to perform before attempting a connection. williamr@2: * As multiple connection attempts can be made, it is necessary for this williamr@2: * routine to ensure it can handle being called multiple times. williamr@2: * May be overridden. Default implementation is blank. williamr@2: */ williamr@2: IMPORT_C virtual void PreConnectOperations(); williamr@2: williamr@2: /** williamr@2: * Operations to perform after attempting a connection. williamr@2: * As multiple connection attempts can be made, it is necessary for this williamr@2: * routine to ensure it can handle being called multiple times. williamr@2: * May be overridden. Default implementation is blank. williamr@2: */ williamr@2: IMPORT_C virtual void PostConnectOperations(); williamr@2: williamr@2: /** williamr@2: * Operations to perform before attempting to send a set of objects. williamr@2: * May be overridden. Default implementation is blank. williamr@2: */ williamr@2: IMPORT_C virtual void PreSendOperations(); williamr@2: williamr@2: /** williamr@2: * Operations to perform after attempting to send a set of objects. williamr@2: * May be overridden. Default implementation is blank. williamr@2: */ williamr@2: IMPORT_C virtual void PostSendOperations(); williamr@2: williamr@2: williamr@2: protected: // for use by derived classes williamr@2: /** williamr@2: * Constructor. williamr@2: * williamr@2: * @param aMsgTypeUid UID of message type williamr@2: * @param aSendObj Reference to the object to send. williamr@2: * @param aConnectTimeoutMicroSeconds Timeout period for Connect operation in microseconds. williamr@2: * @param aPutTimeoutMicroseconds Timeout period for Put operation in microseconds. williamr@2: * @param aObserverRequestStatus TRequestStatus of owning active object. williamr@2: */ williamr@2: williamr@2: IMPORT_C CObexServerSendOperation(TUid aMsgTypeUid, CMsvServerEntry& aSendObj, TInt aConnectTimeoutMicroSeconds, TInt aPutTimeoutMicroSeconds, TRequestStatus& aObserverRequestStatus); williamr@2: williamr@2: /** williamr@2: * Second phase constructor. Sets up connection to the FileServer, initialises attachments or filename list then williamr@2: * starts sending process by initialising. williamr@2: * williamr@2: * @param aConnectPassword Pointer to the password to be used for authentication. williamr@2: * @leave Leaves if insufficient memory. williamr@2: * @leave Leaves if cannot connect to FileServer. williamr@2: */ williamr@2: williamr@2: IMPORT_C void ConstructL(const TDesC* aConnectPassword); williamr@2: williamr@2: /** williamr@2: * Cancels the current operation, deletes the client and Cancel()s the timeout timer. Only completes the observer williamr@2: * (by a call to CompleteObserver) if an external entity (i.e. the owner) has called Cancel(). williamr@2: * Otherwise the observer is not completed. williamr@2: */ williamr@2: williamr@2: IMPORT_C virtual void DoCancel(); williamr@2: williamr@2: /* Constructor, Alternative version williamr@2: * williamr@2: * @param aMsgTypeUid UID of message type williamr@2: * @param aSendObj Reference to the object to send. williamr@2: * @param aConnectTimeoutMicroSeconds Timeout period for Connect operation in microseconds. williamr@2: * @param aPutTimeoutMicroseconds Timeout period for Put operation in microseconds. williamr@2: * @param aObserverRequestStatus TRequestStatus of owning active object. williamr@2: * @param aLastSendAttempt TBool flag to check for the second send attempt and also control header sending. EFalse sends full headers, ETrue only sends name and size. williamr@2: */ williamr@2: williamr@2: IMPORT_C CObexServerSendOperation(TUid aMsgTypeUid, CMsvServerEntry& aSendObj, TInt aConnectTimeoutMicroSeconds, williamr@2: TInt aPutTimeoutMicroSeconds, TRequestStatus& aObserverRequestStatus, williamr@2: TBool aLastSendAttempt); williamr@2: williamr@2: /** williamr@2: * Tells the derived class that the base class is about to complete the observer. williamr@2: * This is the first thing called when CompleteObserver is called. williamr@2: * Since the behaviour of CompleteObserver is to clean up the message that it was trying to send, williamr@2: * this calls gives the derived class an opportunity to either stop this deletion or recover any information williamr@2: * synchronously from the message. williamr@2: * If the derived class has no need to use this functionality, the default implementation allows deletion. williamr@2: * @param aErrorCode The last error code encountered williamr@2: * @return TBool True delete the message williamr@2: * @return TBool False DO NOT delete the message williamr@2: */ williamr@2: IMPORT_C virtual TBool CompletingObserver(TInt aErrorCode); williamr@2: williamr@2: public: // called by CObexSendOpTimeout williamr@2: williamr@2: /** williamr@2: * Called when the current operation times out. Causes the current operation to be cancelled, then reactivates with williamr@2: * the appropriate error code (KErrIrObexClientNoDevicesFound or KErrIrObexClientPutPeerAborted). williamr@2: */ williamr@2: williamr@2: void TimeOut(); williamr@2: williamr@2: public: williamr@2: williamr@2: /** williamr@2: * Returns current progress information. williamr@2: * williamr@2: * @return A reference to a TPckgC package pointer descriptor containing progress information on this send operation. williamr@2: * @leave KErrXXX system wide error codes williamr@2: */ williamr@2: IMPORT_C const TDesC8& ProgressL(); williamr@2: williamr@2: TBool iAsyncInit; williamr@2: williamr@2: private: // From MObexAuthChallengeHandler williamr@2: williamr@2: /** williamr@2: * Called by the Obex Client when authentication is requested to pass the password back. If the password is invalid, this williamr@2: * call should succeed but the send operation as a whole will inevitably fail. williamr@2: * williamr@2: * @param aRelm ignored, but could be used to indicate which password to use. williamr@2: * @leave KErrXXX system wide error codes. Shouldn't leave just because the password is invalid. williamr@2: */ williamr@2: williamr@2: IMPORT_C virtual void GetUserPasswordL(const TDesC& aUserID); williamr@2: williamr@2: private: // From CActive williamr@2: williamr@2: williamr@2: /** williamr@2: * Calls RealRunL(), and traps errors williamr@2: * williamr@2: * @leave Leaves with errors from RealRunL() williamr@2: */ williamr@2: williamr@2: IMPORT_C virtual void RunL(); williamr@2: williamr@2: private: williamr@2: williamr@2: /** williamr@2: * Destructor. Cancel()s, deletes owned objects and Close()s the connection to the FileServer. williamr@2: */ williamr@2: williamr@2: void BuildSpecificDestructor(); williamr@2: williamr@2: /** williamr@2: * Normal second phase constructor. williamr@2: */ williamr@2: williamr@2: void BuildSpecificConstructL(); williamr@2: williamr@2: /** williamr@2: * Cancels the current operation, then reactivates with the given error code. williamr@2: * williamr@2: * @param aError Error code to be passed to CompleteSelf. williamr@2: */ williamr@2: williamr@2: void ActivateRunLWithError(TInt aError); williamr@2: williamr@2: /** williamr@2: * Cancel any pending obex operation without completing the observer. williamr@2: */ williamr@2: williamr@2: void ExplicitCancel(); // Must call this instead of just Cancel(), otherwise the owner of this op will be completed. williamr@2: williamr@2: /** williamr@2: * Complete the observer, reporting any error via the progress. THIS METHOD MUST BE CALLED ONCE ONLY. williamr@2: * williamr@2: */ williamr@2: williamr@2: void CompleteObserverL(); williamr@2: williamr@2: /** williamr@2: * This causes this active object's request to complete which means williamr@2: * RunL() will be called again if we are active (immediately if there williamr@2: * are no higher priority active objects in the active scheduler). williamr@2: * williamr@2: * @param aError Error to be passed forward to the next step of the state machine williamr@2: */ williamr@2: williamr@2: void CompleteSelf(TInt aError); williamr@2: williamr@2: /** williamr@2: * Implementation of the send operation state machine. Progresses as: williamr@2: * Initialise-->Connect-->ConnectAttemptComplete-->SendObject-->(SendNextObject-->)SendComplete-->Disconnected williamr@2: * The SendNextObject state is repeated for each attachment in excess of one. williamr@2: * Also handles UserCancelled and SendError states by CompleteObserver()ing with appropriate error codes. williamr@2: * Leaves will be passed back to RunL and handled there. williamr@2: * williamr@2: * @leave KErrXXX system wide error codes williamr@2: */ williamr@2: williamr@2: void RealRunL(); williamr@2: williamr@2: /** williamr@2: * Delete the outbox entry as operation has 'completed'. williamr@2: * Will be invisible&InPreparation anyway (MS delete will delete it the next williamr@2: * time it starts). williamr@2: */ williamr@2: williamr@2: TInt SynchronousEntryDelete(); williamr@2: williamr@2: /** williamr@2: * Load an attachment into the obex sending buffer, and create a new Obex object of name TMsvEntry::iDetails. williamr@2: * williamr@2: * @param aParent Reference to CMsvServerEntry to be sent. williamr@2: * @param aWhichAttachment Zero-based index of attachment to send. williamr@2: * @leave KErrXXX system wide error codes williamr@2: */ williamr@2: williamr@2: void InitialiseAttachmentL(CMsvServerEntry& aParent, TInt aWhichAttachment); williamr@2: williamr@2: void LoadFileIntoObjectL(const TDesC& aFileName, const TDesC& aObexName, const TDesC8& aMimeType); williamr@2: williamr@2: williamr@2: /** williamr@2: * Checks the last object was sent correctly, and tries to action appropriate error feedback if not. Only to be called williamr@2: * from ESendObject/ESendNextObject or ESendComplete states. williamr@2: * williamr@2: * @param aStatus Status of last object williamr@2: * @return ETrue if message was OK--EFalse if message failed and this function has taken the necessary action williamr@2: */ williamr@2: williamr@2: TBool CheckStatusOfLastObject(TInt aStatus, TObexMtmProgress::TSendState aSendState); williamr@2: williamr@2: /** williamr@2: * Loads the next object to be sent, whether an attachment or a file in the file list. williamr@2: * williamr@2: * @return KErrXXX standard error code williamr@2: * @return KErrNotFound if there were neither attachments nor files in the file list williamr@2: * @leave KErrXXX system wide error codes williamr@2: */ williamr@2: williamr@2: TInt PrepareCurrentObjectAndSetStateL(); williamr@2: williamr@2: /** williamr@2: * Moves the newly sent message to the global sent items folder, and sets active ready for its completion. williamr@2: * williamr@2: * @leave KErrXXX system wide error codes williamr@2: */ williamr@2: williamr@2: void MoveToSentAndSetActiveL(); williamr@2: williamr@2: /** williamr@2: * Restores after the message has been moved to the inbox, and marks the message as visible. williamr@2: */ williamr@2: williamr@2: void CleanupAfterMovedToSent(); williamr@2: williamr@2: /** williamr@2: * Returns a reference to the file session (RFs) of the message williamr@2: * williamr@2: * @return A reference to the file session of the the message williamr@2: */ williamr@2: williamr@2: RFs& FileSession(); williamr@2: williamr@2: williamr@2: #ifdef __OBEX_SEND_OP_FILE_DEBUG_MODE__ williamr@2: /** williamr@2: * Output the obex object to a file in the service folder williamr@2: * williamr@2: * @leave KErrXXX system wide error codes williamr@2: */ williamr@2: williamr@2: TInt PutObexObjectToServiceFileL(); williamr@2: #endif //__OBEX_SEND_OP_FILE_DEBUG_MODE__ williamr@2: williamr@2: protected: williamr@2: CObexClient* iObexClient; /// iProgressPckg; ///