sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\earlyextension\d_testearlyextension.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include "d_testearlyextension.h" sl@0: #include "earlyextension.h" sl@0: sl@0: _LIT(KTestEarlyExtName, "D_TESTEARLYEXTENSION.LDD"); sl@0: sl@0: /** Factory class */ sl@0: class DTestEarlyExtLddFactory : public DLogicalDevice sl@0: { sl@0: public: sl@0: DTestEarlyExtLddFactory(); sl@0: virtual TInt Install(); sl@0: virtual void GetCaps(TDes8 &aDes) const; sl@0: virtual TInt Create(DLogicalChannelBase*& aChannel); sl@0: static TTimeK* iTimeArray; //Pointer to store the time stamps. sl@0: }; sl@0: sl@0: /** Logical channel */ sl@0: class DTestEarlyExtension : public DLogicalChannelBase sl@0: { sl@0: public: sl@0: DTestEarlyExtension(); sl@0: ~DTestEarlyExtension(); sl@0: protected: sl@0: virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); sl@0: virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2); sl@0: virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType); sl@0: private: sl@0: DThread* iClient; sl@0: }; sl@0: sl@0: TTimeK* DTestEarlyExtLddFactory::iTimeArray = NULL; sl@0: sl@0: /** Factory class */ sl@0: DTestEarlyExtLddFactory::DTestEarlyExtLddFactory() sl@0: { sl@0: iParseMask=0; sl@0: iUnitsMask=0; sl@0: } sl@0: sl@0: /** Entry point for this driver */ sl@0: DECLARE_EXTENSION_WITH_PRIORITY(LATE_EXTENSION_PRIORITY) sl@0: { sl@0: // - In extension init1 create and installing ldd factory sl@0: // - Allocating space for 2 array of time stamps sl@0: // - Calling early extension export to get the time stamp stored during its entry point sl@0: // - Taking another time stamp and storing. sl@0: DTestEarlyExtLddFactory* device = new DTestEarlyExtLddFactory; sl@0: if(!device) sl@0: return KErrNoMemory; sl@0: device->iTimeArray = (TTimeK*)new(TTimeK[2]); sl@0: if(!device->iTimeArray) sl@0: { sl@0: Kern::Printf("Memory not allocated"); sl@0: delete device; sl@0: return KErrNoMemory; sl@0: } sl@0: TInt r = Kern::InstallLogicalDevice(device); sl@0: if(r == KErrNone) sl@0: { sl@0: TTimeK temp; sl@0: TestEarlyExtension::GetTimeStamp(temp); sl@0: device->iTimeArray[0] = temp; sl@0: device->iTimeArray[1] = Kern::SystemTime(); sl@0: } sl@0: return r; sl@0: } sl@0: sl@0: DECLARE_EXTENSION_LDD() sl@0: { sl@0: return new DTestEarlyExtLddFactory; sl@0: } sl@0: /** Second stage constuctor */ sl@0: TInt DTestEarlyExtLddFactory::Install() sl@0: { sl@0: return(SetName(&KTestEarlyExtName)); sl@0: } sl@0: sl@0: /** Device capabilities */ sl@0: void DTestEarlyExtLddFactory::GetCaps(TDes8& aDes)const sl@0: { sl@0: } sl@0: sl@0: /** Create logical channel, only open of one channel is allowed at a time */ sl@0: TInt DTestEarlyExtLddFactory::Create(DLogicalChannelBase*& aChannel) sl@0: { sl@0: if (iOpenChannels != 0) //A Channel is already open sl@0: return KErrInUse; sl@0: aChannel = new DTestEarlyExtension; sl@0: if(!aChannel) sl@0: return KErrNoMemory; sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** Create channel */ sl@0: TInt DTestEarlyExtension::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** Constructor of Logical channel */ sl@0: DTestEarlyExtension::DTestEarlyExtension() sl@0: { sl@0: iClient = &Kern::CurrentThread(); sl@0: ((DObject*)iClient)->Open();; sl@0: } sl@0: sl@0: /** Destructor */ sl@0: DTestEarlyExtension::~DTestEarlyExtension() sl@0: { sl@0: // Close our reference on the client thread sl@0: Kern::SafeClose((DObject*&)iClient,NULL); sl@0: } sl@0: sl@0: /** Handle user side requests */ sl@0: TInt DTestEarlyExtension::Request(TInt aReqNo, TAny* a1, TAny* a2) sl@0: { sl@0: switch(aReqNo) sl@0: { sl@0: case (RLddEarlyExtensionTest::EGET_SYSTEM_TIME_STAMPS): sl@0: { //Get time stamps sl@0: kumemput(a1, &(((DTestEarlyExtLddFactory*)iDevice)->iTimeArray[0]), sizeof(Int64)); sl@0: kumemput(a2, &(((DTestEarlyExtLddFactory*)iDevice)->iTimeArray[1]), sizeof(Int64)); sl@0: return KErrNone; sl@0: } sl@0: } sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: /** Restricting handle duplication */ sl@0: TInt DTestEarlyExtension::RequestUserHandle(DThread* aThread, TOwnerType aType) sl@0: { sl@0: if (aType!=EOwnerThread || aThread!=iClient) sl@0: return KErrAccessDenied; sl@0: return KErrNone; sl@0: } sl@0: sl@0: