|
1 /* |
|
2 * Copyright (c) 2006-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: Bluetooth Engine API for connection management functionality. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <e32base.h> |
|
21 #include <featmgr.h> |
|
22 #include <centralrepository.h> |
|
23 |
|
24 #include "btengconnman.h" |
|
25 #include "btengconnhandler.h" |
|
26 #include "debug.h" |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // C++ default constructor |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CBTEngConnMan::CBTEngConnMan( MBTEngConnObserver* aObserver ) |
|
35 : iObserver( aObserver ) |
|
36 { |
|
37 } |
|
38 |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // Symbian 2nd-phase constructor |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 void CBTEngConnMan::ConstructL() |
|
45 { |
|
46 TRACE_FUNC_ENTRY |
|
47 // Check if BT is supported at all |
|
48 FeatureManager::InitializeLibL(); |
|
49 TBool btSupported = FeatureManager::FeatureSupported( KFeatureIdBt ); |
|
50 FeatureManager::UnInitializeLib(); |
|
51 if( !btSupported ) |
|
52 { |
|
53 TRACE_INFO( ( _L( "[BTENGSETTINGS]\t ConstructL: BT not supported!!" ) ) ) |
|
54 User::Leave( KErrNotSupported ); |
|
55 } |
|
56 iConnHandler = CBTEngConnHandler::NewL( iObserver ); |
|
57 |
|
58 TRACE_FUNC_EXIT |
|
59 } |
|
60 |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // NewL |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 EXPORT_C CBTEngConnMan* CBTEngConnMan::NewL( MBTEngConnObserver* aObserver ) |
|
67 { |
|
68 CBTEngConnMan* self = CBTEngConnMan::NewLC( aObserver ); |
|
69 CleanupStack::Pop( self ); |
|
70 return self; |
|
71 } |
|
72 |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // NewLC |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 EXPORT_C CBTEngConnMan* CBTEngConnMan::NewLC( MBTEngConnObserver* aObserver ) |
|
79 { |
|
80 CBTEngConnMan* self = new( ELeave ) CBTEngConnMan( aObserver ); |
|
81 CleanupStack::PushL( self ); |
|
82 self->ConstructL(); |
|
83 return self; |
|
84 } |
|
85 |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // Destructor |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 CBTEngConnMan::~CBTEngConnMan() |
|
92 { |
|
93 TRACE_FUNC_ENTRY |
|
94 delete iConnHandler; |
|
95 } |
|
96 |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // ?implementation_description |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 EXPORT_C TInt CBTEngConnMan::Connect( const TBTDevAddr& aAddr, |
|
103 const TBTDeviceClass& aDeviceClass ) |
|
104 { |
|
105 TRACE_FUNC_ENTRY |
|
106 return iConnHandler->ConnectDevice( aAddr, aDeviceClass ); |
|
107 } |
|
108 |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // ?implementation_description |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 EXPORT_C void CBTEngConnMan::CancelConnect( const TBTDevAddr& aAddr ) |
|
115 { |
|
116 TRACE_FUNC_ENTRY |
|
117 (void) iConnHandler->CancelConnectDevice( aAddr ); |
|
118 } |
|
119 |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // ?implementation_description |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 EXPORT_C TInt CBTEngConnMan::Disconnect( const TBTDevAddr& aAddr, |
|
126 TBTDisconnectType aDiscType ) |
|
127 { |
|
128 TRACE_FUNC_ENTRY |
|
129 return iConnHandler->DisconnectDevice( aAddr, aDiscType ); |
|
130 } |
|
131 |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // ?implementation_description |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 EXPORT_C TInt CBTEngConnMan::IsConnected( const TBTDevAddr& aAddr, |
|
138 TBTEngConnectionStatus& aConnected ) |
|
139 { |
|
140 TRACE_FUNC_ENTRY |
|
141 return iConnHandler->IsDeviceConnected( aAddr, aConnected ); |
|
142 } |
|
143 |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // ?implementation_description |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 EXPORT_C TInt CBTEngConnMan::IsConnectable( const TBTDeviceClass& aDeviceClass, |
|
150 TBool& aConnectable ) |
|
151 { |
|
152 TRACE_FUNC_ENTRY |
|
153 return iConnHandler->IsDeviceConnectable( aDeviceClass, aConnectable ); |
|
154 } |
|
155 |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // ?implementation_description |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 EXPORT_C TInt CBTEngConnMan::SetObserver( MBTEngConnObserver* aObserver ) |
|
162 { |
|
163 TRACE_FUNC_ENTRY |
|
164 return iConnHandler->NotifyConnectionEvents( aObserver ); |
|
165 } |
|
166 |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // ?implementation_description |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 EXPORT_C void CBTEngConnMan::RemoveObserver() |
|
173 { |
|
174 TRACE_FUNC_ENTRY |
|
175 iConnHandler->CancelNotifyConnectionEvents(); |
|
176 } |
|
177 |
|
178 |
|
179 // --------------------------------------------------------------------------- |
|
180 // Get the connected addresses of all baseband connections. |
|
181 // --------------------------------------------------------------------------- |
|
182 // |
|
183 EXPORT_C TInt CBTEngConnMan::GetConnectedAddresses( RBTDevAddrArray& aAddrArray ) |
|
184 { |
|
185 TRACE_FUNC_ENTRY |
|
186 TRAPD( err, iConnHandler->GetConnectedAddressesL( aAddrArray, |
|
187 EBTProfileUndefined ) ); |
|
188 return err; |
|
189 } |
|
190 |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // Get the connected addresses for a specified profile (that is managed |
|
194 // through BT Engine). |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 EXPORT_C TInt CBTEngConnMan::GetConnectedAddresses( RBTDevAddrArray& aAddrArray, |
|
198 TBTProfile aConnectedProfile ) |
|
199 { |
|
200 TRACE_FUNC_ENTRY |
|
201 TRAPD( err, iConnHandler->GetConnectedAddressesL( aAddrArray, |
|
202 aConnectedProfile ) ); |
|
203 return err; |
|
204 } |
|
205 |
|
206 |
|
207 // --------------------------------------------------------------------------- |
|
208 // Initiate pairing with the specified device |
|
209 // --------------------------------------------------------------------------- |
|
210 // |
|
211 EXPORT_C TInt CBTEngConnMan::PairDevice( const TBTDevAddr& aAddr ) |
|
212 { |
|
213 TRACE_FUNC_ENTRY |
|
214 TBTDeviceClass deviceClass; |
|
215 return PairDevice( aAddr, deviceClass ); |
|
216 } |
|
217 |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // Initiate pairing with the specified device (which advertises |
|
221 // specified service class). |
|
222 // --------------------------------------------------------------------------- |
|
223 // |
|
224 EXPORT_C TInt CBTEngConnMan::PairDevice( const TBTDevAddr& aAddr, TBTDeviceClass aDeviceClass ) |
|
225 { |
|
226 TRACE_FUNC_ENTRY |
|
227 return iConnHandler->StartPairing( aAddr, aDeviceClass ); |
|
228 } |
|
229 |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // Cancels an ongoing pairing. |
|
233 // --------------------------------------------------------------------------- |
|
234 // |
|
235 EXPORT_C void CBTEngConnMan::CancelPairDevice() |
|
236 { |
|
237 TRACE_FUNC_ENTRY |
|
238 if( iConnHandler ) |
|
239 { |
|
240 iConnHandler->CancelPairing(); |
|
241 } |
|
242 } |
|
243 |
|
244 |
|
245 // --------------------------------------------------------------------------- |
|
246 // Tell BTEng to start observing the status of an ongoing pairing. |
|
247 // --------------------------------------------------------------------------- |
|
248 // |
|
249 EXPORT_C TInt CBTEngConnMan::StartPairingObserver( const TBTDevAddr& aAddr ) |
|
250 { |
|
251 TRACE_FUNC_ENTRY |
|
252 return CBTEngConnHandler::SetPairingObserver( aAddr, ETrue ); |
|
253 } |
|
254 |
|
255 |
|
256 // --------------------------------------------------------------------------- |
|
257 // Tell BTEng to stop observing the status of an ongoing pairing. |
|
258 // --------------------------------------------------------------------------- |
|
259 // |
|
260 EXPORT_C void CBTEngConnMan::PrepareDiscovery() |
|
261 { |
|
262 TRACE_FUNC_ENTRY |
|
263 (void) iConnHandler->PrepareDiscovery(); |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 // ?implementation_description |
|
268 // --------------------------------------------------------------------------- |
|
269 // |
|
270 EXPORT_C TInt CBTEngConnMan::StopPairingObserver( const TBTDevAddr& aAddr ) |
|
271 { |
|
272 TRACE_FUNC_ENTRY |
|
273 return CBTEngConnHandler::SetPairingObserver( aAddr, EFalse ); |
|
274 } |
|
275 |
|
276 // --------------------------------------------------------------------------- |
|
277 // Check if the remote device is connectable or not. |
|
278 // --------------------------------------------------------------------------- |
|
279 // |
|
280 EXPORT_C TInt CBTEngConnMan::IsConnectable( const TBTDevAddr& aAddr, |
|
281 const TBTDeviceClass& aDeviceClass, TBool& aConnectable ) |
|
282 { |
|
283 TRACE_FUNC_ENTRY |
|
284 return iConnHandler->IsDeviceConnectable( aAddr, aDeviceClass, aConnectable ); |
|
285 } |
|
286 |
|
287 // --------------------------------------------------------------------------- |
|
288 // Default implementation of BTEng ConnMan result observer. |
|
289 // --------------------------------------------------------------------------- |
|
290 // |
|
291 EXPORT_C void MBTEngConnObserver::PairingComplete( TBTDevAddr& aAddr, TInt aErr ) |
|
292 { |
|
293 (void) aAddr; |
|
294 (void) aErr; |
|
295 } |