1 /* |
|
2 * Copyright (c) 2007 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: Handles remote personality - related requests |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CREMOTEPERSONALITYHANDLER_H |
|
20 #define CREMOTEPERSONALITYHANDLER_H |
|
21 |
|
22 #include <cusbdevicecontrolplugin.h> |
|
23 |
|
24 class RUsbWatcher; |
|
25 class RUsb; |
|
26 class RDevUsbcClient; |
|
27 class CSetPersonality; |
|
28 |
|
29 struct TPersonality |
|
30 { |
|
31 |
|
32 TUint8 iId; // Personality id |
|
33 TUint8 iIndex; // Index of a string descriptor |
|
34 |
|
35 }; |
|
36 |
|
37 /** |
|
38 * Setup packet interpretation |
|
39 * |
|
40 * |
|
41 * @lib usbdevcon.lib |
|
42 * @since S60 v.5.0 |
|
43 */ |
|
44 class TSetupPacket |
|
45 { |
|
46 public: |
|
47 |
|
48 /** |
|
49 * Decodes buffer as a SetupPacket |
|
50 * |
|
51 * @since S60 v.5.0 |
|
52 * @param aSetupPacket incoming buffer to be decoded |
|
53 */ |
|
54 void Decode(const RBuf8& aSetupPacket); |
|
55 |
|
56 public: |
|
57 |
|
58 TUint8 iType; // control message type |
|
59 TInt iRequest; // request; has type TInt because can be negative: CRemotePersonalityHandler::EUnknown; |
|
60 TUint16 iValue; // value |
|
61 TUint16 iIndex; // index |
|
62 TUint16 iLength; // length |
|
63 } ; |
|
64 |
|
65 /** |
|
66 * Remote Personality Requests handler |
|
67 * |
|
68 * @lib usbdevcon.lib |
|
69 * @since S60 v.5.0 |
|
70 */ |
|
71 |
|
72 class CRemotePersonalityHandler : public CUsbCMHandler |
|
73 { |
|
74 |
|
75 public: |
|
76 |
|
77 /** Last result */ |
|
78 enum TLastResult |
|
79 { |
|
80 ESuccess = 0x00, |
|
81 EUndefinedError = 0x01, |
|
82 EInvalidRequest= 0x02, |
|
83 ERequestIsNotSupported= 0x03, |
|
84 EFeatureIsNotSupported= 0x04, |
|
85 ENonExistingPersonality=0x10, |
|
86 EDataTransferInProgress=0x11, |
|
87 EEntityIsLocked= 0x12, |
|
88 ENonExistingEntity= 0x20, |
|
89 EInvalidLockState= 0x21, |
|
90 EInvalidPassword= 0x22, |
|
91 ENoAttemptsLeft= 0x23 |
|
92 |
|
93 // 0x80 ..0xFE reserved for vendor usage |
|
94 |
|
95 }; |
|
96 |
|
97 /** Requests */ |
|
98 enum TRequest |
|
99 { |
|
100 EUnknown = -1, |
|
101 EGetAllPersonalities = 0x82, |
|
102 EGetLastResult = 0x84, |
|
103 EGetPersonalityDescriptor = 0x86, |
|
104 EGetPersonality = 0x88, |
|
105 ESetPersonality = 0x89, |
|
106 EGetLockState = 0x8A, |
|
107 ESetLockState = 0x8B |
|
108 }; |
|
109 |
|
110 /** |
|
111 * Two-phased constructor. |
|
112 * |
|
113 * @since S60 v.5.0 |
|
114 * @return Constructed instance |
|
115 */ |
|
116 static CRemotePersonalityHandler* NewL(); |
|
117 |
|
118 /** |
|
119 * Destructor. |
|
120 * |
|
121 * @since S60 v.5.0 |
|
122 */ |
|
123 virtual ~CRemotePersonalityHandler(); |
|
124 |
|
125 /** |
|
126 * Called back when SetPersonality request is completed |
|
127 * @param aResult Result of the SetPersonality request |
|
128 * @since S60 v.5.0 |
|
129 */ |
|
130 void SetPersonalityCallBack(TLastResult aResult); |
|
131 |
|
132 // From MUsbCMHandler |
|
133 |
|
134 /** |
|
135 * Handler's Handle |
|
136 * |
|
137 * @since S60 v.5.0 |
|
138 * @param aSetupPacket request to be handled |
|
139 * @param aData Either data from host to device, or data from device to host |
|
140 * @return Errorcode |
|
141 */ |
|
142 TInt Handle(const RBuf8& aSetupPacket, RBuf8& aData); |
|
143 |
|
144 /** |
|
145 * Initializer |
|
146 * |
|
147 * @since S60 v.5.0 |
|
148 * @param aLdd Link to LDD services |
|
149 * @param aUsbWatcher Link to USB Watcher services |
|
150 * @param aUsbManager Link to USB Manager services |
|
151 */ |
|
152 void Initialize(RDevUsbcClient& aLdd, RUsbWatcher& aUsbWatcher, RUsb& aUsbManager); |
|
153 |
|
154 private: |
|
155 |
|
156 /** |
|
157 * Default constructor. |
|
158 * |
|
159 * @since S60 v.5.0 |
|
160 */ |
|
161 CRemotePersonalityHandler(); |
|
162 |
|
163 /** |
|
164 * Two-phased constructor. |
|
165 * |
|
166 * @since S60 v.5.0 |
|
167 */ |
|
168 void ConstructL(); |
|
169 |
|
170 /** |
|
171 * Internal handler - leaves if error |
|
172 * |
|
173 * @since S60 v.5.0 |
|
174 * @param aSetupPacket request to be handled |
|
175 * @param aData Either data from host to device, or data from device to host |
|
176 */ |
|
177 void DoHandleL(const RBuf8& aSetupPacket, RBuf8& aData); |
|
178 |
|
179 /** |
|
180 * Handles GET_ALL_PERSONALITIES request |
|
181 * |
|
182 * @since S60 v.5.0 |
|
183 * @param aData Contains result on exit |
|
184 */ |
|
185 void GetPersonalitiesL(RBuf8& aData); |
|
186 |
|
187 /** |
|
188 * Handles SET_PERSONALITY request |
|
189 * |
|
190 * @since S60 v.5.0 |
|
191 */ |
|
192 void SetPersonalityL(); |
|
193 |
|
194 /** |
|
195 * Handles GET_LAST_RESULT request |
|
196 * @param aData Last result |
|
197 * @since S60 v.5.0 |
|
198 */ |
|
199 void GetLastResultL(RBuf8& aData); |
|
200 |
|
201 /** |
|
202 * Read personalities from USB Manager to iPersonalities |
|
203 * |
|
204 * @since S60 v.5.0 |
|
205 */ |
|
206 void ReadPersonalitiesL(); |
|
207 |
|
208 /** |
|
209 * Saves personalities descriptions to USB standard strings descriptors |
|
210 * |
|
211 * @since S60 v.5.0 |
|
212 */ |
|
213 void SavePersonalitiesStringsL(); |
|
214 |
|
215 /** |
|
216 * Check if mapping of ids is needed |
|
217 * |
|
218 * @since S60 v.5.0 |
|
219 */ |
|
220 TBool IsMappingNeededL(); |
|
221 |
|
222 /** |
|
223 * Maps old personality ids (3.2) to new ones (5.0) |
|
224 * |
|
225 * @since S60 v.5.0 |
|
226 */ |
|
227 TInt MapPersonalityIdFromDeviceToHostL(TInt aPersonalityId); |
|
228 |
|
229 /** |
|
230 * Maps old personality ids (3.2) to new ones (5.0) |
|
231 * |
|
232 * @since S60 v.5.0 |
|
233 */ |
|
234 TInt MapPersonalityIdFromHostToDeviceL(TInt aPersonalityId); |
|
235 |
|
236 private: // data |
|
237 |
|
238 /** |
|
239 * Result of the last operation |
|
240 * |
|
241 */ |
|
242 TLastResult iLastResult; |
|
243 |
|
244 /** |
|
245 * USB watcher |
|
246 * Not owns. |
|
247 */ |
|
248 RUsbWatcher* iUsbWatcher; |
|
249 |
|
250 /** |
|
251 * USB Manager |
|
252 * Not owns. |
|
253 */ |
|
254 RUsb* iUsbManager; |
|
255 |
|
256 /** |
|
257 * USB client |
|
258 * Not owns. |
|
259 */ |
|
260 RDevUsbcClient* iLdd; |
|
261 |
|
262 /** |
|
263 * Request, being processed currently |
|
264 * |
|
265 */ |
|
266 TSetupPacket iSetupPacket; |
|
267 |
|
268 /** |
|
269 * Supported personalities |
|
270 * |
|
271 */ |
|
272 RArray<TPersonality> iPersonalities; |
|
273 |
|
274 /** |
|
275 * SetPersonality request handler |
|
276 * |
|
277 */ |
|
278 CSetPersonality* iSetPersonalityHandler; |
|
279 |
|
280 /** |
|
281 * ETrue if mapping is needed from old ids set to new one and vice versa |
|
282 * |
|
283 */ |
|
284 TBool iMappingIsNeeded; |
|
285 |
|
286 }; |
|
287 |
|
288 #endif // CREMOTEPERSONALITYHANDLER_H |
|