Pairing and selection issues patch
[profile/ivi/wrt-plugins-ivi-bt.git] / src / JSBluetoothClassDeviceService.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 <JSUtil.h>
19 #include "plugin_config.h"
20 #include "JSBluetoothClassDeviceService.h"
21 #include "BluetoothClassDeviceService.h"
22
23 #include <Logger.h>
24
25 using namespace WrtDeviceApis::Commons;
26 using namespace DeviceAPI::Common;
27
28 namespace DeviceAPI {
29 namespace Bluetooth {
30
31 JSClassDefinition JSBluetoothClassDeviceService::m_classInfo = {
32     0,
33     kJSClassAttributeNone,
34     "BluetoothClassDeviceService",
35     NULL, //ParentClass
36     m_property, //StaticValues
37     NULL, //StaticFunctions
38     initialize, //Initialize
39     finalize, //Finalize
40     NULL, //HasProperty,
41     NULL, //GetProperty,
42     NULL, //SetProperty,
43     NULL, //DeleteProperty,
44     NULL, //GetPropertyNames,
45     NULL, //CallAsFunction,
46     NULL, //CallAsConstructor,
47     NULL, //HasInstance,
48     NULL //ConvertToType
49 };
50
51
52
53 JSClassRef JSBluetoothClassDeviceService::m_jsClassRef = JSClassCreate(JSBluetoothClassDeviceService::getClassInfo());
54
55 JSStaticValue JSBluetoothClassDeviceService::m_property[] = {
56     { "LIMITED_DISCOVERABILITY", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
57     { "POSITIONING", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
58     { "NETWORKING", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
59     { "RENDERING", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
60     { "CAPTURING", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
61     { "OBJECT_TRANSFER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
62     { "AUDIO", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
63     { "TELEPHONY", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
64     { "INFORMATION", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
65     { 0, 0, 0, 0 }
66 };
67
68 const JSClassRef JSBluetoothClassDeviceService::getClassRef()
69 {
70     if (!m_jsClassRef) {
71         m_jsClassRef = JSClassCreate(&m_classInfo);
72     }
73     return m_jsClassRef;
74 }
75
76 const JSClassDefinition* JSBluetoothClassDeviceService::getClassInfo()
77 {
78     return &m_classInfo;
79 }
80
81 JSObjectRef JSBluetoothClassDeviceService::createJSObject(JSContextRef context)
82 {
83     return JSObjectMake(context, getClassRef(), NULL);
84 }
85
86 void JSBluetoothClassDeviceService::initialize(JSContextRef context, JSObjectRef object)
87 {
88     // do nothing
89 }
90
91 void JSBluetoothClassDeviceService::finalize(JSObjectRef object)
92 {
93     // do nothing
94 }
95
96 JSValueRef JSBluetoothClassDeviceService::getProperty(JSContextRef context,
97         JSObjectRef object,
98         JSStringRef propertyName,
99         JSValueRef* exception)
100 {
101     try {
102         std::string name = JSUtil::JSStringToString(context, propertyName);
103         return JSUtil::toJSValueRef(context, BluetoothClassDeviceService::getInstance()->getServiceValue(name));
104     } catch (const BasePlatformException &err) {
105         LoggerW("Getting property is failed: " << err.getMessage().c_str());
106     }
107
108     return NULL;
109 }
110
111
112 } // Bluetooth
113 } // DeviceAPI