1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/t_halattprovider/t_halattprovider.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,157 @@
1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// t_halattprovider.ldd Provides fake HAL attribute values on H4 platform for
1.18 +// advanced pointer event testing.
1.19 +// Fake values are listed in halFunction(TAny* aPtr, TInt aFunction, TAny* a1, TAny* a2).
1.20 +// Only some values from the group EHalGroupDigitiser are changed.
1.21 +// For not changed values from the group EHalGroupDigitiser the original HAL handler is called
1.22 +// (the one loaded before this kernel extension).
1.23 +// Original handler of EHalGroupDigitiser group must be registered in order
1.24 +// to run this kernel extension.
1.25 +//
1.26 +//
1.27 +
1.28 +/**
1.29 + @file
1.30 + @test
1.31 + @internalComponent - Internal Symbian test code
1.32 +*/
1.33 +
1.34 +#include <kernel/kernel.h>
1.35 +#include <e32cmn.h>
1.36 +
1.37 +static SHalEntry gOriginalHandler;
1.38 +static TUint8 gNumberOfPointers;
1.39 +
1.40 +void InitialiseDigitiserHalData()
1.41 + {
1.42 + gNumberOfPointers = 6;
1.43 + }
1.44 +
1.45 +LOCAL_C TInt halFunction(TAny* aPtr, TInt aFunction, TAny* a1, TAny* a2)
1.46 + {
1.47 + TInt r=KErrNone;
1.48 + THalFunc function = gOriginalHandler.iFunction;
1.49 + switch(aFunction)
1.50 + {
1.51 + case EDigitiserHal3DInfo:
1.52 + {
1.53 + // execute the original handler
1.54 + r = (*function)(aPtr, EDigitiserHal3DInfo, a1, a2);
1.55 + TBool receivedFullData = (r == KErrNone);
1.56 + if (r != KErrNone)
1.57 + {
1.58 + // try to get at least TDigitiserInfoV01
1.59 + r = (*function)(aPtr, EDigitiserHalXYInfo, a1, a2);
1.60 + if (r != KErrNone)
1.61 + {
1.62 + Kern::Printf("t_halattprovider error: original handler of EDigitiserHalXYInfo returned %d", r);
1.63 + return r;
1.64 + }
1.65 + }
1.66 +
1.67 + // read data created by the original handler
1.68 + TPckgBuf<TDigitiserInfoV02> vPckg;
1.69 + TDigitiserInfoV02& data = vPckg();
1.70 +
1.71 + Kern::KUDesGet(vPckg, *(TDes8*)a1);
1.72 +
1.73 + // modify the data with the new values
1.74 + vPckg.SetLength(sizeof(TDigitiserInfoV02));
1.75 + data.iPressureSupported=1;
1.76 + data.iZRange=-100; // max proximity
1.77 + data.iProximityStep=5;
1.78 + data.iMaxPointers=8;
1.79 + data.iNumberOfPointers=gNumberOfPointers;
1.80 + data.iMaxPressure=5000;
1.81 + data.iPressureStep=500;
1.82 +
1.83 + if (!receivedFullData)
1.84 + {
1.85 + // original handler has provided only TDigitiserInfoV01, so we have to
1.86 + // fill all fields of TDigitiserInfoV02
1.87 + data.iThetaSupported=0;
1.88 + data.iPhiSupported=0;
1.89 + data.iAlphaSupported=0;
1.90 + }
1.91 +
1.92 + // return the data
1.93 + Kern::InfoCopy(*(TDes8*)a1, vPckg);
1.94 +
1.95 + break;
1.96 + }
1.97 + case EDigitiserHal3DPointer:
1.98 + {
1.99 + // Return value 1 for EPointer3D
1.100 + TBool ret = ETrue;
1.101 + kumemput32(a1,&ret,sizeof(ret));
1.102 + break;
1.103 + }
1.104 + case EDigitiserHalSetNumberOfPointers:
1.105 + // Set request for EPointerNumberOfPointers
1.106 +
1.107 + // this line should be a correct implementation of this function but was not tested
1.108 + //kumemget32(&gNumberOfPointers,a1,sizeof(gNumberOfPointers));
1.109 + Kern::Printf("t_halattprovider error: attempt to use not implemented HAL function EDigitiserHalSetNumberOfPointers");
1.110 + r = KErrNotSupported;
1.111 + break;
1.112 + default:
1.113 + r = (*function)(aPtr, aFunction, a1, a2);
1.114 + break;
1.115 + }
1.116 + return r;
1.117 + }
1.118 +
1.119 +DECLARE_STANDARD_EXTENSION()
1.120 + {
1.121 + TInt r = KErrNone;
1.122 +
1.123 + // Initialise Digitiser HAL Data first.
1.124 + InitialiseDigitiserHalData();
1.125 +
1.126 + NKern::ThreadEnterCS();
1.127 +
1.128 + // Find original handler whose behaviour will be overriden
1.129 + SHalEntry* originalHandlerPtr = Kern::FindHalEntry(EHalGroupDigitiser,0);
1.130 + if (originalHandlerPtr == NULL)
1.131 + {
1.132 + NKern::ThreadLeaveCS();
1.133 + Kern::Printf("t_halattprovider error: original handler of EHalGroupDigitiser group not found");
1.134 + return KErrNotFound;
1.135 + }
1.136 + gOriginalHandler = *originalHandlerPtr; // copy contents of the SHalEntry
1.137 +
1.138 + // Remove original handler
1.139 + r = Kern::RemoveHalEntry(EHalGroupDigitiser, 0);
1.140 + if (r != KErrNone)
1.141 + {
1.142 + NKern::ThreadLeaveCS();
1.143 + Kern::Printf("t_halattprovider error: unable to unregister original handler for EHalGroupDigitiser group, code:%d",r);
1.144 + return r;
1.145 + }
1.146 +
1.147 + // Add new handler
1.148 + r=Kern::AddHalEntry(EHalGroupDigitiser,halFunction,gOriginalHandler.iPtr,0);
1.149 + if (r != KErrNone)
1.150 + {
1.151 + NKern::ThreadLeaveCS();
1.152 + Kern::Printf("t_halattprovider error: unable register handler for EHalGroupDigitiser group, code:%d",r);
1.153 + return r;
1.154 + }
1.155 +
1.156 + NKern::ThreadLeaveCS();
1.157 +
1.158 + Kern::Printf("t_halattprovider: registered successfully");
1.159 + return r;
1.160 + }