mmlibs/mmfw/src/Plugin/StdSourceAndSink/MmffilePriv.h
changeset 0 b8ed18f6c07b
equal deleted inserted replaced
-1:000000000000 0:b8ed18f6c07b
       
     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 //
       
    15 
       
    16 
       
    17 #ifndef __MMFFILEPRIV_H_
       
    18 #define __MMFFILEPRIV_H_
       
    19 
       
    20 #include <f32file.h>
       
    21 
       
    22 #include <mmf/server/mmfclip.h>
       
    23 #include <mmf/server/mmfdatabuffer.h>
       
    24 
       
    25 
       
    26 /**
       
    27  *  @publishedAll
       
    28  *  @released
       
    29  *
       
    30  *  Represents a copy of a KUidMmfTransferBuffer used for reading/writting to the file server
       
    31  */
       
    32 
       
    33 class CTransferBufferCopy : public CBase
       
    34 	{
       
    35 public:
       
    36 	static CTransferBufferCopy* NewL(TInt aMaxLength);
       
    37 
       
    38 	virtual ~CTransferBufferCopy()
       
    39 		{delete iBuffer;}
       
    40 
       
    41 
       
    42 	TDes8& Des() {return iBufferDes;}
       
    43 
       
    44 	TInt MaxLength() {return iBufferDes.MaxLength();}
       
    45 
       
    46 	void ReUse(TInt aMaxLength) {iBufferDes.Set(iBuffer,0, Min(aMaxLength, iMaxLength));}
       
    47 
       
    48 	TBool InUse() {return iInUse;}
       
    49 
       
    50 	void SetInUse(TBool aInUse) {iInUse=aInUse;}
       
    51 
       
    52 private:
       
    53 	CTransferBufferCopy(TInt aMaxLength) : CBase(), iMaxLength(aMaxLength), iBufferDes(0,0,0), iInUse(EFalse){}
       
    54 
       
    55 	void ConstructL();
       
    56 
       
    57 private:
       
    58 	TUint8*	iBuffer;
       
    59 	
       
    60 	//Holds the original MaxLength when class constructed. 
       
    61 	//May be larger than MaxLength of iBufferDes
       
    62 	TInt	iMaxLength;
       
    63 
       
    64 	TPtr8	iBufferDes;
       
    65 
       
    66 	TBool	iInUse;
       
    67 	};
       
    68 
       
    69 
       
    70 
       
    71 
       
    72 /**
       
    73  * @internalComponent
       
    74  *
       
    75  * A request is created when an external object requests or supplies data.  Calls to the File Server are
       
    76  * made asynchronously and a CReadWriteRequest created to notify the caller on completion.
       
    77  *
       
    78  * CReadWriteRequest is an abstract class.  Concrete instances are of CReadRequest & CWriteRequest.
       
    79  * Concrete instances need to know whether to call MDataSink::BufferFilledL() or MDataSource::BufferEmptiedL()
       
    80  */
       
    81 class CReadWriteRequest : public CActive
       
    82 	{
       
    83 public:
       
    84 	CReadWriteRequest(TAny* aSinkOrSource, CMMFBuffer* aBuffer, MAsyncEventHandler* aEventHandler)
       
    85 	: CActive(EPriorityStandard),
       
    86 	iSinkOrSource(aSinkOrSource), 
       
    87 	iBuffer(aBuffer),
       
    88 	iEventHandler(aEventHandler)
       
    89 		{
       
    90 		CActiveScheduler::Add( this );
       
    91 		}
       
    92 
       
    93 	CReadWriteRequest(TAny* aSinkOrSource, CMMFBuffer* aBuffer, CTransferBufferCopy* aOptionalDataBuffer, MAsyncEventHandler* aEventHandler)
       
    94 	: CActive(EPriorityStandard),
       
    95 	iSinkOrSource(aSinkOrSource), 
       
    96 	iBuffer(aBuffer),
       
    97 	iTransferBufferCopy(aOptionalDataBuffer),
       
    98 	iEventHandler(aEventHandler)
       
    99 		{
       
   100 		CActiveScheduler::Add( this );
       
   101 		iTransferBufferCopy->SetInUse(ETrue);
       
   102 		}
       
   103 		
       
   104 	CReadWriteRequest(CReadWriteRequest& aRequest)
       
   105 	: CActive(EPriorityStandard),
       
   106 	iSinkOrSource(aRequest.iSinkOrSource),
       
   107 	iBuffer(aRequest.iBuffer),
       
   108 	iTransferBufferCopy(aRequest.iTransferBufferCopy),
       
   109 	iEventHandler(aRequest.iEventHandler)
       
   110 		{
       
   111 		CActiveScheduler::Add( this );
       
   112 		iTransferBufferCopy->SetInUse(ETrue);
       
   113 		}
       
   114 
       
   115 	inline TBool Processing() const { return iState == EProcessing; }	
       
   116 	inline TBool Completed() const { return iState == ECompleted; }
       
   117 
       
   118 	TDes8& BufferDes() ;
       
   119 	const TDesC8& BufferDesC() ;
       
   120 
       
   121 	~CReadWriteRequest() ;
       
   122 
       
   123 
       
   124 	// CActive functions.
       
   125 	// 
       
   126 	void SetActive() ;
       
   127 	void DoCancel() ;
       
   128 	virtual void RunL() = 0 ;
       
   129 	virtual TInt RunError( TInt aError ) ;
       
   130 	
       
   131 
       
   132 protected :
       
   133 	TAny* iSinkOrSource;
       
   134 	CMMFBuffer* iBuffer;
       
   135 	CTransferBufferCopy* iTransferBufferCopy;
       
   136 
       
   137 	MAsyncEventHandler* iEventHandler;
       
   138 
       
   139 	TDes8* iBufferDes ;
       
   140 	TInt iError ;
       
   141 	TBool iUseTransferBuffer ;
       
   142 	void SetTransferBuffer (TBool aTBuffer) ;
       
   143 	TBool CanUseTransferBuffer () ;
       
   144 	
       
   145 	enum TState
       
   146 		{
       
   147 		EActive,
       
   148 		EProcessing,
       
   149 		ECompleted
       
   150 		};
       
   151 	
       
   152 	TState iState;
       
   153 	} ;
       
   154 
       
   155 /**
       
   156  * @internalComponent
       
   157  */
       
   158 class CReadRequest : public CReadWriteRequest
       
   159 	{
       
   160 public :
       
   161 	CReadRequest(TAny* aSinkOrSource, CMMFBuffer* aBuffer, TUint aPosition, TUint aFileSize, MAsyncEventHandler* aEventHandler)
       
   162 	: CReadWriteRequest(aSinkOrSource, aBuffer, aEventHandler),
       
   163 	iPosition(aPosition), iFileSize(aFileSize)
       
   164 	{ } 
       
   165 
       
   166 	CReadRequest(TAny* aSinkOrSource, CMMFBuffer* aBuffer, CTransferBufferCopy* aOptionalDataBuffer, TUint aPosition, TUint aFileSize, MAsyncEventHandler* aEventHandler)
       
   167 	: CReadWriteRequest(aSinkOrSource, aBuffer, aOptionalDataBuffer, aEventHandler),
       
   168 	iPosition(aPosition), iFileSize(aFileSize)
       
   169 	{ } 
       
   170 
       
   171 	void RunL();
       
   172 private:
       
   173 	TUint iPosition;
       
   174 	TUint iFileSize;
       
   175 	};
       
   176 
       
   177 /**
       
   178  * @internalComponent
       
   179  */
       
   180 class CWriteRequest : public CReadWriteRequest
       
   181 	{
       
   182 public :
       
   183 	CWriteRequest(TAny* aSinkOrSource, CMMFBuffer* aBuffer, MAsyncEventHandler* aEventHandler)
       
   184 	: CReadWriteRequest(aSinkOrSource, aBuffer, aEventHandler)
       
   185 	{ }
       
   186 
       
   187 	CWriteRequest(TAny* aSinkOrSource, CMMFBuffer* aBuffer, CTransferBufferCopy* aOptionalDataBuffer, MAsyncEventHandler* aEventHandler)
       
   188 	: CReadWriteRequest(aSinkOrSource, aBuffer, aOptionalDataBuffer, aEventHandler)
       
   189 	{ }
       
   190 
       
   191 	void RunL();
       
   192 	};
       
   193 
       
   194 
       
   195 #endif
       
   196