253
|
1 |
// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
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 |
//
|
|
15 |
|
|
16 |
/**
|
|
17 |
@file
|
|
18 |
@internalComponent
|
|
19 |
*/
|
|
20 |
|
|
21 |
#include "t_otgdi_fdfactor.h"
|
253
|
22 |
#include "OstTraceDefinitions.h"
|
|
23 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
24 |
#include "t_otgdi_fdfactorTraces.h"
|
|
25 |
#endif
|
0
|
26 |
#include <Usb.h>
|
|
27 |
|
|
28 |
#define LOG_FUNC
|
|
29 |
|
|
30 |
CActorFDF* CActorFDF::NewL(MUsbBusObserver& aObserver)
|
|
31 |
{
|
|
32 |
CActorFDF* self = new (ELeave) CActorFDF(aObserver);
|
|
33 |
CleanupStack::PushL(self);
|
|
34 |
self->ConstructL();
|
|
35 |
CleanupStack::Pop(self);
|
|
36 |
return self;
|
|
37 |
}
|
|
38 |
|
|
39 |
|
|
40 |
CActorFDF::CActorFDF(MUsbBusObserver& aObserver)
|
|
41 |
: CActive(EPriorityStandard),
|
|
42 |
iObserver(aObserver)
|
|
43 |
{
|
|
44 |
}
|
|
45 |
|
|
46 |
|
|
47 |
void CActorFDF::ConstructL()
|
|
48 |
{
|
|
49 |
LOG_FUNC
|
|
50 |
CActiveScheduler::Add(this);
|
|
51 |
|
|
52 |
TInt err(iDriver.Open());
|
|
53 |
if (err != KErrNone)
|
|
54 |
{
|
253
|
55 |
OstTrace1(TRACE_NORMAL, CACTORFDF_CONSTRUCTL, "<Error %d> Unable to open driver channel",err);
|
0
|
56 |
User::Leave(err);
|
|
57 |
}
|
|
58 |
|
|
59 |
err = iDriver.StartHost();
|
|
60 |
if (err != KErrNone)
|
|
61 |
{
|
|
62 |
// Test case did not run successfully
|
253
|
63 |
OstTrace1(TRACE_NORMAL, CACTORFDF_CONSTRUCTL_DUP01, "<Error %d> USB Host stack not starting",err);
|
0
|
64 |
}
|
|
65 |
}
|
|
66 |
|
|
67 |
|
|
68 |
CActorFDF::~CActorFDF()
|
|
69 |
{
|
|
70 |
LOG_FUNC
|
|
71 |
Cancel();
|
|
72 |
|
|
73 |
// Destroy all test device objects that represented connected devices
|
|
74 |
|
|
75 |
RHashMap<TUint,CUsbTestDevice*>::TIter it(iDevices);
|
|
76 |
TInt count(0);
|
|
77 |
for (count=0; count<iDevices.Count(); count++)
|
|
78 |
{
|
|
79 |
delete *it.NextValue();
|
|
80 |
}
|
|
81 |
|
|
82 |
iDevices.Close();
|
|
83 |
|
|
84 |
// Close the channel to the USB Hub driver
|
|
85 |
iDriver.StopHost();
|
|
86 |
iDriver.Close();
|
|
87 |
}
|
|
88 |
|
|
89 |
void CActorFDF::DoCancel()
|
|
90 |
{
|
|
91 |
LOG_FUNC
|
|
92 |
|
|
93 |
iDriver.CancelWaitForBusEvent();
|
|
94 |
}
|
|
95 |
|
|
96 |
void CActorFDF::Monitor()
|
|
97 |
{
|
|
98 |
LOG_FUNC
|
253
|
99 |
OstTrace0(TRACE_NORMAL, CACTORFDF_MONITOR, "Monitoring Bus Events");
|
0
|
100 |
iDriver.WaitForBusEvent(iBusEvent,iStatus);
|
|
101 |
SetActive();
|
|
102 |
}
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
CUsbTestDevice& CActorFDF::DeviceL(TUint aDeviceHandle)
|
|
107 |
{
|
|
108 |
return *iDevices.FindL(aDeviceHandle);
|
|
109 |
}
|
|
110 |
|
|
111 |
void CActorFDF::RunL()
|
|
112 |
{
|
|
113 |
LOG_FUNC
|
|
114 |
|
|
115 |
// Obtain completion code
|
|
116 |
TInt completionCode(iStatus.Int());
|
253
|
117 |
OstTrace1(TRACE_NORMAL, CACTORFDF_RUNL, "Completion code : %d",completionCode);
|
0
|
118 |
|
|
119 |
if (completionCode == KErrNone)
|
|
120 |
{
|
|
121 |
if (iBusEvent.iEventType == RUsbHubDriver::TBusEvent::EDeviceAttached)
|
|
122 |
{
|
|
123 |
// Device Attached
|
253
|
124 |
OstTrace1(TRACE_NORMAL, CACTORFDF_RUNL_DUP01, "Usb device attached: %d",iBusEvent.iDeviceHandle);
|
0
|
125 |
|
|
126 |
// Create the test device object
|
|
127 |
iDevices.InsertL(iBusEvent.iDeviceHandle,CUsbTestDevice::NewL(iDriver,iBusEvent.iDeviceHandle,iObserver));
|
|
128 |
|
|
129 |
// Notify observer
|
|
130 |
iObserver.DeviceInsertedL(iBusEvent.iDeviceHandle);
|
|
131 |
|
|
132 |
// Suspend the newly attached device in preparation for role swap
|
|
133 |
CUsbTestDevice* newDevice = iDevices.FindL(iBusEvent.iDeviceHandle);
|
|
134 |
if(newDevice)
|
|
135 |
{
|
253
|
136 |
OstTrace1(TRACE_NORMAL, CACTORFDF_RUNL_DUP02, "Suspending device %d",iBusEvent.iDeviceHandle);
|
0
|
137 |
TInt err = newDevice->Suspend();
|
|
138 |
if(err)
|
|
139 |
{
|
253
|
140 |
OstTraceExt2(TRACE_NORMAL, CACTORFDF_RUNL_DUP03, "Suspending device %d returned error %d", (TInt)iBusEvent.iDeviceHandle, err);
|
0
|
141 |
}
|
|
142 |
}
|
|
143 |
else
|
|
144 |
{
|
253
|
145 |
OstTrace1(TRACE_NORMAL, CACTORFDF_RUNL_DUP04, "Can't find newly attached device %d",iBusEvent.iDeviceHandle);
|
0
|
146 |
}
|
|
147 |
|
|
148 |
}
|
|
149 |
else if (iBusEvent.iEventType == RUsbHubDriver::TBusEvent::EDeviceRemoved)
|
|
150 |
{
|
|
151 |
// Device Removed
|
253
|
152 |
OstTrace1(TRACE_NORMAL, CACTORFDF_RUNL_DUP05, "Usb device removed: %d",iBusEvent.iDeviceHandle);
|
0
|
153 |
|
|
154 |
// Notify observer
|
|
155 |
iObserver.DeviceRemovedL(iBusEvent.iDeviceHandle);
|
|
156 |
|
|
157 |
// Destroy the device for the handle and remove from the map
|
|
158 |
delete iDevices.FindL(iBusEvent.iDeviceHandle);
|
|
159 |
iDevices.Remove(iBusEvent.iDeviceHandle);
|
|
160 |
}
|
|
161 |
else
|
|
162 |
{
|
253
|
163 |
OstTraceExt2(TRACE_NORMAL, CACTORFDF_RUNL_DUP06, "<Warning> Bus event %d occured, still monitoring, reason = %d",iBusEvent.iEventType, iBusEvent.iReason);
|
0
|
164 |
}
|
|
165 |
}
|
|
166 |
else
|
|
167 |
{
|
253
|
168 |
OstTraceExt2(TRACE_NORMAL, CACTORFDF_RUNL_DUP07, "<Error %d> Bus event %d",completionCode,iBusEvent.iEventType);
|
0
|
169 |
iObserver.BusErrorL(completionCode);
|
|
170 |
}
|
|
171 |
Monitor(); // Requeue for notification of further bus events
|
|
172 |
}
|
|
173 |
|
|
174 |
|
|
175 |
TInt CActorFDF::RunError(TInt aError)
|
|
176 |
{
|
|
177 |
LOG_FUNC
|
253
|
178 |
OstTrace1(TRACE_NORMAL, CACTORFDF_RUNERROR, "<Error %d> CActorFDF::RunError",aError);
|
0
|
179 |
return KErrNone;
|
|
180 |
}
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
CUsbTestDevice* CUsbTestDevice::NewL(RUsbHubDriver& aHubDriver,TUint aDeviceHandle,MUsbBusObserver& aObserver)
|
|
193 |
{
|
|
194 |
CUsbTestDevice* self = new (ELeave) CUsbTestDevice(aHubDriver,aDeviceHandle,aObserver);
|
|
195 |
CleanupStack::PushL(self);
|
|
196 |
self->ConstructL();
|
|
197 |
CleanupStack::Pop(self);
|
|
198 |
return self;
|
|
199 |
}
|
|
200 |
|
|
201 |
CUsbTestDevice::CUsbTestDevice(RUsbHubDriver& aHubDriver,TUint aHandle,MUsbBusObserver& aObserver)
|
|
202 |
: CActive(EPriorityUserInput),
|
|
203 |
iDriver(aHubDriver),
|
|
204 |
iHandle(aHandle),
|
|
205 |
iObserver(aObserver)
|
|
206 |
{
|
|
207 |
LOG_FUNC
|
|
208 |
|
|
209 |
CActiveScheduler::Add(this);
|
|
210 |
}
|
|
211 |
|
|
212 |
CUsbTestDevice::~CUsbTestDevice()
|
|
213 |
{
|
|
214 |
LOG_FUNC
|
|
215 |
Cancel();
|
|
216 |
iDevice.Close();
|
|
217 |
}
|
|
218 |
|
|
219 |
void CUsbTestDevice::ConstructL()
|
|
220 |
{
|
|
221 |
LOG_FUNC
|
|
222 |
|
|
223 |
// Open the usb device object
|
|
224 |
User::LeaveIfError(iDevice.Open(iDriver,iHandle));
|
|
225 |
|
|
226 |
TInt err(iDevice.GetDeviceDescriptor(iDeviceDescriptor));
|
|
227 |
if (err != KErrNone)
|
|
228 |
{
|
253
|
229 |
OstTraceExt2(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL, "<Error %d> Getting device (%d) descriptor",err,(TInt)iHandle);
|
0
|
230 |
User::Leave(err);
|
|
231 |
}
|
|
232 |
|
|
233 |
err = iDevice.GetConfigurationDescriptor(iConfigDescriptor);
|
|
234 |
if (err != KErrNone)
|
|
235 |
{
|
253
|
236 |
OstTraceExt2(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP01, "<Error %d> Getting device (%d) configuration descriptor",err,(TInt)iHandle);
|
0
|
237 |
User::Leave(err);
|
|
238 |
}
|
|
239 |
|
|
240 |
iDeviceSpec = iDeviceDescriptor.USBBcd();
|
|
241 |
iPid = iDeviceDescriptor.ProductId();
|
|
242 |
iVid = iDeviceDescriptor.VendorId();
|
|
243 |
|
253
|
244 |
OstTrace1(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP02, "%dmA configuration maximum power consumption",iConfigDescriptor.MaxPower()*2);
|
|
245 |
OstTrace1(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP03, "%d number of interface(s)",iConfigDescriptor.NumInterfaces());
|
|
246 |
OstTraceExt2(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP04, "Vendor Id=0x%04x, Product Id=0x%04x",iVid,iPid);
|
|
247 |
OstTrace1(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP05, "TotalLength() = %d",iConfigDescriptor.TotalLength());
|
0
|
248 |
|
|
249 |
// Get changes in device state
|
|
250 |
iDevice.QueueDeviceStateChangeNotification(iCurrentState,iStatus); // iCurrentState now holds the current device state
|
|
251 |
SetActive();
|
|
252 |
}
|
|
253 |
|
|
254 |
RUsbDevice& CUsbTestDevice::Device()
|
|
255 |
{
|
|
256 |
return iDevice;
|
|
257 |
}
|
|
258 |
|
|
259 |
TUint16 CUsbTestDevice::DeviceSpec() const
|
|
260 |
{
|
|
261 |
return iDeviceSpec;
|
|
262 |
}
|
|
263 |
|
|
264 |
TUint16 CUsbTestDevice::ProductId() const
|
|
265 |
{
|
|
266 |
return iPid;
|
|
267 |
}
|
|
268 |
|
|
269 |
TUint16 CUsbTestDevice::VendorId() const
|
|
270 |
{
|
|
271 |
return iVid;
|
|
272 |
}
|
|
273 |
|
|
274 |
const TUsbConfigurationDescriptor& CUsbTestDevice::ConfigurationDescriptor() const
|
|
275 |
{
|
|
276 |
return iConfigDescriptor;
|
|
277 |
}
|
|
278 |
|
|
279 |
const TUsbDeviceDescriptor& CUsbTestDevice::DeviceDescriptor() const
|
|
280 |
{
|
|
281 |
return iDeviceDescriptor;
|
|
282 |
}
|
|
283 |
|
|
284 |
TInt CUsbTestDevice::Suspend()
|
|
285 |
{
|
|
286 |
return iDevice.Suspend();
|
|
287 |
}
|
|
288 |
|
|
289 |
void CUsbTestDevice::DoCancel()
|
|
290 |
{
|
|
291 |
LOG_FUNC
|
|
292 |
iDevice.CancelDeviceStateChangeNotification();
|
|
293 |
}
|
|
294 |
|
|
295 |
|
|
296 |
void CUsbTestDevice::RunL()
|
|
297 |
{
|
|
298 |
LOG_FUNC
|
|
299 |
|
|
300 |
TInt completionCode(iStatus.Int());
|
|
301 |
|
|
302 |
if ( completionCode != KErrCancel )
|
|
303 |
{
|
253
|
304 |
OstTrace1(TRACE_NORMAL, CUSBTESTDEVICE_RUNL, "CUsbTestDevice::RunL completionCode(%d)",completionCode);
|
0
|
305 |
}
|
|
306 |
|
|
307 |
if(completionCode == KErrNone)
|
|
308 |
{
|
|
309 |
RUsbDevice::TDeviceState newState;
|
|
310 |
iDevice.QueueDeviceStateChangeNotification(newState,iStatus);
|
|
311 |
SetActive();
|
|
312 |
iObserver.DeviceStateChangeL(iCurrentState,newState,completionCode);
|
|
313 |
iCurrentState = newState;
|
|
314 |
}
|
|
315 |
}
|
|
316 |
|
|
317 |
|
|
318 |
TInt CUsbTestDevice::RunError(TInt aError)
|
|
319 |
{
|
|
320 |
LOG_FUNC
|
|
321 |
|
253
|
322 |
OstTrace1(TRACE_NORMAL, CUSBTESTDEVICE_RUNERROR, "<Error %d>",aError);
|
0
|
323 |
return KErrNone;
|
|
324 |
}
|
|
325 |
|
|
326 |
CFdfTOtgdiWatcher* CFdfTOtgdiWatcher::NewL()
|
|
327 |
{
|
|
328 |
CFdfTOtgdiWatcher* self = new(ELeave)CFdfTOtgdiWatcher();
|
|
329 |
CleanupStack::PushL(self);
|
|
330 |
self->ConstructL();
|
|
331 |
CleanupStack::Pop(self);
|
|
332 |
return self;
|
|
333 |
}
|
|
334 |
|
|
335 |
void CFdfTOtgdiWatcher::DoCancel()
|
|
336 |
{
|
|
337 |
TInt err=iTotgdiProcess.RendezvousCancel(iStatus);
|
|
338 |
if(err)
|
|
339 |
{
|
253
|
340 |
OstTrace1(TRACE_NORMAL, CFDFTOTGDIWATCHER_DOCANCEL, "Cancelling Rendezvous completed with %d",err);
|
0
|
341 |
}
|
|
342 |
}
|
|
343 |
|
|
344 |
void CFdfTOtgdiWatcher::RunL()
|
|
345 |
{
|
|
346 |
// The t_otgdi process has signalled its rendezvous
|
|
347 |
// Time to stop the active scheduler, tidy up and go away
|
253
|
348 |
OstTrace0(TRACE_NORMAL, CFDFTOTGDIWATCHER_RUNL, "Rendezvous signalled from t_otgdi");
|
0
|
349 |
CActiveScheduler::Stop();
|
|
350 |
}
|
|
351 |
|
|
352 |
void CFdfTOtgdiWatcher::ConstructL()
|
|
353 |
{
|
|
354 |
CActiveScheduler::Add(this);
|
|
355 |
|
|
356 |
// Need to get an RProcess handle to the t_otgdi.exe process
|
|
357 |
// so we can wait on its rendezvous
|
|
358 |
TFullName totgdiProcessName;
|
|
359 |
|
|
360 |
FindTOtgdiProcessName(totgdiProcessName);
|
|
361 |
|
|
362 |
TInt err=iTotgdiProcess.Open(totgdiProcessName);
|
|
363 |
|
|
364 |
if(err)
|
|
365 |
{
|
253
|
366 |
OstTrace0(TRACE_NORMAL, CFDFTOTGDIWATCHER_CONSTRUCTL, "Couldn't open process handle to t_otgdi.exe");
|
0
|
367 |
}
|
|
368 |
User::LeaveIfError(err);
|
|
369 |
|
|
370 |
iTotgdiProcess.Rendezvous(iStatus);
|
|
371 |
|
|
372 |
SetActive();
|
|
373 |
}
|
|
374 |
|
|
375 |
TInt CFdfTOtgdiWatcher::FindTOtgdiProcessName(TFullName& aProcessName)
|
|
376 |
{
|
253
|
377 |
OstTrace0(TRACE_NORMAL, CFDFTOTGDIWATCHER_FINDTOTGDIPROCESSNAME, "Into FindTOtgdiProcessName");
|
0
|
378 |
TInt successCode = KErrNotFound;
|
|
379 |
TFindProcess fp;
|
|
380 |
fp.Find(_L("t_otgdi.exe*")); // Process name match pattern
|
|
381 |
while(fp.Next(aProcessName)==KErrNone)
|
|
382 |
{
|
253
|
383 |
OstTraceExt1(TRACE_NORMAL, CFDFTOTGDIWATCHER_FINDTOTGDIPROCESSNAME_DUP01, "FDFActor Found process %S",aProcessName);
|
0
|
384 |
successCode = KErrNone;
|
|
385 |
}
|
|
386 |
return successCode;
|
|
387 |
}
|
|
388 |
|
|
389 |
CFdfTOtgdiWatcher::CFdfTOtgdiWatcher()
|
|
390 |
: CActive(EPriorityNormal)
|
|
391 |
{
|
|
392 |
}
|
|
393 |
|
|
394 |
CFdfTOtgdiWatcher::~CFdfTOtgdiWatcher()
|
|
395 |
{
|
253
|
396 |
OstTrace0(TRACE_NORMAL, CFDFTOTGDIWATCHER_DCFDFTOTGDIWATCHER, "About to call CFdfTOtgdiWatcher::Cancel");
|
0
|
397 |
Cancel();
|
253
|
398 |
OstTrace0(TRACE_NORMAL, CFDFTOTGDIWATCHER_DCFDFTOTGDIWATCHER_DUP01, "About to call iTotgdiProcess.Close");
|
0
|
399 |
iTotgdiProcess.Close();
|
|
400 |
}
|
|
401 |
|