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.
18 #include <CommonsJavaScript/Converter.h>
19 #include <CommonsJavaScript/Validator.h>
20 #include <CommonsJavaScript/JSUtils.h>
21 #include <CommonsJavaScript/JSCallbackManager.h>
22 #include <CommonsJavaScript/Utils.h>
23 #include <Tizen/Common/JSTizenExceptionFactory.h>
24 #include <Tizen/Common/JSTizenException.h>
25 #include "JSBluetoothClassDeviceService.h"
26 #include "plugin_config.h"
31 using namespace WrtDeviceApis;
32 using namespace WrtDeviceApis::CommonsJavaScript;
33 using namespace TizenApis::Commons;
39 JSClassDefinition JSBluetoothClassDeviceService::m_classInfo =
42 kJSClassAttributeNone,
43 "BluetoothClassDeviceService",
62 JSStaticValue JSBluetoothClassDeviceService::m_properties[] =
64 {"LIMITED_DISCOVERABILITY", JSBluetoothClassDeviceService::getProperty, NULL, kJSPropertyAttributeReadOnly },
65 {"POSITIONING", JSBluetoothClassDeviceService::getProperty, NULL, kJSPropertyAttributeReadOnly },
66 {"NETWORKING", JSBluetoothClassDeviceService::getProperty, NULL, kJSPropertyAttributeReadOnly },
67 {"RENDERING", JSBluetoothClassDeviceService::getProperty, NULL, kJSPropertyAttributeReadOnly },
68 {"CAPTURING", JSBluetoothClassDeviceService::getProperty, NULL, kJSPropertyAttributeReadOnly },
69 {"OBJECT_TRANSFER", JSBluetoothClassDeviceService::getProperty, NULL, kJSPropertyAttributeReadOnly },
70 {"AUDIO", JSBluetoothClassDeviceService::getProperty, NULL, kJSPropertyAttributeReadOnly },
71 {"TELEPHONY", JSBluetoothClassDeviceService::getProperty, NULL, kJSPropertyAttributeReadOnly },
72 {"INFORMATION", JSBluetoothClassDeviceService::getProperty, NULL, kJSPropertyAttributeReadOnly },
77 const JSClassRef JSBluetoothClassDeviceService::getClassRef()
81 m_jsClassRef = JSClassCreate(&m_classInfo);
86 const JSClassDefinition* JSBluetoothClassDeviceService::getClassInfo()
91 JSClassRef JSBluetoothClassDeviceService::m_jsClassRef = JSClassCreate(JSBluetoothClassDeviceService::getClassInfo());
93 void JSBluetoothClassDeviceService::initialize(JSContextRef context, JSObjectRef object)
95 LogDebug("JSBluetoothClassDeviceService::initialize ");
96 JSBluetoothClassDeviceServicePriv* priv = static_cast<JSBluetoothClassDeviceServicePriv*>(JSObjectGetPrivate(object));
100 BluetoothClassPtr btClass(new BluetoothClass());
101 priv = new JSBluetoothClassDeviceServicePriv( context, btClass);
102 if(!JSObjectSetPrivate(object, static_cast<void*>(priv)))
104 LogError("Object can't store private data.");
110 LogDebug("JSBluetoothClassDeviceService::already exist ");
115 JSObjectRef JSBluetoothClassDeviceService::createJSObject(JSContextRef context)
117 BluetoothClassPtr btClass(new BluetoothClass());
118 JSBluetoothClassDeviceServicePriv* priv = new JSBluetoothClassDeviceServicePriv( context, btClass);
119 btClass->setReadOnly();
121 return JSObjectMake(context, getClassRef(), priv);
124 void JSBluetoothClassDeviceService::finalize(JSObjectRef object)
126 JSBluetoothClassDeviceServicePriv* priv = static_cast<JSBluetoothClassDeviceServicePriv*>(JSObjectGetPrivate(object));
128 LogDebug("JSBluetoothClassDeviceService::Finalrize");
132 JSObjectSetPrivate(object, NULL);
137 bool JSBluetoothClassDeviceService::hasInstance(JSContextRef context, JSObjectRef constructor,
138 JSValueRef possibleInstance, JSValueRef* exception)
140 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
143 JSValueRef JSBluetoothClassDeviceService::getProperty(JSContextRef context,
145 JSStringRef propertyName,
146 JSValueRef* exception)
150 Converter converter(context);
151 JSBluetoothClassDeviceServicePriv* priv = static_cast<JSBluetoothClassDeviceServicePriv*>(JSObjectGetPrivate(object));
157 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
160 BluetoothClassPtr btClass(priv->getObject());
161 std::string key = converter.toString(propertyName);
164 if (btClass->find(key, value) == false)
166 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "can not find property" << key);
168 return converter.toJSValueRef(value);
170 Catch (WrtDeviceApis::Commons::InvalidArgumentException)
172 LogError("InvalidArgumentException");
173 return JSTizenExceptionFactory::postException(context, exception,
174 JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error");
176 Catch (WrtDeviceApis::Commons::SecurityException)
178 LogError("permission denied error");
179 return JSTizenExceptionFactory::postException(context, exception,
180 JSTizenException::PERMISSION_DENIED_ERROR, "permission denied error");
183 Catch (WrtDeviceApis::Commons::Exception)
185 LogError("UnkownException");
186 return JSTizenExceptionFactory::postException(context, exception,
187 JSTizenException::UNKNOWN_ERROR, "Unkown error");
190 return JSValueMakeNull(context);