windowing/windowserver/test/t_halattprovider/t_halattprovider.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     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 "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 // t_halattprovider.ldd Provides fake HAL attribute values on H4 platform for
       
    15 // advanced pointer event testing.
       
    16 // Fake values are listed in halFunction(TAny* aPtr, TInt aFunction, TAny* a1, TAny* a2).
       
    17 // Only some values from the group EHalGroupDigitiser are changed.
       
    18 // For not changed values from the group EHalGroupDigitiser the original HAL handler is called
       
    19 // (the one loaded before this kernel extension).
       
    20 // Original handler of EHalGroupDigitiser group must be registered in order
       
    21 // to run this kernel extension.
       
    22 // 
       
    23 //
       
    24 
       
    25 /**
       
    26  @file
       
    27  @test
       
    28  @internalComponent - Internal Symbian test code
       
    29 */
       
    30 
       
    31 #include <kernel/kernel.h>
       
    32 #include <e32cmn.h>
       
    33 
       
    34 static SHalEntry gOriginalHandler;
       
    35 static TUint8 gNumberOfPointers;
       
    36 
       
    37 void InitialiseDigitiserHalData()
       
    38 	{
       
    39 	gNumberOfPointers = 6;
       
    40 	}
       
    41 
       
    42 LOCAL_C TInt halFunction(TAny* aPtr, TInt aFunction, TAny* a1, TAny* a2)
       
    43 	{
       
    44 	TInt r=KErrNone;
       
    45 	THalFunc function = gOriginalHandler.iFunction;
       
    46 	switch(aFunction)
       
    47 		{
       
    48 		case EDigitiserHal3DInfo:
       
    49 			{
       
    50 			// execute the original handler
       
    51 			r = (*function)(aPtr, EDigitiserHal3DInfo, a1, a2);
       
    52 			TBool receivedFullData = (r == KErrNone);
       
    53 			if (r != KErrNone)
       
    54 				{
       
    55 				// try to get at least TDigitiserInfoV01
       
    56 				r = (*function)(aPtr, EDigitiserHalXYInfo, a1, a2);
       
    57 				if (r != KErrNone)
       
    58 					{
       
    59 					Kern::Printf("t_halattprovider error: original handler of EDigitiserHalXYInfo returned %d", r);
       
    60 					return r;
       
    61 					}
       
    62 				}
       
    63 			
       
    64 			// read data created by the original handler
       
    65 			TPckgBuf<TDigitiserInfoV02> vPckg;
       
    66 			TDigitiserInfoV02& data = vPckg();
       
    67 			
       
    68 			Kern::KUDesGet(vPckg, *(TDes8*)a1);
       
    69 			
       
    70 			// modify the data with the new values
       
    71 			vPckg.SetLength(sizeof(TDigitiserInfoV02));
       
    72 			data.iPressureSupported=1;
       
    73 			data.iZRange=-100; // max proximity
       
    74 			data.iProximityStep=5;
       
    75 			data.iMaxPointers=8;
       
    76 			data.iNumberOfPointers=gNumberOfPointers;
       
    77 			data.iMaxPressure=5000;
       
    78 			data.iPressureStep=500;
       
    79 			
       
    80 			if (!receivedFullData)
       
    81 				{
       
    82 				// original handler has provided only TDigitiserInfoV01, so we have to
       
    83 				// fill all fields of TDigitiserInfoV02
       
    84 				data.iThetaSupported=0;
       
    85 				data.iPhiSupported=0;
       
    86 				data.iAlphaSupported=0;
       
    87 				}
       
    88 			
       
    89 			// return the data
       
    90 			Kern::InfoCopy(*(TDes8*)a1, vPckg);
       
    91 			
       
    92 			break;
       
    93 			}
       
    94 		case EDigitiserHal3DPointer:
       
    95 			{
       
    96 			// Return value 1 for EPointer3D
       
    97 			TBool ret = ETrue; 
       
    98 			kumemput32(a1,&ret,sizeof(ret));
       
    99 			break;
       
   100 			}
       
   101 		case EDigitiserHalSetNumberOfPointers:
       
   102 			// Set request for EPointerNumberOfPointers
       
   103 			
       
   104 			// this line should be a correct implementation of this function but was not tested
       
   105 			//kumemget32(&gNumberOfPointers,a1,sizeof(gNumberOfPointers));
       
   106 			Kern::Printf("t_halattprovider error: attempt to use not implemented HAL function EDigitiserHalSetNumberOfPointers");
       
   107 			r = KErrNotSupported;
       
   108 			break;
       
   109 		default:
       
   110 			r = (*function)(aPtr, aFunction, a1, a2);
       
   111 			break;
       
   112 		}
       
   113 	return r;
       
   114 	}
       
   115 
       
   116 DECLARE_STANDARD_EXTENSION()
       
   117 	{
       
   118 	TInt r = KErrNone;
       
   119 	
       
   120 	// Initialise Digitiser HAL Data first.
       
   121 	InitialiseDigitiserHalData();
       
   122 	
       
   123 	NKern::ThreadEnterCS();
       
   124 	
       
   125 	// Find original handler whose behaviour will be overriden
       
   126 	SHalEntry* originalHandlerPtr = Kern::FindHalEntry(EHalGroupDigitiser,0);
       
   127 	if (originalHandlerPtr == NULL)
       
   128 		{
       
   129 		NKern::ThreadLeaveCS();
       
   130 		Kern::Printf("t_halattprovider error: original handler of EHalGroupDigitiser group not found");
       
   131 		return KErrNotFound;
       
   132 		}
       
   133 	gOriginalHandler = *originalHandlerPtr; // copy contents of the SHalEntry
       
   134 	
       
   135 	// Remove original handler
       
   136 	r = Kern::RemoveHalEntry(EHalGroupDigitiser, 0);
       
   137 	if (r != KErrNone)
       
   138 		{
       
   139 		NKern::ThreadLeaveCS();
       
   140 		Kern::Printf("t_halattprovider error: unable to unregister original handler for EHalGroupDigitiser group, code:%d",r);
       
   141 		return r;
       
   142 		}
       
   143 	
       
   144 	// Add new handler
       
   145 	r=Kern::AddHalEntry(EHalGroupDigitiser,halFunction,gOriginalHandler.iPtr,0);
       
   146 	if (r != KErrNone)
       
   147 		{
       
   148 		NKern::ThreadLeaveCS();
       
   149 		Kern::Printf("t_halattprovider error: unable register handler for EHalGroupDigitiser group, code:%d",r);
       
   150 		return r;
       
   151 		}
       
   152 
       
   153 	NKern::ThreadLeaveCS();
       
   154 	
       
   155 	Kern::Printf("t_halattprovider: registered successfully");
       
   156 	return r;
       
   157 	}