|
1 /* |
|
2 * Copyright (c) 2008 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: Declares main application class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __BTHIDSERVER_H__ |
|
20 #define __BTHIDSERVER_H__ |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <es_sock.h> |
|
24 #include <btmanclient.h> |
|
25 #include <f32file.h> |
|
26 #include <ecom/ecom.h> |
|
27 #include <btdevice.h> |
|
28 #include <e32std.h> |
|
29 #include <bttypes.h> //linkkey |
|
30 #include <btnotif.h> |
|
31 |
|
32 |
|
33 #include "hidinterfaces.h" |
|
34 #include "bthidclient.h" |
|
35 #include "btconnectionobserver.h" |
|
36 #include "listenerobserver.h" |
|
37 #include "genericserver.h" |
|
38 #include "hidlayoutids.h" |
|
39 #include "genericactive.h" |
|
40 |
|
41 class CBTConnection; |
|
42 class CSocketListener; |
|
43 class CBTHidConnection; |
|
44 class CBTHidDevice; |
|
45 class CGenericHid; |
|
46 class CBTHidNotifierHelper; |
|
47 |
|
48 /** |
|
49 * An instance of class CBTHidServer is the main server class. |
|
50 * |
|
51 * @since Series 60 2.6 |
|
52 */ |
|
53 class CBTHidServer : public CGenericServer, |
|
54 public MBTConnectionObserver, |
|
55 public MListenerObserver, |
|
56 public MTransportLayer |
|
57 { |
|
58 public: |
|
59 |
|
60 /*! |
|
61 Create a CBTHidServer object using two phase construction, |
|
62 and return a pointer to the created object |
|
63 @result Pointer to created CBTHidServer object |
|
64 */ |
|
65 static CBTHidServer* NewL(); |
|
66 |
|
67 /*! |
|
68 Create a CBTHidServer object using two phase construction, |
|
69 and return a pointer to the created object, leaving a pointer to the |
|
70 object on the cleanup stack. |
|
71 @result Pointer to created CBTHidServer object. |
|
72 */ |
|
73 static CBTHidServer* NewLC(); |
|
74 |
|
75 /*! |
|
76 Destroy the object and release all memory objects. |
|
77 */ |
|
78 ~CBTHidServer(); |
|
79 |
|
80 /*! |
|
81 Panic the client. |
|
82 @param aMessage the message channel to the client |
|
83 @param aReason the reason code for the panic. |
|
84 */ |
|
85 static void PanicClient(const RMessage2& aMessage, TInt aReason); |
|
86 |
|
87 void StartShutdownTimerIfNoSession(); |
|
88 |
|
89 void CancelShutdownTimer(); |
|
90 |
|
91 /*! |
|
92 Increments the count of the active sessions for this server. |
|
93 */ |
|
94 void IncrementSessions(); |
|
95 |
|
96 /*! |
|
97 Decrements the count of the active sessions for this server. . |
|
98 If no more sessions are in use the server terminates. |
|
99 */ |
|
100 void DecrementSessions(); |
|
101 |
|
102 /*! |
|
103 Returns a count of the BT HID connections the server is managing. |
|
104 @result Number of connections |
|
105 */ |
|
106 TUint ConnectionCount(); |
|
107 |
|
108 /*! |
|
109 Gives access to the device details for a numbered connection. |
|
110 @param aConnID connection ID. |
|
111 @result Reference to a device details object |
|
112 */ |
|
113 CBTHidDevice& ConnectionDetailsL(TInt aConnID); |
|
114 |
|
115 void CleanOldConnection(TInt aConnID); |
|
116 /*! |
|
117 Asks the server to create a new connection object. |
|
118 @result ID for the connection |
|
119 */ |
|
120 TInt NewConnectionL(); |
|
121 |
|
122 /*! |
|
123 Asks the server to do a first-time connection to a device. |
|
124 @param aConnID ID of the connection returned from NewConnectionL |
|
125 */ |
|
126 void DoFirstConnectionL(TInt aConnID); |
|
127 |
|
128 /*! |
|
129 Asks the server to delete a new connection object |
|
130 @param aConnID ID of the connection returned from NewConnectionL |
|
131 */ |
|
132 void DeleteNewConnection(TInt aConnID); |
|
133 |
|
134 /* |
|
135 * Keep the connection alive, initial reconnect from HID device available... |
|
136 */ |
|
137 void DisconnectDeviceL(const TBTDevAddr& aAddress); |
|
138 void DisconnectAllDeviceL(); |
|
139 |
|
140 /** |
|
141 * Asks the server to disconnect (virtual cable unplug) a device totally, |
|
142 * remove the connection entry from the connection container. |
|
143 @param aAddress bluetooth address of the device to disconnect. |
|
144 */ |
|
145 void CloseBluetoothConnection(const TBTDevAddr& aAddress); |
|
146 void CloseAllBluetoothConnection(); |
|
147 |
|
148 /*! |
|
149 Finds out the connection status for a given Bluetooth address connected with HID profile |
|
150 @param aBDAddr reference to TBTAddr that is checked from Bluetooth registry |
|
151 @result TBTEngConnectionStatus |
|
152 */ |
|
153 TBTEngConnectionStatus ConnectStatus(const TBTDevAddr& aAddress); |
|
154 |
|
155 /*! |
|
156 Panic the server. |
|
157 @param aPanic panic code |
|
158 */ |
|
159 static void PanicServer(TInt aPanic); |
|
160 |
|
161 TBool GetConnectionAddress(TDes8& aAddressBuf); |
|
162 |
|
163 TBool IsAllowToConnectFromServerSide(TUint aDeviceSubClass); |
|
164 TBool IsAllowToConnectFromClientSide(TBTDevAddr devAddr); |
|
165 TUint GetDeviceSubClass(TBTDevAddr aDevAddr); |
|
166 TBool IsKeyboard(TUint aDeviceSubClass); |
|
167 TBool IsPointer(TUint aDeviceSubClass); |
|
168 |
|
169 TBTDevAddr ConflictAddress(); |
|
170 |
|
171 public: |
|
172 // from MBTConnectionObserver |
|
173 void HandleControlData(TInt aConnID, const TDesC8& aBuffer); |
|
174 |
|
175 void HandleCommandAck(TInt aConnID, TInt aStatus); |
|
176 |
|
177 void HandleInterruptData(TInt aConnID, const TDesC8& aBuffer); |
|
178 |
|
179 void FirstTimeConnectionComplete(TInt aConnID, TInt aStatus); |
|
180 |
|
181 void LinkLost(TInt aConnID); |
|
182 |
|
183 void LinkRestored(TInt aConnID); |
|
184 |
|
185 void Disconnected(TInt aConnID); |
|
186 |
|
187 void Unplugged(TInt aConnID); |
|
188 |
|
189 public: |
|
190 //from MListenerObserver |
|
191 void SocketAccepted(TUint aPort, TInt aErrorCode); |
|
192 |
|
193 public: |
|
194 //from MTransportLayer |
|
195 TUint CountryCodeL(TInt aConnID); |
|
196 |
|
197 TUint VendorIdL(TInt aConnID); |
|
198 |
|
199 TUint ProductIdL(TInt aConnID); |
|
200 |
|
201 void GetProtocolL(TInt aConnID, TUint16 aInterface); |
|
202 |
|
203 void SetProtocolL(TInt aConnID, TUint16 aValue, TUint16 aInterface); |
|
204 |
|
205 void GetReportL(TInt aConnID, TUint8 aReportType, TUint8 aReportID, |
|
206 TUint16 aInterface, TUint16 aLength); |
|
207 |
|
208 void SetReportL(TInt aConnID, TUint8 aReportType, TUint8 aReportID, |
|
209 TUint16 aInterface, const TDesC8& aReport); |
|
210 |
|
211 void DataOutL(TInt aConnID, TUint8 aReportID, TUint16 aInterface, |
|
212 const TDesC8& aReport); |
|
213 |
|
214 void GetIdleL(TInt aConnID, TUint8 aReportID, TUint16 aInterface); |
|
215 |
|
216 void SetIdleL(TInt aConnID, TUint8 aDuration, TUint8 aReportID, |
|
217 TUint16 aInterface); |
|
218 |
|
219 void NotifierRequestCompleted(); |
|
220 |
|
221 protected: |
|
222 // From CActive |
|
223 /*! |
|
224 Process any errors |
|
225 @param aError the leave code reported. |
|
226 */ |
|
227 TInt RunError(TInt aError); |
|
228 static TInt TimerFired(TAny* aThis); |
|
229 |
|
230 private: |
|
231 |
|
232 /*! |
|
233 Perform the first phase of two phase construction |
|
234 */ |
|
235 CBTHidServer(); |
|
236 |
|
237 /*! |
|
238 Perform the second phase construction of a CBTHidServer object |
|
239 */ |
|
240 void ConstructL(); |
|
241 |
|
242 /*! |
|
243 Shuts down socket listeners on error and inform user |
|
244 @param aError The error which caused the shutdown. |
|
245 */ |
|
246 void ShutdownListeners(TInt aError); |
|
247 |
|
248 /*! |
|
249 Retrieve the Connection object for a given ID. |
|
250 @param aConnID The connection ID. |
|
251 @return A pointer to a CBTHidConnection object. |
|
252 */ |
|
253 CBTHidConnection* IdentifyConnectionL(TInt aConnID) const; |
|
254 |
|
255 /*! |
|
256 Loads virtually-cabled device details from the filestore. |
|
257 @param aStoreName file to load from. |
|
258 */ |
|
259 void LoadVirtuallyCabledDevicesL(const TDesC& aStoreName); |
|
260 |
|
261 /*! |
|
262 Stores virtually-cabled device details from the filestore. |
|
263 @param aStoreName file to write to. |
|
264 */ |
|
265 void StoreVirtuallyCabledDevicesL(const TDesC& aStoreName); |
|
266 |
|
267 /*! |
|
268 Stores virtually-cabled device details from the filestore. |
|
269 (Non-Leaving Version) |
|
270 @param aStoreName file to write to. |
|
271 */ |
|
272 void StoreVirtuallyCabledDevices(const TDesC& aStoreName); |
|
273 |
|
274 /*! |
|
275 Updates all current sessions with the current status of a connection |
|
276 @param aDeviceDetails details of the device whose status has changed |
|
277 @param aState new state of the connection |
|
278 */ |
|
279 void InformClientsOfStatusChange(const CBTHidDevice& aDeviceDetails, |
|
280 TBTHidConnState aState); |
|
281 |
|
282 void GlobalNotify(const TBTDevAddr& aDeviceAddr, TBTHidConnState aState); |
|
283 |
|
284 TInt HandleAsyncRequest(const TBTDevAddr& aDeviceAddr, TInt note); |
|
285 |
|
286 void HandleAsyncRequestL(const TBTDevAddr& aDeviceAddr, TInt aNote); |
|
287 |
|
288 void InformStatusChange(const TBTDevAddr& aAddress, |
|
289 TBTHidConnState aState); |
|
290 /*! |
|
291 Inform the Generic HID of a new connection (and start the driver if required) |
|
292 @param aConnection a CBTHidConnection object for the device connected. |
|
293 @param aStartDriver ETrue to start the driver, EFalse otherwise. |
|
294 */ |
|
295 void |
|
296 GenericHIDConnectL(CBTHidConnection* aConnection, |
|
297 TBool aStartDriver); |
|
298 |
|
299 private: |
|
300 // From CServer2 |
|
301 |
|
302 /*! |
|
303 Create a time server session, and return a pointer to the created object |
|
304 @param aVersion version |
|
305 @result Pointer to new session |
|
306 */ |
|
307 CSession2* NewSessionL(const TVersion &aVersion, |
|
308 const RMessage2& aMessage) const; |
|
309 |
|
310 private: |
|
311 /* Internal function to override the security settings of Control channel |
|
312 * listener. Used if we are listening for unauthenticated/unauthorised device. |
|
313 * For example: Microsoft keyboard with Nokia 6630 PR#1 needs this. |
|
314 */ |
|
315 void CheckAndSetControlListenerSecurityL(TBool aSec); |
|
316 |
|
317 /*! The active session count */ |
|
318 TInt iSessionCount; |
|
319 |
|
320 /*! The file server session */ |
|
321 RFs iFs; |
|
322 |
|
323 /*! The socket server session */ |
|
324 RSocketServ iSocketServ; |
|
325 |
|
326 /*! A temporary socket to accept a connection on the control channel */ |
|
327 RSocket* iTempControl; |
|
328 |
|
329 /*! A temporary socket to accept a connection on the interrupt channel */ |
|
330 RSocket* iTempInterrupt; |
|
331 |
|
332 /*! Flag indicating the Autorisation setting on incoming connections */ |
|
333 TBool iAuthorisationFlag; |
|
334 |
|
335 /*! Socket listener for the control channel */ |
|
336 CSocketListener* iControlListener; |
|
337 |
|
338 /*! Socket listener for the interrupt channel */ |
|
339 CSocketListener* iInterruptListener; |
|
340 |
|
341 /*! The Generic HID object */ |
|
342 CGenericHid* iGenHID; |
|
343 |
|
344 /*! Main container index for the server */ |
|
345 CObjectConIx* iMasterContIndex; |
|
346 |
|
347 /*! Container for BT Connection Objects */ |
|
348 CObjectCon* iBTConnContainer; |
|
349 |
|
350 /*! Index for the BT Connection container */ |
|
351 CObjectIx* iBTConnIndex; |
|
352 |
|
353 /*! BT address of a Bluetooth device currently connected in conflict*/ |
|
354 TBTDevAddr iConflictAddr; |
|
355 |
|
356 /*! BT address of a Bluetooth device last used */ |
|
357 TBTDevAddr iLastUsedAddr; |
|
358 TBool iActiveState; |
|
359 |
|
360 //Shutdown Timer |
|
361 CPeriodic* iShutDownTimer; |
|
362 |
|
363 RNotifier iNotifier; |
|
364 |
|
365 RPointerArray<CBTHidNotifierHelper> iReqs; |
|
366 |
|
367 }; |
|
368 |
|
369 |
|
370 /** |
|
371 * This wraps up a UI Notification for the BTHidServer |
|
372 */ |
|
373 |
|
374 class CBTHidNotifierHelper : public CActive |
|
375 { |
|
376 public: |
|
377 |
|
378 static CBTHidNotifierHelper* NewL(CBTHidServer& aHidServer, TInt aNote, const TBTDevAddr& aDeviceAddr); |
|
379 |
|
380 ~CBTHidNotifierHelper(); |
|
381 |
|
382 void Start(); |
|
383 |
|
384 private: |
|
385 |
|
386 CBTHidNotifierHelper(CBTHidServer& aHidServer, TInt aNote, const TBTDevAddr& aDeviceAddr); |
|
387 |
|
388 void ConstructL(); |
|
389 void RunL(); |
|
390 void DoCancel(); |
|
391 |
|
392 private: |
|
393 |
|
394 CBTHidServer& iHidServer; |
|
395 |
|
396 RNotifier iNotifier; |
|
397 |
|
398 TPckgBuf<TInt> iNoResult; |
|
399 |
|
400 TBTGenericInfoNotiferParamsPckg iGenericInfoNotifierType; |
|
401 }; |
|
402 |
|
403 #endif |