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.
19 #include <CommonsJavaScript/Converter.h>
20 #include <CommonsJavaScript/Validator.h>
21 #include <CommonsJavaScript/JSUtils.h>
22 #include <CommonsJavaScript/JSCallbackManager.h>
23 #include <CommonsJavaScript/Utils.h>
24 #include <JSTizenExceptionFactory.h>
25 #include <JSTizenException.h>
26 #include <SecurityExceptions.h>
27 #include "BluetoothFactory.h"
28 #include "IBluetoothAdapterManager.h"
29 #include "BluetoothProperty.h"
30 #include "JSBluetoothManager.h"
31 #include "JSBluetoothAdapter.h"
32 #include "JSBluetoothClassDeviceMajor.h"
33 #include "JSBluetoothClassDeviceMinor.h"
34 #include "JSBluetoothClassDeviceService.h"
35 #include "plugin_config.h"
38 using namespace WrtDeviceApis::Commons;
39 using namespace DeviceAPI::Common;
42 #define DEVICE_MAJOR "deviceMajor"
43 #define DEVICE_MINOR "deviceMinor"
44 #define DEVICE_SERVICE "deviceService"
50 JSClassRef JSBluetoothManager::m_jsClassRef = NULL;
52 JSClassDefinition JSBluetoothManager::m_classInfo =
55 kJSClassAttributeNone,
74 JSStaticFunction JSBluetoothManager::m_function[] =
76 { "getDefaultAdapter", getDefaultAdapter, kJSPropertyAttributeNone },
80 const JSClassRef JSBluetoothManager::getClassRef()
84 m_jsClassRef = JSClassCreate(&m_classInfo);
89 JSValueRef JSBluetoothManager::getDefaultAdapter(JSContextRef context, JSObjectRef object,
90 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
91 JSValueRef* exception)
93 JSBluetoothManagerPriv* priv = static_cast<JSBluetoothManagerPriv*>(JSObjectGetPrivate(thisObject));
101 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
104 AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
105 bluetoothExportedNames[BLUETOOTH_FUNCTION_API_MANAGER_GET_DEFAULT_ADAPTER]);
106 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
108 JSContextRef globalContext = priv->getContext();
110 return JSBluetoothAdapter::createJSObject(globalContext);
112 Catch (WrtDeviceApis::Commons::SecurityException)
114 LogError("permission denied error");
115 return JSTizenExceptionFactory::postException(context, exception,
116 JSTizenException::PERMISSION_DENIED_ERROR, "permission denied error");
119 Catch(WrtDeviceApis::Commons::UnsupportedException)
121 LogError("UnkownException");
122 return JSTizenExceptionFactory::postException(context, exception,
123 JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception");
125 Catch(WrtDeviceApis::Commons::Exception)
127 LogError("UnkownException");
128 return JSTizenExceptionFactory::postException(context, exception,
129 JSTizenException::UNKNOWN_ERROR, "Unkown error");
133 const JSClassDefinition* JSBluetoothManager::getClassInfo()
139 void JSBluetoothManager::initialize(JSContextRef context, JSObjectRef object)
141 JSBluetoothManagerPriv *priv = static_cast<JSBluetoothManagerPriv*>(JSObjectGetPrivate(object));
142 LogDebug("JSBluetoothManager::initialize");
146 LogError("already exist");
150 priv = new JSBluetoothManagerPriv(context);
152 if(!JSObjectSetPrivate(object, static_cast<void*>(priv)))
154 LogError("Object can't store private data.");
159 setAttributesIntoJSObject(context, object);
162 void JSBluetoothManager::finalize(JSObjectRef object)
164 JSBluetoothManagerPriv* priv = static_cast<JSBluetoothManagerPriv*>(JSObjectGetPrivate(object));
165 LogDebug("JSBluetoothManager::Finalrize");
169 JSObjectSetPrivate(object, NULL);
170 LogDebug("Deleting BluetoothManager");
175 bool JSBluetoothManager::hasInstance(JSContextRef context, JSObjectRef constructor,
176 JSValueRef possibleInstance, JSValueRef* exception)
178 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
181 void JSBluetoothManager::setAttributesIntoJSObject(JSContextRef context, JSObjectRef object)
184 JSUtil::setProperty(context, object, DEVICE_MAJOR,
185 JSBluetoothClassDeviceMajor::createJSObject(context), kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete);
188 JSUtil::setProperty(context, object, DEVICE_MINOR,
189 JSBluetoothClassDeviceMinor::createJSObject(context), kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete);
192 JSUtil::setProperty(context, object, DEVICE_SERVICE,
193 JSBluetoothClassDeviceService::createJSObject(context), kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete);