2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <SecurityExceptions.h>
21 #include <ArgumentValidator.h>
22 #include <GlobalContextManager.h>
23 #include <PlatformException.h>
24 #include <PropertyBag.h>
26 #include "plugin_config.h"
27 #include "JSBluetoothManager.h"
28 #include "JSBluetoothClassDeviceMajor.h"
29 #include "JSBluetoothClassDeviceMinor.h"
30 #include "JSBluetoothClassDeviceService.h"
31 //#include "BluetoothManager.h"
32 #include "JSBluetoothAdapter.h"
33 #include "BluetoothAdapter.h"
35 #include <TimeTracer.h>
38 using namespace WrtDeviceApis::Commons;
39 using namespace DeviceAPI::Common;
44 JSClassDefinition JSBluetoothManager::m_classInfo = {
46 kJSClassAttributeNone,
49 m_property, //StaticValues
50 m_function, //StaticFunctions
51 initialize, //Initialize
56 NULL, //DeleteProperty,
57 NULL, //GetPropertyNames,
58 NULL, //CallAsFunction,
59 NULL, //CallAsConstructor,
64 JSStaticValue JSBluetoothManager::m_property[] = {
65 { BLUETOOTH_MANAGER_DEVICE_MAJOR, getReadOnlyProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
66 { BLUETOOTH_MANAGER_DEVICE_MINOR, getReadOnlyProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
67 { BLUETOOTH_MANAGER_DEVICE_SERVICE, getReadOnlyProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},
71 JSStaticFunction JSBluetoothManager::m_function[] = {
72 { BLUETOOTH_MANAGER_API_GET_DEFAULT_ADAPTER, getDefaultAdapter, kJSPropertyAttributeNone },
76 JSClassRef JSBluetoothManager::m_jsClassRef = JSClassCreate(JSBluetoothManager::getClassInfo());
78 const JSClassRef JSBluetoothManager::getClassRef()
81 m_jsClassRef = JSClassCreate(&m_classInfo);
86 const JSClassDefinition* JSBluetoothManager::getClassInfo()
91 void JSBluetoothManager::initialize(JSContextRef context, JSObjectRef object)
93 if (!JSObjectGetPrivate(object)) {
94 PropertyBag *priv = new PropertyBag();
97 priv->setProperty(context, BLUETOOTH_MANAGER_DEVICE_MAJOR,
98 JSBluetoothClassDeviceMajor::createJSObject(context));
101 priv->setProperty(context, BLUETOOTH_MANAGER_DEVICE_MINOR,
102 JSBluetoothClassDeviceMinor::createJSObject(context));
105 priv->setProperty(context, BLUETOOTH_MANAGER_DEVICE_SERVICE,
106 JSBluetoothClassDeviceService::createJSObject(context));
108 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
109 LoggerW("Failed to set private data");
114 LoggerW("Failed to create private data");
118 LoggerW("Private data already exists");
122 void JSBluetoothManager::finalize(JSObjectRef object)
124 PropertyBag *priv = static_cast<PropertyBag*>(JSObjectGetPrivate(object));
126 JSObjectSetPrivate(object, NULL);
131 JSValueRef JSBluetoothManager::getReadOnlyProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) {
132 PropertyBag *priv = static_cast<PropertyBag*>(JSObjectGetPrivate(object));
134 LoggerW("There is no private data");
138 std::string name = JSUtil::JSStringToString(context, propertyName);
139 return priv->getProperty(context, propertyName);
142 JSValueRef JSBluetoothManager::getDefaultAdapter(JSContextRef context,
144 JSObjectRef thisObject,
145 size_t argumentCount,
146 const JSValueRef arguments[],
147 JSValueRef* exception)
149 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
152 AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_MANAGER_API_GET_DEFAULT_ADAPTER);
153 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
156 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
157 return JSBluetoothAdapter::createJSObject(context);
159 } catch (const BasePlatformException &err) {
160 return JSWebAPIErrorFactory::postException(context, exception, err);
162 DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothManager.getDefaultAdapter().");
163 return JSWebAPIErrorFactory::postException(context, exception, err);