1 /* |
|
2 * Copyright (c) 2010 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: The repository of remote devices from BT registry |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef BTDEVICEREPOSITORYIMPL_H |
|
19 #define BTDEVICEREPOSITORYIMPL_H |
|
20 |
|
21 #include <bttypes.h> |
|
22 #include <bt_sock.h> |
|
23 #include <btmanclient.h> |
|
24 #include <e32property.h> |
|
25 #include <btengconnman.h> |
|
26 #include <btservices/btsimpleactive.h> |
|
27 #include <btservices/btdevextension.h> |
|
28 |
|
29 class MBtDevRepositoryObserver; |
|
30 |
|
31 /** |
|
32 * Class CBtDevRepositoryImpl |
|
33 * |
|
34 * This class keep a storage of remote device information. |
|
35 * |
|
36 */ |
|
37 NONSHARABLE_CLASS( CBtDevRepositoryImpl ) : |
|
38 public CBase, |
|
39 public MBtSimpleActiveObserver, |
|
40 public MBTEngConnObserver |
|
41 { |
|
42 public: |
|
43 |
|
44 /** |
|
45 * Two-phase constructor |
|
46 */ |
|
47 static CBtDevRepositoryImpl* NewL(); |
|
48 |
|
49 /** |
|
50 * Destructor |
|
51 */ |
|
52 ~CBtDevRepositoryImpl(); |
|
53 |
|
54 /** |
|
55 * Add an observer to this reposity for receivng repository update |
|
56 * events. |
|
57 * @param aObserver the observer to be added. |
|
58 */ |
|
59 void AddObserverL( MBtDevRepositoryObserver* aObserver ); |
|
60 |
|
61 /** |
|
62 * Remove an observer from this repository. |
|
63 * @param aObserver the observer to be removed. |
|
64 */ |
|
65 void RemoveObserver( MBtDevRepositoryObserver* aObserver ); |
|
66 |
|
67 /** |
|
68 * Tells if this repository has finished the initialization. |
|
69 * Initialization completion means the repository has retieved all |
|
70 * Bluetooth devices from BT registry, and it is subscribing to |
|
71 * registry update events. |
|
72 */ |
|
73 TBool IsInitialized() const; |
|
74 |
|
75 /** |
|
76 * Gets all devices in this repository. |
|
77 * @return the device list. |
|
78 */ |
|
79 const RDevExtensionArray& AllDevices() const; |
|
80 |
|
81 /** |
|
82 * Get a specific device by the given address. |
|
83 * @param aAddr the address of the device to be retrieved |
|
84 * @return the device pointer, NULL if the device is unavailable. |
|
85 */ |
|
86 const CBtDevExtension* Device( const TBTDevAddr& aAddr ) const; |
|
87 |
|
88 /** |
|
89 * Forces the repository to initialize its data store. |
|
90 * At Initialization completion, corresponding callback will be invoked. |
|
91 * Initialization completion means the repository has retieved all |
|
92 * Bluetooth devices from BT registry, and it is subscribing to |
|
93 * registry update events. |
|
94 * |
|
95 */ |
|
96 void ReInitialize(); |
|
97 |
|
98 /** |
|
99 * Returns the service (limited to services managed in bteng scope) |
|
100 * level connection status of the specified device. |
|
101 * |
|
102 * @param aAddr the address of the device |
|
103 * @return one of TBTEngConnectionStatus enums |
|
104 */ |
|
105 //TBTEngConnectionStatus IsDeviceConnected( const TBTDevAddr& aAddr ); |
|
106 |
|
107 private: |
|
108 |
|
109 // from MBtSimpleActiveObserver |
|
110 |
|
111 /** |
|
112 * Callback from RunL() to notify that an outstanding request has completed. |
|
113 * |
|
114 * @since Symbian^4 |
|
115 * @param aActive Pointer to the active object that completed. |
|
116 * @param aStatus The status of the completed request. |
|
117 */ |
|
118 void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus ); |
|
119 |
|
120 /** |
|
121 * Callback from Docancel() for handling cancelation of an outstanding request. |
|
122 * |
|
123 * @since Symbian^4 |
|
124 * @param aId The ID that identifies the outstanding request. |
|
125 */ |
|
126 void CancelRequest( TInt aRequestId ); |
|
127 |
|
128 /** |
|
129 * Callback from RunError() to notify that an error has occurred in RunL. |
|
130 * |
|
131 * @since Symbian^4 |
|
132 * @param aActive Pointer to the active object that completed. |
|
133 * @param aError The error occurred in RunL. |
|
134 */ |
|
135 void HandleError( CBtSimpleActive* aActive, TInt aError ); |
|
136 |
|
137 // From MBTEngConnObserver |
|
138 |
|
139 /** |
|
140 * Indicates to the caller that a service-level connection has completed. |
|
141 * This function is called for both incoming and outgoing connections. |
|
142 * This function is also called when an outgoing connection request fails, |
|
143 * e.g. with error code KErrCouldNotConnect. |
|
144 * When this function is called, new commands can be issued to the |
|
145 * CBTEngConnMan API immediately. |
|
146 * @param aAddr The address of the remote device. |
|
147 * @param aErr Status information of the connection. KErrNone if the |
|
148 * connection succeeded, otherwise the error code with |
|
149 * which the outgoing connection failed. KErrAlreadyExists |
|
150 * is returned if there already is an existing connection |
|
151 * for the selected profile(s), or otherwise e.g. |
|
152 * KErrCouldNotConnect or KErrDisconnected for indicating |
|
153 * connection problems. |
|
154 * @param aConflicts If there already is a connection for the selected |
|
155 * profile(s) of an outgoing connection request (the |
|
156 * selection is performed by BTEng), then this array |
|
157 * contains the bluetooth device addresses of the |
|
158 * remote devices for those connections. |
|
159 */ |
|
160 void ConnectComplete( TBTDevAddr& aAddr, TInt aErr, |
|
161 RBTDevAddrArray* aConflicts = NULL ); |
|
162 |
|
163 /** |
|
164 * Indicates to the caller that a service-level connection has disconnected. |
|
165 * When this function is called, new commands can be issued to the |
|
166 * CBTEngConnMan API immediately. |
|
167 * |
|
168 * @param aAddr The address of the remote device. |
|
169 * @param aErr The error code with which the disconnection occured. |
|
170 * KErrNone for a normal disconnection, |
|
171 * or e.g. KErrDisconnected if the connection was lost. |
|
172 */ |
|
173 void DisconnectComplete( TBTDevAddr& aAddr, TInt aErr ); |
|
174 |
|
175 private: |
|
176 |
|
177 /** |
|
178 * C++ default constructor |
|
179 */ |
|
180 CBtDevRepositoryImpl(); |
|
181 |
|
182 /** |
|
183 * Symbian 2nd-phase constructor |
|
184 */ |
|
185 void ConstructL(); |
|
186 |
|
187 /** |
|
188 * Creates a registry view which shall contain all remote devices. |
|
189 */ |
|
190 void CreateRemoteDeviceView(); |
|
191 |
|
192 /** |
|
193 * retrieves remote devices from registry. |
|
194 */ |
|
195 void GetRemoteDevicesL(); |
|
196 |
|
197 /** |
|
198 * handles the completion of paired device view creation |
|
199 */ |
|
200 void HandleCreateRemoteDeviceViewCompletedL( TInt aStatus); |
|
201 |
|
202 /** |
|
203 * handles the completion of getting paired devices |
|
204 */ |
|
205 void HandleGetRemoteDevicesCompletedL( TInt aStatus ); |
|
206 |
|
207 /** |
|
208 * Copy the remote devices to internal array storage. |
|
209 */ |
|
210 void UpdateRemoteDeviceRepositoryL(); |
|
211 |
|
212 private: |
|
213 |
|
214 /** |
|
215 * The observers |
|
216 * do not own them. |
|
217 */ |
|
218 RPointerArray<MBtDevRepositoryObserver> iObservers; |
|
219 |
|
220 /** |
|
221 * Registry sub session for remote device db. |
|
222 * not own |
|
223 */ |
|
224 RBTRegistry iBTRegistry; |
|
225 |
|
226 // own. |
|
227 RBTRegServ iBTRegServ; |
|
228 |
|
229 /** |
|
230 * AO for registry operations |
|
231 * own. |
|
232 */ |
|
233 CBtSimpleActive* iRegistryActive; |
|
234 |
|
235 /** |
|
236 * the counter of not handled registry events. |
|
237 */ |
|
238 TInt iNotHandledRegEventCounter; |
|
239 |
|
240 /** |
|
241 * temporary instance to retrieve paired devices. |
|
242 * own. |
|
243 */ |
|
244 CBTRegistryResponse* iRegRespRemoteDevices; |
|
245 |
|
246 /** |
|
247 * Property containing the BT registry change monitoring key |
|
248 * own. |
|
249 */ |
|
250 RProperty iBtRegistryKey; |
|
251 |
|
252 /** |
|
253 * AO for subscribing registry PubSub key |
|
254 * own. |
|
255 */ |
|
256 CBtSimpleActive* iRegistryKeyActive; |
|
257 |
|
258 /** |
|
259 * For connection status |
|
260 */ |
|
261 CBTEngConnMan* iBtengConn; |
|
262 |
|
263 /** |
|
264 * contains the list of all devices. |
|
265 * own. |
|
266 */ |
|
267 RDevExtensionArray iDevices; |
|
268 |
|
269 TInt iInitialized; |
|
270 |
|
271 }; |
|
272 |
|
273 #endif /*BTDEVICEREPOSITORYIMPL_H*/ |
|