2 // Tizen Web Device API
3 // Copyright (c) 2012 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.
18 #include <PlatformException.h>
21 #include "plugin_config.h"
22 #include "BluetoothDevice.h"
23 #include "BluetoothAdapter.h"
24 #include "JSBluetoothClass.h"
28 using namespace DeviceAPI::Common;
33 BluetoothDevice::BluetoothDevice(bt_adapter_device_discovery_info_s *discoveryInfo)
35 Common::SecurityAccessor();
36 mName = std::string(discoveryInfo->remote_name);
37 mAddress = std::string(discoveryInfo->remote_address);
38 mDeviceClass = BluetoothClassSharedPtr(new BluetoothClass(discoveryInfo->bt_class));
39 for(int i = 0; i < discoveryInfo->service_count; i++) {
40 mUUIDs.push_back(std::string(discoveryInfo->service_uuid[i]));
45 BluetoothDevice::BluetoothDevice(bt_device_info_s *deviceInfo)
47 Common::SecurityAccessor();
48 mName = std::string(deviceInfo->remote_name);
49 mAddress = std::string(deviceInfo->remote_address);
50 mDeviceClass = BluetoothClassSharedPtr(new BluetoothClass(deviceInfo->bt_class));
52 for(int i = 0; i < deviceInfo->service_count; i++) {
53 mUUIDs.push_back(std::string(deviceInfo->service_uuid[i]));
58 BluetoothDevice::~BluetoothDevice()
60 BluetoothAdapter::getInstance()->removeConnReq(mAddress);
63 void BluetoothDevice::updateInfo(bt_device_info_s *deviceInfo)
65 mName = std::string(deviceInfo->remote_name);
67 for(int i = 0; i < deviceInfo->service_count; i++) {
68 mUUIDs.push_back(std::string(deviceInfo->service_uuid[i]));
73 std::string BluetoothDevice::getName() const
78 std::string BluetoothDevice::getAddress() const
83 void BluetoothDevice::copyAceCheckAccessFunction(const Common::SecurityAccessor *securityAccessor)
85 Common::SecurityAccessor::copyAceCheckAccessFunction(securityAccessor);
86 mDeviceClass->copyAceCheckAccessFunction(securityAccessor);
89 JSValueRef BluetoothDevice::getDeviceClass(JSContextRef context)
92 JSValueRef deviceClass = mLocalProperty.getProperty(context, BLUETOOTH_DEVICE_DEVICE_CLASS);
93 if(deviceClass == NULL) {
94 deviceClass = JSBluetoothClass::createJSObject(context, mDeviceClass);
95 mLocalProperty.setProperty(context, BLUETOOTH_DEVICE_DEVICE_CLASS, deviceClass);
100 return JSBluetoothClass::createJSObject(context, mDeviceClass);
103 bool BluetoothDevice::isBonded() const
106 bt_device_info_s *deviceInfo = NULL;
107 if(bt_adapter_get_bonded_device_info(mAddress.c_str(), &deviceInfo) == BT_ERROR_NONE && deviceInfo != NULL) {
108 ret = deviceInfo->is_bonded;
109 bt_adapter_free_device_info(deviceInfo);
115 bool BluetoothDevice::isTrusted() const
118 bt_device_info_s *deviceInfo = NULL;
119 if(bt_adapter_get_bonded_device_info(mAddress.c_str(), &deviceInfo) == BT_ERROR_NONE && deviceInfo != NULL) {
120 ret = deviceInfo->is_authorized;
121 bt_adapter_free_device_info(deviceInfo);
127 bool BluetoothDevice::isConnected() const
130 bt_device_info_s *deviceInfo = NULL;
131 if(bt_adapter_get_bonded_device_info(mAddress.c_str(), &deviceInfo) == BT_ERROR_NONE && deviceInfo != NULL) {
132 ret = deviceInfo->is_connected;
133 bt_adapter_free_device_info(deviceInfo);
139 JSValueRef BluetoothDevice::getUUIDs(JSContextRef context)
142 if(isUpdated == true) {
143 mLocalProperty.setProperty(context, BLUETOOTH_DEVICE_UUIDS, JSUtil::toJSValueRef(context, mUUIDs));
147 return mLocalProperty.getProperty(context, BLUETOOTH_DEVICE_UUIDS);
149 return JSUtil::toJSValueRef(context, mUUIDs);