sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: // include\mmf\server\mmfdatabuffer.h
sl@0: // 
sl@0: //
sl@0: 
sl@0: 
sl@0: #ifndef __MMF_SERVER_DATABUFFER_H__
sl@0: #define __MMF_SERVER_DATABUFFER_H__
sl@0: 
sl@0: #include <e32base.h>
sl@0: 
sl@0: 
sl@0: #include <mmf/server/mmfbuffer.h>
sl@0: 
sl@0: /** 
sl@0: @publishedAll
sl@0: @released
sl@0: 
sl@0: Default buffer size if none is specified.
sl@0: */
sl@0: static const TInt KMMFDataBufferDefaultBufferSize = 32;
sl@0: 
sl@0: /**
sl@0: @publishedAll
sl@0: @released
sl@0: 
sl@0: This class is an abstract class for databuffers that can be presented in the form of a descriptor.
sl@0: A constructor is provided which instantiates a CMMFDescriptorBuffer buffer by default.
sl@0: 
sl@0: @see CMMFDescriptorBuffer
sl@0: */
sl@0: class CMMFDataBuffer : public CMMFBuffer
sl@0: 	{
sl@0: public:
sl@0: 	IMPORT_C static CMMFDataBuffer* NewL();
sl@0: 	IMPORT_C static CMMFDataBuffer* NewL(TInt aMaxBufferSize);
sl@0: 	/**
sl@0: 	Destructor.
sl@0: 	*/
sl@0: 	virtual ~CMMFDataBuffer() {};
sl@0: 
sl@0: 	/**
sl@0: 	Returns a reference to the data contained in the buffer (non const version).
sl@0: 
sl@0: 	This is a virtual function that each derived class must implement.
sl@0: 
sl@0: 	@return A reference to the buffer.
sl@0: 	*/
sl@0: 	virtual TDes8& Data() = 0;
sl@0: 
sl@0: 	/**
sl@0: 	Returns a reference to the data contained in the buffer (const version).
sl@0: 
sl@0: 	This is a virtual function that each derived class must implement.
sl@0: 
sl@0: 	@return A reference to the buffer.
sl@0: 	*/
sl@0: 	virtual const TDesC8& Data() const = 0;
sl@0: 
sl@0: 	/**
sl@0: 	Returns the buffer size, in bytes.
sl@0: 
sl@0: 	This is a virtual function that each derived class must implement.
sl@0: 
sl@0: 	@return The buffer size in bytes.
sl@0: 	*/
sl@0: 	virtual TUint BufferSize() const = 0;
sl@0: 
sl@0: 	/**
sl@0: 	Sets the request size. 
sl@0: 
sl@0: 	Used where a component, such as a data source,
sl@0: 	may not be able to write to the entire maximum length of the buffer
sl@0: 	(variable bit rate codecs for example).
sl@0: 
sl@0: 	This is a virtual function that each derived class must implement.
sl@0: 
sl@0: 	@param  aSize
sl@0: 	        The requested size, in bytes.
sl@0: 	*/
sl@0: 	virtual void SetRequestSizeL(TInt aSize) = 0;
sl@0: protected:
sl@0: 	/**
sl@0: 	Protected constructor.
sl@0: 	*/
sl@0: 	CMMFDataBuffer(TUid aType): CMMFBuffer(aType) {};
sl@0: 	};
sl@0: 
sl@0: 
sl@0: /**
sl@0: @publishedAll
sl@0: @released
sl@0: 
sl@0: This class is a wrapper class to give a descriptor the same API as a CMMFDataBuffer.
sl@0: 
sl@0: The purpose of this class is that components such as codecs can use CMMFDataBuffers transparently
sl@0: without having to be concerned with whether the buffer is a descriptor buffer
sl@0: or a transfer buffer.
sl@0: */
sl@0: class CMMFDescriptorBuffer : public CMMFDataBuffer
sl@0: 	{
sl@0: public:
sl@0: 	IMPORT_C static CMMFDescriptorBuffer* NewL();
sl@0: 	IMPORT_C static CMMFDescriptorBuffer* NewL(TInt aMaxBufferSize);
sl@0: 	IMPORT_C ~CMMFDescriptorBuffer();
sl@0: 	IMPORT_C void ReAllocBufferL(TInt aMaxBufferSize);
sl@0: 	virtual TDes8& Data();
sl@0: 	virtual const TDesC8& Data() const;
sl@0: 	virtual void SetStatus(TBufferStatus aStatus);
sl@0: 	virtual void SetRequestSizeL(TInt aSize);
sl@0: 	virtual TUint BufferSize() const;
sl@0: 	virtual void SetPosition (TUint aPosition);
sl@0: private:
sl@0: 	CMMFDescriptorBuffer() : CMMFDataBuffer(KUidMmfDescriptorBuffer), iPtr(0,0,0) {};
sl@0: 	void ConstructL(TInt aMaxBufferSize);
sl@0: private:
sl@0: 	TUint8* iData;
sl@0: 	TPtr8 iPtr;
sl@0: 	};
sl@0: 
sl@0: 
sl@0: /**
sl@0: @publishedAll
sl@0: @released
sl@0: 
sl@0: This class is a wrapper class to give a transfer buffer/window the same API as a CMMFDataBuffer.
sl@0: The purpose of this class is so that components such as codecs can use CMMFDataBuffers transparently
sl@0: without having to be concerned with whether the buffer is a descriptor buffer
sl@0: or a transfer buffer.
sl@0: 
sl@0: The class assumes that a valid RTransferWindow with a RTransferBuffer mapped in already exists.
sl@0: 
sl@0: Note:
sl@0: CMMFTransferBuffers are not supported in EKA2.
sl@0: */
sl@0: 
sl@0: 
sl@0: class RTransferWindow
sl@0: 	{
sl@0: 	// dummy class
sl@0: 	};
sl@0: 	
sl@0: 
sl@0: class CMMFTransferBuffer : public CMMFDataBuffer
sl@0: 	{
sl@0: public:
sl@0: 
sl@0: 	IMPORT_C static CMMFTransferBuffer* NewL(RTransferWindow& aTransferWindow, TUint aDataLength = 0);
sl@0: 	IMPORT_C ~CMMFTransferBuffer();
sl@0: 	virtual TDes8& Data();
sl@0: 	virtual const TDesC8& Data() const;
sl@0: 	virtual TUint BufferSize() const;
sl@0: 	virtual void SetRequestSizeL(TInt aSize);
sl@0: 	virtual void SetPosition (TUint aPosition);
sl@0: 	IMPORT_C RTransferWindow& TransferWindow();
sl@0: 	IMPORT_C void MapOutBuffer();
sl@0: 	IMPORT_C TInt UpdateTransferWindow(RTransferWindow& aTransferWindow, TUint aDataLength = 0);
sl@0: 
sl@0: private:
sl@0: 	/**
sl@0: 	Private constructor.
sl@0: 	*/
sl@0: 	CMMFTransferBuffer() : CMMFDataBuffer(KUidMmfTransferBuffer), iPtr(0,0,0){};
sl@0: 	void ConstructL(RTransferWindow& aTransferWindow, TUint aDataLength);
sl@0: 
sl@0: private:
sl@0: 	RTransferWindow iTransferWindow;
sl@0: 	TBool iTransferWindowMappedInOK;
sl@0: 	TPtr8 iPtr;
sl@0: 	};
sl@0: 
sl@0: 
sl@0: /**
sl@0: @publishedAll
sl@0: @released
sl@0: 
sl@0: This class is a wrapper class intended to provide support for shared I/O buffers under EKA2
sl@0: This class, unlike other data buffers does not own memory - rather it contains a pointer to already allocated memory
sl@0: The purpose of this class is that components such as codecs can use CMMFDataBuffers transparently
sl@0: without having to be concerned with whether the buffer is a standard buffer or memory residing in shared I/O
sl@0: 
sl@0: Users of this class need to be very careful when using buffers of this type.
sl@0: It cannot be assumed that a buffer of this type can be written/read by any process other than the current one - example - handing CMMFPtrBuffer to the file server may not work since the file server's process may not have access to write data buffer.
sl@0: */
sl@0: class CMMFPtrBuffer : public CMMFDataBuffer
sl@0: 	{
sl@0: public:
sl@0: 	IMPORT_C static CMMFPtrBuffer* NewL();		//unitialised, pointer will be set via SetPtr
sl@0: 	IMPORT_C static CMMFPtrBuffer* NewL(const TPtr8& aPtr);
sl@0: 	IMPORT_C ~CMMFPtrBuffer();
sl@0: 	IMPORT_C void SetPtr(const TPtr8& aPtr);
sl@0: 	virtual TDes8& Data();
sl@0: 	virtual const TDesC8& Data() const;
sl@0: 	virtual void SetStatus(TBufferStatus aStatus);	
sl@0: 	virtual void SetRequestSizeL(TInt aSize);
sl@0: 	virtual TUint BufferSize() const;
sl@0: 	virtual void SetPosition (TUint aPosition);
sl@0: private:
sl@0: 	CMMFPtrBuffer() : CMMFDataBuffer(KUidMmfPtrBuffer), iPtr(0,0,0) {};
sl@0: 	void ConstructL(const TPtr8& aPtr);
sl@0: private:
sl@0: 	TPtr8 iPtr;
sl@0: 	};
sl@0: 
sl@0: #endif