Update contrib.
     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".
 
     8 // Initial Contributors:
 
     9 // Nokia Corporation - initial contribution.
 
    14 // e32test\earlyextension\d_testearlyextension.cpp
 
    18 #include <kernel/kernel.h>
 
    19 #include "d_testearlyextension.h"
 
    20 #include "earlyextension.h"
 
    22 _LIT(KTestEarlyExtName, "D_TESTEARLYEXTENSION.LDD");
 
    25 class DTestEarlyExtLddFactory : public DLogicalDevice
 
    28 	DTestEarlyExtLddFactory();
 
    29 	virtual TInt Install();
 
    30 	virtual void GetCaps(TDes8 &aDes) const;
 
    31 	virtual TInt Create(DLogicalChannelBase*& aChannel);
 
    32 	static TTimeK* iTimeArray; //Pointer to store the time stamps.
 
    35 /** Logical channel */
 
    36 class DTestEarlyExtension : public DLogicalChannelBase
 
    39 	DTestEarlyExtension();
 
    40 	~DTestEarlyExtension();
 
    42 	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
 
    43 	virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
 
    44 	virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
 
    49 TTimeK* DTestEarlyExtLddFactory::iTimeArray = NULL;
 
    52 DTestEarlyExtLddFactory::DTestEarlyExtLddFactory()
 
    58 /** Entry point for this driver */
 
    59 DECLARE_EXTENSION_WITH_PRIORITY(LATE_EXTENSION_PRIORITY)
 
    61 	// - In extension init1 create and installing ldd factory
 
    62 	// - Allocating space for 2 array of time stamps
 
    63 	// - Calling early extension export to get the time stamp stored during its entry point
 
    64 	// - Taking another time stamp and storing.
 
    65 	DTestEarlyExtLddFactory* device = new DTestEarlyExtLddFactory;
 
    68 	device->iTimeArray = (TTimeK*)new(TTimeK[2]);
 
    69 	if(!device->iTimeArray)
 
    71 		Kern::Printf("Memory not allocated");
 
    75 	TInt r = Kern::InstallLogicalDevice(device);
 
    79 		TestEarlyExtension::GetTimeStamp(temp);
 
    80 		device->iTimeArray[0] = temp;
 
    81 		device->iTimeArray[1] = Kern::SystemTime();
 
    86 DECLARE_EXTENSION_LDD()
 
    88 	return new DTestEarlyExtLddFactory;
 
    90 /** Second stage constuctor */
 
    91 TInt DTestEarlyExtLddFactory::Install()
 
    93     return(SetName(&KTestEarlyExtName));
 
    96 /** Device capabilities */
 
    97 void DTestEarlyExtLddFactory::GetCaps(TDes8& aDes)const
 
   101 /** Create logical channel, only open of one channel is allowed at a time */
 
   102 TInt DTestEarlyExtLddFactory::Create(DLogicalChannelBase*& aChannel)
 
   104     if (iOpenChannels != 0) //A Channel is already open
 
   106     aChannel = new DTestEarlyExtension;
 
   112 /** Create channel */
 
   113 TInt DTestEarlyExtension::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
 
   118 /** Constructor of Logical channel */
 
   119 DTestEarlyExtension::DTestEarlyExtension()
 
   121 	iClient = &Kern::CurrentThread();
 
   122 	((DObject*)iClient)->Open();;
 
   126 DTestEarlyExtension::~DTestEarlyExtension()
 
   128 	// Close our reference on the client thread
 
   129 	Kern::SafeClose((DObject*&)iClient,NULL);
 
   132 /** Handle user side requests */
 
   133 TInt DTestEarlyExtension::Request(TInt aReqNo, TAny* a1, TAny* a2)
 
   137 		case (RLddEarlyExtensionTest::EGET_SYSTEM_TIME_STAMPS):
 
   139 			kumemput(a1, &(((DTestEarlyExtLddFactory*)iDevice)->iTimeArray[0]), sizeof(Int64));
 
   140 			kumemput(a2, &(((DTestEarlyExtLddFactory*)iDevice)->iTimeArray[1]), sizeof(Int64));
 
   144 	return KErrNotSupported;
 
   147 /** Restricting handle duplication */
 
   148 TInt DTestEarlyExtension::RequestUserHandle(DThread* aThread, TOwnerType aType)
 
   150 	if (aType!=EOwnerThread || aThread!=iClient)
 
   151 		return KErrAccessDenied;