os/kernelhwsrv/kerneltest/e32test/digitiser/d_ldddigitisertest.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.
     1 // Copyright (c) 2008-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 the License "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 // e32test\digitiser\d_ldddigitisertest.cpp
    15 // LDD for testing the Digitiser  Hal Calls.
    16 // 
    17 //
    18 
    19 #include <kernel/kernel.h>
    20 
    21 #include "d_ldddigitisertest.h"
    22 
    23 const TUint KMaxDeviceNumber=10;
    24 
    25 TUint 	gDeviceNumber=1;					// Device Number
    26 TUint	gRegisteredDeviceNumber;			// Represents the registered Hal Entry
    27 TBool	gHalEntryRegistered; 				// States HAL Entry Successfully registered or not
    28 static	TDigitiserInfoV02 gDigitserHalData;	// Buffer to  hold the HAL data; 
    29 static	TUint gPointer3DSupported;			// States whether the pointing device supports 3rd dimension.
    30 
    31 class DDigitiserLDDTestFactory : public DLogicalDevice
    32 //
    33 // Test LDD factory
    34 //
    35 	{
    36 public:
    37 	DDigitiserLDDTestFactory();
    38 	virtual TInt Install(); 								//overriding pure virtual
    39 	virtual void GetCaps(TDes8& aDes) const;				//overriding pure virtual
    40 	virtual TInt Create(DLogicalChannelBase*& aChannel); 	//overriding pure virtual
    41 	};
    42 
    43 class DDigitiserLDDTestChannel : public DLogicalChannelBase
    44 //
    45 // Test logical channel
    46 //
    47 	{
    48 public:
    49 	virtual ~DDigitiserLDDTestChannel();
    50 protected:
    51 	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
    52 	virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
    53 	};
    54 
    55 // Initialise Digitiser HAL Data
    56 void initialiseDigitiserHalData()
    57 	{
    58 //  TDigitiserInfoV02 Class Data layout
    59   
    60 //class TDigitiserInfoV02 : public TDigitiserInfoV01
    61 //	{	
    62 //public :
    63 //	TInt iZRange;				/**< The maximum distance to screen a pointing device will be detected (settable).*/
    64 //	TUint8 iThetaSupported;		/**< A Boolean value that indicates if Theta polar angle detection (tilt) is supported.*/
    65 //	TUint8 iPhiSupported;		/**< A Boolean value that indicates if Phi polar angle detection (tilt) is supported.*/
    66 //	TUint8 iAlphaSupported;		/**< A Boolean value that indicates if rotation of the pointing device along its main axis is supported.*/
    67 //	TUint8 iPressureSupported; 	/**< A Boolean value that indicates if pressure applied on screen is supported.*/
    68 //	TInt iProximityStep;    	/**<proximity resolution, e.g. proximity readings change in steps of 1, 5, 10, ... */
    69 //	TInt iMaxPressure;      	/**< maximum pressure reading*/
    70 //	TInt iPressureStep;     	/**< pressure resolution, */	
    71 //	TUint8 iMaxPointers;    	/**< max number of multi-touch pointers supported by hardware/driver.*/ 
    72 //	TUint8 iNumberOfPointers;	/**< Number of pointers it supports (settable).*/
    73 //	};
    74 
    75     gPointer3DSupported=1;
    76     gDigitserHalData.iZRange=100;
    77 	gDigitserHalData.iThetaSupported=1;
    78 	gDigitserHalData.iPhiSupported=1;
    79 	gDigitserHalData.iPressureSupported=1;
    80 	gDigitserHalData.iAlphaSupported=1;
    81 	gDigitserHalData.iProximityStep=5;
    82 	gDigitserHalData.iMaxPointers=2;
    83 	gDigitserHalData.iNumberOfPointers=2;
    84 	gDigitserHalData.iMaxPressure=5000;
    85 	gDigitserHalData.iPressureStep=500;
    86 	}
    87 
    88 LOCAL_C TInt halFunction(TAny* /*aPtr*/, TInt aFunction, TAny* a1, TAny* /*a2*/)
    89 	{
    90 	TInt r=KErrNone;
    91 	TPckgBuf<TDigitiserInfoV02> vPckg(gDigitserHalData);
    92 	switch(aFunction)
    93 		{
    94 		case EDigitiserHal3DInfo:
    95 			// Get Request for all but EPointer3D. Copy the TDigitiserInfoV02 object to a1
    96 			Kern::InfoCopy(*(TDes8*)a1,vPckg);
    97 			break;
    98 		case EDigitiserHal3DPointer:
    99 			// Get request EPointer3D
   100 			kumemput32(a1,&gPointer3DSupported,sizeof(gPointer3DSupported));
   101 			break;
   102 		case EDigitiserHalSetZRange:
   103 			// Set requeest for EPointer3DMaxProximity (iZRange)
   104 			gDigitserHalData.iZRange=(TInt)a1;
   105 			break;
   106 		case EDigitiserHalSetNumberOfPointers:
   107 			// Set request for EPointerNumberOfPointers
   108 			gDigitserHalData.iNumberOfPointers=static_cast<TUint8>((TInt)a1);
   109 			break;
   110 		default:
   111 			r=KErrNotSupported;
   112 			break;
   113 		}
   114 	return r;
   115 	}
   116 
   117 #ifdef GRAPHICS_VERSION
   118 DECLARE_EXTENSION_LDD()
   119 	{
   120 	return new DDigitiserLDDTestFactory;
   121 	}
   122 DECLARE_STANDARD_EXTENSION()
   123 	{
   124 	TInt r;
   125 	// Initialise Digitiser HAL Data first.
   126 	initialiseDigitiserHalData();
   127 	// Find device number
   128 	do
   129 		{
   130 		r=Kern::AddHalEntry(EHalGroupDigitiser,halFunction,NULL,gDeviceNumber);
   131 		}
   132 	while((r==KErrInUse) && (++gDeviceNumber < KMaxDeviceNumber));
   133 		
   134 	if((gDeviceNumber < KMaxDeviceNumber) && (r==KErrNone))
   135 		{
   136 		gHalEntryRegistered = ETrue;
   137 		gRegisteredDeviceNumber = gDeviceNumber;
   138 		}
   139 	else
   140 		{
   141 		gHalEntryRegistered = EFalse;
   142 		r=KErrInUse;
   143 		}
   144 	return r;
   145 	}
   146 #else
   147 DECLARE_STANDARD_LDD()
   148 	{
   149 	return new DDigitiserLDDTestFactory;
   150 	}
   151 #endif
   152 
   153 //
   154 // Constructor
   155 //
   156 DDigitiserLDDTestFactory::DDigitiserLDDTestFactory()
   157 	{
   158 	}
   159 
   160 TInt DDigitiserLDDTestFactory::Create(DLogicalChannelBase*& aChannel)
   161 	{
   162 //
   163 // Create new channel
   164 //  
   165 	aChannel=new DDigitiserLDDTestChannel;
   166 	return aChannel?KErrNone:KErrNoMemory;
   167 	}
   168 
   169 TInt DDigitiserLDDTestFactory::Install()
   170 //
   171 // Install the LDD - overriding pure virtual
   172 	{
   173 	return SetName(&KLddName);
   174 	}
   175 
   176 void DDigitiserLDDTestFactory::GetCaps(TDes8& /*aDes*/) const
   177 //
   178 // Get capabilities - overriding pure virtual
   179 //
   180 	{
   181 	}
   182 
   183 TInt DDigitiserLDDTestChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
   184 //
   185 // Create channel
   186 //
   187 	{
   188 	return KErrNone;
   189 	}
   190 
   191 DDigitiserLDDTestChannel::~DDigitiserLDDTestChannel()
   192 //
   193 // Destructor
   194 //
   195 	{
   196 	}
   197 
   198 TInt DDigitiserLDDTestChannel::Request(TInt aReqNo, TAny* a1, TAny* /*a2*/)
   199 	{
   200 	TInt r=KErrNone;
   201 	switch(aReqNo)
   202 		{
   203 		case (RLddDigitiserTest::EADDHALENTRY):
   204 #ifndef GRAPHICS_VERSION
   205             NKern::ThreadEnterCS();
   206 			do
   207 			{
   208 		    r=Kern::AddHalEntry(EHalGroupDigitiser,halFunction,this,gDeviceNumber);
   209 			}
   210             while((r==KErrInUse) && (++gDeviceNumber < KMaxDeviceNumber));
   211 			NKern::ThreadLeaveCS();
   212 
   213 			if((gDeviceNumber < KMaxDeviceNumber) && (r==KErrNone))
   214 				{
   215 				gHalEntryRegistered=ETrue;
   216 				gRegisteredDeviceNumber=gDeviceNumber;
   217 				}
   218 			else
   219 				{
   220 				gHalEntryRegistered=EFalse;
   221 				r=KErrInUse;
   222 				}
   223 #else
   224 			r=KErrNotSupported;
   225 #endif
   226 			break;
   227 		case (RLddDigitiserTest::EREMOVEHALENTRY):
   228 			if(gHalEntryRegistered)
   229 				{
   230 				r=Kern::RemoveHalEntry(EHalGroupDigitiser,gRegisteredDeviceNumber);
   231 				}
   232 		break;
   233 		case (RLddDigitiserTest::EGETREGISTEREDDEVICENUMBER):
   234 			if(gHalEntryRegistered)
   235 				{
   236 				r=gRegisteredDeviceNumber;
   237 				}
   238 			else
   239 				{
   240 				r=KErrNotFound;
   241 				}
   242 			break;
   243 		case (RLddDigitiserTest::EINITIALISEHALDATA):
   244 #ifndef GRAPHICS_VERSION
   245 			initialiseDigitiserHalData();
   246 #else
   247 			r=KErrNone;
   248 #endif
   249 			break;
   250 		case (RLddDigitiserTest::EGET_EPOINTER3D):
   251 			r=gPointer3DSupported;
   252 			break;
   253 		case (RLddDigitiserTest::ESET_EPOINTER3D):
   254 			gPointer3DSupported=(TUint32)a1;
   255 			break;
   256 		case (RLddDigitiserTest::EGET_EPOINTERMAXPROXIMITY):
   257 			r=gDigitserHalData.iZRange;
   258 			break;
   259 		case (RLddDigitiserTest::ESET_EPOINTERMAXPROXIMITY):
   260 			gDigitserHalData.iZRange=(TInt)a1;
   261 			break;
   262 		case (RLddDigitiserTest::EGET_EPOINTER3DTHETASUPPORTED):
   263 			r=gDigitserHalData.iThetaSupported;
   264 			break;
   265 		case (RLddDigitiserTest::ESET_EPOINTER3DTHETASUPPORTED):
   266 			gDigitserHalData.iThetaSupported=static_cast<TUint8>((TInt)a1);
   267 			break;
   268 		case (RLddDigitiserTest::EGET_EPOINTER3DPHISUPPORTED):
   269 			r=gDigitserHalData.iPhiSupported;
   270 			break;
   271 		case (RLddDigitiserTest::ESET_EPOINTER3DPHISUPPORTED):
   272 			gDigitserHalData.iPhiSupported=static_cast<TUint8>((TInt)a1);
   273 			break;
   274 		case (RLddDigitiserTest::EGET_EPOINTER3DROTATIONSUPPORTED):
   275 			r=gDigitserHalData.iAlphaSupported;
   276 			break;
   277 		case (RLddDigitiserTest::ESET_EPOINTER3DROTATIONSUPPORTED):
   278 			gDigitserHalData.iAlphaSupported=static_cast<TUint8>((TInt)a1);
   279 			break;
   280 		case (RLddDigitiserTest::EGET_EPOINTER3DPRESSURESUPPORTED):
   281 			r=gDigitserHalData.iPressureSupported;
   282 			break;
   283 		case (RLddDigitiserTest::ESET_EPOINTER3DPRESSURESUPPORTED):
   284 			gDigitserHalData.iPressureSupported=static_cast<TUint8>((TInt)a1);
   285 			break;
   286 		case (RLddDigitiserTest::EGET_EPOINTER3DPROXIMITYSTEP):
   287 			r=gDigitserHalData.iProximityStep;
   288 			break;
   289 		case (RLddDigitiserTest::ESET_EPOINTER3DPROXIMITYSTEP):
   290 			gDigitserHalData.iProximityStep=(TInt)a1;
   291 			break;
   292 		case (RLddDigitiserTest::EGET_EPOINTER3DMAXPOINTERS):
   293 			r=gDigitserHalData.iMaxPointers;
   294 			break;
   295 		case (RLddDigitiserTest::ESET_EPOINTER3DMAXPOINTERS):
   296 			gDigitserHalData.iMaxPointers=static_cast<TUint8>((TInt)a1);
   297 			break;
   298 		case (RLddDigitiserTest::EGET_EPOINTER3DNUMBEROFPOINTERS):
   299 			r=gDigitserHalData.iNumberOfPointers;
   300 			break;
   301 		case (RLddDigitiserTest::ESET_EPOINTER3DNUMBEROFPOINTERS):
   302 			gDigitserHalData.iNumberOfPointers=static_cast<TUint8>((TInt)a1);
   303 			break;
   304 		case (RLddDigitiserTest::EGET_EPOINTER3DMAXPRESSURE):
   305 			r=gDigitserHalData.iMaxPressure;
   306 			break;
   307 		case (RLddDigitiserTest::ESET_EPOINTER3DMAXPRESSURE):
   308 			gDigitserHalData.iMaxPressure=(TInt)a1;
   309 			break;
   310 		case (RLddDigitiserTest::EGET_EPOINTER3DPRESSURESTEP):
   311 			r=gDigitserHalData.iPressureStep;
   312 			break;
   313 		case (RLddDigitiserTest::ESET_EPOINTER3DPRESSURESTEP):
   314 			gDigitserHalData.iPressureStep=(TInt)a1;
   315 			break;
   316 		default:
   317 			r=KErrNotSupported;
   318 			break;
   319 		} 
   320 	return r;
   321 	}