author | hgs |
Fri, 23 Apr 2010 22:08:41 +0100 | |
changeset 121 | 661475905584 |
parent 31 | 56f325a607ea |
permissions | -rw-r--r-- |
0 | 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". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32test\system\d_nanowait.cpp |
|
15 |
// LDD for testing nanosecond blocking |
|
16 |
// |
|
17 |
// |
|
18 |
||
19 |
#include "plat_priv.h" |
|
20 |
#include "d_nanowait.h" |
|
21 |
||
22 |
const TInt KMajorVersionNumber=0; |
|
23 |
const TInt KMinorVersionNumber=1; |
|
24 |
const TInt KBuildVersionNumber=1; |
|
25 |
||
26 |
||
27 |
// global Dfc Que |
|
28 |
TDynamicDfcQue* gDfcQ; |
|
29 |
||
30 |
||
31 |
class DNanoWaitFactory : public DLogicalDevice |
|
32 |
// |
|
33 |
// NanoWait LDD factory |
|
34 |
// |
|
35 |
{ |
|
36 |
public: |
|
37 |
DNanoWaitFactory(); |
|
38 |
~DNanoWaitFactory(); |
|
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 |
|
42 |
}; |
|
43 |
||
44 |
class DNanoWait : public DLogicalChannel |
|
45 |
// |
|
46 |
// nanowait LDD channel |
|
47 |
// |
|
48 |
{ |
|
49 |
public: |
|
50 |
DNanoWait(); |
|
51 |
~DNanoWait(); |
|
52 |
protected: |
|
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); |
|
56 |
public: |
|
57 |
inline DThread* Client() { return iThread; } |
|
58 |
public: |
|
59 |
DThread* iThread; |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
60 |
TDynamicDfcQue* iDfcQ; |
0 | 61 |
}; |
62 |
||
63 |
||
64 |
||
65 |
DECLARE_STANDARD_LDD() |
|
66 |
{ |
|
67 |
return new DNanoWaitFactory; |
|
68 |
} |
|
69 |
||
70 |
DNanoWaitFactory::DNanoWaitFactory() |
|
71 |
// |
|
72 |
// Constructor |
|
73 |
// |
|
74 |
{ |
|
75 |
iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber); |
|
76 |
//iParseMask=0;//No units, no info, no PDD |
|
77 |
//iUnitsMask=0;//Only one thing |
|
78 |
} |
|
79 |
||
80 |
TInt DNanoWaitFactory::Create(DLogicalChannelBase*& aChannel) |
|
81 |
// |
|
82 |
// Create a new DMsTim on this logical device |
|
83 |
// |
|
84 |
{ |
|
85 |
aChannel=new DNanoWait; |
|
86 |
return aChannel?KErrNone:KErrNoMemory; |
|
87 |
} |
|
88 |
||
89 |
const TInt KDNanoWaitThreadPriority = 27; |
|
90 |
_LIT(KDNanoWaitThread,"DNanoWaitThread"); |
|
91 |
||
92 |
TInt DNanoWaitFactory::Install() |
|
93 |
// |
|
94 |
// Install the LDD - overriding pure virtual |
|
95 |
// |
|
96 |
{ |
|
97 |
// Allocate a kernel thread to run the DFC |
|
98 |
TInt r = Kern::DynamicDfcQCreate(gDfcQ, KDNanoWaitThreadPriority, KDNanoWaitThread); |
|
99 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
#ifdef CPU_AFFINITY_ANY |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
101 |
NKern::ThreadSetCpuAffinity((NThread*)(gDfcQ->iThread), KCpuAffinityAny); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
102 |
#endif |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
103 |
|
0 | 104 |
if (r != KErrNone) |
105 |
return r; |
|
106 |
||
107 |
return SetName(&KNanoWaitLddName); |
|
108 |
} |
|
109 |
||
110 |
void DNanoWaitFactory::GetCaps(TDes8& aDes) const |
|
111 |
// |
|
112 |
// Get capabilities - overriding pure virtual |
|
113 |
// |
|
114 |
{ |
|
115 |
TCapsNanoWaitV01 b; |
|
116 |
b.iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber); |
|
117 |
Kern::InfoCopy(aDes,(TUint8*)&b,sizeof(b)); |
|
118 |
} |
|
119 |
||
120 |
/** |
|
121 |
Destructor |
|
122 |
*/ |
|
123 |
DNanoWaitFactory::~DNanoWaitFactory() |
|
124 |
{ |
|
125 |
if (gDfcQ) |
|
126 |
gDfcQ->Destroy(); |
|
127 |
} |
|
128 |
||
129 |
DNanoWait::DNanoWait() |
|
130 |
// |
|
131 |
// Constructor |
|
132 |
// |
|
133 |
{ |
|
134 |
iThread=&Kern::CurrentThread(); |
|
135 |
iThread->Open(); |
|
136 |
} |
|
137 |
||
138 |
TInt DNanoWait::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer) |
|
139 |
// |
|
140 |
// Create channel |
|
141 |
// |
|
142 |
{ |
|
143 |
||
144 |
if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer)) |
|
145 |
return KErrNotSupported; |
|
146 |
SetDfcQ(gDfcQ); |
|
147 |
iMsgQ.Receive(); |
|
148 |
return KErrNone; |
|
149 |
} |
|
150 |
||
151 |
DNanoWait::~DNanoWait() |
|
152 |
// |
|
153 |
// Destructor |
|
154 |
// |
|
155 |
{ |
|
156 |
Kern::SafeClose((DObject*&)iThread, NULL); |
|
157 |
} |
|
158 |
||
159 |
void DNanoWait::HandleMsg(TMessageBase* aMsg) |
|
160 |
{ |
|
161 |
TInt r=KErrNone; |
|
162 |
TThreadMessage& m=*(TThreadMessage*)aMsg; |
|
163 |
TInt id=m.iValue; |
|
164 |
if (id==(TInt)ECloseMsg) |
|
165 |
{ |
|
166 |
m.Complete(KErrNone,EFalse); |
|
167 |
iMsgQ.CompleteAll(KErrServerTerminated); |
|
168 |
return; |
|
169 |
} |
|
170 |
else |
|
171 |
{ |
|
172 |
r=DoControl(id,m.Ptr0(),m.Ptr1()); |
|
173 |
} |
|
174 |
m.Complete(r,ETrue); |
|
175 |
} |
|
176 |
||
177 |
TInt DNanoWait::DoControl(TInt aFunction, TAny* a1, TAny* a2) |
|
178 |
{ |
|
179 |
TInt r=KErrNone; |
|
180 |
TInt interval=(TInt)a2; |
|
181 |
switch (aFunction) |
|
182 |
{ |
|
183 |
case RNanoWait::EControlStartNanoWait: |
|
184 |
{ |
|
185 |
TInt loopCount=(TInt)a1; |
|
186 |
for( int loop = 0; loop < loopCount; loop++) |
|
187 |
{ |
|
188 |
Kern::NanoWait(interval); |
|
189 |
} |
|
190 |
break; |
|
191 |
} |
|
192 |
default: |
|
193 |
r=KErrNotSupported; |
|
194 |
break; |
|
195 |
} |
|
196 |
return r; |
|
197 |
} |
|
198 |