1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/earlyextension/d_testearlyextension.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,155 @@
1.4 +// Copyright (c) 2007-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 the License "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 +// e32test\earlyextension\d_testearlyextension.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <kernel/kernel.h>
1.22 +#include "d_testearlyextension.h"
1.23 +#include "earlyextension.h"
1.24 +
1.25 +_LIT(KTestEarlyExtName, "D_TESTEARLYEXTENSION.LDD");
1.26 +
1.27 +/** Factory class */
1.28 +class DTestEarlyExtLddFactory : public DLogicalDevice
1.29 + {
1.30 +public:
1.31 + DTestEarlyExtLddFactory();
1.32 + virtual TInt Install();
1.33 + virtual void GetCaps(TDes8 &aDes) const;
1.34 + virtual TInt Create(DLogicalChannelBase*& aChannel);
1.35 + static TTimeK* iTimeArray; //Pointer to store the time stamps.
1.36 + };
1.37 +
1.38 +/** Logical channel */
1.39 +class DTestEarlyExtension : public DLogicalChannelBase
1.40 + {
1.41 +public:
1.42 + DTestEarlyExtension();
1.43 + ~DTestEarlyExtension();
1.44 +protected:
1.45 + virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
1.46 + virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
1.47 + virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
1.48 +private:
1.49 + DThread* iClient;
1.50 + };
1.51 +
1.52 +TTimeK* DTestEarlyExtLddFactory::iTimeArray = NULL;
1.53 +
1.54 +/** Factory class */
1.55 +DTestEarlyExtLddFactory::DTestEarlyExtLddFactory()
1.56 + {
1.57 + iParseMask=0;
1.58 + iUnitsMask=0;
1.59 + }
1.60 +
1.61 +/** Entry point for this driver */
1.62 +DECLARE_EXTENSION_WITH_PRIORITY(LATE_EXTENSION_PRIORITY)
1.63 + {
1.64 + // - In extension init1 create and installing ldd factory
1.65 + // - Allocating space for 2 array of time stamps
1.66 + // - Calling early extension export to get the time stamp stored during its entry point
1.67 + // - Taking another time stamp and storing.
1.68 + DTestEarlyExtLddFactory* device = new DTestEarlyExtLddFactory;
1.69 + if(!device)
1.70 + return KErrNoMemory;
1.71 + device->iTimeArray = (TTimeK*)new(TTimeK[2]);
1.72 + if(!device->iTimeArray)
1.73 + {
1.74 + Kern::Printf("Memory not allocated");
1.75 + delete device;
1.76 + return KErrNoMemory;
1.77 + }
1.78 + TInt r = Kern::InstallLogicalDevice(device);
1.79 + if(r == KErrNone)
1.80 + {
1.81 + TTimeK temp;
1.82 + TestEarlyExtension::GetTimeStamp(temp);
1.83 + device->iTimeArray[0] = temp;
1.84 + device->iTimeArray[1] = Kern::SystemTime();
1.85 + }
1.86 + return r;
1.87 + }
1.88 +
1.89 +DECLARE_EXTENSION_LDD()
1.90 + {
1.91 + return new DTestEarlyExtLddFactory;
1.92 + }
1.93 +/** Second stage constuctor */
1.94 +TInt DTestEarlyExtLddFactory::Install()
1.95 + {
1.96 + return(SetName(&KTestEarlyExtName));
1.97 + }
1.98 +
1.99 +/** Device capabilities */
1.100 +void DTestEarlyExtLddFactory::GetCaps(TDes8& aDes)const
1.101 + {
1.102 + }
1.103 +
1.104 +/** Create logical channel, only open of one channel is allowed at a time */
1.105 +TInt DTestEarlyExtLddFactory::Create(DLogicalChannelBase*& aChannel)
1.106 + {
1.107 + if (iOpenChannels != 0) //A Channel is already open
1.108 + return KErrInUse;
1.109 + aChannel = new DTestEarlyExtension;
1.110 + if(!aChannel)
1.111 + return KErrNoMemory;
1.112 + return KErrNone;
1.113 + }
1.114 +
1.115 +/** Create channel */
1.116 +TInt DTestEarlyExtension::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
1.117 + {
1.118 + return KErrNone;
1.119 + }
1.120 +
1.121 +/** Constructor of Logical channel */
1.122 +DTestEarlyExtension::DTestEarlyExtension()
1.123 + {
1.124 + iClient = &Kern::CurrentThread();
1.125 + ((DObject*)iClient)->Open();;
1.126 + }
1.127 +
1.128 +/** Destructor */
1.129 +DTestEarlyExtension::~DTestEarlyExtension()
1.130 + {
1.131 + // Close our reference on the client thread
1.132 + Kern::SafeClose((DObject*&)iClient,NULL);
1.133 + }
1.134 +
1.135 +/** Handle user side requests */
1.136 +TInt DTestEarlyExtension::Request(TInt aReqNo, TAny* a1, TAny* a2)
1.137 + {
1.138 + switch(aReqNo)
1.139 + {
1.140 + case (RLddEarlyExtensionTest::EGET_SYSTEM_TIME_STAMPS):
1.141 + { //Get time stamps
1.142 + kumemput(a1, &(((DTestEarlyExtLddFactory*)iDevice)->iTimeArray[0]), sizeof(Int64));
1.143 + kumemput(a2, &(((DTestEarlyExtLddFactory*)iDevice)->iTimeArray[1]), sizeof(Int64));
1.144 + return KErrNone;
1.145 + }
1.146 + }
1.147 + return KErrNotSupported;
1.148 + }
1.149 +
1.150 +/** Restricting handle duplication */
1.151 +TInt DTestEarlyExtension::RequestUserHandle(DThread* aThread, TOwnerType aType)
1.152 + {
1.153 + if (aType!=EOwnerThread || aThread!=iClient)
1.154 + return KErrAccessDenied;
1.155 + return KErrNone;
1.156 + }
1.157 +
1.158 +