2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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 <CommonsJavaScript/Converter.h>
18 #include <CommonsJavaScript/Validator.h>
19 #include <CommonsJavaScript/JSUtils.h>
20 #include <CommonsJavaScript/JSCallbackManager.h>
21 #include <CommonsJavaScript/Utils.h>
22 #include <Tizen/Common/JSTizenExceptionFactory.h>
23 #include <Tizen/Common/JSTizenException.h>
24 #include "JSBluetoothClassDeviceMajor.h"
25 #include "plugin_config.h"
30 using namespace WrtDeviceApis;
31 using namespace WrtDeviceApis::CommonsJavaScript;
32 using namespace TizenApis::Commons;
38 JSClassDefinition JSBluetoothClassDeviceMajor::m_classInfo =
41 kJSClassAttributeNone,
42 "BluetoothClassDeviceMajor",
61 JSStaticValue JSBluetoothClassDeviceMajor::m_properties[] =
63 {"MISC", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
64 {"COMPUTER", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
65 {"PHONE", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
66 {"NETWORK", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
67 {"AUDIO_VIDEO", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
68 {"PERIPHERAL", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
69 {"IMAGING", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
70 {"WEARABLE", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
71 {"TOY", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
72 {"HEALTH", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
73 {"UNCATEGORIZED", JSBluetoothClassDeviceMajor::getProperty, NULL, kJSPropertyAttributeReadOnly },
78 const JSClassRef JSBluetoothClassDeviceMajor::getClassRef()
81 m_jsClassRef = JSClassCreate(&m_classInfo);
86 const JSClassDefinition* JSBluetoothClassDeviceMajor::getClassInfo()
91 JSClassRef JSBluetoothClassDeviceMajor::m_jsClassRef = JSClassCreate(JSBluetoothClassDeviceMajor::getClassInfo());
93 void JSBluetoothClassDeviceMajor::initialize(JSContextRef context, JSObjectRef object)
95 LogDebug("JSBluetoothClassDeviceMajor::initialize ");
96 JSBluetoothClassDeviceMajorPriv* priv = static_cast<JSBluetoothClassDeviceMajorPriv*>(JSObjectGetPrivate(object));
100 BluetoothClassPtr btClass(new BluetoothClass());
101 priv = new JSBluetoothClassDeviceMajorPriv( context, btClass);
102 if(!JSObjectSetPrivate(object, static_cast<void*>(priv)))
104 LogError("Object can't store private data.");
110 LogDebug("JSBluetoothClassDeviceMajor::already exist ");
115 JSObjectRef JSBluetoothClassDeviceMajor::createJSObject(JSContextRef context)
117 BluetoothClassPtr btClass(new BluetoothClass());
118 JSBluetoothClassDeviceMajorPriv* priv = new JSBluetoothClassDeviceMajorPriv( context, btClass);
119 btClass->setReadOnly();
121 return JSObjectMake(context, getClassRef(), priv);
125 void JSBluetoothClassDeviceMajor::finalize(JSObjectRef object)
127 JSBluetoothClassDeviceMajorPriv* priv = static_cast<JSBluetoothClassDeviceMajorPriv*>(JSObjectGetPrivate(object));
129 LogDebug("JSBluetoothClassDeviceMajor::Finalrize");
133 JSObjectSetPrivate(object, NULL);
138 bool JSBluetoothClassDeviceMajor::hasInstance(JSContextRef context, JSObjectRef constructor,
139 JSValueRef possibleInstance, JSValueRef* exception) {
140 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
143 JSValueRef JSBluetoothClassDeviceMajor::getProperty(JSContextRef context,
145 JSStringRef propertyName,
146 JSValueRef* exception)
150 JSBluetoothClassDeviceMajorPriv* priv = static_cast<JSBluetoothClassDeviceMajorPriv*>(JSObjectGetPrivate(object));
157 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
160 Converter converter(context);
161 BluetoothClassPtr btClass(priv->getObject());
162 std::string key = converter.toString(propertyName);
165 if (btClass->find(key, value) == false)
167 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "can not find property" << key);
169 return converter.toJSValueRef(value);
171 Catch (WrtDeviceApis::Commons::InvalidArgumentException)
173 LogError("InvalidArgumentException");
174 return JSTizenExceptionFactory::postException(context, exception,
175 JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error");
177 Catch (WrtDeviceApis::Commons::SecurityException)
179 LogError("permission denied error");
180 return JSTizenExceptionFactory::postException(context, exception,
181 JSTizenException::PERMISSION_DENIED_ERROR, "permission denied error");
184 Catch (WrtDeviceApis::Commons::Exception)
186 LogError("UnkownException");
187 return JSTizenExceptionFactory::postException(context, exception,
188 JSTizenException::UNKNOWN_ERROR, "Unkown error");
190 return JSValueMakeNull(context);