os/kernelhwsrv/kerneltest/e32test/dll/d_wsdextension.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // e32test\earlyextension\d_testearlyextension.cpp
    15 // 
    16 //
    17 
    18 #include <kernel/kernel.h>
    19 #include "d_wsdextension.h"
    20 
    21 _LIT(KWsdExtName, "D_WSDEXTENSION.LDD");
    22 
    23 /** Factory class */
    24 class DWsdExtLddFactory : public DLogicalDevice
    25 	{
    26 public:
    27 	DWsdExtLddFactory();
    28 	virtual TInt Install();
    29 	virtual void GetCaps(TDes8 &aDes) const;
    30 	virtual TInt Create(DLogicalChannelBase*& aChannel);
    31 	static TInt iData;
    32 	};
    33 
    34 /** Logical channel */
    35 class DWsdExtension : public DLogicalChannelBase
    36 	{
    37 public:
    38 	DWsdExtension();
    39 	~DWsdExtension();
    40 protected:
    41 	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
    42 	virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
    43 	virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
    44 private:
    45 	DThread* iClient;
    46 	};
    47 
    48 TInt DWsdExtLddFactory::iData = 0xEFEFEFEF;
    49 
    50 /** Factory class */
    51 DWsdExtLddFactory::DWsdExtLddFactory()
    52 	{
    53     iParseMask=0;
    54     iUnitsMask=0;
    55 	}
    56 
    57 /** Entry point for this driver */
    58 //DECLARE_EXTENSION_WITH_PRIORITY(LATE_EXTENSION_PRIORITY)
    59 DECLARE_STANDARD_EXTENSION()
    60 	{
    61 	Kern::Printf("D_WSDEXTENSION.LDD Start");
    62 	DWsdExtLddFactory* device = new DWsdExtLddFactory;
    63 	if(!device)
    64 		return KErrNoMemory;
    65 	TInt r = Kern::InstallLogicalDevice(device);
    66 	return r;
    67 	}
    68 
    69 DECLARE_EXTENSION_LDD()
    70 	{
    71 	Kern::Printf("D_WSDEXTENSION.LDD Start 2");
    72 	return new DWsdExtLddFactory;
    73 	}
    74 /** Second stage constuctor */
    75 TInt DWsdExtLddFactory::Install()
    76 	{
    77 	Kern::Printf("D_WSDEXTENSION.LDD Install");
    78     return(SetName(&KWsdExtName));
    79 	}
    80 
    81 /** Device capabilities */
    82 void DWsdExtLddFactory::GetCaps(TDes8& aDes)const
    83 	{
    84 		aDes.FillZ();
    85 	}
    86 
    87 /** Create logical channel, only open of one channel is allowed at a time */
    88 TInt DWsdExtLddFactory::Create(DLogicalChannelBase*& aChannel)
    89 	{
    90     if (iOpenChannels != 0) //A Channel is already open
    91 		return KErrInUse;
    92     aChannel = new DWsdExtension;
    93     if(!aChannel)
    94 		return KErrNoMemory;
    95     return KErrNone;
    96 	}
    97 
    98 /** Create channel */
    99 TInt DWsdExtension::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
   100 	{
   101 	return KErrNone;
   102 	}
   103 
   104 /** Constructor of Logical channel */
   105 DWsdExtension::DWsdExtension()
   106 	{
   107 	iClient = &Kern::CurrentThread();
   108 	((DObject*)iClient)->Open();
   109 	}
   110 
   111 /** Destructor */
   112 DWsdExtension::~DWsdExtension()
   113 	{
   114 	// Close our reference on the client thread
   115 	Kern::SafeClose((DObject*&)iClient,NULL);
   116 	}
   117 
   118 /** Handle user side requests */
   119 TInt DWsdExtension::Request(TInt aReqNo, TAny* a1, TAny*)
   120 	{
   121 	switch(aReqNo)
   122 		{
   123 		case (RLddWsdExtension::EGET_STATIC_DATA):
   124 			{ 
   125 				TInt i=0;
   126 				i=DWsdExtLddFactory::iData;
   127 				kumemput(a1, &DWsdExtLddFactory::iData, sizeof(TInt));
   128 				return KErrNone;
   129 			}
   130 		}
   131 	return KErrNotSupported;
   132 	}
   133 
   134 /** Restricting handle duplication */
   135 TInt DWsdExtension::RequestUserHandle(DThread* aThread, TOwnerType aType)
   136 	{
   137 	if (aType!=EOwnerThread || aThread!=iClient)
   138 		return KErrAccessDenied;
   139 	return KErrNone;
   140 	}
   141 
   142