tizen 2.3.1 release
[framework/web/mobile/wrt-plugins-tizen.git] / src / Bluetooth / BluetoothHealthApplication.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 #include "BluetoothHealthApplication.h"
19 #include "plugin_config.h"
20
21 #include <bluetooth.h>
22 #include <Logger.h>
23 #include <GlobalContextManager.h>
24
25 using namespace DeviceAPI::Common;
26
27 namespace DeviceAPI {
28 namespace Bluetooth {
29
30 BluetoothHealthApplication::BluetoothHealthApplication(std::string appID,
31     std::string name, unsigned short dataType)
32 {
33     Common::SecurityAccessor();
34     mAppID = appID;
35     mName = name;
36     mDataType = dataType;
37     mIsRegistered = true;
38 }
39
40 BluetoothHealthApplication::~BluetoothHealthApplication()
41 {
42     if(mIsRegistered)
43         bt_hdp_unregister_sink_app(mAppID.c_str());
44 }
45
46 std::string BluetoothHealthApplication::getAppID() const
47 {
48     return mAppID;
49 }
50
51 unsigned short BluetoothHealthApplication::getDataType() const
52 {
53     return mDataType;
54 }
55
56 std::string BluetoothHealthApplication::getName() const
57 {
58     return mName;
59 }
60
61 bool BluetoothHealthApplication::setOnConnect(JSContextRef context,
62     JSObjectRef onConnect)
63 {
64     LOGD("Enter");
65
66     MultiCallbackUserDataPtr callback(
67         new MultiCallbackUserData(GlobalContextManager::getInstance()->
68             getGlobalContext(context)));
69
70     if(!callback){
71         LOGW("Can't create MultiCallbackUserData");
72         return false;
73     }
74     callback->setCallback("onconnect", onConnect);
75     mOnConnect = callback;
76
77     return mLocalProperty.setProperty(context,
78         BLUETOOTH_HEALTH_APPLICATION_ONCONNECT, onConnect);
79 }
80
81 MultiCallbackUserDataPtr BluetoothHealthApplication::getOnConnect() const
82 {
83     return mOnConnect;
84 }
85
86 JSValueRef BluetoothHealthApplication::getOnConnect(JSContextRef context)
87 {
88     LOGD("Enter");
89
90     JSValueRef onConnect = mLocalProperty.getProperty(context,
91         BLUETOOTH_HEALTH_APPLICATION_ONCONNECT);
92
93     if(onConnect == NULL) {
94         LOGD("onconnect is null");
95         return JSValueMakeNull(context);
96     }
97
98     return onConnect;
99 }
100
101 bool BluetoothHealthApplication::getRegistrationState() const
102 {
103     return mIsRegistered;
104 }
105
106 void BluetoothHealthApplication::setRegistrationState(bool isRegistered)
107 {
108     mIsRegistered = isRegistered;
109 }
110
111 } // Bluetooth
112 } // DeviceAPI