os/mm/mmlibs/mmfw/src/Plugin/StdSourceAndSink/MmffilePriv.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 		
   116 	TBool Completed() ;
   117 	TDes8& BufferDes() ;
   118 	const TDesC8& BufferDesC() ;
   119 
   120 	~CReadWriteRequest() ;
   121 
   122 
   123 	// CActive functions.
   124 	// 
   125 	void SetActive() ;
   126 	void DoCancel() ;
   127 	virtual void RunL() = 0 ;
   128 	virtual TInt RunError( TInt aError ) ;
   129 	
   130 
   131 protected :
   132 	TAny* iSinkOrSource;
   133 	CMMFBuffer* iBuffer;
   134 	CTransferBufferCopy* iTransferBufferCopy;
   135 
   136 	MAsyncEventHandler* iEventHandler;
   137 	TBool iCompleted ;
   138 	TDes8* iBufferDes ;
   139 	TInt iError ;
   140 	TBool iUseTransferBuffer ;
   141 	void SetTransferBuffer (TBool aTBuffer) ;
   142 	TBool CanUseTransferBuffer () ;
   143 	} ;
   144 
   145 /**
   146  * @internalComponent
   147  */
   148 class CReadRequest : public CReadWriteRequest
   149 	{
   150 public :
   151 	CReadRequest(TAny* aSinkOrSource, CMMFBuffer* aBuffer, TUint aPosition, TUint aFileSize, MAsyncEventHandler* aEventHandler)
   152 	: CReadWriteRequest(aSinkOrSource, aBuffer, aEventHandler),
   153 	iPosition(aPosition), iFileSize(aFileSize)
   154 	{ } 
   155 
   156 	CReadRequest(TAny* aSinkOrSource, CMMFBuffer* aBuffer, CTransferBufferCopy* aOptionalDataBuffer, TUint aPosition, TUint aFileSize, MAsyncEventHandler* aEventHandler)
   157 	: CReadWriteRequest(aSinkOrSource, aBuffer, aOptionalDataBuffer, aEventHandler),
   158 	iPosition(aPosition), iFileSize(aFileSize)
   159 	{ } 
   160 
   161 	void RunL();
   162 private:
   163 	TUint iPosition;
   164 	TUint iFileSize;
   165 	};
   166 
   167 /**
   168  * @internalComponent
   169  */
   170 class CWriteRequest : public CReadWriteRequest
   171 	{
   172 public :
   173 	CWriteRequest(TAny* aSinkOrSource, CMMFBuffer* aBuffer, MAsyncEventHandler* aEventHandler)
   174 	: CReadWriteRequest(aSinkOrSource, aBuffer, aEventHandler)
   175 	{ }
   176 
   177 	CWriteRequest(TAny* aSinkOrSource, CMMFBuffer* aBuffer, CTransferBufferCopy* aOptionalDataBuffer, MAsyncEventHandler* aEventHandler)
   178 	: CReadWriteRequest(aSinkOrSource, aBuffer, aOptionalDataBuffer, aEventHandler)
   179 	{ }
   180 
   181 	void RunL();
   182 	};
   183 
   184 
   185 #endif
   186