os/kernelhwsrv/kerneltest/e32test/dll/d_wsdextension.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_wsdextension.h"
sl@0
    20
sl@0
    21
_LIT(KWsdExtName, "D_WSDEXTENSION.LDD");
sl@0
    22
sl@0
    23
/** Factory class */
sl@0
    24
class DWsdExtLddFactory : public DLogicalDevice
sl@0
    25
	{
sl@0
    26
public:
sl@0
    27
	DWsdExtLddFactory();
sl@0
    28
	virtual TInt Install();
sl@0
    29
	virtual void GetCaps(TDes8 &aDes) const;
sl@0
    30
	virtual TInt Create(DLogicalChannelBase*& aChannel);
sl@0
    31
	static TInt iData;
sl@0
    32
	};
sl@0
    33
sl@0
    34
/** Logical channel */
sl@0
    35
class DWsdExtension : public DLogicalChannelBase
sl@0
    36
	{
sl@0
    37
public:
sl@0
    38
	DWsdExtension();
sl@0
    39
	~DWsdExtension();
sl@0
    40
protected:
sl@0
    41
	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
sl@0
    42
	virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
sl@0
    43
	virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
sl@0
    44
private:
sl@0
    45
	DThread* iClient;
sl@0
    46
	};
sl@0
    47
sl@0
    48
TInt DWsdExtLddFactory::iData = 0xEFEFEFEF;
sl@0
    49
sl@0
    50
/** Factory class */
sl@0
    51
DWsdExtLddFactory::DWsdExtLddFactory()
sl@0
    52
	{
sl@0
    53
    iParseMask=0;
sl@0
    54
    iUnitsMask=0;
sl@0
    55
	}
sl@0
    56
sl@0
    57
/** Entry point for this driver */
sl@0
    58
//DECLARE_EXTENSION_WITH_PRIORITY(LATE_EXTENSION_PRIORITY)
sl@0
    59
DECLARE_STANDARD_EXTENSION()
sl@0
    60
	{
sl@0
    61
	Kern::Printf("D_WSDEXTENSION.LDD Start");
sl@0
    62
	DWsdExtLddFactory* device = new DWsdExtLddFactory;
sl@0
    63
	if(!device)
sl@0
    64
		return KErrNoMemory;
sl@0
    65
	TInt r = Kern::InstallLogicalDevice(device);
sl@0
    66
	return r;
sl@0
    67
	}
sl@0
    68
sl@0
    69
DECLARE_EXTENSION_LDD()
sl@0
    70
	{
sl@0
    71
	Kern::Printf("D_WSDEXTENSION.LDD Start 2");
sl@0
    72
	return new DWsdExtLddFactory;
sl@0
    73
	}
sl@0
    74
/** Second stage constuctor */
sl@0
    75
TInt DWsdExtLddFactory::Install()
sl@0
    76
	{
sl@0
    77
	Kern::Printf("D_WSDEXTENSION.LDD Install");
sl@0
    78
    return(SetName(&KWsdExtName));
sl@0
    79
	}
sl@0
    80
sl@0
    81
/** Device capabilities */
sl@0
    82
void DWsdExtLddFactory::GetCaps(TDes8& aDes)const
sl@0
    83
	{
sl@0
    84
		aDes.FillZ();
sl@0
    85
	}
sl@0
    86
sl@0
    87
/** Create logical channel, only open of one channel is allowed at a time */
sl@0
    88
TInt DWsdExtLddFactory::Create(DLogicalChannelBase*& aChannel)
sl@0
    89
	{
sl@0
    90
    if (iOpenChannels != 0) //A Channel is already open
sl@0
    91
		return KErrInUse;
sl@0
    92
    aChannel = new DWsdExtension;
sl@0
    93
    if(!aChannel)
sl@0
    94
		return KErrNoMemory;
sl@0
    95
    return KErrNone;
sl@0
    96
	}
sl@0
    97
sl@0
    98
/** Create channel */
sl@0
    99
TInt DWsdExtension::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
sl@0
   100
	{
sl@0
   101
	return KErrNone;
sl@0
   102
	}
sl@0
   103
sl@0
   104
/** Constructor of Logical channel */
sl@0
   105
DWsdExtension::DWsdExtension()
sl@0
   106
	{
sl@0
   107
	iClient = &Kern::CurrentThread();
sl@0
   108
	((DObject*)iClient)->Open();
sl@0
   109
	}
sl@0
   110
sl@0
   111
/** Destructor */
sl@0
   112
DWsdExtension::~DWsdExtension()
sl@0
   113
	{
sl@0
   114
	// Close our reference on the client thread
sl@0
   115
	Kern::SafeClose((DObject*&)iClient,NULL);
sl@0
   116
	}
sl@0
   117
sl@0
   118
/** Handle user side requests */
sl@0
   119
TInt DWsdExtension::Request(TInt aReqNo, TAny* a1, TAny*)
sl@0
   120
	{
sl@0
   121
	switch(aReqNo)
sl@0
   122
		{
sl@0
   123
		case (RLddWsdExtension::EGET_STATIC_DATA):
sl@0
   124
			{ 
sl@0
   125
				TInt i=0;
sl@0
   126
				i=DWsdExtLddFactory::iData;
sl@0
   127
				kumemput(a1, &DWsdExtLddFactory::iData, sizeof(TInt));
sl@0
   128
				return KErrNone;
sl@0
   129
			}
sl@0
   130
		}
sl@0
   131
	return KErrNotSupported;
sl@0
   132
	}
sl@0
   133
sl@0
   134
/** Restricting handle duplication */
sl@0
   135
TInt DWsdExtension::RequestUserHandle(DThread* aThread, TOwnerType aType)
sl@0
   136
	{
sl@0
   137
	if (aType!=EOwnerThread || aThread!=iClient)
sl@0
   138
		return KErrAccessDenied;
sl@0
   139
	return KErrNone;
sl@0
   140
	}
sl@0
   141
sl@0
   142