2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 // @file FNetBtBluetoothManager.cpp
18 // @brief This is the implementation file for the BluetoothManager class.
21 #include <FNetBtBluetoothManager.h>
22 #include <FNetBtBluetoothDevice.h>
23 #include <FNetBtIBluetoothManagerEventListener.h>
24 #include <FNetBtIBluetoothDeviceEventListener.h>
25 #include <FBaseByteBuffer.h>
26 #include <FBaseColIList.h>
27 #include <FBaseSysLog.h>
28 #include <FSec_AccessController.h>
29 #include <FSys_SystemInfoImpl.h>
30 #include "FNetBt_BluetoothManagerImpl.h"
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Runtime;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Security;
37 namespace Tizen { namespace Net { namespace Bluetooth
40 BluetoothManager::BluetoothManager(void)
45 BluetoothManager::~BluetoothManager(void)
51 BluetoothManager::Construct(IBluetoothManagerEventListener& listener)
54 bool isBtSupported = false;
56 r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.bluetooth", isBtSupported);
57 SysTryReturnResult(NID_NET_BT, (r == E_SUCCESS) && (isBtSupported == true), E_UNSUPPORTED_OPERATION,
58 "Bluetooth is not supported.");
60 SysAssertf(__pImpl == null,
61 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
63 __pImpl = new (std::nothrow) _BluetoothManagerImpl;
65 SysTryReturnResult(NID_NET_BT, __pImpl != null, E_OUT_OF_MEMORY, "Creation of a __pImpl instance failed.");
67 r = __pImpl->Construct(listener);
79 BluetoothManager::Activate(void)
84 r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_ADMIN);
85 SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
86 "The application does not have the privilege to call this method.");
88 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
90 return __pImpl->Activate();
94 BluetoothManager::Deactivate(void)
99 r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_ADMIN);
100 SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
101 "The application does not have the privilege to call this method.");
103 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
105 return __pImpl->Deactivate();
109 BluetoothManager::IsAvailable(BluetoothConnectionType type) const
111 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
113 return __pImpl->IsAvailable(type);
116 const BluetoothDevice*
117 BluetoothManager::GetLocalDevice(void) const
120 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
122 return __pImpl->GetLocalDevice();
126 BluetoothManager::GetLocalDeviceAddress(void) const
128 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
130 return __pImpl->GetLocalDeviceAddress();
134 BluetoothManager::GetLocalDeviceName(void) const
136 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
138 return __pImpl->GetLocalDeviceName();
141 BluetoothDeviceStateType
142 BluetoothManager::GetLocalDeviceState() const
144 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
146 return __pImpl->GetLocalDeviceState();
150 BluetoothManager::IsActivated(void) const
152 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
154 return __pImpl->IsActivated();
157 BluetoothDiscoverableMode
158 BluetoothManager::GetDiscoverableMode(void) const
160 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
162 return __pImpl->GetDiscoverableMode();
166 BluetoothManager::GetRemainingTimeAsDiscoverable(void) const
168 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
170 return __pImpl->GetRemainingTimeAsDiscoverable();
174 BluetoothManager::IsDiscoveryInProgress(void) const
176 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
178 return __pImpl->IsDiscoveryInProgress();
182 BluetoothManager::SetLocalDeviceName(const Tizen::Base::String& deviceName)
184 result r = E_SUCCESS;
187 r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_ADMIN);
188 SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
189 "The application does not have the privilege to call this method.");
191 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
193 return __pImpl->SetLocalDeviceName(deviceName);
197 BluetoothManager::SetDiscoverableMode(BluetoothDiscoverableMode mode, int seconds)
199 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
201 // Privilege check will be done by Impl class
202 return __pImpl->SetDiscoverableMode(mode, seconds);
206 BluetoothManager::RefreshPairedDeviceList(void)
208 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
210 return __pImpl->RefreshPairedDeviceList();
213 const BluetoothDevice*
214 BluetoothManager::GetPairedDeviceByAddress(const Tizen::Base::ByteBuffer& deviceAddress) const
218 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
220 return __pImpl->GetPairedDeviceByAddress(deviceAddress);
224 BluetoothManager::GetPairedDeviceByAddressN(const Tizen::Base::ByteBuffer& deviceAddress) const
228 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
230 return __pImpl->GetPairedDeviceByAddressN(deviceAddress);
233 Tizen::Base::Collection::IList*
234 BluetoothManager::GetPairedDeviceByNameN(const Base::String& deviceName) const
238 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
240 return __pImpl->GetPairedDeviceByNameN(deviceName);
243 const BluetoothDevice*
244 BluetoothManager::GetPairedDeviceAt(int index) const
248 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
250 return __pImpl->GetPairedDeviceAt(index);
253 const Tizen::Base::Collection::IList*
254 BluetoothManager::GetPairedDeviceList(void) const
258 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
260 return __pImpl->GetPairedDeviceList();
263 Tizen::Base::Collection::IList*
264 BluetoothManager::GetPairedDeviceListN(void) const
268 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
270 return __pImpl->GetPairedDeviceListN();
274 BluetoothManager::SetBluetoothDeviceListener(IBluetoothDeviceEventListener* pListener)
276 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
278 return __pImpl->SetBluetoothDeviceListener(pListener);
282 BluetoothManager::StartDiscovery(void)
284 result r = E_SUCCESS;
287 r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_GAP);
288 SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
289 "The application does not have the privilege to call this method.");
291 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
293 return __pImpl->StartDiscovery();
297 BluetoothManager::CancelDiscovery(void)
299 result r = E_SUCCESS;
302 r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_GAP);
303 SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
304 "The application does not have the privilege to call this method.");
306 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
308 return __pImpl->CancelDiscovery();
312 BluetoothManager::RetrieveServiceList(const BluetoothDevice& pairedDevice)
314 result r = E_SUCCESS;
317 r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_GAP);
318 SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
319 "The application does not have the privilege to call this method.");
321 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
323 return __pImpl->RetrieveServiceList(pairedDevice);
327 BluetoothManager::Pair(const BluetoothDevice& remoteDevice)
329 result r = E_SUCCESS;
332 r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_GAP);
333 SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
334 "The application does not have the privilege to call this method.");
336 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
338 return __pImpl->Pair(remoteDevice);
342 BluetoothManager::CancelPair(void)
344 result r = E_SUCCESS;
347 r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_GAP);
348 SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
349 "The application does not have the privilege to call this method.");
351 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
353 return __pImpl->CancelPair();
357 BluetoothManager::Unpair(const BluetoothDevice& pairedDevice)
359 result r = E_SUCCESS;
362 r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_GAP);
363 SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
364 "The application does not have the privilege to call this method.");
366 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
368 return __pImpl->Unpair(pairedDevice);
371 } } } // Tizen::Net::Bluetooth