mmfenh/progressivedownload/ProgressiveDownloadSource/src/MmffilePriv.h
changeset 16 43d09473c595
parent 14 80975da52420
child 22 128eb6a32b84
equal deleted inserted replaced
14:80975da52420 16:43d09473c595
     1 /*
       
     2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Progressive Download Utility
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __MMFFILEPRIV_H_
       
    20 #define __MMFFILEPRIV_H_
       
    21 
       
    22 #include <f32file.h>
       
    23 
       
    24 #include <mmf/server/mmfclip.h>
       
    25 #include <mmf/server/mmfdatabuffer.h>
       
    26 
       
    27 
       
    28 /**
       
    29  *  @publishedAll
       
    30  *
       
    31  *  Represents a copy of a KUidMmfTransferBuffer used for reading/writting to the file server
       
    32  */
       
    33 
       
    34 class CTransferBufferCopy : public CBase
       
    35 	{
       
    36 public:
       
    37 	static CTransferBufferCopy* NewL(TInt aMaxLength);
       
    38 
       
    39 	virtual ~CTransferBufferCopy()
       
    40 		{delete iBuffer;}
       
    41 
       
    42 
       
    43 	TDes8& Des() {return iBufferDes;}
       
    44 
       
    45 	TInt MaxLength() {return iBufferDes.MaxLength();}
       
    46 
       
    47 	void ReUse(TInt aMaxLength) {iBufferDes.Set(iBuffer,0, Min(aMaxLength, iMaxLength));}
       
    48 
       
    49 	TBool InUse() {return iInUse;}
       
    50 
       
    51 	void SetInUse(TBool aInUse) {iInUse=aInUse;}
       
    52 
       
    53 private:
       
    54 	CTransferBufferCopy(TInt aMaxLength) : CBase(), iMaxLength(aMaxLength), iBufferDes(0,0,0), iInUse(EFalse){}
       
    55 
       
    56 	void ConstructL();
       
    57 
       
    58 private:
       
    59 	TUint8*	iBuffer;
       
    60 
       
    61 	//Holds the original MaxLength when class constructed.
       
    62 	//May be larger than MaxLength of iBufferDes
       
    63 	TInt	iMaxLength;
       
    64 
       
    65 	TPtr8	iBufferDes;
       
    66 
       
    67 	TBool	iInUse;
       
    68 	};
       
    69 
       
    70 
       
    71 
       
    72 
       
    73 /**
       
    74  * @internalComponent
       
    75  *
       
    76  * A request is created when an external object requests or supplies data.  Calls to the File Server are
       
    77  * made asynchronously and a CReadWriteRequest created to notify the caller on completion.
       
    78  *
       
    79  * CReadWriteRequest is an abstract class.  Concrete instances are of CReadRequest & CWriteRequest.
       
    80  * Concrete instances need to know whether to call MDataSink::BufferFilledL() or MDataSource::BufferEmptiedL()
       
    81  */
       
    82 class CReadWriteRequest : public CActive
       
    83 	{
       
    84 public:
       
    85 	CReadWriteRequest(TAny* aSinkOrSource, CMMFBuffer* aBuffer,MAsyncEventHandler* aEventHandler)
       
    86 	: CActive(EPriorityStandard),
       
    87 	iSinkOrSource(aSinkOrSource),
       
    88 	iBuffer(aBuffer),
       
    89 	iEventHandler(aEventHandler)
       
    90 		{
       
    91 		CActiveScheduler::Add( this );
       
    92 		}
       
    93 
       
    94 	CReadWriteRequest(TAny* aSinkOrSource, CMMFBuffer* aBuffer, CTransferBufferCopy* aOptionalDataBuffer, MAsyncEventHandler* aEventHandler)
       
    95 	: CActive(EPriorityStandard),
       
    96 	iSinkOrSource(aSinkOrSource),
       
    97 	iBuffer(aBuffer),
       
    98 	iTransferBufferCopy(aOptionalDataBuffer),
       
    99 	iEventHandler(aEventHandler)
       
   100 		{
       
   101 		CActiveScheduler::Add( this );
       
   102 		iTransferBufferCopy->SetInUse(ETrue);
       
   103 		}
       
   104 
       
   105 	CReadWriteRequest(CReadWriteRequest& aRequest)
       
   106 	: CActive(EPriorityStandard),
       
   107 	iSinkOrSource(aRequest.iSinkOrSource),
       
   108 	iBuffer(aRequest.iBuffer),
       
   109 	iTransferBufferCopy(aRequest.iTransferBufferCopy),
       
   110 	iEventHandler(aRequest.iEventHandler)
       
   111 		{
       
   112 		CActiveScheduler::Add( this );
       
   113 		iTransferBufferCopy->SetInUse(ETrue);
       
   114 		}
       
   115 
       
   116 
       
   117 	TBool Completed() ;
       
   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 	TBool iCompleted ;
       
   139 	TDes8* iBufferDes ;
       
   140 	TInt iError ;
       
   141 	TBool iUseTransferBuffer ;
       
   142 	void SetTransferBuffer (TBool aTBuffer) ;
       
   143 	TBool CanUseTransferBuffer () ;
       
   144 	} ;
       
   145 
       
   146 /**
       
   147  * @internalComponent
       
   148  */
       
   149 class CReadRequest : public CReadWriteRequest
       
   150 	{
       
   151 public :
       
   152 	CReadRequest(TAny* aSinkOrSource, CMMFBuffer* aBuffer, TUint aPosition, TUint aFileSize, TInt aBytesDownloaded,MAsyncEventHandler* aEventHandler)
       
   153 	: CReadWriteRequest(aSinkOrSource, aBuffer, aEventHandler),
       
   154 	iPosition(aPosition), iFileSize(aFileSize),iBytesDownloaded(aBytesDownloaded)
       
   155 	{ }
       
   156 
       
   157 	CReadRequest(TAny* aSinkOrSource, CMMFBuffer* aBuffer, CTransferBufferCopy* aOptionalDataBuffer, TUint aPosition, TUint aFileSize,TInt aBytesDownloaded, MAsyncEventHandler* aEventHandler)
       
   158 	: CReadWriteRequest(aSinkOrSource, aBuffer, aOptionalDataBuffer,aEventHandler),
       
   159 	iPosition(aPosition), iFileSize(aFileSize),iBytesDownloaded(aBytesDownloaded)
       
   160 	{ }
       
   161 
       
   162 	void RunL();
       
   163 private:
       
   164 	TUint iPosition;
       
   165 	TUint iFileSize;
       
   166 	TInt iBytesDownloaded;
       
   167 	};
       
   168 
       
   169 /**
       
   170  * @internalComponent
       
   171  */
       
   172 class CWriteRequest : public CReadWriteRequest
       
   173 	{
       
   174 public :
       
   175 	CWriteRequest(TAny* aSinkOrSource, CMMFBuffer* aBuffer, MAsyncEventHandler* aEventHandler)
       
   176 	: CReadWriteRequest(aSinkOrSource, aBuffer, aEventHandler)
       
   177 	{ }
       
   178 
       
   179 	CWriteRequest(TAny* aSinkOrSource, CMMFBuffer* aBuffer, CTransferBufferCopy* aOptionalDataBuffer, MAsyncEventHandler* aEventHandler)
       
   180 	: CReadWriteRequest(aSinkOrSource, aBuffer, aOptionalDataBuffer, aEventHandler)
       
   181 	{ }
       
   182 
       
   183 	void RunL();
       
   184 	};
       
   185 
       
   186 
       
   187 #endif
       
   188