|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: OTG watcher state machine owner |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_USBOTGWATCHER_H |
|
20 #define C_USBOTGWATCHER_H |
|
21 |
|
22 #include <e32base.h> |
|
23 |
|
24 #include <usbotgdefs.h> |
|
25 |
|
26 #include "definitions.h" |
|
27 |
|
28 #ifndef STIF |
|
29 #include <usbman.h> |
|
30 #include "cusbidpinobserver.h" |
|
31 #include "cusbvbusobserver.h" |
|
32 #include "cusbotgstateobserver.h" |
|
33 #include "cusbbusactivityobserver.h" |
|
34 #include "cusbhosteventnotificationobserver.h" |
|
35 #include "cusbmessagenotificationobserver.h" |
|
36 #else |
|
37 #include "mockusbman.h" |
|
38 #include "mockcusbidpinobserver.h" |
|
39 #include "mockcusbvbusobserver.h" |
|
40 #include "mockcusbotgstateobserver.h" |
|
41 #include "mockcusbbusactivityobserver.h" |
|
42 #include "mockcusbhosteventnotificationobserver.h" |
|
43 #include "mockcusbmessagenotificationobserver.h" |
|
44 #endif |
|
45 |
|
46 #include "cusbservicecontrol.h" |
|
47 |
|
48 class CUsbState; |
|
49 class CUsbStateHostHandle; |
|
50 |
|
51 class CUsbNotifManager; |
|
52 |
|
53 /** |
|
54 * UsbWatcher main class |
|
55 * Implements states machines and owns them |
|
56 * |
|
57 */ |
|
58 class CUsbOtgWatcher : public CBase, |
|
59 MUsbIdPinObserver, |
|
60 MUsbVBusObserver, |
|
61 MUsbOtgStateObserver, |
|
62 MUsbBusActivityObserver, |
|
63 MUsbHostEventNotificationObserver, |
|
64 MUsbMessageNotificationObserver, |
|
65 MUsbServiceControlObserver |
|
66 { |
|
67 |
|
68 // Making CUsbState friend secures changing states |
|
69 // Methods to change state to be called only by CUsbStates children |
|
70 friend class CUsbState; |
|
71 friend class CtUsbOtgWatcher; |
|
72 |
|
73 public: |
|
74 /** |
|
75 * Two-phased constructor. |
|
76 * @param aUsb usbman API |
|
77 */ |
|
78 IMPORT_C static CUsbOtgWatcher* NewL(RUsb& aUsb); |
|
79 |
|
80 /** |
|
81 * Check ID-Pin state |
|
82 * @return ETrue if the ID-Pin is present (A-Device) |
|
83 */ |
|
84 IMPORT_C TBool IsDeviceA(); |
|
85 |
|
86 /** |
|
87 * Destructor. |
|
88 */ |
|
89 IMPORT_C virtual ~CUsbOtgWatcher(); |
|
90 |
|
91 /** |
|
92 * Sets personality |
|
93 * @param aStatus for async. request |
|
94 * @param aPersonalityID to be set |
|
95 */ |
|
96 void SetPersonalityL(TRequestStatus& aStatus, TInt aPersonalityID); |
|
97 |
|
98 /** |
|
99 * Cancels setting personality async. |
|
100 */ |
|
101 void CancelSetPersonalityL(); |
|
102 |
|
103 /** |
|
104 * |
|
105 * Sets previous personality |
|
106 * @param aStatus Asynchronously |
|
107 */ |
|
108 void SetPreviousPersonalityL(TRequestStatus& aStatus); |
|
109 |
|
110 /** |
|
111 * Sets previous personality |
|
112 */ |
|
113 void SetPreviousPersonalityL(); |
|
114 |
|
115 /** |
|
116 * Cancels async. set prev personality request |
|
117 */ |
|
118 void CancelSetPreviousPersonalityL(); |
|
119 |
|
120 /** |
|
121 * Sets prev. personality on disconnecting device |
|
122 */ |
|
123 void SetPreviousPreviousPersonalityOnDisconnectL(); |
|
124 |
|
125 /** |
|
126 * Policy for session start defined here |
|
127 */ |
|
128 TBool CanStartSessionL(); |
|
129 |
|
130 /********************************************************************************/ |
|
131 // Events from observers come here |
|
132 |
|
133 // From IdPin observer |
|
134 /** |
|
135 * Id Pin OFF |
|
136 */ |
|
137 void IdPinOffL(); |
|
138 /** |
|
139 * Id Pin On |
|
140 */ |
|
141 void IdPinOnL(); |
|
142 /** |
|
143 * Id Pin On |
|
144 * @param aError |
|
145 */ |
|
146 void IdPinErrorL(TInt aError); |
|
147 |
|
148 // From VBus observer |
|
149 /** |
|
150 * VBus down |
|
151 */ |
|
152 void VBusDownL(); |
|
153 /** |
|
154 * VBus UP |
|
155 */ |
|
156 void VBusUpL(); |
|
157 /** |
|
158 * VBus observer error |
|
159 * @param aError error code |
|
160 */ |
|
161 void VBusObserverErrorL(TInt aError); |
|
162 |
|
163 // From OTG state observer |
|
164 /** |
|
165 * Became to Idle when A |
|
166 */ |
|
167 void AIdleL(); |
|
168 /** |
|
169 * Became a Host when A |
|
170 */ |
|
171 void AHostL(); |
|
172 /** |
|
173 * Became a peripheral when A |
|
174 */ |
|
175 void APeripheralL(); |
|
176 /** |
|
177 * VBus error happen |
|
178 */ |
|
179 void AVBusErrorL(); |
|
180 /** |
|
181 * Became to Idle when B |
|
182 */ |
|
183 void BIdleL(); |
|
184 /** |
|
185 * Became a peripheral when B |
|
186 */ |
|
187 void BPeripheralL(); |
|
188 /** |
|
189 * Became a Host when B |
|
190 */ |
|
191 void BHostL(); |
|
192 |
|
193 /** |
|
194 * Error handler |
|
195 * @param aError error code |
|
196 */ |
|
197 void OtgStateErrorL(TInt aError); |
|
198 |
|
199 // From bus activity observer |
|
200 /** |
|
201 * Bus is in idle |
|
202 */ |
|
203 void BusIdleL(); |
|
204 /** |
|
205 * Bus active |
|
206 */ |
|
207 void BusActiveL(); |
|
208 /** |
|
209 * error |
|
210 * @param aError error happened |
|
211 */ |
|
212 void BusActivityErrorL(TInt aError); |
|
213 |
|
214 // From Host Event notification observer |
|
215 /** |
|
216 * Device is attached |
|
217 * @param aInfo Device event data |
|
218 */ |
|
219 void DeviceAttachedL(TDeviceEventInformation aInfo); |
|
220 /** |
|
221 * Device is detached |
|
222 * @param aInfo Device event data |
|
223 */ |
|
224 void DeviceDetachedL(TDeviceEventInformation aInfo); |
|
225 /** |
|
226 * Drivers successfully loaded |
|
227 * @param aInfo Device event data |
|
228 */ |
|
229 void DriverLoadSuccessL(TDeviceEventInformation aInfo); |
|
230 /** |
|
231 * Drivers loaded partially |
|
232 * @param aInfo Device event data |
|
233 */ |
|
234 void DriverLoadPartialSuccessL(TDeviceEventInformation aInfo); |
|
235 /** |
|
236 * Drivers loading failed |
|
237 * @param aInfo Device event data |
|
238 */ |
|
239 void DriverLoadFailureL(TDeviceEventInformation aInfo); |
|
240 /** |
|
241 * Error happened during observing |
|
242 * @param aError error code |
|
243 */ |
|
244 void HostEventNotificationErrorL(TInt aError); |
|
245 |
|
246 // From message notification observer |
|
247 /** |
|
248 * Message received |
|
249 * @param aMassage message id |
|
250 */ |
|
251 void MessageNotificationReceivedL(TInt aMessage); |
|
252 /** |
|
253 * Connected to hub in wrong level |
|
254 */ |
|
255 void BadHubPositionL(); |
|
256 /** |
|
257 * VBus error happened |
|
258 */ |
|
259 void VBusErrorL(); |
|
260 /** |
|
261 * SRP request received |
|
262 */ |
|
263 void SrpReceivedL(); |
|
264 /** |
|
265 * Session request received |
|
266 */ |
|
267 void SessionRequestedL(); |
|
268 /** |
|
269 * Error handler |
|
270 * @param error code |
|
271 */ |
|
272 void MessageNotificationErrorL(TInt aError); |
|
273 |
|
274 // From CUsbServiceControl |
|
275 /** |
|
276 * called when request for usb services is completed |
|
277 * if there were few requests in a row, during operation, |
|
278 * only the last one's completion is notified |
|
279 * @param aError error code |
|
280 */ |
|
281 void UsbServiceControlReqCompletedL(TInt aError); |
|
282 |
|
283 /******************************************************************************* */ |
|
284 |
|
285 // getters |
|
286 |
|
287 /** |
|
288 * @return IdPin observer |
|
289 */ |
|
290 CUsbIdPinObserver* IdPinObserver() const; |
|
291 /** |
|
292 * @return VBus observer |
|
293 */ |
|
294 CUsbVBusObserver* VBusObserver() const; |
|
295 /** |
|
296 * @return OTG state observer |
|
297 */ |
|
298 CUsbOtgStateObserver* OtgStateObserver() const; |
|
299 /** |
|
300 * @return Bus Activity observer |
|
301 */ |
|
302 CUsbBusActivityObserver* BusActivityObserver() const; |
|
303 /** |
|
304 * @return HostEvent notification observer |
|
305 */ |
|
306 CUsbHostEventNotificationObserver* HostEventNotificationObserver() const; |
|
307 /** |
|
308 * @return Message notification observer |
|
309 */ |
|
310 CUsbMessageNotificationObserver* MessageNotificationObserver() const; |
|
311 /** |
|
312 * @return usbman |
|
313 */ |
|
314 RUsb& Usb(); |
|
315 /** |
|
316 * @return current device state |
|
317 */ |
|
318 CUsbState* CurrentState() const; |
|
319 /** |
|
320 * @return current host state |
|
321 */ |
|
322 CUsbState* CurrentHostState() const; |
|
323 /** |
|
324 * @param aStateId State Id |
|
325 * @return state object by its id |
|
326 */ |
|
327 CUsbState* State(TUsbStateIds aStateId) const; |
|
328 /** |
|
329 * @return notif manager |
|
330 */ |
|
331 CUsbNotifManager* NotifManager(); |
|
332 /** |
|
333 * @return Handle state |
|
334 */ |
|
335 CUsbStateHostHandle* HostHandle() const; |
|
336 |
|
337 /** |
|
338 * Handles problems in host functioning |
|
339 * @param aWhatKindOf problem Id to be handled |
|
340 */ |
|
341 void HandleHostProblemL(TInt aWhatKindOf); |
|
342 |
|
343 /** |
|
344 * Used for test purposes |
|
345 */ |
|
346 void PrintStateToLog(); |
|
347 |
|
348 private: |
|
349 |
|
350 /** |
|
351 * Default constructor |
|
352 * @param aUsb usbman API |
|
353 */ |
|
354 CUsbOtgWatcher(RUsb& aUsb); |
|
355 |
|
356 /** |
|
357 * 2nd phase construction |
|
358 */ |
|
359 void ConstructL(); |
|
360 |
|
361 /** |
|
362 * Starts session |
|
363 */ |
|
364 void StartSessionL(); |
|
365 |
|
366 /** |
|
367 * Changes device's state machine state |
|
368 * |
|
369 * @param aNewStateId New state id |
|
370 */ |
|
371 void ChangeStateL(TUsbStateIds aNewStateId); |
|
372 |
|
373 /** |
|
374 * Changes host's state machine state |
|
375 * |
|
376 * @param aNewStateId new host state (id) |
|
377 */ |
|
378 void ChangeHostStateL(TUsbStateIds aNewStateId); |
|
379 |
|
380 /** |
|
381 * Used for test purposes |
|
382 * @return KErrNone if test is OK, otherwise errorcode |
|
383 */ |
|
384 TInt SelfTestL(); |
|
385 |
|
386 private: |
|
387 // data |
|
388 |
|
389 /** |
|
390 * usbman API |
|
391 */ |
|
392 RUsb& iUsb; |
|
393 |
|
394 /** |
|
395 * Personality to be set in device role |
|
396 */ |
|
397 TInt iPersonalityId; |
|
398 |
|
399 /** |
|
400 * Device state machine |
|
401 * Own. |
|
402 */ |
|
403 CUsbState* iState; |
|
404 |
|
405 /** |
|
406 * Host state machine |
|
407 * Own. |
|
408 */ |
|
409 CUsbState* iHostState; |
|
410 |
|
411 /** |
|
412 * Id pin Observer |
|
413 * Own. |
|
414 */ |
|
415 CUsbIdPinObserver* iIdPinObserver; |
|
416 |
|
417 /** |
|
418 * vbus observer |
|
419 * Own. |
|
420 */ |
|
421 CUsbVBusObserver* iVBusObserver; |
|
422 |
|
423 /** |
|
424 * otg state observer |
|
425 * Own. |
|
426 */ |
|
427 CUsbOtgStateObserver* iOtgStateObserver; |
|
428 |
|
429 /** |
|
430 * bus activity observer |
|
431 * Own. |
|
432 */ |
|
433 CUsbBusActivityObserver* iBusActivityObserver; |
|
434 |
|
435 /** |
|
436 * host event notification observer |
|
437 * Own. |
|
438 */ |
|
439 CUsbHostEventNotificationObserver* iHostEventNotificationObserver; |
|
440 |
|
441 /** |
|
442 * message notification observer |
|
443 * Own. |
|
444 */ |
|
445 CUsbMessageNotificationObserver* iMessageNotificationObserver; |
|
446 |
|
447 /** |
|
448 * All states objects kept here |
|
449 * Own. |
|
450 */ |
|
451 RPointerArray<CUsbState> iStates; |
|
452 |
|
453 /** |
|
454 * notif manager |
|
455 * Own. |
|
456 */ |
|
457 CUsbNotifManager* iNotifManager; |
|
458 |
|
459 /** |
|
460 * usb service control |
|
461 * Starts and stops usb service, changes personalities |
|
462 * Own. |
|
463 */ |
|
464 CUsbServiceControl* iUsbServiceControl; |
|
465 }; |
|
466 |
|
467 #endif // C_USBOTGWATCHER_H |