kerneltest/e32test/earlyextension/d_testearlyextension.cpp
author Tom Cosgrove <tom.cosgrove@nokia.com>
Fri, 28 May 2010 16:29:07 +0100
changeset 137 8aab599e3476
parent 0 a41df078684a
permissions -rw-r--r--
Fix for bug 2283 (RVCT 4.0 support is missing from PDK 3.0.h) Have multiple extension sections in the bld.inf, one for each version of the compiler. The RVCT version building the tools will build the runtime libraries for its version, but make sure we extract all the other versions from zip archives. Also add the archive for RVCT4.

// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of the License "Eclipse Public License v1.0"
// which accompanies this distribution, and is available
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
//
// Initial Contributors:
// Nokia Corporation - initial contribution.
//
// Contributors:
//
// Description:
// e32test\earlyextension\d_testearlyextension.cpp
// 
//

#include <kernel/kernel.h>
#include "d_testearlyextension.h"
#include "earlyextension.h"

_LIT(KTestEarlyExtName, "D_TESTEARLYEXTENSION.LDD");

/** Factory class */
class DTestEarlyExtLddFactory : public DLogicalDevice
	{
public:
	DTestEarlyExtLddFactory();
	virtual TInt Install();
	virtual void GetCaps(TDes8 &aDes) const;
	virtual TInt Create(DLogicalChannelBase*& aChannel);
	static TTimeK* iTimeArray; //Pointer to store the time stamps.
	};

/** Logical channel */
class DTestEarlyExtension : public DLogicalChannelBase
	{
public:
	DTestEarlyExtension();
	~DTestEarlyExtension();
protected:
	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
	virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
	virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
private:
	DThread* iClient;
	};

TTimeK* DTestEarlyExtLddFactory::iTimeArray = NULL;

/** Factory class */
DTestEarlyExtLddFactory::DTestEarlyExtLddFactory()
	{
    iParseMask=0;
    iUnitsMask=0;
	}

/** Entry point for this driver */
DECLARE_EXTENSION_WITH_PRIORITY(LATE_EXTENSION_PRIORITY)
	{
	// - In extension init1 create and installing ldd factory
	// - Allocating space for 2 array of time stamps
	// - Calling early extension export to get the time stamp stored during its entry point
	// - Taking another time stamp and storing.
	DTestEarlyExtLddFactory* device = new DTestEarlyExtLddFactory;
	if(!device)
		return KErrNoMemory;
	device->iTimeArray = (TTimeK*)new(TTimeK[2]);
	if(!device->iTimeArray)
		{
		Kern::Printf("Memory not allocated");
		delete device;
		return KErrNoMemory;
		}
	TInt r = Kern::InstallLogicalDevice(device);
	if(r == KErrNone)
		{
		TTimeK temp;
		TestEarlyExtension::GetTimeStamp(temp);
		device->iTimeArray[0] = temp;
		device->iTimeArray[1] = Kern::SystemTime();
		}
	return r;
	}

DECLARE_EXTENSION_LDD()
	{
	return new DTestEarlyExtLddFactory;
	}
/** Second stage constuctor */
TInt DTestEarlyExtLddFactory::Install()
	{
    return(SetName(&KTestEarlyExtName));
	}

/** Device capabilities */
void DTestEarlyExtLddFactory::GetCaps(TDes8& aDes)const
	{
	}

/** Create logical channel, only open of one channel is allowed at a time */
TInt DTestEarlyExtLddFactory::Create(DLogicalChannelBase*& aChannel)
	{
    if (iOpenChannels != 0) //A Channel is already open
		return KErrInUse;
    aChannel = new DTestEarlyExtension;
    if(!aChannel)
		return KErrNoMemory;
    return KErrNone;
	}

/** Create channel */
TInt DTestEarlyExtension::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
	{
	return KErrNone;
	}

/** Constructor of Logical channel */
DTestEarlyExtension::DTestEarlyExtension()
	{
	iClient = &Kern::CurrentThread();
	((DObject*)iClient)->Open();;
	}

/** Destructor */
DTestEarlyExtension::~DTestEarlyExtension()
	{
	// Close our reference on the client thread
	Kern::SafeClose((DObject*&)iClient,NULL);
	}

/** Handle user side requests */
TInt DTestEarlyExtension::Request(TInt aReqNo, TAny* a1, TAny* a2)
	{
	switch(aReqNo)
		{
		case (RLddEarlyExtensionTest::EGET_SYSTEM_TIME_STAMPS):
			{ //Get time stamps
			kumemput(a1, &(((DTestEarlyExtLddFactory*)iDevice)->iTimeArray[0]), sizeof(Int64));
			kumemput(a2, &(((DTestEarlyExtLddFactory*)iDevice)->iTimeArray[1]), sizeof(Int64));
			return KErrNone;
			}
		}
	return KErrNotSupported;
	}

/** Restricting handle duplication */
TInt DTestEarlyExtension::RequestUserHandle(DThread* aThread, TOwnerType aType)
	{
	if (aType!=EOwnerThread || aThread!=iClient)
		return KErrAccessDenied;
	return KErrNone;
	}