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 <API/Bluetooth/BluetoothProperty.h>
26 #include "JSBluetoothManager.h"
27 #include "JSBluetoothClassDeviceMajor.h"
28 #include "JSBluetoothClassDeviceMinor.h"
29 #include "JSBluetoothClassDeviceService.h"
32 using namespace TizenApis::Api::Bluetooth;
33 using namespace WrtDeviceApis::Commons;
34 using namespace TizenApis::Commons;
40 JSClassRef JSBluetoothManager::m_jsClassRef = NULL;
42 JSClassDefinition JSBluetoothManager::m_classInfo =
45 kJSClassAttributeNone,
66 JSStaticValue JSBluetoothManager::m_properties[] =
68 /* {PROTOCOL_TYPE_RFCOMM, getProperty, NULL, kJSPropertyAttributeReadOnly},
69 {PROTOCOL_TYPE_L2CAP, getProperty, NULL, kJSPropertyAttributeReadOnly},
70 {SECURITY_LEVEL_LOW, getProperty, NULL, kJSPropertyAttributeReadOnly},
71 {SECURITY_LEVEL_MEDIUM, getProperty, NULL, kJSPropertyAttributeReadOnly},
72 {SECURITY_LEVEL_HIGH, getProperty, NULL, kJSPropertyAttributeReadOnly},*/
73 {"DeviceMajor", getProperty, NULL, kJSPropertyAttributeReadOnly},
74 {"DeviceMinor", getProperty, NULL, kJSPropertyAttributeReadOnly},
75 {"DeviceService", getProperty, NULL, kJSPropertyAttributeReadOnly},
81 const JSClassRef JSBluetoothManager::getClassRef()
85 m_jsClassRef = JSClassCreate(&m_classInfo);
91 void JSBluetoothManager::getPropertyNames(JSContextRef context,
93 JSPropertyNameAccumulatorRef propertyNames)
98 JSValueRef JSBluetoothManager::getProperty(JSContextRef context,
100 JSStringRef propertyName,
101 JSValueRef* exception)
108 if(JSStringIsEqualToUTF8CString(propertyName, PROTOCOL_TYPE_RFCOMM))
110 return converter.toJSValueRef(PROTOCOL_TYPE_RFCOMM_VALUE);
112 else if(JSStringIsEqualToUTF8CString(propertyName, PROTOCOL_TYPE_L2CAP))
114 return converter.toJSValueRef(PROTOCOL_TYPE_L2CAP_VALUE);
116 else if(JSStringIsEqualToUTF8CString(propertyName, SECURITY_LEVEL_LOW))
118 return converter.toJSValueRef(SECURITY_LEVEL_LOW_VALUE);
120 else if(JSStringIsEqualToUTF8CString(propertyName, SECURITY_LEVEL_MEDIUM))
122 return converter.toJSValueRef(SECURITY_LEVEL_MEDIUM_VALUE);
124 else if(JSStringIsEqualToUTF8CString(propertyName, SECURITY_LEVEL_HIGH))
126 return converter.toJSValueRef(SECURITY_LEVEL_HIGH_VALUE);
128 else*/ if(JSStringIsEqualToUTF8CString(propertyName, "DeviceMajor"))
130 return JSBluetoothClassDeviceMajor::createJSObject(context);
132 else if(JSStringIsEqualToUTF8CString(propertyName, "DeviceMinor"))
134 return JSBluetoothClassDeviceMinor::createJSObject(context);
136 else if(JSStringIsEqualToUTF8CString(propertyName, "DeviceService"))
138 return JSBluetoothClassDeviceService::createJSObject(context);
142 Catch (WrtDeviceApis::Commons::ConversionException)
144 LogError("ConversionException");
145 return JSTizenExceptionFactory::postException(context, exception,
146 JSTizenException::INVALID_VALUES_ERROR, "invalid value error");
148 Catch (WrtDeviceApis::Commons::InvalidArgumentException)
150 LogError("InvalidArgumentException");
151 return JSTizenExceptionFactory::postException(context, exception,
152 JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error");
154 Catch(WrtDeviceApis::Commons::Exception)
156 LogError("UnkownException");
157 return JSTizenExceptionFactory::postException(context, exception,
158 JSTizenException::UNKNOWN_ERROR, "Unkown error");
160 return JSValueMakeUndefined(context);
165 const JSClassDefinition* JSBluetoothManager::getClassInfo()
171 void JSBluetoothManager::initialize(JSContextRef context, JSObjectRef object)
173 JSBluetoothManagerPriv *priv = static_cast<JSBluetoothManagerPriv*>(JSObjectGetPrivate(object));
174 LogDebug("JSBluetoothManager::initialize");
178 LogError("already exist");
182 priv = new JSBluetoothManagerPriv(context);
184 if(!JSObjectSetPrivate(object, static_cast<void*>(priv)))
186 LogError("Object can't store private data.");
192 void JSBluetoothManager::finalize(JSObjectRef object)
194 JSBluetoothManagerPriv* priv = static_cast<JSBluetoothManagerPriv*>(JSObjectGetPrivate(object));
195 LogDebug("JSBluetoothManager::Finalrize");
199 JSObjectSetPrivate(object, NULL);
200 LogDebug("Deleting BluetoothManager");
205 bool JSBluetoothManager::hasInstance(JSContextRef context, JSObjectRef constructor,
206 JSValueRef possibleInstance, JSValueRef* exception)
208 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());