os/kernelhwsrv/kerneltest/e32test/pccd/d_medt2.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\pccd\d_medt2.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#if defined(_UNICODE)
sl@0
    19
#if !defined(UNICODE)
sl@0
    20
#define UNICODE
sl@0
    21
#endif
sl@0
    22
#endif
sl@0
    23
#include <kernel/kernel.h>
sl@0
    24
const TInt KTestDriverBufferMaxSize=0x1000;	// 4K
sl@0
    25
sl@0
    26
class DPhysicalDeviceMediaTest : public DPhysicalDeviceMedia
sl@0
    27
	{
sl@0
    28
public:
sl@0
    29
	DPhysicalDeviceMediaTest();
sl@0
    30
	virtual TInt Install();
sl@0
    31
	virtual TInt Remove();
sl@0
    32
	virtual void GetCaps(TDes8 &aDes) const;
sl@0
    33
	virtual CBase *CreateL(TInt aDevice,const TDesC *anInfo,const TVersion &aVer);
sl@0
    34
	virtual TInt Priority();
sl@0
    35
	};
sl@0
    36
								
sl@0
    37
class DMediaDriverTest : public DMediaDriver
sl@0
    38
	{
sl@0
    39
public:
sl@0
    40
	DMediaDriverTest();
sl@0
    41
	TInt DoCreate(TMediaDevice aMediaDevice);
sl@0
    42
	void DoRead(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aTrg);
sl@0
    43
	void DoWrite(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aSrc);
sl@0
    44
	void DoFormat(TInt64 &aPos,TInt aLength);
sl@0
    45
	TInt Enlarge(TInt aLength);
sl@0
    46
	TInt ReduceSize(TInt64 &aPos,TInt aLength);
sl@0
    47
	void Close();
sl@0
    48
	TInt PartitionInfo(TPartitionInfo &anInfo);
sl@0
    49
	void Caps(TDes8& aCapsBuf);
sl@0
    50
private:
sl@0
    51
	static void WriteCompleteCallBack(TAny *aMediaDriver,TInt aDelay);
sl@0
    52
	static void FormatCompleteCallBack(TAny *aMediaDriver,TInt aDelay);
sl@0
    53
private:
sl@0
    54
	TUint8 iBuf[KTestDriverBufferMaxSize];
sl@0
    55
	TTickLink iWriteTickLink;
sl@0
    56
	TTickLink iFormatTickLink;
sl@0
    57
	};
sl@0
    58
sl@0
    59
DPhysicalDeviceMediaTest::DPhysicalDeviceMediaTest()
sl@0
    60
//
sl@0
    61
// Constructor
sl@0
    62
//
sl@0
    63
	{
sl@0
    64
	iUnitsMask=0x1; // Support only one 
sl@0
    65
	iVersion=TVersion(KMediaDriverInterfaceMajorVersionNumber,KMediaDriverInterfaceMinorVersionNumber,KMediaDriverInterfaceBuildVersionNumber);
sl@0
    66
	}
sl@0
    67
sl@0
    68
TInt DPhysicalDeviceMediaTest::Install()
sl@0
    69
//
sl@0
    70
// Install the test Media PDD.
sl@0
    71
//
sl@0
    72
	{
sl@0
    73
sl@0
    74
    TPtrC name=_L("Media.Tst2");
sl@0
    75
	return(SetName(&name));
sl@0
    76
	}
sl@0
    77
sl@0
    78
TInt DPhysicalDeviceMediaTest::Remove()
sl@0
    79
//
sl@0
    80
// Remove the test Media PDD.
sl@0
    81
//
sl@0
    82
	{
sl@0
    83
	return(KErrNone);
sl@0
    84
	}
sl@0
    85
sl@0
    86
void DPhysicalDeviceMediaTest::GetCaps(TDes8 &/* aDes */) const
sl@0
    87
//
sl@0
    88
// Return the media drivers capabilities.
sl@0
    89
//
sl@0
    90
	{
sl@0
    91
	}
sl@0
    92
								 
sl@0
    93
CBase *DPhysicalDeviceMediaTest::CreateL(TInt aDevice,const TDesC * /* anInfo */,const TVersion &aVer)
sl@0
    94
//
sl@0
    95
// Create a test media driver.
sl@0
    96
//
sl@0
    97
	{
sl@0
    98
	if (User::QueryVersionSupported(iVersion,aVer)==EFalse)
sl@0
    99
		User::Leave(KErrNotSupported);
sl@0
   100
	DMediaDriverTest *mD=new(ELeave) DMediaDriverTest;
sl@0
   101
	TInt ret=mD->DoCreate((TMediaDevice)aDevice);
sl@0
   102
	if (ret!=KErrNone)
sl@0
   103
		{
sl@0
   104
		delete mD;
sl@0
   105
		User::Leave(ret);
sl@0
   106
		}
sl@0
   107
	return(mD);
sl@0
   108
	}
sl@0
   109
sl@0
   110
TInt DPhysicalDeviceMediaTest::Priority()
sl@0
   111
//
sl@0
   112
// Return the priority of this media driver
sl@0
   113
//
sl@0
   114
	{
sl@0
   115
sl@0
   116
	return(KMediaDriverPriorityLow); 
sl@0
   117
	}
sl@0
   118
sl@0
   119
DMediaDriverTest::DMediaDriverTest()
sl@0
   120
//
sl@0
   121
// Constructor.
sl@0
   122
//
sl@0
   123
	{
sl@0
   124
sl@0
   125
//	Mem::FillZ(&iBuf[0],sizeof(iBuf));
sl@0
   126
    iFlags=KMediaDrvMultipleReqs;
sl@0
   127
	}
sl@0
   128
sl@0
   129
TInt DMediaDriverTest::DoCreate(TMediaDevice aMediaDevice)
sl@0
   130
//
sl@0
   131
// Create the media driver.
sl@0
   132
//
sl@0
   133
	{
sl@0
   134
sl@0
   135
   	if (!__IS_REMOVABLE(aMediaDevice))
sl@0
   136
		return(KErrNotSupported);
sl@0
   137
	SetTotalSizeInBytes(KTestDriverBufferMaxSize);
sl@0
   138
	return(KErrNone);
sl@0
   139
	}
sl@0
   140
sl@0
   141
void DMediaDriverTest::DoRead(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aTrg)
sl@0
   142
//
sl@0
   143
// Read from specified area of media.
sl@0
   144
//
sl@0
   145
	{
sl@0
   146
sl@0
   147
	TInt ret=KErrNone;
sl@0
   148
	if (!aTrg.IsCurrentThread())
sl@0
   149
		ret=KErrGeneral;
sl@0
   150
	else
sl@0
   151
		{
sl@0
   152
		if ((ret=aTrg.CurrentThreadDescCheck(aLength))==KErrNone)
sl@0
   153
            {
sl@0
   154
			TDes8 &t=*((TDes8*)aTrg.iPtr);
sl@0
   155
			Mem::Copy((TAny*)(t.Ptr()+aTrg.iOffset),&iBuf[aPos.Low()],aLength);
sl@0
   156
			t.SetLength(aLength+aTrg.iOffset);
sl@0
   157
			}
sl@0
   158
		}
sl@0
   159
    Complete(KMediaDrvReadReq,ret);
sl@0
   160
	}
sl@0
   161
sl@0
   162
const TInt KWriteAsyncTime=100000;	// 100mS
sl@0
   163
void DMediaDriverTest::DoWrite(TInt64 &aPos,TInt aLength,TMediaDrvDescData &aSrc)
sl@0
   164
//
sl@0
   165
// Write to specifed area of media.
sl@0
   166
//
sl@0
   167
	{
sl@0
   168
sl@0
   169
	if (!aSrc.IsCurrentThread())
sl@0
   170
        Complete(KMediaDrvWriteReq,KErrGeneral);
sl@0
   171
	else
sl@0
   172
        {
sl@0
   173
		Mem::Copy(&iBuf[aPos.Low()],((TDesC8*)aSrc.iPtr)->Ptr()+aSrc.iOffset,aLength);
sl@0
   174
	    iWriteTickLink.OneShotInMicroSeconds(KWriteAsyncTime,DMediaDriverTest::WriteCompleteCallBack,this);
sl@0
   175
        }
sl@0
   176
	}
sl@0
   177
sl@0
   178
const TInt KFormatAsyncTime=5000000;	// 5S
sl@0
   179
void DMediaDriverTest::DoFormat(TInt64 &aPos,TInt aLength)
sl@0
   180
//
sl@0
   181
// Format the specified area of the media.
sl@0
   182
//
sl@0
   183
	{
sl@0
   184
sl@0
   185
    Mem::Fill(&iBuf[aPos.Low()],aLength,0xFF);
sl@0
   186
	iFormatTickLink.OneShotInMicroSeconds(KFormatAsyncTime,DMediaDriverTest::FormatCompleteCallBack,this);
sl@0
   187
	}
sl@0
   188
sl@0
   189
TInt DMediaDriverTest::Enlarge(TInt /*aLength*/)
sl@0
   190
//
sl@0
   191
// Enlarge the drive
sl@0
   192
//
sl@0
   193
	{
sl@0
   194
sl@0
   195
	return(KErrNotSupported);
sl@0
   196
	}
sl@0
   197
sl@0
   198
TInt DMediaDriverTest::ReduceSize(TInt64& /*aPos*/,TInt /*aLength*/)
sl@0
   199
//
sl@0
   200
// Reduce in size the drive
sl@0
   201
//
sl@0
   202
	{
sl@0
   203
sl@0
   204
	return(KErrNotSupported);
sl@0
   205
	}
sl@0
   206
sl@0
   207
void DMediaDriverTest::Close()
sl@0
   208
//
sl@0
   209
// Close the media driver
sl@0
   210
//
sl@0
   211
	{
sl@0
   212
    
sl@0
   213
	iWriteTickLink.Cancel();
sl@0
   214
	iFormatTickLink.Cancel();
sl@0
   215
    }
sl@0
   216
sl@0
   217
TInt DMediaDriverTest::PartitionInfo(TPartitionInfo &anInfo)
sl@0
   218
//
sl@0
   219
// Return partition information on the media.
sl@0
   220
//
sl@0
   221
	{
sl@0
   222
sl@0
   223
	anInfo.iPartitionCount=1;
sl@0
   224
	anInfo.iEntry[0].iPartitionBaseAddr=0;
sl@0
   225
	anInfo.iEntry[0].iPartitionLen=anInfo.iMediaSizeInBytes=TotalSizeInBytes();
sl@0
   226
	return(KErrNone);
sl@0
   227
	}
sl@0
   228
sl@0
   229
void DMediaDriverTest::Caps(TDes8& aCapsBuf)
sl@0
   230
//
sl@0
   231
// Return the capabilities of the media
sl@0
   232
	{
sl@0
   233
sl@0
   234
	TLocalDriveCapsV2 caps;
sl@0
   235
	caps.iType=EMediaFlash; // Pretend its a Flash device
sl@0
   236
	caps.iConnectionBusType=EConnectionBusInternal;
sl@0
   237
	caps.iDriveAtt=KDriveAttLocal|KDriveAttRemovable;
sl@0
   238
	caps.iMediaAtt=KMediaAttFormattable;
sl@0
   239
	caps.iFileSystemId=KDriveFileSysFAT;
sl@0
   240
	caps.iHiddenSectors=0;
sl@0
   241
	aCapsBuf.FillZ(aCapsBuf.MaxLength());
sl@0
   242
	aCapsBuf.Copy((TUint8 *)&caps,Min(aCapsBuf.MaxLength(),sizeof(caps)));
sl@0
   243
	}
sl@0
   244
sl@0
   245
void DMediaDriverTest::WriteCompleteCallBack(TAny *aMediaDriver,TInt /*aDelay*/)
sl@0
   246
//
sl@0
   247
// Complete a write request
sl@0
   248
//
sl@0
   249
	{
sl@0
   250
sl@0
   251
	DMediaDriverTest &md=*(DMediaDriverTest*)aMediaDriver;
sl@0
   252
    md.Complete(KMediaDrvWriteReq,KErrNone);
sl@0
   253
	return;
sl@0
   254
	}
sl@0
   255
sl@0
   256
void DMediaDriverTest::FormatCompleteCallBack(TAny *aMediaDriver,TInt /*aDelay*/)
sl@0
   257
//
sl@0
   258
// Complete a format request
sl@0
   259
//
sl@0
   260
	{
sl@0
   261
sl@0
   262
	DMediaDriverTest &md=*(DMediaDriverTest*)aMediaDriver;
sl@0
   263
    md.Complete(KMediaDrvFormatReq,KErrNone);
sl@0
   264
	return;
sl@0
   265
	}
sl@0
   266
sl@0
   267
DECLARE_STANDARD_PDD()
sl@0
   268
	{
sl@0
   269
	return new DPhysicalDeviceMediaTest;
sl@0
   270
	}
sl@0
   271