|
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; |
|
60 }; |
|
61 |
|
62 |
|
63 |
|
64 DECLARE_STANDARD_LDD() |
|
65 { |
|
66 return new DNanoWaitFactory; |
|
67 } |
|
68 |
|
69 DNanoWaitFactory::DNanoWaitFactory() |
|
70 // |
|
71 // Constructor |
|
72 // |
|
73 { |
|
74 iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber); |
|
75 //iParseMask=0;//No units, no info, no PDD |
|
76 //iUnitsMask=0;//Only one thing |
|
77 } |
|
78 |
|
79 TInt DNanoWaitFactory::Create(DLogicalChannelBase*& aChannel) |
|
80 // |
|
81 // Create a new DMsTim on this logical device |
|
82 // |
|
83 { |
|
84 aChannel=new DNanoWait; |
|
85 return aChannel?KErrNone:KErrNoMemory; |
|
86 } |
|
87 |
|
88 const TInt KDNanoWaitThreadPriority = 27; |
|
89 _LIT(KDNanoWaitThread,"DNanoWaitThread"); |
|
90 |
|
91 TInt DNanoWaitFactory::Install() |
|
92 // |
|
93 // Install the LDD - overriding pure virtual |
|
94 // |
|
95 { |
|
96 // Allocate a kernel thread to run the DFC |
|
97 TInt r = Kern::DynamicDfcQCreate(gDfcQ, KDNanoWaitThreadPriority, KDNanoWaitThread); |
|
98 |
|
99 if (r != KErrNone) |
|
100 return r; |
|
101 |
|
102 return SetName(&KNanoWaitLddName); |
|
103 } |
|
104 |
|
105 void DNanoWaitFactory::GetCaps(TDes8& aDes) const |
|
106 // |
|
107 // Get capabilities - overriding pure virtual |
|
108 // |
|
109 { |
|
110 TCapsNanoWaitV01 b; |
|
111 b.iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber); |
|
112 Kern::InfoCopy(aDes,(TUint8*)&b,sizeof(b)); |
|
113 } |
|
114 |
|
115 /** |
|
116 Destructor |
|
117 */ |
|
118 DNanoWaitFactory::~DNanoWaitFactory() |
|
119 { |
|
120 if (gDfcQ) |
|
121 gDfcQ->Destroy(); |
|
122 } |
|
123 |
|
124 DNanoWait::DNanoWait() |
|
125 // |
|
126 // Constructor |
|
127 // |
|
128 { |
|
129 iThread=&Kern::CurrentThread(); |
|
130 iThread->Open(); |
|
131 } |
|
132 |
|
133 TInt DNanoWait::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer) |
|
134 // |
|
135 // Create channel |
|
136 // |
|
137 { |
|
138 |
|
139 if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer)) |
|
140 return KErrNotSupported; |
|
141 SetDfcQ(gDfcQ); |
|
142 iMsgQ.Receive(); |
|
143 return KErrNone; |
|
144 } |
|
145 |
|
146 DNanoWait::~DNanoWait() |
|
147 // |
|
148 // Destructor |
|
149 // |
|
150 { |
|
151 Kern::SafeClose((DObject*&)iThread, NULL); |
|
152 } |
|
153 |
|
154 void DNanoWait::HandleMsg(TMessageBase* aMsg) |
|
155 { |
|
156 TInt r=KErrNone; |
|
157 TThreadMessage& m=*(TThreadMessage*)aMsg; |
|
158 TInt id=m.iValue; |
|
159 if (id==(TInt)ECloseMsg) |
|
160 { |
|
161 m.Complete(KErrNone,EFalse); |
|
162 iMsgQ.CompleteAll(KErrServerTerminated); |
|
163 return; |
|
164 } |
|
165 else |
|
166 { |
|
167 r=DoControl(id,m.Ptr0(),m.Ptr1()); |
|
168 } |
|
169 m.Complete(r,ETrue); |
|
170 } |
|
171 |
|
172 TInt DNanoWait::DoControl(TInt aFunction, TAny* a1, TAny* a2) |
|
173 { |
|
174 TInt r=KErrNone; |
|
175 TInt interval=(TInt)a2; |
|
176 switch (aFunction) |
|
177 { |
|
178 case RNanoWait::EControlStartNanoWait: |
|
179 { |
|
180 TInt loopCount=(TInt)a1; |
|
181 for( int loop = 0; loop < loopCount; loop++) |
|
182 { |
|
183 Kern::NanoWait(interval); |
|
184 } |
|
185 break; |
|
186 } |
|
187 default: |
|
188 r=KErrNotSupported; |
|
189 break; |
|
190 } |
|
191 return r; |
|
192 } |
|
193 |