|
1 /* |
|
2 * Copyright (c) 1997-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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef __BREAKCONTROLLER_H__ |
|
19 #define __BREAKCONTROLLER_H__ |
|
20 |
|
21 #include <e32base.h> |
|
22 |
|
23 class CCdcAcmClass; |
|
24 class MHostPushedChangeObserver; |
|
25 |
|
26 NONSHARABLE_CLASS(CBreakController) : public CActive |
|
27 /** |
|
28 * Break (timed signal) handler |
|
29 * |
|
30 * This class provides a simple active object that manages the timing aspect |
|
31 * of a break: there is only one of these, that is used to manage both |
|
32 * client-induced breaks (routed in via the ACM port) and break commands sent |
|
33 * here from the (USB) Host. |
|
34 * |
|
35 * Note that only one of the device and the host can be 'in charge of' a |
|
36 * break. If the host, say, is dealing with a timed break, then it is illegal |
|
37 * for the device to issue a timed break, though the host may override the |
|
38 * timed break with a new timed break or a locked break. |
|
39 */ |
|
40 { |
|
41 public: |
|
42 enum TRequester |
|
43 { |
|
44 ENone, |
|
45 EDevice, |
|
46 EHost, |
|
47 }; |
|
48 |
|
49 enum TState |
|
50 { |
|
51 EInactive, |
|
52 ETiming, |
|
53 ELocked, |
|
54 ENumStates |
|
55 }; |
|
56 |
|
57 public: |
|
58 static CBreakController* NewL(CCdcAcmClass& aParentAcm); |
|
59 ~CBreakController(); |
|
60 |
|
61 public: // API for requesting breaks |
|
62 TInt BreakRequest(TRequester aRequester, |
|
63 TState aState, |
|
64 TTimeIntervalMicroSeconds32 aDelay = 0); |
|
65 |
|
66 private: |
|
67 CBreakController(CCdcAcmClass& aParentAcm); |
|
68 void ConstructL(); |
|
69 |
|
70 private: |
|
71 void StateMachine(TState aBreakState, TTimeIntervalMicroSeconds32 aDelay); |
|
72 |
|
73 void Publish(TState aNewState); |
|
74 |
|
75 static TBool ScInvalid(CBreakController *aThis, |
|
76 TTimeIntervalMicroSeconds32 aDelay); |
|
77 static TBool ScInactive(CBreakController *aThis, |
|
78 TTimeIntervalMicroSeconds32 aDelay); |
|
79 static TBool ScSetTimer(CBreakController *aThis, |
|
80 TTimeIntervalMicroSeconds32 aDelay); |
|
81 static TBool ScLocked(CBreakController *aThis, |
|
82 TTimeIntervalMicroSeconds32 aDelay); |
|
83 |
|
84 private: // from CActive |
|
85 void RunL(); |
|
86 void DoCancel(); |
|
87 |
|
88 private: // owned |
|
89 typedef TBool ( *PBFNT ) (CBreakController *aThis, |
|
90 TTimeIntervalMicroSeconds32 aDelay); |
|
91 PBFNT StateDispatcher[ENumStates][ENumStates]; |
|
92 RTimer iTimer; |
|
93 TState iBreakState; |
|
94 // Whoever's in charge of the current break. |
|
95 TRequester iRequester; |
|
96 |
|
97 private: // unowned |
|
98 CCdcAcmClass& iParentAcm; ///< use to tell (USB) Host about changes |
|
99 }; |
|
100 |
|
101 #endif // __BREAKCONTROLLER_H__ |