Update contrib.
1 // Copyright (c) 1997-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\system\d_nanowait.cpp
15 // LDD for testing nanosecond blocking
19 #include "plat_priv.h"
20 #include "d_nanowait.h"
22 const TInt KMajorVersionNumber=0;
23 const TInt KMinorVersionNumber=1;
24 const TInt KBuildVersionNumber=1;
28 TDynamicDfcQue* gDfcQ;
31 class DNanoWaitFactory : public DLogicalDevice
33 // NanoWait LDD factory
39 virtual TInt Install(); //overriding pure virtual
40 virtual void GetCaps(TDes8& aDes) const; //overriding pure virtual
41 virtual TInt Create(DLogicalChannelBase*& aChannel); //overriding pure virtual
44 class DNanoWait : public DLogicalChannel
46 // nanowait LDD channel
53 virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
54 TInt DoControl(TInt aFunction, TAny* a1, TAny* a2);
55 virtual void HandleMsg(TMessageBase* aMsg);
57 inline DThread* Client() { return iThread; }
60 TDynamicDfcQue* iDfcQ;
65 DECLARE_STANDARD_LDD()
67 return new DNanoWaitFactory;
70 DNanoWaitFactory::DNanoWaitFactory()
75 iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
76 //iParseMask=0;//No units, no info, no PDD
77 //iUnitsMask=0;//Only one thing
80 TInt DNanoWaitFactory::Create(DLogicalChannelBase*& aChannel)
82 // Create a new DMsTim on this logical device
85 aChannel=new DNanoWait;
86 return aChannel?KErrNone:KErrNoMemory;
89 const TInt KDNanoWaitThreadPriority = 27;
90 _LIT(KDNanoWaitThread,"DNanoWaitThread");
92 TInt DNanoWaitFactory::Install()
94 // Install the LDD - overriding pure virtual
97 // Allocate a kernel thread to run the DFC
98 TInt r = Kern::DynamicDfcQCreate(gDfcQ, KDNanoWaitThreadPriority, KDNanoWaitThread);
100 #ifdef CPU_AFFINITY_ANY
101 NKern::ThreadSetCpuAffinity((NThread*)(gDfcQ->iThread), KCpuAffinityAny);
107 return SetName(&KNanoWaitLddName);
110 void DNanoWaitFactory::GetCaps(TDes8& aDes) const
112 // Get capabilities - overriding pure virtual
116 b.iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
117 Kern::InfoCopy(aDes,(TUint8*)&b,sizeof(b));
123 DNanoWaitFactory::~DNanoWaitFactory()
129 DNanoWait::DNanoWait()
134 iThread=&Kern::CurrentThread();
138 TInt DNanoWait::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
144 if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
145 return KErrNotSupported;
151 DNanoWait::~DNanoWait()
156 Kern::SafeClose((DObject*&)iThread, NULL);
159 void DNanoWait::HandleMsg(TMessageBase* aMsg)
162 TThreadMessage& m=*(TThreadMessage*)aMsg;
164 if (id==(TInt)ECloseMsg)
166 m.Complete(KErrNone,EFalse);
167 iMsgQ.CompleteAll(KErrServerTerminated);
172 r=DoControl(id,m.Ptr0(),m.Ptr1());
177 TInt DNanoWait::DoControl(TInt aFunction, TAny* a1, TAny* a2)
180 TInt interval=(TInt)a2;
183 case RNanoWait::EControlStartNanoWait:
185 TInt loopCount=(TInt)a1;
186 for( int loop = 0; loop < loopCount; loop++)
188 Kern::NanoWait(interval);