tizen 2.3.1 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / Bluetooth / JSBluetoothClassDeviceMajor.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 "JSBluetoothClassDeviceMajor.h"
21 #include "BluetoothClassDeviceMajor.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 JSBluetoothClassDeviceMajor::m_classInfo = {
32     0,
33     kJSClassAttributeNone,
34     "BluetoothClassDeviceMajor",
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 JSClassRef JSBluetoothClassDeviceMajor::m_jsClassRef = JSClassCreate(JSBluetoothClassDeviceMajor::getClassInfo());
52
53 JSStaticValue JSBluetoothClassDeviceMajor::m_property[] = {
54     { "MISC", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
55     { "COMPUTER", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
56     { "PHONE", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
57     { "NETWORK", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
58     { "AUDIO_VIDEO", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
59     { "PERIPHERAL", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
60     { "IMAGING", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
61     { "WEARABLE", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
62     { "TOY", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
63     { "HEALTH", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
64     { "UNCATEGORIZED", getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
65     { 0, 0, 0, 0 }
66 };
67
68
69 const JSClassRef JSBluetoothClassDeviceMajor::getClassRef()
70 {
71     if (!m_jsClassRef) {
72         m_jsClassRef = JSClassCreate(&m_classInfo);
73     }
74     return m_jsClassRef;
75 }
76
77 const JSClassDefinition* JSBluetoothClassDeviceMajor::getClassInfo()
78 {
79     return &m_classInfo;
80 }
81
82 JSObjectRef JSBluetoothClassDeviceMajor::createJSObject(JSContextRef context)
83 {
84     return JSObjectMake(context, getClassRef(), NULL);
85 }
86
87 void JSBluetoothClassDeviceMajor::initialize(JSContextRef context, JSObjectRef object)
88 {
89     // Do nothing
90 }
91
92 void JSBluetoothClassDeviceMajor::finalize(JSObjectRef object)
93 {
94     // Do nothing
95 }
96
97 JSValueRef JSBluetoothClassDeviceMajor::getProperty(JSContextRef context,
98         JSObjectRef object,
99         JSStringRef propertyName,
100         JSValueRef* exception)
101 {
102     try {
103         std::string name = JSUtil::JSStringToString(context, propertyName);
104         return JSUtil::toJSValueRef(context, BluetoothClassDeviceMajor::getInstance()->getMajorValue(name));
105     } catch (const BasePlatformException &err) {
106         LOGW("Getting property is failed: %s", err.getMessage().c_str());
107     }
108
109     return NULL;
110 }
111
112
113 } // Bluetooth
114 } // DeviceAPI