|
1 // Copyright (c) 2006-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\power\d_lddpowerseqtest.cpp |
|
15 // LDD for testing the power up and down sequence |
|
16 // |
|
17 // |
|
18 |
|
19 #include <kernel/kernel.h> |
|
20 #include <kernel/kpower.h> |
|
21 #include "d_lddpowerseqtest.h" |
|
22 |
|
23 |
|
24 _LIT(KLitPower1,"PowerSeqTest1"); |
|
25 _LIT(KLitPower2,"PowerSeqTest2"); |
|
26 |
|
27 // |
|
28 // Variables to store asynchronous status request and time count user variables address. |
|
29 // |
|
30 TRequestStatus *aStatus_up1; |
|
31 TRequestStatus *aStatus_up2; |
|
32 TRequestStatus *aStatus_down1; |
|
33 TRequestStatus *aStatus_down2; |
|
34 TUint *time_power1down; |
|
35 TUint *time_power2down; |
|
36 TUint *time_power1up; |
|
37 TUint *time_power2up; |
|
38 TUint sleepTime; |
|
39 |
|
40 |
|
41 class DTest1; |
|
42 // |
|
43 // Power handler1 |
|
44 // |
|
45 class DTest1PowerHandler : public DPowerHandler |
|
46 { |
|
47 public: |
|
48 DTest1PowerHandler(); |
|
49 |
|
50 void PowerUp(); |
|
51 void PowerDown(TPowerState); |
|
52 }; |
|
53 |
|
54 // |
|
55 // Power handler2 |
|
56 // |
|
57 class DTest2PowerHandler : public DPowerHandler |
|
58 { |
|
59 public: |
|
60 DTest2PowerHandler(); |
|
61 void PowerUp(); |
|
62 void PowerDown(TPowerState); |
|
63 }; |
|
64 |
|
65 class DTestFactory : public DLogicalDevice |
|
66 // |
|
67 // Test LDD factory |
|
68 // |
|
69 { |
|
70 public: |
|
71 DTestFactory(); |
|
72 virtual TInt Install(); //overriding pure virtual |
|
73 virtual void GetCaps(TDes8& aDes) const; //overriding pure virtual |
|
74 virtual TInt Create(DLogicalChannelBase*& aChannel); //overriding pure virtual |
|
75 }; |
|
76 |
|
77 class DTest1 : public DLogicalChannelBase |
|
78 // |
|
79 // Test logical channel |
|
80 // |
|
81 { |
|
82 public: |
|
83 virtual ~DTest1(); |
|
84 protected: |
|
85 virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); |
|
86 virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2); |
|
87 DTest1PowerHandler power1; |
|
88 DTest2PowerHandler power2; |
|
89 }; |
|
90 |
|
91 |
|
92 |
|
93 DECLARE_STANDARD_LDD() |
|
94 { |
|
95 return new DTestFactory; |
|
96 } |
|
97 |
|
98 // |
|
99 // Constructor |
|
100 // |
|
101 DTestFactory::DTestFactory() |
|
102 { |
|
103 |
|
104 } |
|
105 |
|
106 TInt DTestFactory::Create(DLogicalChannelBase*& aChannel) |
|
107 { |
|
108 // |
|
109 // Create new channel |
|
110 // |
|
111 aChannel=new DTest1; |
|
112 return aChannel?KErrNone:KErrNoMemory; |
|
113 } |
|
114 |
|
115 TInt DTestFactory::Install() |
|
116 // |
|
117 // Install the LDD - overriding pure virtual |
|
118 // |
|
119 { |
|
120 return SetName(&KLddName); |
|
121 } |
|
122 |
|
123 void DTestFactory::GetCaps(TDes8& /*aDes*/) const |
|
124 // |
|
125 // Get capabilities - overriding pure virtual |
|
126 // |
|
127 { |
|
128 } |
|
129 |
|
130 TInt DTest1::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/) |
|
131 // |
|
132 // Create channel |
|
133 // |
|
134 { |
|
135 //try to remove a handler that hasn't been added yet - should not cause any problems |
|
136 power1.Remove(); |
|
137 //Add power handlers |
|
138 power2.Add(); |
|
139 power1.Add(); |
|
140 return KErrNone; |
|
141 } |
|
142 |
|
143 DTest1::~DTest1() |
|
144 // |
|
145 // Destructor |
|
146 // |
|
147 { |
|
148 power1.Remove(); |
|
149 power2.Remove(); |
|
150 //try to remove a handler twice - should not cause any problems |
|
151 power2.Remove(); |
|
152 } |
|
153 |
|
154 TInt DTest1::Request(TInt aReqNo, TAny* a1, TAny* a2) |
|
155 { |
|
156 // |
|
157 // Store status requests and time stamp variable for each power up and power down |
|
158 // |
|
159 |
|
160 if(aReqNo<0) |
|
161 { |
|
162 // 'Request' functions... |
|
163 TRequestStatus* s = (TRequestStatus*)a1; |
|
164 TAny* args[2]; |
|
165 kumemget32(args,a2,sizeof(args)); // get user side arguments |
|
166 |
|
167 switch(~aReqNo) |
|
168 { |
|
169 case RLddTest1::EPOWERDOWN_POWER1: |
|
170 aStatus_down1 = s; |
|
171 time_power1down = (TUint*)args[0]; |
|
172 break; |
|
173 |
|
174 case RLddTest1::EPOWERDOWN_POWER2: |
|
175 aStatus_down2 = s; |
|
176 time_power2down = (TUint*)args[0]; |
|
177 break; |
|
178 |
|
179 case RLddTest1::EPOWERUP_POWER1: |
|
180 aStatus_up1 = s; |
|
181 time_power1up = (TUint*)args[0]; |
|
182 break; |
|
183 |
|
184 case RLddTest1::EPOWERUP_POWER2: |
|
185 aStatus_up2 = s; |
|
186 time_power2up = (TUint*)args[0]; |
|
187 break; |
|
188 } |
|
189 } |
|
190 else |
|
191 { |
|
192 // 'Control' functions... |
|
193 switch(aReqNo) |
|
194 { |
|
195 // DoControl |
|
196 case RLddTest1::ESET_SLEEPTIME: |
|
197 sleepTime = (TUint)a1; |
|
198 break; |
|
199 } |
|
200 } |
|
201 |
|
202 return KErrNone; |
|
203 } |
|
204 |
|
205 DTest1PowerHandler::DTest1PowerHandler():DPowerHandler(KLitPower1) |
|
206 { |
|
207 // |
|
208 // Power handler1 constructor |
|
209 // |
|
210 } |
|
211 |
|
212 DTest2PowerHandler::DTest2PowerHandler():DPowerHandler(KLitPower2) |
|
213 { |
|
214 // |
|
215 // Power handler2 constructor |
|
216 // |
|
217 } |
|
218 |
|
219 |
|
220 void DTest1PowerHandler::PowerUp() |
|
221 { |
|
222 // |
|
223 // Sleep for sometime to get different tick counts for comparision. |
|
224 // Copy the tick count to user variable and complete the request |
|
225 // |
|
226 NKern::Sleep(sleepTime); |
|
227 |
|
228 TUint temp = NKern::TickCount(); |
|
229 kumemput(time_power1up, (const TUint *)&temp, sizeof(temp)); |
|
230 |
|
231 Kern::RequestComplete(aStatus_up1, KErrNone); |
|
232 |
|
233 PowerUpDone(); |
|
234 |
|
235 } |
|
236 |
|
237 void DTest2PowerHandler::PowerUp() |
|
238 { |
|
239 // |
|
240 // Copy the tick count to user variable and complete the request |
|
241 // |
|
242 |
|
243 TUint temp = NKern::TickCount(); |
|
244 kumemput(time_power2up, (const TUint *)&temp, sizeof(temp)); |
|
245 |
|
246 Kern::RequestComplete(aStatus_up2, KErrNone); |
|
247 |
|
248 PowerUpDone(); |
|
249 } |
|
250 |
|
251 void DTest1PowerHandler::PowerDown(TPowerState /*aState*/) |
|
252 { |
|
253 // |
|
254 // Copy the tick count to user variable and complete the request |
|
255 // |
|
256 |
|
257 TUint temp = NKern::TickCount(); |
|
258 kumemput(time_power1down, (const TUint *)&temp, sizeof(temp)); |
|
259 |
|
260 Kern::RequestComplete(aStatus_down1, KErrNone); |
|
261 |
|
262 PowerDownDone(); |
|
263 } |
|
264 |
|
265 void DTest2PowerHandler::PowerDown(TPowerState /*aState*/) |
|
266 { |
|
267 // |
|
268 // Sleep for sometime to get different tick counts for comparision. |
|
269 // Copy the tick count to user variable and complete the request |
|
270 // |
|
271 |
|
272 NKern::Sleep(sleepTime); |
|
273 |
|
274 TUint temp = NKern::TickCount(); |
|
275 kumemput(time_power2down, (const TUint *)&temp, sizeof(temp)); |
|
276 |
|
277 Kern::RequestComplete(aStatus_down2, KErrNone); |
|
278 |
|
279 PowerDownDone(); |
|
280 } |