os/kernelhwsrv/kerneltest/e32test/earlyextension/d_testearlyextension.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\earlyextension\d_testearlyextension.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <kernel/kernel.h>
sl@0
    19
#include "d_testearlyextension.h"
sl@0
    20
#include "earlyextension.h"
sl@0
    21
sl@0
    22
_LIT(KTestEarlyExtName, "D_TESTEARLYEXTENSION.LDD");
sl@0
    23
sl@0
    24
/** Factory class */
sl@0
    25
class DTestEarlyExtLddFactory : public DLogicalDevice
sl@0
    26
	{
sl@0
    27
public:
sl@0
    28
	DTestEarlyExtLddFactory();
sl@0
    29
	virtual TInt Install();
sl@0
    30
	virtual void GetCaps(TDes8 &aDes) const;
sl@0
    31
	virtual TInt Create(DLogicalChannelBase*& aChannel);
sl@0
    32
	static TTimeK* iTimeArray; //Pointer to store the time stamps.
sl@0
    33
	};
sl@0
    34
sl@0
    35
/** Logical channel */
sl@0
    36
class DTestEarlyExtension : public DLogicalChannelBase
sl@0
    37
	{
sl@0
    38
public:
sl@0
    39
	DTestEarlyExtension();
sl@0
    40
	~DTestEarlyExtension();
sl@0
    41
protected:
sl@0
    42
	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
sl@0
    43
	virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
sl@0
    44
	virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
sl@0
    45
private:
sl@0
    46
	DThread* iClient;
sl@0
    47
	};
sl@0
    48
sl@0
    49
TTimeK* DTestEarlyExtLddFactory::iTimeArray = NULL;
sl@0
    50
sl@0
    51
/** Factory class */
sl@0
    52
DTestEarlyExtLddFactory::DTestEarlyExtLddFactory()
sl@0
    53
	{
sl@0
    54
    iParseMask=0;
sl@0
    55
    iUnitsMask=0;
sl@0
    56
	}
sl@0
    57
sl@0
    58
/** Entry point for this driver */
sl@0
    59
DECLARE_EXTENSION_WITH_PRIORITY(LATE_EXTENSION_PRIORITY)
sl@0
    60
	{
sl@0
    61
	// - In extension init1 create and installing ldd factory
sl@0
    62
	// - Allocating space for 2 array of time stamps
sl@0
    63
	// - Calling early extension export to get the time stamp stored during its entry point
sl@0
    64
	// - Taking another time stamp and storing.
sl@0
    65
	DTestEarlyExtLddFactory* device = new DTestEarlyExtLddFactory;
sl@0
    66
	if(!device)
sl@0
    67
		return KErrNoMemory;
sl@0
    68
	device->iTimeArray = (TTimeK*)new(TTimeK[2]);
sl@0
    69
	if(!device->iTimeArray)
sl@0
    70
		{
sl@0
    71
		Kern::Printf("Memory not allocated");
sl@0
    72
		delete device;
sl@0
    73
		return KErrNoMemory;
sl@0
    74
		}
sl@0
    75
	TInt r = Kern::InstallLogicalDevice(device);
sl@0
    76
	if(r == KErrNone)
sl@0
    77
		{
sl@0
    78
		TTimeK temp;
sl@0
    79
		TestEarlyExtension::GetTimeStamp(temp);
sl@0
    80
		device->iTimeArray[0] = temp;
sl@0
    81
		device->iTimeArray[1] = Kern::SystemTime();
sl@0
    82
		}
sl@0
    83
	return r;
sl@0
    84
	}
sl@0
    85
sl@0
    86
DECLARE_EXTENSION_LDD()
sl@0
    87
	{
sl@0
    88
	return new DTestEarlyExtLddFactory;
sl@0
    89
	}
sl@0
    90
/** Second stage constuctor */
sl@0
    91
TInt DTestEarlyExtLddFactory::Install()
sl@0
    92
	{
sl@0
    93
    return(SetName(&KTestEarlyExtName));
sl@0
    94
	}
sl@0
    95
sl@0
    96
/** Device capabilities */
sl@0
    97
void DTestEarlyExtLddFactory::GetCaps(TDes8& aDes)const
sl@0
    98
	{
sl@0
    99
	}
sl@0
   100
sl@0
   101
/** Create logical channel, only open of one channel is allowed at a time */
sl@0
   102
TInt DTestEarlyExtLddFactory::Create(DLogicalChannelBase*& aChannel)
sl@0
   103
	{
sl@0
   104
    if (iOpenChannels != 0) //A Channel is already open
sl@0
   105
		return KErrInUse;
sl@0
   106
    aChannel = new DTestEarlyExtension;
sl@0
   107
    if(!aChannel)
sl@0
   108
		return KErrNoMemory;
sl@0
   109
    return KErrNone;
sl@0
   110
	}
sl@0
   111
sl@0
   112
/** Create channel */
sl@0
   113
TInt DTestEarlyExtension::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
sl@0
   114
	{
sl@0
   115
	return KErrNone;
sl@0
   116
	}
sl@0
   117
sl@0
   118
/** Constructor of Logical channel */
sl@0
   119
DTestEarlyExtension::DTestEarlyExtension()
sl@0
   120
	{
sl@0
   121
	iClient = &Kern::CurrentThread();
sl@0
   122
	((DObject*)iClient)->Open();;
sl@0
   123
	}
sl@0
   124
sl@0
   125
/** Destructor */
sl@0
   126
DTestEarlyExtension::~DTestEarlyExtension()
sl@0
   127
	{
sl@0
   128
	// Close our reference on the client thread
sl@0
   129
	Kern::SafeClose((DObject*&)iClient,NULL);
sl@0
   130
	}
sl@0
   131
sl@0
   132
/** Handle user side requests */
sl@0
   133
TInt DTestEarlyExtension::Request(TInt aReqNo, TAny* a1, TAny* a2)
sl@0
   134
	{
sl@0
   135
	switch(aReqNo)
sl@0
   136
		{
sl@0
   137
		case (RLddEarlyExtensionTest::EGET_SYSTEM_TIME_STAMPS):
sl@0
   138
			{ //Get time stamps
sl@0
   139
			kumemput(a1, &(((DTestEarlyExtLddFactory*)iDevice)->iTimeArray[0]), sizeof(Int64));
sl@0
   140
			kumemput(a2, &(((DTestEarlyExtLddFactory*)iDevice)->iTimeArray[1]), sizeof(Int64));
sl@0
   141
			return KErrNone;
sl@0
   142
			}
sl@0
   143
		}
sl@0
   144
	return KErrNotSupported;
sl@0
   145
	}
sl@0
   146
sl@0
   147
/** Restricting handle duplication */
sl@0
   148
TInt DTestEarlyExtension::RequestUserHandle(DThread* aThread, TOwnerType aType)
sl@0
   149
	{
sl@0
   150
	if (aType!=EOwnerThread || aThread!=iClient)
sl@0
   151
		return KErrAccessDenied;
sl@0
   152
	return KErrNone;
sl@0
   153
	}
sl@0
   154
sl@0
   155