1 // Tizen Web Device API
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 #include <GlobalContextManager.h>
18 #include <PlatformException.h>
20 #include "BluetoothHealthChannel.h"
21 #include "JSBluetoothDevice.h"
22 #include "JSBluetoothHealthApplication.h"
25 #include <TimeTracer.h>
27 using namespace DeviceAPI::Common;
32 BluetoothHealthChannel::BluetoothHealthChannel(unsigned int channel, BluetoothDeviceSharedPtr remoteDevice,
33 bt_hdp_channel_type_e type, BluetoothHealthApplicationSharedPtr application)
35 Common::SecurityAccessor();
37 mRemoteDevice = remoteDevice;
38 if(type == BT_HDP_CHANNEL_TYPE_RELIABLE) {
39 mChannelTypeStr = "RELIABLE";
42 mChannelTypeStr = "STREAMING";
49 BluetoothHealthChannel::~BluetoothHealthChannel()
52 bt_hdp_disconnect(mRemoteDevice->getAddress().c_str(), mChannel);
56 bool BluetoothHealthChannel::getConnectionState() const
61 void BluetoothHealthChannel::setConnectionState(bool isConnected)
63 mIsConnected = isConnected;
66 unsigned int BluetoothHealthChannel::getChannel() const
71 std::string BluetoothHealthChannel::getChannelTypeStr() const
73 return mChannelTypeStr;
76 bt_hdp_channel_type_e BluetoothHealthChannel::getChannelType() const
81 JSValueRef BluetoothHealthChannel::getApp(JSContextRef context)
83 return JSBluetoothHealthApplication::createJSObject(context, mApp);
86 JSValueRef BluetoothHealthChannel::getPeer(JSContextRef context)
88 return JSBluetoothDevice::createJSObject(context, mRemoteDevice);
91 Common::MultiCallbackUserDataPtr BluetoothHealthChannel::getListener() const
96 unsigned long BluetoothHealthChannel::sendData(char* data, unsigned long size)
98 unsigned long ret = 0;
99 TIME_TRACER_ITEM_BEGIN("sendData::bt_hdp_send_data", 1);
100 if(bt_hdp_send_data(mChannel, data, static_cast<unsigned int>(size)) == BT_ERROR_NONE) {
101 TIME_TRACER_ITEM_END("sendData::bt_hdp_send_data", 1);
102 LoggerD("bt_hdp_send_data() succeeded");
106 throw UnknownException("Unknown error");
113 void BluetoothHealthChannel::close()
117 LoggerD("Already disconnected");
121 TIME_TRACER_ITEM_BEGIN("close::bt_hdp_disconnect", 1);
122 if(bt_hdp_disconnect(mRemoteDevice->getAddress().c_str(), mChannel) != BT_ERROR_NONE) {
123 LoggerE("bt_hdp_disconnect() failed");
124 throw UnknownException("Unknown error");
126 TIME_TRACER_ITEM_END("close::bt_hdp_disconnect", 1);
128 mIsConnected = false;
133 void BluetoothHealthChannel::setListener(Common::MultiCallbackUserDataPtr callback)
135 mListener = callback;
138 void BluetoothHealthChannel::unsetListener()