|
1 /* |
|
2 * ============================================================================ |
|
3 * Name : btnotifconnectiontracker.h |
|
4 * Part of : bluetoothengine / btnotif |
|
5 * Description : Bluetooth connection tracker and manager. |
|
6 * |
|
7 * Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
8 * All rights reserved. |
|
9 * This component and the accompanying materials are made available |
|
10 * under the terms of "Eclipse Public License v1.0" |
|
11 * which accompanies this distribution, and is available |
|
12 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
13 * |
|
14 * Initial Contributors: |
|
15 * Nokia Corporation - initial contribution. |
|
16 * |
|
17 * Contributors: |
|
18 * Nokia Corporation |
|
19 * ============================================================================ |
|
20 * Template version: 4.2 |
|
21 */ |
|
22 |
|
23 #ifndef BTNOTIFCONNECTIONTRACKER_H |
|
24 #define BTNOTIFCONNECTIONTRACKER_H |
|
25 |
|
26 |
|
27 #include <e32property.h> |
|
28 #include <btmanclient.h> |
|
29 #include <bluetooth/pairing.h> |
|
30 #include <btengconnman.h> |
|
31 #include <btservices/btsimpleactive.h> |
|
32 #include "btnotifserver.h" |
|
33 |
|
34 class CBTNotifConnection; |
|
35 class CBTNotificationManager; |
|
36 class CbtnotifConnectionTrackerTest; |
|
37 |
|
38 |
|
39 |
|
40 /** |
|
41 * CBTNotifConnectionTracker keeps track of remote device connections |
|
42 * |
|
43 * @since Symbian^4 |
|
44 */ |
|
45 NONSHARABLE_CLASS( CBTNotifConnectionTracker ) : public CBase, |
|
46 public MBluetoothPhysicalLinksNotifier, |
|
47 public MBTEngConnObserver, |
|
48 public MBtSimpleActiveObserver |
|
49 { |
|
50 |
|
51 public: |
|
52 |
|
53 /** |
|
54 * Two-phased constructor. |
|
55 * @param aServer Pointer to our parent |
|
56 */ |
|
57 static CBTNotifConnectionTracker* NewL( CBTNotifServer* aServer ); |
|
58 |
|
59 /** |
|
60 * Destructor. |
|
61 */ |
|
62 virtual ~CBTNotifConnectionTracker(); |
|
63 |
|
64 /** |
|
65 * Get a pointer to the btnotif server object. |
|
66 * |
|
67 * @since Symbian^4 |
|
68 * @return The server. |
|
69 */ |
|
70 inline CBTNotifServer* Server() const |
|
71 { return iServer; } |
|
72 |
|
73 /** |
|
74 * Get a pointer to the notification manager. |
|
75 * This handle can be used for queueing notifications. |
|
76 * |
|
77 * @since Symbian^4 |
|
78 * @return The notification manager. |
|
79 */ |
|
80 inline CBTNotificationManager* NotificationManager() const |
|
81 { return iServer->NotificationManager(); } |
|
82 |
|
83 /** |
|
84 * Get the shared handle to BT registry server. |
|
85 * This handle can be used for creating subsessions. |
|
86 * |
|
87 * @since Symbian^4 |
|
88 * @return Session with BT registry server. |
|
89 */ |
|
90 inline RBTRegServ& RegistryServerSession() |
|
91 { return iBTRegistrySession; } |
|
92 |
|
93 /** |
|
94 * Get the handle to the socket server. |
|
95 * This handle can be used for creating subsessions. |
|
96 * |
|
97 * @since Symbian^4 |
|
98 * @return Session with the socket server. |
|
99 */ |
|
100 inline RSocketServ& SocketServerSession() |
|
101 { return iSockServ; } |
|
102 |
|
103 /** |
|
104 * Get the handle to the Bluetooth pairing server. |
|
105 * This handle can be used for creating subsessions. |
|
106 * |
|
107 * @since Symbian^4 |
|
108 * @return Session with the socket server or NULL. |
|
109 */ |
|
110 inline RBluetoothPairingServer* PairingServerSession() |
|
111 { return iPairingServ; } |
|
112 |
|
113 /** |
|
114 * Processes a message from a notifier client related to connections. |
|
115 * |
|
116 * @since Symbian^4 |
|
117 * @param aMessage The message containing the details of the client request. |
|
118 */ |
|
119 void DispatchNotifierMessageL( const RMessage2& aMessage ); |
|
120 |
|
121 /** |
|
122 * Handle a request related to pairing. |
|
123 * |
|
124 * @since Symbian^4 |
|
125 * @param aUid The UID of the notification request. |
|
126 */ |
|
127 void HandleBondingRequestL( const RMessage2& aMessage ); |
|
128 |
|
129 /** |
|
130 * Handle a change in the number of physical connections. |
|
131 * This also handles the case where a connection monitor has finished |
|
132 * its processing, and is now ready for removal. |
|
133 * |
|
134 * @since Symbian^4 |
|
135 */ |
|
136 void HandleLinkCountChangeL(); |
|
137 |
|
138 /** |
|
139 * Check repeated connection attempts, and record rejected/accepted queries. |
|
140 * |
|
141 * @since Symbian^4 |
|
142 * @param aDevice The details of the remote device for this query. |
|
143 * @param aAccepted ETrue if the user accepted the request, EFalse if rejected. |
|
144 * @return ETrue if the user should be queried for blocking this device, |
|
145 * EFalse if no query should be launched by the caller. |
|
146 */ |
|
147 TBool UpdateBlockingHistoryL( const CBTDevice* aDevice, TBool aAccepted ); |
|
148 |
|
149 // from base class MBluetoothPhysicalLinksNotifier |
|
150 /** Notification of a requested connection coming up. |
|
151 * If no error is reported, then that connection is ready for use. |
|
152 * |
|
153 * @since Symbian^4 |
|
154 * @param aErr the returned error |
|
155 */ |
|
156 virtual void HandleCreateConnectionCompleteL( TInt aErr ); |
|
157 |
|
158 /** Notification of a requested disconnection having taken place. |
|
159 * If no error is reported, then that connection has been closed. |
|
160 * |
|
161 * @since Symbian^4 |
|
162 * @param aErr the returned error |
|
163 */ |
|
164 virtual void HandleDisconnectCompleteL( TInt aErr ); |
|
165 |
|
166 /** Notification that all existing connections have been torn down. |
|
167 * If no error is reported, then there are no Bluetooth connections existing. |
|
168 * |
|
169 * @since Symbian^4 |
|
170 * @param aErr the returned error |
|
171 */ |
|
172 virtual void HandleDisconnectAllCompleteL( TInt aErr ); |
|
173 |
|
174 // from base class MBTEngConnObserver |
|
175 |
|
176 /** |
|
177 * From MBTEngConnObserver. |
|
178 * Indicates to the caller that a service-level connection has completed. |
|
179 * This function is called for both incoming and outgoing connections. |
|
180 * This function is also called when an outgoing connection request fails, |
|
181 * e.g. with error code KErrCouldNotConnect. |
|
182 * When this function is called, new commands can be issued to the |
|
183 * CBTEngConnMan API immediately. |
|
184 * |
|
185 * @since S60 v3.2 |
|
186 * @param aAddr The address of the remote device. |
|
187 * @param aErr Status information of the connection. KErrNone if the |
|
188 * connection succeeded, otherwise the error code with |
|
189 * which the outgoing connection failed. KErrAlreadyExists |
|
190 * is returned if there already is an existing connection |
|
191 * for the selected profile(s), or otherwise e.g. |
|
192 * KErrCouldNotConnect or KErrDisconnected for indicating |
|
193 * connection problems. |
|
194 * @param aConflicts If there already is a connection for the selected |
|
195 * profile(s) of an outgoing connection request (the |
|
196 * selection is performed by BTEng), then this array |
|
197 * contains the bluetooth device addresses of the |
|
198 * remote devices for those connections. |
|
199 */ |
|
200 virtual void ConnectComplete( TBTDevAddr& aAddr, TInt aErr, |
|
201 RBTDevAddrArray* aConflicts = NULL ); |
|
202 |
|
203 /** |
|
204 * From MBTEngConnObserver. |
|
205 * Indicates to the caller that a service-level connection has disconnected. |
|
206 * When this function is called, new commands can be issued to the |
|
207 * CBTEngConnMan API immediately. |
|
208 * |
|
209 * @since S60 v3.2 |
|
210 * @param aAddr The address of the remote device. |
|
211 * @param aErr The error code with which the disconnection occured. |
|
212 * KErrNone for a normal disconnection, |
|
213 * or e.g. KErrDisconnected if the connection was lost. |
|
214 */ |
|
215 virtual void DisconnectComplete( TBTDevAddr& aAddr, TInt aErr ); |
|
216 |
|
217 // from base class MBtSimpleActiveObserver |
|
218 |
|
219 /** |
|
220 * From MBtSimpleActiveObserver. |
|
221 * Callback to notify that an outstanding request has completed. |
|
222 * |
|
223 * @since Symbian^4 |
|
224 * @param aActive The active object helper that completed this request. |
|
225 * @param aStatus The status of the completed request. |
|
226 */ |
|
227 virtual void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ); |
|
228 |
|
229 /** |
|
230 * From MBtSimpleActiveObserver. |
|
231 * Callback for handling cancelation of an outstanding request. |
|
232 * |
|
233 * @since Symbian^4 |
|
234 * @param aId The ID that identifies the outstanding request. |
|
235 */ |
|
236 virtual void CancelRequest( TInt aRequestId ); |
|
237 |
|
238 /** |
|
239 * Callback to notify that an error has occurred in RunL. |
|
240 * |
|
241 * @param aActive Pointer to the active object that completed. |
|
242 * @param sError The error occured in RunL |
|
243 */ |
|
244 virtual void HandleError( CBtSimpleActive* aActive, |
|
245 TInt aError ); |
|
246 |
|
247 private: |
|
248 |
|
249 CBTNotifConnectionTracker( CBTNotifServer* aServer ); |
|
250 |
|
251 void ConstructL(); |
|
252 |
|
253 /** |
|
254 * Parse a client message and find the correct connection handler |
|
255 * for dispatching a request. |
|
256 * The parsed client message may be a request that is being served, |
|
257 * in case a cancel request has come in. The opcode identifies the |
|
258 * client message that is currently being dispatched. |
|
259 * |
|
260 * @since Symbian^4 |
|
261 * @param aOpcode The opcode of the original request. |
|
262 * @param aMessage The client message to parse. |
|
263 * @param aBuffer On return this contains the parameters read from the message. |
|
264 * @return The connection that is identified by the address in the |
|
265 * message, or NULL if none found. |
|
266 */ |
|
267 CBTNotifConnection* FindConnectionFromMessageL( TInt aOpcode, |
|
268 const RMessage2& aMessage, TDes8& aBuffer ); |
|
269 |
|
270 /** |
|
271 * Parse the Bluetooth address from a request for some notification. |
|
272 * |
|
273 * @since Symbian^4 |
|
274 * @param aUid The UID of the notification request. |
|
275 * @param aParamsBuf Descriptor containing the parameter read from the |
|
276 * client message. |
|
277 * @return Bluetooth address parsed from the descriptor. |
|
278 */ |
|
279 TBTDevAddr ParseAddressL( TInt aUid, const TDesC8& aParamsBuf ) const; |
|
280 |
|
281 /** |
|
282 * Find the handler of a specific connection. |
|
283 * |
|
284 * @since Symbian^4 |
|
285 * @param aAddr The remote device address identifying the connection. |
|
286 * @return Connnection handler or NULL; |
|
287 */ |
|
288 CBTNotifConnection* FindConnectionHandler( const TBTDevAddr& aAddr ) const; |
|
289 |
|
290 /** |
|
291 * Record and check the time between connection attempts. |
|
292 * |
|
293 * @since Symbian^4 |
|
294 * @param aAccepted ETrue if the user accepted the request, EFalse if rejected. |
|
295 * @return EFalse if the attempt followed the previous attempt too fast, |
|
296 * otherwise ETrue. |
|
297 */ |
|
298 TBool RecordConnectionAttempts( TBool aAccepted ); |
|
299 |
|
300 private: // data |
|
301 |
|
302 /** |
|
303 * PubSub key for tracking the number of connections. |
|
304 */ |
|
305 RProperty iLinkCount; |
|
306 |
|
307 // ToDo: remove this when registry notifications API is available!! |
|
308 /** |
|
309 * PubSub key for tracking registry changes. |
|
310 */ |
|
311 RProperty iRegistryChange; |
|
312 |
|
313 /** |
|
314 * Helper active object for observing the link count. |
|
315 * Own. |
|
316 */ |
|
317 CBtSimpleActive* iRegistryActive; |
|
318 // End ToDo |
|
319 |
|
320 /** |
|
321 * Array of pointers to observers of individual connections. |
|
322 */ |
|
323 RPointerArray<CBTNotifConnection> iConnArray; |
|
324 // RHashMap<TBTDevAddr,CBTNotifConnection*> iConnArray; |
|
325 |
|
326 /** |
|
327 * Time of the last denied connection attempt. |
|
328 */ |
|
329 TInt64 iLastReject; |
|
330 |
|
331 /** |
|
332 * Array of device addresses that the user has denied access. |
|
333 */ |
|
334 RArray<TBTDevAddr> iDeniedRequests; |
|
335 |
|
336 /** |
|
337 * Single session with BTRegistry, to be used for subsessions. |
|
338 */ |
|
339 RBTRegServ iBTRegistrySession; |
|
340 |
|
341 /** |
|
342 * Single session with the socket server, to be used for subsessions. |
|
343 */ |
|
344 RSocketServ iSockServ; |
|
345 |
|
346 /** |
|
347 * Address placeholder for receiving secure simple pairing results. |
|
348 */ |
|
349 TBTDevAddr iSspResultAddr; |
|
350 |
|
351 /** |
|
352 * Session with pairing server for receiving secure simple pairing results. |
|
353 */ |
|
354 RBluetoothPairingResult iSspResultSession; |
|
355 |
|
356 /** |
|
357 * Single session with the pairing server, to be used for subsessions. |
|
358 * Own. |
|
359 */ |
|
360 RBluetoothPairingServer* iPairingServ; |
|
361 |
|
362 /** |
|
363 * Object for managing the piconet. |
|
364 * Own. |
|
365 */ |
|
366 CBTEngConnMan* iConnMan; |
|
367 |
|
368 /** |
|
369 * Object for managing the piconet. |
|
370 * Own. |
|
371 */ |
|
372 CBluetoothPhysicalLinks* iPhyLinks; |
|
373 |
|
374 /** |
|
375 * Helper active object for observing the link count. |
|
376 * Own. |
|
377 */ |
|
378 CBtSimpleActive* iLinkCountActive; |
|
379 |
|
380 /** |
|
381 * Helper active object for receiving secure simple pairing results. |
|
382 * Own. |
|
383 */ |
|
384 CBtSimpleActive* iSspResultActive; |
|
385 |
|
386 /** |
|
387 * Reference to our parent the server class. |
|
388 * Not own. |
|
389 */ |
|
390 CBTNotifServer* iServer; |
|
391 |
|
392 BTUNITTESTHOOK |
|
393 |
|
394 }; |
|
395 |
|
396 #endif // BTNOTIFCONNECTIONTRACKER_H |