Update change log and spec for wrt-plugins-tizen_0.4.70
[framework/web/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, std::string name, unsigned short dataType)
31 {
32         Common::SecurityAccessor();
33     mAppID = appID;
34     mName = name;
35     mDataType = dataType;
36     mIsRegistered = true;
37 }
38
39 BluetoothHealthApplication::~BluetoothHealthApplication()
40 {
41     if(mIsRegistered)
42         bt_hdp_unregister_sink_app(mAppID.c_str());
43 }
44
45 std::string BluetoothHealthApplication::getAppID() const
46 {
47     return mAppID;
48 }
49
50 unsigned short BluetoothHealthApplication::getDataType() const
51 {
52     return mDataType;
53 }
54
55 std::string BluetoothHealthApplication::getName() const
56 {
57     return mName;
58 }
59
60 bool BluetoothHealthApplication::setOnConnect(JSContextRef context, JSObjectRef onConnect)
61 {
62     LoggerD("Enter");
63     
64     MultiCallbackUserDataPtr callback(
65             new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));
66     if(!callback){
67         LoggerW("Can't create MultiCallbackUserData");
68         return false;
69     }    
70     callback->setCallback("onconnect", onConnect);
71     mOnConnect = callback;
72
73     return mLocalProperty.setProperty(context, BLUETOOTH_HEALTH_APPLICATION_ONCONNECT, onConnect);
74 }
75
76 MultiCallbackUserDataPtr BluetoothHealthApplication::getOnConnect() const
77 {
78     return mOnConnect;
79 }
80
81 JSValueRef BluetoothHealthApplication::getOnConnect(JSContextRef context)
82 {
83     LoggerD("Enter");
84
85     JSValueRef onConnect = mLocalProperty.getProperty(context, BLUETOOTH_HEALTH_APPLICATION_ONCONNECT);
86     if(onConnect == NULL) {
87         LoggerD("onconnect is null");
88         return JSValueMakeNull(context);
89     }
90     
91     return onConnect;
92 }
93
94 bool BluetoothHealthApplication::getRegistrationState() const
95 {
96     return mIsRegistered;
97 }
98
99 void BluetoothHealthApplication::setRegistrationState(bool isRegistered)
100 {
101     mIsRegistered = isRegistered;
102 }
103
104
105 } // Bluetooth
106 } // DeviceAPI