diff -r 7fdc9a71d314 -r 8ad140f3dd41 hti/HtiCommPlugins/HtiBtCommPlugin/BtEngine/inc/socketswriter.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hti/HtiCommPlugins/HtiBtCommPlugin/BtEngine/inc/socketswriter.h Wed Oct 13 16:17:58 2010 +0300 @@ -0,0 +1,97 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Writes to socket. +* +*/ + + +#ifndef __SOCKETSWRITER_H__ +#define __SOCKETSWRITER_H__ + +// INCLUDES +#include +#include "timeoutnotifier.h" + +// FORWARD DECLARATIONS +class CTimeOutTimer; +class MSocketObserver; + +const TInt KSocketWriteBufferSize = 1024; +const TInt KTransferBufferSize = 8 * 1024; + +// CLASS DECLARATION +class CSocketsWriter : public CActive, public MTimeOutNotifier + { + public: + + static CSocketsWriter* NewL( MSocketObserver& aEngineNotifier, + RSocket& aSocket ); + virtual ~CSocketsWriter(); + + /** + * Add data to iTransferBuffer and start sending if not already sending + * Leaves with KErrOverflow, if there is not enough free space. + * This can be called as long as there is space in buffer. + */ + void SendL(const TDesC8& aData); + + void CancelSending(); + + /** + * Return number of bytes that can be added to iTransferBuffer. + */ + TInt FreeSpaceInSendBuffer(); + + TInt SendBufferMaxSize(); + + protected: // from CActive + + void DoCancel(); + void RunL(); + + protected: // from MTimeOutNotifier + + void TimerExpired(); + + private: // Constructors and destructors + + CSocketsWriter( MSocketObserver& aEngineNotifier, RSocket& aSocket ); + void ConstructL(); + + private: // New functions + + void SendNextPacket(); + + private: // Enumerations + + enum TWriteState + { + ESending, + EIdle // nothing to be sent + }; + + private: // Data + + RSocket& iSocket; + MSocketObserver& iObserver; + TBuf8 iTransferBuffer; + TBuf8 iWriteBuffer; + CTimeOutTimer* iTimer; + TInt iTimeOut; // microseconds + TWriteState iWriteStatus; + }; + +#endif // __SOCKETSWRITER_H__ + +// End of File