|
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: Personality switch function. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef C_USBPERSONALITYSWITCH_H |
|
19 #define C_USBPERSONALITYSWITCH_H |
|
20 |
|
21 #include <e32base.h> |
|
22 #include <d32usbdi.h> |
|
23 |
|
24 const TInt KGetAllPersonalitiesReq = 0x82; |
|
25 const TInt KSetPersonalityReq = 0x89; |
|
26 |
|
27 const TInt KNumOfPersShift = 3; |
|
28 const TInt KCurrPersShift = 2; |
|
29 const TInt KFirstPersonalityIdShift = 4; |
|
30 const TInt KLenghtOfPersonalityData = 2; |
|
31 |
|
32 class MUsbPersonalitySwitchObserver |
|
33 { |
|
34 public: |
|
35 enum TState |
|
36 { |
|
37 EIdle = 0, |
|
38 ERequestingAllPersonalities, |
|
39 ERequestingSetPersonality, |
|
40 EGetAllPersonalitiesCompleted, |
|
41 ESetPersonalityCompleted, |
|
42 ERequestCancelled, |
|
43 ERequestFailed |
|
44 }; |
|
45 public: |
|
46 virtual void UsbPersonalitySwitchStateChangedL(TState aState, TInt aData) = 0; |
|
47 }; |
|
48 |
|
49 /* * |
|
50 * Reads personalities, if possible, switches peripheral to mass storage. |
|
51 * It is assumed that USB is started already |
|
52 */ |
|
53 NONSHARABLE_CLASS(CUsbPersonalitySwitch) : public CActive |
|
54 { |
|
55 enum TState |
|
56 { |
|
57 EIdle = 0, |
|
58 EGetAllPersonalities, |
|
59 ESetPersonality /*, |
|
60 EGetAllPersResult, |
|
61 EGetSetPersResult*/ |
|
62 }; |
|
63 |
|
64 public: |
|
65 |
|
66 /** |
|
67 * Two-phased constructor |
|
68 * |
|
69 * @param aObserver will get call back |
|
70 * @param aTimerId timer id |
|
71 */ |
|
72 static CUsbPersonalitySwitch * NewL(MUsbPersonalitySwitchObserver* aObserver); |
|
73 |
|
74 /** |
|
75 * Destructor. |
|
76 */ |
|
77 virtual ~CUsbPersonalitySwitch(); |
|
78 |
|
79 /** |
|
80 * calls RunL after aMilliseconds |
|
81 * @param aMilliseconds time in millisecs |
|
82 */ |
|
83 TInt SwitchPersonalityL(TUint32 aDeviceId, TInt aPersonalityToBeSet); |
|
84 |
|
85 void CancelSwitchPersonalityL(); |
|
86 |
|
87 public: |
|
88 |
|
89 // from base class CActive |
|
90 /** |
|
91 * Called when request is completed |
|
92 */ |
|
93 void RunL(); |
|
94 |
|
95 /** |
|
96 * called when RunL leaves |
|
97 * @param aError error code |
|
98 * @return error code |
|
99 */ |
|
100 TInt RunError(TInt aError); |
|
101 |
|
102 /** |
|
103 * Called when request is cancelled |
|
104 */ |
|
105 void DoCancel(); |
|
106 |
|
107 private: |
|
108 |
|
109 /** |
|
110 * Default constructor |
|
111 * @param aObserver will get call back |
|
112 * @param aTimerId timer id |
|
113 */ |
|
114 CUsbPersonalitySwitch(MUsbPersonalitySwitchObserver* aObserver); |
|
115 |
|
116 /** |
|
117 * 2nd phase construction |
|
118 */ |
|
119 void ConstructL(); |
|
120 |
|
121 void Reset(); |
|
122 |
|
123 private: |
|
124 // data |
|
125 |
|
126 /** |
|
127 * Observer |
|
128 * not own |
|
129 */ |
|
130 MUsbPersonalitySwitchObserver* iObserver; |
|
131 |
|
132 RUsbInterface iUsbInterface; |
|
133 |
|
134 /** |
|
135 * timer id |
|
136 */ |
|
137 TInt iPersonalityToBeSet; |
|
138 |
|
139 RUsbInterface::TUsbTransferRequestDetails iTransfer; |
|
140 |
|
141 RBuf8 iSendData; |
|
142 |
|
143 RBuf8 iRcvData; |
|
144 |
|
145 TState iState; |
|
146 }; |
|
147 |
|
148 #endif // C_USBPERSONALITYSWITCH_H |