From c03be72177a1162f84ef9af0bb5caca3bff7c9c6 Mon Sep 17 00:00:00 2001 From: Dongjin Choi Date: Mon, 24 Jun 2013 03:44:23 +0900 Subject: [PATCH] Update change log and spec for wrt-plugins-tizen_0.4.44 [model] REDWOOD [binary_type] PDA [customer] OPEN [Issue#] N/A [Problem] Memory leak [Cause] Misused the platform APIs [Solution] Release the bundle passed by platform\ [Issue#] N_SE-41597 [Problem] Calendar item end date not updated when saving the duration and the end date at once. [Cause] End date has priority over duration when saving an item. [Solution] Adjust the endDate if the duration attribute alone is changed before saving. [Issue#] N/A [Problem] crash when contact image is updated [Cause] misuse platform API(maybe changing platform policy) [Solution] modify code [Issue] DCM 2018 [Problem] crash when setting error msg on std::string [Cause] std::string is thread unsafe [Solution] use raw string. [Issue#] N/A [Problem] some wrong parameter is not handled on replyResult [Cause] using old argument validator [Solution] use new argument validator [Systeminfo] Add 'buildVersion', 'isAutoRotation' attribute [Issue] N/A [Problem] W3C spec guides that doesn't throw any exception in constructor. [Cause] N/A [Solution] remove throwing an exception [Bluetooth] Add Bluetooth Health Device Profile APIs [WebSetting] Add the initial version of web setting API(setUserAgentString, removeAllCookies). [Issue#] N/A [Problem] there are no way to get meta data by API [Cause] N/A [Solution] Add API to return meta data of application [Systeminfo] Add 'profile' attribute [SystemInfo] changed ThreadEnum [Issue#] N/A [Problem] N/A [Cause] N/A [Solution] Inserted LED Properties of Notification [team] WebAPI [request] N/A [horizontal_expansion] N/A --- packaging/wrt-plugins-tizen.spec | 2 +- pkgconfigs/wrt-plugins-tizen-websetting.pc.in | 12 + src/Application/ApplicationConverter.cpp | 21 +- src/Application/ApplicationConverter.h | 5 +- src/Application/ApplicationManager.cpp | 61 +++- src/Application/ApplicationManager.h | 2 + src/Application/ApplicationMetaData.cpp | 51 +++ src/Application/ApplicationMetaData.h | 52 +++ src/Application/CMakeLists.txt | 2 + src/Application/JSApplicationManager.cpp | 36 +- src/Application/JSApplicationManager.h | 6 + src/Application/JSApplicationMetaData.cpp | 142 ++++++++ src/Application/JSApplicationMetaData.h | 81 +++++ src/Application/JSRequestedApplicationControl.cpp | 82 ++--- src/Application/config.xml | 5 + src/Application/plugin_config.cpp | 66 ++-- src/Application/plugin_config.h | 1 + src/Bluetooth/BluetoothAdapter.cpp | 202 +++++++++-- src/Bluetooth/BluetoothAdapter.h | 5 + src/Bluetooth/BluetoothCallback.cpp | 103 ++++++ src/Bluetooth/BluetoothCallback.h | 44 +++ src/Bluetooth/BluetoothCallbackUtil.h | 4 +- src/Bluetooth/BluetoothHealthApplication.cpp | 102 ++++++ src/Bluetooth/BluetoothHealthApplication.h | 63 ++++ src/Bluetooth/BluetoothHealthChannel.cpp | 142 ++++++++ src/Bluetooth/BluetoothHealthChannel.h | 69 ++++ src/Bluetooth/BluetoothHealthProfileHandler.cpp | 397 +++++++++++++++++++++ src/Bluetooth/BluetoothHealthProfileHandler.h | 89 +++++ .../BluetoothHealthProfileHandlerCallback.cpp | 116 ++++++ .../BluetoothHealthProfileHandlerCallback.h | 47 +++ src/Bluetooth/BluetoothServiceHandler.cpp | 5 +- src/Bluetooth/BluetoothServiceHandler.h | 2 +- src/Bluetooth/BluetoothSocket.cpp | 13 +- src/Bluetooth/CMakeLists.txt | 10 +- src/Bluetooth/JSBluetoothAdapter.cpp | 184 ++++++++-- src/Bluetooth/JSBluetoothAdapter.h | 21 ++ src/Bluetooth/JSBluetoothClass.cpp | 9 +- src/Bluetooth/JSBluetoothDevice.cpp | 12 +- src/Bluetooth/JSBluetoothDevice.h | 1 + src/Bluetooth/JSBluetoothHealthApplication.cpp | 244 +++++++++++++ src/Bluetooth/JSBluetoothHealthApplication.h | 103 ++++++ src/Bluetooth/JSBluetoothHealthChannel.cpp | 334 +++++++++++++++++ src/Bluetooth/JSBluetoothHealthChannel.h | 110 ++++++ src/Bluetooth/JSBluetoothHealthProfileHandler.cpp | 208 +++++++++++ src/Bluetooth/JSBluetoothHealthProfileHandler.h | 80 +++++ src/Bluetooth/JSBluetoothManager.cpp | 16 +- src/Bluetooth/JSBluetoothProfileHandler.cpp | 114 ++++++ src/Bluetooth/JSBluetoothProfileHandler.h | 68 ++++ src/Bluetooth/JSBluetoothServiceHandler.cpp | 6 +- src/Bluetooth/JSBluetoothSocket.cpp | 23 +- src/Bluetooth/plugin_config.cpp | 110 ++++++ src/Bluetooth/plugin_config.h | 23 +- src/CMakeLists.txt | 1 + src/Calendar/JSCalendarItemProperties.cpp | 60 ++-- src/Calendar/JSCalendarItemProperties.h | 4 +- src/Contact/ContactObjectA2PConverter.cpp | 4 + src/DataControl/DataControlAsyncCallbackManager.h | 3 +- src/DataControl/EventSelect.h | 28 +- src/Download/JSDownloadRequest.cpp | 7 +- src/MessagePort/MessagePortManagerProxy.cpp | 2 + src/Notification/JSStatusNotification.cpp | 43 ++- src/Notification/StatusNotification.cpp | 139 ++++++++ src/Notification/StatusNotification.h | 9 + src/Notification/plugin_config.h | 5 +- src/Systeminfo/CMakeLists.txt | 1 - src/Systeminfo/JSDeviceCapabilitiesInfo.cpp | 10 +- src/Systeminfo/JSDeviceOrientationInfo.cpp | 4 + src/Systeminfo/Systeminfo.cpp | 21 +- src/Systeminfo/SysteminfoListener.cpp | 4 +- src/Systeminfo/SysteminfoPropertyInfo.h | 8 +- src/WebSetting/CMakeLists.txt | 48 +++ src/WebSetting/JSWebSettingManager.cpp | 191 ++++++++++ src/WebSetting/JSWebSettingManager.h | 86 +++++ src/WebSetting/WebSettingManager.cpp | 113 ++++++ src/WebSetting/WebSettingManager.h | 50 +++ src/WebSetting/WebSettingTypes.h | 32 ++ src/WebSetting/config.xml | 15 + src/WebSetting/plugin_config.cpp | 44 +++ src/WebSetting/plugin_config.h | 46 +++ src/WebSetting/plugin_initializer.cpp | 81 +++++ 80 files changed, 4575 insertions(+), 190 deletions(-) create mode 100755 pkgconfigs/wrt-plugins-tizen-websetting.pc.in create mode 100644 src/Application/ApplicationMetaData.cpp create mode 100644 src/Application/ApplicationMetaData.h create mode 100644 src/Application/JSApplicationMetaData.cpp create mode 100644 src/Application/JSApplicationMetaData.h create mode 100644 src/Bluetooth/BluetoothCallback.cpp create mode 100644 src/Bluetooth/BluetoothCallback.h create mode 100644 src/Bluetooth/BluetoothHealthApplication.cpp create mode 100644 src/Bluetooth/BluetoothHealthApplication.h create mode 100644 src/Bluetooth/BluetoothHealthChannel.cpp create mode 100644 src/Bluetooth/BluetoothHealthChannel.h create mode 100644 src/Bluetooth/BluetoothHealthProfileHandler.cpp create mode 100644 src/Bluetooth/BluetoothHealthProfileHandler.h create mode 100644 src/Bluetooth/BluetoothHealthProfileHandlerCallback.cpp create mode 100644 src/Bluetooth/BluetoothHealthProfileHandlerCallback.h create mode 100644 src/Bluetooth/JSBluetoothHealthApplication.cpp create mode 100644 src/Bluetooth/JSBluetoothHealthApplication.h create mode 100644 src/Bluetooth/JSBluetoothHealthChannel.cpp create mode 100644 src/Bluetooth/JSBluetoothHealthChannel.h create mode 100644 src/Bluetooth/JSBluetoothHealthProfileHandler.cpp create mode 100644 src/Bluetooth/JSBluetoothHealthProfileHandler.h create mode 100644 src/Bluetooth/JSBluetoothProfileHandler.cpp create mode 100644 src/Bluetooth/JSBluetoothProfileHandler.h mode change 100644 => 100755 src/Systeminfo/JSDeviceOrientationInfo.cpp create mode 100755 src/WebSetting/CMakeLists.txt create mode 100755 src/WebSetting/JSWebSettingManager.cpp create mode 100644 src/WebSetting/JSWebSettingManager.h create mode 100755 src/WebSetting/WebSettingManager.cpp create mode 100755 src/WebSetting/WebSettingManager.h create mode 100644 src/WebSetting/WebSettingTypes.h create mode 100644 src/WebSetting/config.xml create mode 100644 src/WebSetting/plugin_config.cpp create mode 100644 src/WebSetting/plugin_config.h create mode 100755 src/WebSetting/plugin_initializer.cpp diff --git a/packaging/wrt-plugins-tizen.spec b/packaging/wrt-plugins-tizen.spec index 89e6274..57d58a9 100755 --- a/packaging/wrt-plugins-tizen.spec +++ b/packaging/wrt-plugins-tizen.spec @@ -1,6 +1,6 @@ Name: wrt-plugins-tizen Summary: JavaScript plugins for WebRuntime -Version: 0.4.43 +Version: 0.4.44 Release: 0 Group: Development/Libraries License: Apache License, Version 2.0 diff --git a/pkgconfigs/wrt-plugins-tizen-websetting.pc.in b/pkgconfigs/wrt-plugins-tizen-websetting.pc.in new file mode 100755 index 0000000..e7346e1 --- /dev/null +++ b/pkgconfigs/wrt-plugins-tizen-websetting.pc.in @@ -0,0 +1,12 @@ +prefix=/usr +project_name=@CMAKE_PROJECT_NAME@ +module_name=websetting +exec_prefix=${prefix} +libdir=${prefix}/lib/wrt-plugins/tizen-${module_name} +includedir=${prefix}/include/${project_name} + +Name: wrt-plugins-tizen-${module_name} +Description: wrt-plugins-tizen-${module_name} +Version: @CMAKE_PROJECT_VERSION@ +Libs: -L${libdir} -lwrt-plugins-tizen-${module_name} +Cflags: -I${includedir}/${module_name} diff --git a/src/Application/ApplicationConverter.cpp b/src/Application/ApplicationConverter.cpp index 849aacb..02318b1 100644 --- a/src/Application/ApplicationConverter.cpp +++ b/src/Application/ApplicationConverter.cpp @@ -30,6 +30,7 @@ #include "JSApplicationControlData.h" #include "JSApplicationControl.h" #include "JSRequestedApplicationControl.h" +#include "JSApplicationMetaData.h" #include "JSApplicationCert.h" namespace DeviceAPI { @@ -66,7 +67,7 @@ JSValueRef ApplicationConverter::toJSValueRefFromApplicationCert(const Applicati } -JSValueRef ApplicationConverter::toJSValueRefFromeApplicationCerts(const ApplicationCertArrayPtr &arg) +JSValueRef ApplicationConverter::toJSValueRefFromApplicationCerts(const ApplicationCertArrayPtr &arg) { if(arg == NULL) { Throw(Commons::InvalidArgumentException); @@ -75,6 +76,24 @@ JSValueRef ApplicationConverter::toJSValueRefFromeApplicationCerts(const Applica } +JSValueRef ApplicationConverter::toJSValueRefFromApplicationMetaData(const ApplicationMetaDataPtr &arg) +{ + if(arg == NULL) { + Throw(Commons::ConversionException); + } + return CommonsJavaScript::JSUtils::makeObject(m_context, JSApplicationMetaData::getClassRef(), arg); +} + + +JSValueRef ApplicationConverter::toJSValueRefFromApplicationMetaDataArray(const ApplicationMetaDataArrayPtr &arg) +{ + if(arg == NULL) { + Throw(Commons::InvalidArgumentException); + } + return toJSValueRef_(*arg, &ApplicationConverter::toJSValueRefFromApplicationMetaData, this); +} + + JSValueRef ApplicationConverter::toJSValueRefFromApplicationInformation(const ApplicationInformationPtr &arg) { if(arg == NULL) { diff --git a/src/Application/ApplicationConverter.h b/src/Application/ApplicationConverter.h index 033ef63..a62bde0 100755 --- a/src/Application/ApplicationConverter.h +++ b/src/Application/ApplicationConverter.h @@ -27,6 +27,7 @@ #include "ApplicationControlData.h" #include "ApplicationControl.h" #include "ApplicationCert.h" +#include "ApplicationMetaData.h" #include "Application.h" #include @@ -42,7 +43,9 @@ public: JSValueRef toJSValueRefFromApplication(const ApplicationPtr &arg); JSValueRef toJSValueRefFromApplicationInformation(const ApplicationInformationPtr &arg); JSValueRef toJSValueRefFromApplicationCert(const ApplicationCertPtr &arg); - JSValueRef toJSValueRefFromeApplicationCerts(const ApplicationCertArrayPtr &arg); + JSValueRef toJSValueRefFromApplicationCerts(const ApplicationCertArrayPtr &arg); + JSValueRef toJSValueRefFromApplicationMetaData(const ApplicationMetaDataPtr &arg); + JSValueRef toJSValueRefFromApplicationMetaDataArray(const ApplicationMetaDataArrayPtr &arg); ApplicationInformationPtr toApplicationInformation(const JSValueRef &jsValue); JSValueRef toJSValueRef(const ApplicationInformationArrayPtr &arg); ApplicationInformationArrayPtr toApplicationInformationArray(const JSValueRef &jsValue); diff --git a/src/Application/ApplicationManager.cpp b/src/Application/ApplicationManager.cpp index 47ce3b8..75d11d4 100644 --- a/src/Application/ApplicationManager.cpp +++ b/src/Application/ApplicationManager.cpp @@ -28,7 +28,6 @@ #include "ApplicationContext.h" #include "ApplicationControlData.h" #include "ApplicationControl.h" -#include "ApplicationCert.h" #include "Application.h" #include @@ -369,6 +368,24 @@ namespace { return true; } + + static int app_meta_data_cb(const char *meta_key, const char *meta_value, void *user_data) + { + if ((meta_key == NULL) || (meta_value == NULL)) { + LoggerE("meta_key or meta_value is null"); + return 0; + } + + ApplicationMetaDataPtr metaData(new ApplicationMetaData()); + + metaData->setKey(meta_key); + metaData->setValue(meta_value); + + ApplicationMetaDataArray *metaDataArray = (ApplicationMetaDataArray *)user_data; + metaDataArray->push_back(metaData); + + return 0; + } } ApplicationManager::ApplicationManager() : @@ -800,13 +817,12 @@ ApplicationCertArrayPtr ApplicationManager::getAppCerts(const std::string id) return certArray; } +std::string ApplicationManager::getAppSharedURI(const std::string id) +{ #define TIZENAPIS_APP_FILE_SCHEME "file://" #define TIZENAPIS_APP_SLASH "/" #define TIZENAPIS_APP_SHARED "shared" - -std::string ApplicationManager::getAppSharedURI(const std::string id) -{ std::string appId; if (id.empty()) { @@ -867,6 +883,43 @@ std::string ApplicationManager::getAppSharedURI(const std::string id) return sharedURI; } +ApplicationMetaDataArrayPtr ApplicationManager::getAppMetaData(const std::string id) +{ + std::string appId = id; + + // in case of no argument, get application information of current. + if (appId.empty()) + { + appId = get_current_app_id(); + } + + int ret = 0; + pkgmgrinfo_appinfo_h handle; + + TIME_TRACER_ITEM_BEGIN("(getAppMetaData)pkgmgrinfo_appinfo_get_appinfo", 0); + ret = pkgmgrinfo_appinfo_get_appinfo(appId.c_str(), &handle); + TIME_TRACER_ITEM_END("(getAppMetaData)pkgmgrinfo_appinfo_get_appinfo", 0); + + if (ret != PMINFO_R_OK) { + ThrowMsg(NotFoundException, "Cannot found application with given appId"); + } + + ApplicationMetaDataArrayPtr metaDataArray(new ApplicationMetaDataArray()); + + TIME_TRACER_ITEM_BEGIN("(getAppMetaData)pkgmgrinfo_appinfo_foreach_metadata", 0); + ret = pkgmgrinfo_appinfo_foreach_metadata(handle, app_meta_data_cb, (void*)metaDataArray.Get()); + TIME_TRACER_ITEM_END("(getAppMetaData)pkgmgrinfo_appinfo_foreach_metadata", 0); + + if (ret != PMINFO_R_OK) { + LoggerE("pkgmgrinfo_appinfo_metadata_filter_foreach() failed"); + pkgmgrinfo_appinfo_destroy_appinfo(handle); + ThrowMsg(UnknownException, "fail to get custom tag"); + } + + pkgmgrinfo_appinfo_destroy_appinfo(handle); + + return metaDataArray; +} void ApplicationManager::OnRequestReceived(const EventApplicationLaunchPtr& event) { diff --git a/src/Application/ApplicationManager.h b/src/Application/ApplicationManager.h index 8640820..b50125a 100644 --- a/src/Application/ApplicationManager.h +++ b/src/Application/ApplicationManager.h @@ -30,6 +30,7 @@ #include "ApplicationContext.h" #include "ApplicationInformation.h" #include "ApplicationCert.h" +#include "ApplicationMetaData.h" //#include #include @@ -65,6 +66,7 @@ public: static ApplicationInformationPtr getAppInfo(const std::string id); static ApplicationCertArrayPtr getAppCerts(const std::string id); static std::string getAppSharedURI(const std::string appId); + static ApplicationMetaDataArrayPtr getAppMetaData(const std::string id); protected: virtual void OnRequestReceived(const EventApplicationLaunchPtr& event); diff --git a/src/Application/ApplicationMetaData.cpp b/src/Application/ApplicationMetaData.cpp new file mode 100644 index 0000000..2711e8d --- /dev/null +++ b/src/Application/ApplicationMetaData.cpp @@ -0,0 +1,51 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include "ApplicationMetaData.h" + +namespace DeviceAPI { +namespace Application { +ApplicationMetaData::ApplicationMetaData() +{ +} + +ApplicationMetaData::~ApplicationMetaData() +{ +} + +std::string ApplicationMetaData::getKey() const +{ + return m_key; +} + +void ApplicationMetaData::setKey(const std::string &key) +{ + m_key = key; +} + +std::string ApplicationMetaData::getValue() const +{ + return m_value; +} + +void ApplicationMetaData::setValue(const std::string &value) +{ + m_value = value; +} + +} +} diff --git a/src/Application/ApplicationMetaData.h b/src/Application/ApplicationMetaData.h new file mode 100644 index 0000000..60e3b29 --- /dev/null +++ b/src/Application/ApplicationMetaData.h @@ -0,0 +1,52 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef TIZENAPIS_API_APPLICATION_META_DATA_H_ +#define TIZENAPIS_API_APPLICATION_META_DATA_H_ + +#include +#include +#include + +namespace DeviceAPI { +namespace Application { + +class ApplicationMetaData; +typedef DPL::SharedPtr ApplicationMetaDataPtr; + +typedef std::vector ApplicationMetaDataArray; +typedef DPL::SharedPtr ApplicationMetaDataArrayPtr; + + +class ApplicationMetaData +{ + public: + ApplicationMetaData(); + ~ApplicationMetaData(); + + std::string getKey() const; + void setKey(const std::string &key); + std::string getValue() const; + void setValue(const std::string &value); + + private: + std::string m_key; + std::string m_value; +}; +} +} +#endif diff --git a/src/Application/CMakeLists.txt b/src/Application/CMakeLists.txt index 3a2dddf..78b69ff 100644 --- a/src/Application/CMakeLists.txt +++ b/src/Application/CMakeLists.txt @@ -34,6 +34,7 @@ SET(SRCS_IMPL ApplicationFactory.cpp ApplicationInformation.cpp ApplicationCert.cpp + ApplicationMetaData.cpp IApplicationManager.cpp ApplicationManager.cpp AppManagerWrapper.cpp @@ -52,6 +53,7 @@ SET(SRCS_IMPL JSApplicationEventCallbackManager.cpp JSApplicationInformation.cpp JSApplicationCert.cpp + JSApplicationMetaData.cpp ) ADD_LIBRARY(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL}) diff --git a/src/Application/JSApplicationManager.cpp b/src/Application/JSApplicationManager.cpp index 8d3138c..b0b5893 100644 --- a/src/Application/JSApplicationManager.cpp +++ b/src/Application/JSApplicationManager.cpp @@ -97,6 +97,7 @@ JSStaticFunction JSApplicationManager::m_function[] = { { APPLICATION_FUNCTION_API_FIND_APP_CONTROL, JSApplicationManager::findAppControl, kJSPropertyAttributeNone }, { APPLICATION_FUNCTION_API_GET_APP_CERTS, JSApplicationManager::getAppCerts, kJSPropertyAttributeNone }, { APPLICATION_FUNCTION_API_GET_APP_SHARED_URI, JSApplicationManager::getAppSharedURI, kJSPropertyAttributeNone }, + { APPLICATION_FUNCTION_API_GET_APP_META_DATA, JSApplicationManager::getAppMetaData, kJSPropertyAttributeNone }, { 0, 0, 0 } }; @@ -826,7 +827,7 @@ JSValueRef JSApplicationManager::getAppCerts(JSContextRef context, ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); TIME_TRACER_ITEM_END(__FUNCTION__, 0); - return converter->toJSValueRefFromeApplicationCerts(result); + return converter->toJSValueRefFromApplicationCerts(result); } catch (const BasePlatformException &err) { return JSWebAPIErrorFactory::postException(context, exception, err); @@ -867,6 +868,39 @@ JSValueRef JSApplicationManager::getAppSharedURI(JSContextRef context, } } +JSValueRef JSApplicationManager::getAppMetaData(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + + TIME_TRACER_ITEM_BEGIN("(getAppMetaData)ACE", 0); + //AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_GET_APP_META_DATA); + //TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + TIME_TRACER_ITEM_END("(getAppMetaData)ACE", 0); + + try { + ArgumentValidator validator(context, argumentCount, arguments); + + ApplicationMetaDataArrayPtr result = ApplicationManager::getAppMetaData(validator.toString(0, true, "")); + ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); + + TIME_TRACER_ITEM_END(__FUNCTION__, 0); + return converter->toJSValueRefFromApplicationMetaDataArray(result); + + } catch (const BasePlatformException &err) { + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (const WrtDeviceApis::Commons::NotFoundException& ex) { + return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, ex.GetMessage()); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error in ApplicationManager.getAppCerts()."); + return JSWebAPIErrorFactory::postException(context, exception, err); + } +} + void JSApplicationManager::setTitleProperty(JSContextRef context, std::string propertyValue){ WrtDeviceApis::CommonsJavaScript::Converter converter(context); diff --git a/src/Application/JSApplicationManager.h b/src/Application/JSApplicationManager.h index 3f28d1d..c7826d0 100644 --- a/src/Application/JSApplicationManager.h +++ b/src/Application/JSApplicationManager.h @@ -140,6 +140,12 @@ private: const JSValueRef arguments[], JSValueRef* exception); /** + * Get meta data of specific application + */ + static JSValueRef getAppMetaData(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, + const JSValueRef arguments[], JSValueRef* exception); + + /** * This structure contains properties and callbacks that define a type of object. */ static JSClassDefinition m_classInfo; diff --git a/src/Application/JSApplicationMetaData.cpp b/src/Application/JSApplicationMetaData.cpp new file mode 100644 index 0000000..8abeb0e --- /dev/null +++ b/src/Application/JSApplicationMetaData.cpp @@ -0,0 +1,142 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + + +#include +#include +#include +#include + +//#include +#include + +#include "ApplicationMetaData.h" +#include "JSApplicationMetaData.h" +#include +#include + +namespace DeviceAPI { +namespace Application { + +using namespace WrtDeviceApis; +using namespace DeviceAPI::Common; + + +JSClassRef JSApplicationMetaData::m_classRef = NULL; + +JSClassDefinition JSApplicationMetaData::m_classInfo = { + 0, + kJSClassAttributeNone, + TIZEN_INTERFACE_APPLICATION_META_DATA, + 0, + m_property, + 0, + initialize, + finalize, + NULL, //HasProperty, + NULL, //GetProperty, + NULL, //SetProperty, + NULL, //DeleteProperty, + NULL, //GetPropertyNames, + NULL, //CallAsFunction, + NULL, //CallAsConstructor, + NULL, + NULL, //ConvertToType +}; + +JSStaticValue JSApplicationMetaData::m_property[] = { + { TIZEN_APPLICATION_META_DATA_KEY, getProperty, NULL, kJSPropertyAttributeReadOnly }, + { TIZEN_APPLICATION_META_DATA_VALUE, getProperty, NULL, kJSPropertyAttributeReadOnly }, + { 0, 0, 0, 0 } +}; + +JSClassRef DLL_EXPORT JSApplicationMetaData::getClassRef() { + if (!m_classRef) { + m_classRef = JSClassCreate(&m_classInfo); + } + return m_classRef; +} + + +void JSApplicationMetaData::initialize(JSContextRef context, JSObjectRef object) +{ +} + +void JSApplicationMetaData::finalize(JSObjectRef object) +{ + JSApplicationMetaDataPriv* priv = static_cast(JSObjectGetPrivate(object)); + JSObjectSetPrivate(object, NULL); + delete priv; +} + +bool JSApplicationMetaData::isObjectOfClass(JSContextRef context, JSValueRef value) +{ + return JSValueIsObjectOfClass(context, value, getClassRef()); +} + +ApplicationMetaDataPtr JSApplicationMetaData::getPrivData(JSObjectRef object) +{ + JSApplicationMetaDataPriv *priv = static_cast(JSObjectGetPrivate(object)); + if (!priv) { + throw TypeMismatchException("Private object is null"); + } + ApplicationMetaDataPtr result = priv->getObject(); + if (!result) { + throw TypeMismatchException("Private object is null"); + } + return result; +} + + +JSValueRef JSApplicationMetaData::getProperty(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) +{ + try { + CommonsJavaScript::Converter converter(context); + ApplicationMetaDataPtr privateData = getPrivData(object); + + if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_META_DATA_KEY)) { + return converter.toJSValueRef(privateData->getKey()); + } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_META_DATA_VALUE)) { + std::string value = privateData->getValue(); + + // if key is not exist, return NULL + if (value.empty()) { + return JSValueMakeNull(context); + } + + // if key does not have value, return empty string. + if (value.compare("(null)") == 0) { + value.clear(); + } + + return converter.toJSValueRef(value); + } + } catch (const BasePlatformException &err) { + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured"); + return JSWebAPIErrorFactory::postException(context, exception, err); + } + + return JSValueMakeUndefined(context); +} + +} +} diff --git a/src/Application/JSApplicationMetaData.h b/src/Application/JSApplicationMetaData.h new file mode 100644 index 0000000..e58aa36 --- /dev/null +++ b/src/Application/JSApplicationMetaData.h @@ -0,0 +1,81 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + + +#ifndef TIZENAPIS_TIZEN_JS_APPLICATION_META_DATA_H_ +#define TIZENAPIS_TIZEN_JS_APPLICATION_META_DATA_H_ + +#include +#include +#include + +namespace DeviceAPI { +namespace Application { + +#define TIZEN_INTERFACE_APPLICATION_META_DATA "ApplicationMetaData" + +#define TIZEN_APPLICATION_META_DATA_KEY "key" +#define TIZEN_APPLICATION_META_DATA_VALUE "value" + + +typedef WrtDeviceApis::CommonsJavaScript::PrivateObject JSApplicationMetaDataPriv; + +class JSApplicationMetaData{ +public: + /* + * This initializes this JS class in the JS Engine. + */ + static JSClassRef getClassRef(); + + static bool isObjectOfClass(JSContextRef context, JSValueRef value); + +private: + /** + * The callback invoked when an object is first created. + */ + static void initialize(JSContextRef context, JSObjectRef object); + + /** + * The callback invoked when an object is finalized. + */ + static void finalize(JSObjectRef object); + + /** + * This structure contains properties and callbacks that define a type of object. + */ + static JSClassDefinition m_classInfo; + + /** + * This member variable contains the initialization values for the static properties of this class. + * The values are given according to the data structure JSPropertySpec + */ + static JSStaticValue m_property[]; + + static JSClassRef m_classRef; + + static ApplicationMetaDataPtr getPrivData(JSObjectRef object); + + static JSValueRef getProperty(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception); + +}; + +} +} +#endif diff --git a/src/Application/JSRequestedApplicationControl.cpp b/src/Application/JSRequestedApplicationControl.cpp index 6d4a45e..5b59cf7 100644 --- a/src/Application/JSRequestedApplicationControl.cpp +++ b/src/Application/JSRequestedApplicationControl.cpp @@ -17,13 +17,10 @@ #include #include -#include -#include -#include -#include + #include -#include -#include +#include +#include #include "plugin_config.h" #include "ApplicationConverter.h" @@ -56,13 +53,13 @@ JSClassDefinition JSRequestedApplicationControl::m_classInfo = { initialize, finalize, NULL, //HasProperty, - getProperty, + NULL, NULL, //SetProperty, NULL, //DeleteProperty, NULL, //GetPropertyNames, NULL, //CallAsFunction, NULL, //CallAsConstructor, - hasInstance, + NULL, NULL, //ConvertToType }; @@ -161,7 +158,7 @@ JSValueRef JSRequestedApplicationControl::getProperty(JSContextRef context, JSOb return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mistmatch error."); } - Try { + try { RequestedApplicationControlPtr providerMgr = priv->getObject(); ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); @@ -170,9 +167,11 @@ JSValueRef JSRequestedApplicationControl::getProperty(JSContextRef context, JSOb } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALLER_APP_ID)) { return converter->toJSValueRef(providerMgr->getCallerAppId()); } - } Catch(WrtDeviceApis::Commons::Exception) { - LoggerE("Exception: "<< _rethrown_exception.GetMessage()); - return JSDOMExceptionFactory::UnknownException.make(context, exception); + } catch (const BasePlatformException &err) { + LoggerW("Getting property is failed. %s", err.getMessage().c_str()); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error in RequestedApplicationControl.replyFailure()."); + LoggerW("Getting property is failed. %s", err.getMessage().c_str()); } /* do not return undefined object to find method */ @@ -195,35 +194,34 @@ JSValueRef JSRequestedApplicationControl::replyResult(JSContextRef context, TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); JSRequestedApplicationControlPriv *priv = static_cast(JSObjectGetPrivate(thisObject)); - Try { + try { if (!priv) { ThrowMsg(ConversionException, "Object is null."); } - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); + ArgumentValidator validator(context, argumentCount, arguments); - RequestedApplicationControlPtr providerMgr = priv->getObject(); - std::vector resultArray; - if (argumentCount > 0) { - resultArray = converter->toApplicationControlDataArray(arguments[0]); + JSObjectRef dataArrayObj = validator.toArrayObject(0, true); + std::vector dataArray; + if (dataArrayObj) { + ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); + dataArray = converter->toApplicationControlDataArray(arguments[0]); } - providerMgr->replyResult(resultArray); + RequestedApplicationControlPtr providerMgr = priv->getObject(); + providerMgr->replyResult(dataArray); + TIME_TRACER_ITEM_END(__FUNCTION__, 0); - } Catch (ConversionException) { - LoggerE("Exception: "<<_rethrown_exception.GetMessage()); - return JSWebAPIErrorFactory::postException(context, exception,JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage()); - } Catch (NotFoundException) { - LoggerE("Exception: "<<_rethrown_exception.GetMessage()); - return JSWebAPIErrorFactory::postException(context, exception,JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage()); - } Catch (NullPointerException) { - LoggerE("Exception: "<<_rethrown_exception.GetMessage()); - return JSWebAPIErrorFactory::postException(context, exception,JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage()); - } Catch (Exception) { - LoggerE("Exception: "<<_rethrown_exception.GetMessage()); - return JSWebAPIErrorFactory::postException(context, exception,JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage()); - } return JSValueMakeUndefined(context); + + } catch (const BasePlatformException &err) { + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch(const ConversionException& err) { + return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ""); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error in RequestedApplicationControl.replyResult()."); + return JSWebAPIErrorFactory::postException(context, exception, err); + } } JSValueRef JSRequestedApplicationControl::replyFailure(JSContextRef context, @@ -236,26 +234,24 @@ JSValueRef JSRequestedApplicationControl::replyFailure(JSContextRef context, TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); JSRequestedApplicationControlPriv *priv = static_cast(JSObjectGetPrivate(thisObject)); - Try { + try { if (!priv) { ThrowMsg(ConversionException, "Object is null."); } RequestedApplicationControlPtr providerMgr = priv->getObject(); providerMgr->replyFailure(); + TIME_TRACER_ITEM_END(__FUNCTION__, 0); - } Catch (NotFoundException) { - LoggerE("Exception: "<<_rethrown_exception.GetMessage()); - return JSWebAPIErrorFactory::postException(context, exception,JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage()); - } Catch (NullPointerException) { - LoggerE("Exception: "<<_rethrown_exception.GetMessage()); - return JSWebAPIErrorFactory::postException(context, exception,JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage()); - } Catch (Exception) { - LoggerE("Exception: "<<_rethrown_exception.GetMessage()); - return JSWebAPIErrorFactory::postException(context, exception,JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage()); - } return JSValueMakeUndefined(context); + + } catch (const BasePlatformException &err) { + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error in RequestedApplicationControl.replyFailure()."); + return JSWebAPIErrorFactory::postException(context, exception, err); + } } } diff --git a/src/Application/config.xml b/src/Application/config.xml index 022f496..415b85d 100755 --- a/src/Application/config.xml +++ b/src/Application/config.xml @@ -31,5 +31,10 @@ http://tizen.org/privilege/application.read appmanager.certificate + + + http://tizen.org/privilege/application.info + application.info + diff --git a/src/Application/plugin_config.cpp b/src/Application/plugin_config.cpp index 291d57b..636a017 100755 --- a/src/Application/plugin_config.cpp +++ b/src/Application/plugin_config.cpp @@ -29,6 +29,8 @@ #define APPLICATION_FEATURE_API_KILL "http://tizen.org/privilege/application.kill" #define APPLICATION_FEATURE_API_KILL2 "http://tizen.org/privilege/appmanager.kill" #define APPLICATION_FEATURE_API_CERT "http://tizen.org/privilege/appmanager.certificate" +#define APPLICATION_FEATURE_API_INFO "http://tizen.org/privilege/application.info" + // for backword compatibility #define APPLICATION_FEATURE_API_READ "http://tizen.org/privilege/application.read" @@ -37,6 +39,7 @@ #define APPLICATION_DEVICE_CAP_LAUNCH "application.launch" #define APPLICATION_DEVICE_CAP_KILL "appmanager.kill" #define APPLICATION_DEVICE_CAP_CERT "appmanager.certificate" +#define APPLICATION_DEVICE_CAP_INFO "application.info" //#define APPLICATION_DEVICE_CAP_READ "application.read" //#define APPLICATION_DEVICE_CAP_INSTALL "application.install" @@ -64,34 +67,39 @@ static FunctionMapping createApplicationFunctions() */ ACE_CREATE_DEVICE_CAP(DEVICE_CAP_APPLICATION_LAUNCH, APPLICATION_DEVICE_CAP_LAUNCH); ACE_CREATE_DEVICE_CAP(DEVICE_CAP_APPLICATION_KILL, APPLICATION_DEVICE_CAP_KILL); - ACE_CREATE_DEVICE_CAP(DEVICE_CAP_APPLICATION_CERT, APPLICATION_DEVICE_CAP_CERT); + ACE_CREATE_DEVICE_CAP(DEVICE_CAP_APPLICATION_CERT, APPLICATION_DEVICE_CAP_CERT); + ACE_CREATE_DEVICE_CAP(DEVICE_CAP_APPLICATION_INFO, APPLICATION_DEVICE_CAP_INFO); ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_APPLICATION_LAUNCH); ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_APPLICATION_KILL); - ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_APPLICATION_CERT); + ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_APPLICATION_CERT); + ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_APPLICATION_INFO); + ACE_ADD_DEVICE_CAP(DEVICE_LIST_APPLICATION_LAUNCH, DEVICE_CAP_APPLICATION_LAUNCH); ACE_ADD_DEVICE_CAP(DEVICE_LIST_APPLICATION_KILL, DEVICE_CAP_APPLICATION_KILL); - ACE_ADD_DEVICE_CAP(DEVICE_LIST_APPLICATION_CERT, DEVICE_CAP_APPLICATION_CERT); + ACE_ADD_DEVICE_CAP(DEVICE_LIST_APPLICATION_CERT, DEVICE_CAP_APPLICATION_CERT); + ACE_ADD_DEVICE_CAP(DEVICE_LIST_APPLICATION_INFO, DEVICE_CAP_APPLICATION_INFO); #if 0 - ACE_CREATE_DEVICE_CAPS_LIST(EMPTY_DEVICE_LIST); - - ACE_CREATE_DEVICE_CAP(DEVICE_CAP_APPLICATION_READ, APPLICATION_DEVICE_CAP_READ); - ACE_CREATE_DEVICE_CAP(DEVICE_CAP_APPLICATION_INSTALL, APPLICATION_DEVICE_CAP_INSTALL); - ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_APPLICATION_READ); - ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_APPLICATION_INSTALL); - ACE_ADD_DEVICE_CAP(DEVICE_LIST_APPLICATION_READ, DEVICE_CAP_APPLICATION_READ); - ACE_ADD_DEVICE_CAP(DEVICE_LIST_APPLICATION_INSTALL, DEVICE_CAP_APPLICATION_INSTALL); + ACE_CREATE_DEVICE_CAPS_LIST(EMPTY_DEVICE_LIST); + + ACE_CREATE_DEVICE_CAP(DEVICE_CAP_APPLICATION_READ, APPLICATION_DEVICE_CAP_READ); + ACE_CREATE_DEVICE_CAP(DEVICE_CAP_APPLICATION_INSTALL, APPLICATION_DEVICE_CAP_INSTALL); + ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_APPLICATION_READ); + ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_APPLICATION_INSTALL); + ACE_ADD_DEVICE_CAP(DEVICE_LIST_APPLICATION_READ, DEVICE_CAP_APPLICATION_READ); + ACE_ADD_DEVICE_CAP(DEVICE_LIST_APPLICATION_INSTALL, DEVICE_CAP_APPLICATION_INSTALL); #endif /** * Api Features */ ACE_CREATE_FEATURE(FEATURE_APPLICATION_LAUNCH, APPLICATION_FEATURE_API_LAUNCH); - ACE_CREATE_FEATURE(FEATURE_APPLICATION_KILL, APPLICATION_FEATURE_API_KILL); - ACE_CREATE_FEATURE(FEATURE_APPLICATION_KILL2, APPLICATION_FEATURE_API_KILL2); - ACE_CREATE_FEATURE(FEATURE_APPLICATION_CERT, APPLICATION_FEATURE_API_CERT); - ACE_CREATE_FEATURE(FEATURE_APPLICATION_READ, APPLICATION_FEATURE_API_READ); + ACE_CREATE_FEATURE(FEATURE_APPLICATION_KILL, APPLICATION_FEATURE_API_KILL); + ACE_CREATE_FEATURE(FEATURE_APPLICATION_KILL2, APPLICATION_FEATURE_API_KILL2); + ACE_CREATE_FEATURE(FEATURE_APPLICATION_CERT, APPLICATION_FEATURE_API_CERT); + ACE_CREATE_FEATURE(FEATURE_APPLICATION_READ, APPLICATION_FEATURE_API_READ); + ACE_CREATE_FEATURE(FEATURE_APPLICATION_INFO, APPLICATION_FEATURE_API_INFO); ACE_CREATE_FEATURE_LIST(APPLICATION_FEATURES_APPLICATION_LAUNCH); @@ -99,15 +107,19 @@ static FunctionMapping createApplicationFunctions() ACE_CREATE_FEATURE_LIST(APPLICATION_FEATURES_APPLICATION_KILL); ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_KILL, FEATURE_APPLICATION_KILL); - ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_KILL, FEATURE_APPLICATION_KILL2); + ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_KILL, FEATURE_APPLICATION_KILL2); + + ACE_CREATE_FEATURE_LIST(APPLICATION_FEATURES_APPLICATION_CERT); + ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_CERT, FEATURE_APPLICATION_CERT); + ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_CERT, FEATURE_APPLICATION_READ); + + ACE_CREATE_FEATURE_LIST(APPLICATION_FEATURES_APPLICATION_INFO); + ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_INFO, FEATURE_APPLICATION_INFO); - ACE_CREATE_FEATURE_LIST(APPLICATION_FEATURES_APPLICATION_CERT); - ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_CERT, FEATURE_APPLICATION_CERT); - ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_CERT, FEATURE_APPLICATION_READ); #if 0 - ACE_CREATE_FEATURE(FEATURE_APPLICATION_READ, APPLICATION_FEATURE_API_READ); - ACE_CREATE_FEATURE(FEATURE_APPLICATION_INSTALL, APPLICATION_FEATURE_API_INSTALL); + ACE_CREATE_FEATURE(FEATURE_APPLICATION_READ, APPLICATION_FEATURE_API_READ); + ACE_CREATE_FEATURE(FEATURE_APPLICATION_INSTALL, APPLICATION_FEATURE_API_INSTALL); ACE_CREATE_FEATURE_LIST(APPLICATION_FEATURES_APPLICATION_READ); ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_READ, FEATURE_APPLICATION_READ); @@ -166,7 +178,17 @@ static FunctionMapping createApplicationFunctions() APPLICATION_FUNCTION_API_GET_APP_CERTS, getAppCertsFunc)); - + // getAppMetaData + AceFunction getAppMetaDataFunc = ACE_CREATE_FUNCTION( + FUNCTION_GET_APP_META_DATA, + APPLICATION_FUNCTION_API_GET_APP_META_DATA, + APPLICATION_FEATURES_APPLICATION_INFO, + DEVICE_LIST_APPLICATION_INFO); + + applicationMapping.insert(std::make_pair( + APPLICATION_FUNCTION_API_GET_APP_META_DATA, + getAppMetaDataFunc)); + #if 0 // setUserAgent diff --git a/src/Application/plugin_config.h b/src/Application/plugin_config.h index 0e44e7e..0cfd8fb 100755 --- a/src/Application/plugin_config.h +++ b/src/Application/plugin_config.h @@ -47,6 +47,7 @@ #define APPLICATION_FUNCTION_API_REPLY_RESULT "replyResult" #define APPLICATION_FUNCTION_API_REPLY_FAILURE "replyFailure" #define APPLICATION_FUNCTION_API_GET_APP_SHARED_URI "getAppSharedURI" +#define APPLICATION_FUNCTION_API_GET_APP_META_DATA "getAppMetaData" #define APPLICATION_FUNCTION_API_SET_USER_AGENT "setUserAgent" namespace DeviceAPI { diff --git a/src/Bluetooth/BluetoothAdapter.cpp b/src/Bluetooth/BluetoothAdapter.cpp index 8ea4789..09b970c 100644 --- a/src/Bluetooth/BluetoothAdapter.cpp +++ b/src/Bluetooth/BluetoothAdapter.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "BluetoothAdapter.h" #include "BluetoothCallbackUtil.h" @@ -36,17 +37,28 @@ namespace Bluetooth { void BluetoothAdapter::onStateChangedCB(int result, bt_adapter_state_e adapterState, void *userData) { + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + BluetoothAdapterPtr object = static_cast(userData); if(!object) { LoggerW("userData is NULL"); return; } + + bool previousState = object->mEnabled; object->mEnabled = (adapterState == BT_ADAPTER_ENABLED) ? true : false; + // call onstatechanged in ChangeListener + if(previousState != object->mEnabled && result == BT_ERROR_NONE && object->mChangeListener != NULL) { + LoggerD("call onstatechanged in ChangeListener"); + object->mChangeListener->invokeCallback("onstatechanged", JSUtil::toJSValueRef(object->mChangeListener->getContext(), object->mEnabled)); + } + + // call a result callback of setPowered() if(object->mUserDataList[SET_POWERED] != NULL) { // requested event - bool state = (adapterState == BT_ADAPTER_ENABLED) ? true : false; - if(object->mRequestedState != state) { - LoggerW("Requested state is same to current state"); + LoggerD("call a result callback of setPowered()"); + if(object->mRequestedState != object->mEnabled) { + LoggerW("Requested state is not equal to current state"); return; } @@ -75,37 +87,64 @@ void BluetoothAdapter::onStateChangedCB(int result, bt_adapter_state_e adapterSt else { // unexpected event LoggerW("Bluetooth state is changed unexpectedly"); } + + TIME_TRACER_ITEM_END(__FUNCTION__, 1); } void BluetoothAdapter::onNameChangedCB(char *name, void *userData) { + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + BluetoothAdapterPtr object = static_cast(userData); if(!object) { LoggerW("userData is NULL"); return; } + + // call onnamechanged in ChangeListener + if(object->mChangeListener != NULL) { + LoggerD("call onnamechanged in ChangeListener"); + object->mChangeListener->invokeCallback("onnamechanged", JSUtil::toJSValueRef(object->mChangeListener->getContext(), std::string(name))); + } + // call a result callback of setName() if(object->mUserDataList[SET_NAME] != NULL && !strcmp(object->mRequestedName.c_str(), name)) { // requested event MultiCallbackUserDataPtr callback = static_cast(object->mUserDataList[SET_NAME]); object->mUserDataList[SET_NAME].reset(); if(callback) callback->invokeCallback("success"); - bt_adapter_unset_name_changed_cb(); + //bt_adapter_unset_name_changed_cb(); } else { // unexpected event LoggerW("Bluetooth name is changed unexpectedly"); } + + TIME_TRACER_ITEM_END(__FUNCTION__, 1); } void BluetoothAdapter::onVisibilityChangedCB(int result, bt_adapter_visibility_mode_e visibilityMode, void *userData) { + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + BluetoothAdapterPtr object = static_cast(userData); if(!object) { LoggerW("userData is NULL"); return; } + bool previousVisible = object->mVisible; + object->mVisible = (visibilityMode != BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE) ? true : false; + + // call onvisibilitychanged in ChangeListener + if(object->mChangeListener != NULL) { + if(previousVisible != object->mVisible) { + LoggerD("call onvisibilitychanged in ChangeListener"); + object->mChangeListener->invokeCallback("onvisibilitychanged", JSUtil::toJSValueRef(object->mChangeListener->getContext(), object->mVisible)); + } + } + + // call a result callback of setVisible() if(object->mUserDataList[SET_VISIBLE] != NULL) { // requested event //bool visibility = (visibilityMode == BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE) ? false : true; if(object->mRequestedVisibility != visibilityMode) { @@ -128,11 +167,13 @@ void BluetoothAdapter::onVisibilityChangedCB(int result, bt_adapter_visibility_m } } - bt_adapter_unset_visibility_mode_changed_cb(); + //bt_adapter_unset_visibility_mode_changed_cb(); } else { // unexpected event LoggerW("Bluetooth visibility is changed unexpectedly"); } + + TIME_TRACER_ITEM_END(__FUNCTION__, 1); } void BluetoothAdapter::onDiscoveryStateChangedCB(int result, bt_adapter_device_discovery_state_e discoveryState, @@ -331,6 +372,8 @@ bool BluetoothAdapter::foreachBondedDevicesCB(bt_device_info_s *deviceInfo, void void BluetoothAdapter::onBondCreatedCB(int result, bt_device_info_s *deviceInfo, void *userData) { + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + BluetoothAdapterPtr object = static_cast(userData); if(!object) { LoggerW("userData is NULL"); @@ -370,10 +413,14 @@ void BluetoothAdapter::onBondCreatedCB(int result, bt_device_info_s *deviceInfo, else { // unexpected event LoggerW("A bonding is created unexpectedly"); } + + TIME_TRACER_ITEM_END(__FUNCTION__, 1); } void BluetoothAdapter::onBondDestroyedCB(int result, char *remoteAddress, void *userData) { + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + BluetoothAdapterPtr object = static_cast(userData); if(!object) { LoggerW("userData is NULL"); @@ -404,10 +451,14 @@ void BluetoothAdapter::onBondDestroyedCB(int result, char *remoteAddress, void * else { // unexpected event LoggerW("A bonding is destroyed unexpectedly"); } + + TIME_TRACER_ITEM_END(__FUNCTION__, 1); } void BluetoothAdapter::onSocketConnected(int result, bt_socket_connection_state_e state, bt_socket_connection_s *connection, void *userData) { + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + BluetoothAdapterPtr object = static_cast(userData); if(!object) { LoggerW("userData is NULL"); @@ -557,6 +608,8 @@ void BluetoothAdapter::onSocketConnected(int result, bt_socket_connection_state_ if(object->mRegisteredUUID.size() == 0 && object->mConnReqMap.size() == 0 && object->mConnectedSocket.size() == 0) { bt_socket_unset_connection_state_changed_cb(); } + + TIME_TRACER_ITEM_END(__FUNCTION__, 1); } void BluetoothAdapter::onSocketReceivedCB(bt_socket_received_data_s *data, void *userData) @@ -589,18 +642,21 @@ void BluetoothAdapter::onSocketReceivedCB(bt_socket_received_data_s *data, void } BluetoothAdapter::BluetoothAdapter(): - mEnabled(false) + mEnabled(false), mVisible(false) { - if(bt_initialize() != BT_ERROR_NONE) { - LoggerE("bt_initialize() failed"); - } - bt_adapter_state_e state; if (bt_adapter_get_state(&state) == BT_ERROR_NONE) { if (state == BT_ADAPTER_ENABLED) { mEnabled = true; } - } + } + + bt_adapter_visibility_mode_e mode; + if (bt_adapter_get_visibility(&mode, NULL) == BT_ERROR_NONE) { + if (mode != BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE) { + mVisible = true; + } + } if(bt_adapter_set_state_changed_cb(onStateChangedCB, this) != BT_ERROR_NONE) { LoggerE("bt_adapter_set_state_changed_cb() failed"); @@ -608,7 +664,15 @@ BluetoothAdapter::BluetoothAdapter(): if(bt_adapter_set_device_discovery_state_changed_cb(onDiscoveryStateChangedCB, this) != BT_ERROR_NONE) { LoggerE("bt_adapter_set_device_discovery_state_changed_cb() failed"); - } + } + + if(bt_adapter_set_name_changed_cb(onNameChangedCB, this) != BT_ERROR_NONE) { + LoggerE("bt_adapter_set_name_changed_cb() failed"); + } + + if(bt_adapter_set_visibility_mode_changed_cb(onVisibilityChangedCB, this) != BT_ERROR_NONE) { + LoggerE("bt_adapter_set_visibility_mode_changed_cb() failed"); + } } BluetoothAdapter::~BluetoothAdapter() @@ -750,7 +814,9 @@ std::string BluetoothAdapter::getName() const char* name = NULL; std::string str = ""; + TIME_TRACER_ITEM_BEGIN("getName::bt_adapter_get_name", 1); if(bt_adapter_get_name(&name) == BT_ERROR_NONE) { + TIME_TRACER_ITEM_END("getName::bt_adapter_get_name", 1); if (name != NULL) { str = name; @@ -758,6 +824,7 @@ std::string BluetoothAdapter::getName() const } } else { + TIME_TRACER_ITEM_END("getName::bt_adapter_get_name", 1); LoggerE("bt_adapter_get_name() failed"); } @@ -775,7 +842,6 @@ void BluetoothAdapter::setName(std::string &name, MultiCallbackUserDataPtr userD } if(mUserDataList[SET_NAME] == NULL) { - bt_adapter_set_name_changed_cb(onNameChangedCB, this); mUserDataList[SET_NAME] = userData; } else { LoggerE("Already requested"); @@ -783,8 +849,10 @@ void BluetoothAdapter::setName(std::string &name, MultiCallbackUserDataPtr userD BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error); return; } - + + TIME_TRACER_ITEM_BEGIN("setName::bt_adapter_set_name", 1); int ret = bt_adapter_set_name(name.c_str()); + TIME_TRACER_ITEM_END("setName::bt_adapter_set_name", 1); switch(ret) { case BT_ERROR_NONE: @@ -807,8 +875,10 @@ void BluetoothAdapter::setName(std::string &name, MultiCallbackUserDataPtr userD BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error); } } - - bt_adapter_unset_name_changed_cb(); + + //TIME_TRACER_ITEM_BEGIN("setName::bt_adapter_unset_name_changed_cb", 1); + //bt_adapter_unset_name_changed_cb(); + //TIME_TRACER_ITEM_END("setName::bt_adapter_unset_name_changed_cb", 1); mUserDataList[SET_NAME].reset(); } else { // Not enabled LoggerE("Bluetooth device is turned off"); @@ -845,6 +915,8 @@ bool BluetoothAdapter::getPowered() const void BluetoothAdapter::setPowered(bool powered, MultiCallbackUserDataPtr userData) { + TIME_TRACER_ITEM_BEGIN("setPowered::check current state", 1); + if(powered == mEnabled) { LoggerD("same state"); BluetoothCallbackUtil::syncToAsyncSuccessCallback(userData); @@ -861,9 +933,13 @@ void BluetoothAdapter::setPowered(bool powered, MultiCallbackUserDataPtr userDat return; } + TIME_TRACER_ITEM_END("setPowered::check current state", 1); + mRequestedState = powered; if(powered == true) { + TIME_TRACER_ITEM_BEGIN("setPowered::bt_adapter_enable", 1); int ret = bt_adapter_enable(); + TIME_TRACER_ITEM_END("setPowered::bt_adapter_enable", 1); switch(ret) { case BT_ERROR_NONE: @@ -893,7 +969,9 @@ void BluetoothAdapter::setPowered(bool powered, MultiCallbackUserDataPtr userDat } } } else { + TIME_TRACER_ITEM_BEGIN("setPowered::bt_adapter_disable", 1); int ret = bt_adapter_disable(); + TIME_TRACER_ITEM_END("setPowered::bt_adapter_disable", 1); switch(ret) { case BT_ERROR_NONE: @@ -929,6 +1007,7 @@ void BluetoothAdapter::setPowered(bool powered, MultiCallbackUserDataPtr userDat bool BluetoothAdapter::getVisible() const { +/* bt_adapter_visibility_mode_e mode; if (bt_adapter_get_visibility(&mode, NULL) == BT_ERROR_NONE) { @@ -938,6 +1017,8 @@ bool BluetoothAdapter::getVisible() const } return false; +*/ + return mVisible; } void BluetoothAdapter::setVisible(bool visible, unsigned int timeout, MultiCallbackUserDataPtr userData) @@ -953,12 +1034,15 @@ void BluetoothAdapter::setVisible(bool visible, unsigned int timeout, MultiCallb bt_adapter_visibility_mode_e current = BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE; int time = 0; + + TIME_TRACER_ITEM_BEGIN("setVisible::bt_adapter_get_visibility", 1); if(bt_adapter_get_visibility(¤t , &time) != BT_ERROR_NONE) { LoggerE("bt_adapter_get_visibility() failed"); UnknownException *error = new UnknownException("Can't get current visibility"); BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error); return; } + TIME_TRACER_ITEM_END("setVisible::bt_adapter_get_visibility", 1); if(discoverable_mode == current) { if(discoverable_mode != BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE) { @@ -974,7 +1058,6 @@ void BluetoothAdapter::setVisible(bool visible, unsigned int timeout, MultiCallb } if(mUserDataList[SET_VISIBLE] == NULL) { - bt_adapter_set_visibility_mode_changed_cb(onVisibilityChangedCB, this); mUserDataList[SET_VISIBLE] = userData; } else { UnknownException *error = new UnknownException("Already requested"); @@ -982,8 +1065,10 @@ void BluetoothAdapter::setVisible(bool visible, unsigned int timeout, MultiCallb return; } - mRequestedVisibility = discoverable_mode; + mRequestedVisibility = discoverable_mode; + TIME_TRACER_ITEM_BEGIN("setVisible::bt_adapter_set_visibility", 1); int ret = bt_adapter_set_visibility(discoverable_mode, timeout); + TIME_TRACER_ITEM_END("setVisible::bt_adapter_set_visibility", 1); switch(ret) { case BT_ERROR_NONE: { @@ -1002,8 +1087,12 @@ void BluetoothAdapter::setVisible(bool visible, unsigned int timeout, MultiCallb BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error); } } - + + /* + TIME_TRACER_ITEM_BEGIN("setVisible::bt_adapter_unset_visibility_mode_changed_cb", 1); bt_adapter_unset_visibility_mode_changed_cb(); + TIME_TRACER_ITEM_END("setVisible::bt_adapter_unset_visibility_mode_changed_cb", 1); + */ mUserDataList[SET_VISIBLE].reset(); } else { // Not enabled ServiceNotAvailableException *error = new ServiceNotAvailableException("Bluetooth device is turned off"); @@ -1014,6 +1103,8 @@ void BluetoothAdapter::setVisible(bool visible, unsigned int timeout, MultiCallb void BluetoothAdapter::discoverDevices(MultiCallbackUserDataPtr userData) { + TIME_TRACER_ITEM_BEGIN("discoverDevices::current state", 1); + if(mUserDataList[DISCOVER_DEVICES] == NULL) { mUserDataList[DISCOVER_DEVICES] = userData; @@ -1027,9 +1118,13 @@ void BluetoothAdapter::discoverDevices(MultiCallbackUserDataPtr userData) BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error); return; } + + TIME_TRACER_ITEM_END("discoverDevices::current state", 1); - if(mEnabled == true) { + if(mEnabled == true) { + TIME_TRACER_ITEM_BEGIN("discoverDevices::bt_adapter_start_device_discovery", 1); int ret = bt_adapter_start_device_discovery(); + TIME_TRACER_ITEM_END("discoverDevices::bt_adapter_start_device_discovery", 1); switch(ret) { case BT_ERROR_NONE: { @@ -1081,8 +1176,10 @@ void BluetoothAdapter::stopDiscovery(MultiCallbackUserDataPtr userData) BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error); return; } - + + TIME_TRACER_ITEM_BEGIN("stopDiscovery::bt_adapter_stop_device_discovery", 1); int ret = bt_adapter_stop_device_discovery(); + TIME_TRACER_ITEM_END("stopDiscovery::bt_adapter_stop_device_discovery", 1); switch(ret) { case BT_ERROR_NONE: { @@ -1128,7 +1225,9 @@ void BluetoothAdapter::createBonding(std::string &address, MultiCallbackUserData } if(mUserDataList[CREATE_BONDING] == NULL) { + TIME_TRACER_ITEM_BEGIN("createBonding::bt_device_set_bond_created_cb", 1); bt_device_set_bond_created_cb(onBondCreatedCB, this); + TIME_TRACER_ITEM_END("createBonding::bt_device_set_bond_created_cb", 1); mCreateBondingAddress = address; mUserDataList[CREATE_BONDING] = userData; } else { @@ -1139,7 +1238,9 @@ void BluetoothAdapter::createBonding(std::string &address, MultiCallbackUserData } if(mEnabled == true) { + TIME_TRACER_ITEM_BEGIN("createBonding::bt_device_create_bond", 1); int ret = bt_device_create_bond(address.c_str()); + TIME_TRACER_ITEM_END("createBonding::bt_device_create_bond", 1); switch(ret) { case BT_ERROR_NONE: @@ -1167,7 +1268,9 @@ void BluetoothAdapter::createBonding(std::string &address, MultiCallbackUserData BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error); } + TIME_TRACER_ITEM_BEGIN("createBonding::bt_device_unset_bond_created_cb", 1); bt_device_unset_bond_created_cb(); + TIME_TRACER_ITEM_END("createBonding::bt_device_unset_bond_created_cb", 1); mCreateBondingAddress.clear(); mUserDataList[CREATE_BONDING].reset(); } @@ -1182,7 +1285,9 @@ void BluetoothAdapter::destroyBonding(std::string &address, MultiCallbackUserDat } if(mUserDataList[DESTROY_BONDING] == NULL) { + TIME_TRACER_ITEM_BEGIN("destroyBonding::bt_device_set_bond_destroyed_cb", 1); bt_device_set_bond_destroyed_cb(onBondDestroyedCB, this); + TIME_TRACER_ITEM_END("destroyBonding::bt_device_set_bond_destroyed_cb", 1); mDestroyBondingAddress = address; mUserDataList[DESTROY_BONDING] = userData; } else { @@ -1194,14 +1299,19 @@ void BluetoothAdapter::destroyBonding(std::string &address, MultiCallbackUserDat if(mEnabled == true) { bt_device_info_s *deviceInfo = NULL; + TIME_TRACER_ITEM_BEGIN("destroyBonding::bt_adapter_get_bonded_device_info", 1); if(bt_adapter_get_bonded_device_info(address.c_str(), &deviceInfo) != BT_ERROR_NONE || deviceInfo == NULL) { + TIME_TRACER_ITEM_END("destroyBonding::bt_adapter_get_bonded_device_info", 1); LoggerD("There is no bonding"); NotFoundException *error = new NotFoundException("Not found"); BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error); } else { + TIME_TRACER_ITEM_END("destroyBonding::bt_adapter_get_bonded_device_info", 1); bt_adapter_free_device_info(deviceInfo); + TIME_TRACER_ITEM_BEGIN("destroyBonding::bt_device_destroy_bond", 1); int ret = bt_device_destroy_bond(address.c_str()); + TIME_TRACER_ITEM_END("destroyBonding::bt_device_destroy_bond", 1); switch(ret) { case BT_ERROR_NONE: @@ -1227,7 +1337,10 @@ void BluetoothAdapter::destroyBonding(std::string &address, MultiCallbackUserDat BluetoothCallbackUtil::syncToAsyncErrorCallback(userData, error); } + TIME_TRACER_ITEM_BEGIN("destroyBonding::bt_device_unset_bond_destroyed_cb", 1); bt_device_unset_bond_destroyed_cb(); + TIME_TRACER_ITEM_END("destroyBonding::bt_device_unset_bond_destroyed_cb", 1); + mDestroyBondingAddress.clear(); mUserDataList[DESTROY_BONDING].reset(); } @@ -1248,13 +1361,17 @@ void BluetoothAdapter::connectToServiceByUUID(std::string &remoteAddress, std::s if(mEnabled == true) { + TIME_TRACER_ITEM_BEGIN("connectToServiceByUUID::bt_socket_connect_rfcomm", 1); int ret = bt_socket_connect_rfcomm(remoteAddress.c_str(), uuid.c_str()); + TIME_TRACER_ITEM_END("connectToServiceByUUID::bt_socket_connect_rfcomm", 1); switch(ret) { case BT_ERROR_NONE: { LoggerD("bt_socket_connect_rfcomm() succeeded"); + TIME_TRACER_ITEM_BEGIN("connectToServiceByUUID::bt_socket_set_connection_state_changed_cb", 1); bt_socket_set_connection_state_changed_cb(onSocketConnected, this); + TIME_TRACER_ITEM_END("connectToServiceByUUID::bt_socket_set_connection_state_changed_cb", 1); BluetoothConnReqPtr connReq = new BluetoothConnReq(uuid, userData); mConnReqMap.insert(std::pair(remoteAddress, connReq)); @@ -1317,6 +1434,8 @@ void BluetoothAdapter::returnKnownDevices(Common::MultiCallbackUserDataPtr userD void BluetoothAdapter::returnDevice(std::string &address, Common::MultiCallbackUserDataPtr userData) { + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + if(!isValidAddress(address)) { LoggerE("Wrong address"); userData->invokeCallback("error", JSWebAPIErrorFactory::makeErrorObject(userData->getContext(), NotFoundException("Wrong address"))); @@ -1325,13 +1444,17 @@ void BluetoothAdapter::returnDevice(std::string &address, Common::MultiCallbackU if(mEnabled == true) { bt_device_info_s *deviceInfo = NULL; + + TIME_TRACER_ITEM_BEGIN("returnDevice::bt_adapter_get_bonded_device_info", 1); if(bt_adapter_get_bonded_device_info(address.c_str(), &deviceInfo) == BT_ERROR_NONE && - deviceInfo != NULL) { + deviceInfo != NULL) { + TIME_TRACER_ITEM_END("returnDevice::bt_adapter_get_bonded_device_info", 1); BluetoothDeviceSharedPtr device(new BluetoothDevice(deviceInfo)); bt_adapter_free_device_info(deviceInfo); LoggerD("invoke successCallback"); userData->invokeCallback("success", JSBluetoothDevice::createJSObject(userData->getContext(), device)); + TIME_TRACER_ITEM_END("returnDevice::bt_adapter_get_bonded_device_info", 1); return; } @@ -1361,10 +1484,14 @@ void BluetoothAdapter::returnDevice(std::string &address, Common::MultiCallbackU JSWebAPIErrorFactory::makeErrorObject(userData->getContext(), ServiceNotAvailableException("Bluetooth device is turned off")) ); } + + TIME_TRACER_ITEM_END(__FUNCTION__, 1); } void BluetoothAdapter::returnRegisteredService(std::string &uuid, std::string &name, Common::MultiCallbackUserDataPtr userData) { + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + if(!isValidUUID(uuid)) { LoggerE("Wrong UUID"); userData->invokeCallback("error", JSWebAPIErrorFactory::makeErrorObject(userData->getContext(), InvalidValuesException("Wrong UUID"))); @@ -1374,20 +1501,27 @@ void BluetoothAdapter::returnRegisteredService(std::string &uuid, std::string &n if(mEnabled == true) { bool isRegistered; + TIME_TRACER_ITEM_BEGIN("returnRegisteredService::bt_adapter_is_service_used", 1); if(bt_adapter_is_service_used(uuid.c_str(), &isRegistered) == BT_ERROR_NONE && isRegistered == true) { + TIME_TRACER_ITEM_END("returnRegisteredService::bt_adapter_is_service_used", 1); LoggerD("Already registered"); userData->invokeCallback("error", JSWebAPIErrorFactory::makeErrorObject(userData->getContext(), InvalidValuesException("Already registered"))); return; - } + } + TIME_TRACER_ITEM_END("returnRegisteredService::bt_adapter_is_service_used", 1); int socket = -1; + TIME_TRACER_ITEM_BEGIN("returnRegisteredService::bt_socket_create_rfcomm", 1); int ret = bt_socket_create_rfcomm(uuid.c_str(), &socket); + TIME_TRACER_ITEM_END("returnRegisteredService::bt_socket_create_rfcomm", 1); switch(ret) { case BT_ERROR_NONE: { LoggerD("bt_socket_create_rfcomm() succeeded"); + TIME_TRACER_ITEM_BEGIN("returnRegisteredService::bt_socket_listen_and_accept_rfcomm", 1); int ret = bt_socket_listen_and_accept_rfcomm(socket, 0); + TIME_TRACER_ITEM_END("returnRegisteredService::bt_socket_listen_and_accept_rfcomm", 1); switch(ret) { case BT_ERROR_NONE: { @@ -1435,6 +1569,28 @@ void BluetoothAdapter::returnRegisteredService(std::string &uuid, std::string &n JSWebAPIErrorFactory::makeErrorObject(userData->getContext(), ServiceNotAvailableException("Bluetooth device is turned off")) ); } + + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); +} + +void BluetoothAdapter::setChangeListener(MultiCallbackUserDataPtr userData) +{ + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + + LoggerD("Enter"); + mChangeListener = userData; + + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); +} + +void BluetoothAdapter::unsetChangeListener() +{ + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + + LoggerD("Enter"); + mChangeListener.reset(); + + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); } diff --git a/src/Bluetooth/BluetoothAdapter.h b/src/Bluetooth/BluetoothAdapter.h index 604ced4..8b573e0 100644 --- a/src/Bluetooth/BluetoothAdapter.h +++ b/src/Bluetooth/BluetoothAdapter.h @@ -85,6 +85,9 @@ public: void unregisterUUID(std::string &uuid); bool closeConnectedSocket(int socket); void removeConnReq(std::string &remoteAddress); + + void setChangeListener(Common::MultiCallbackUserDataPtr userData); + void unsetChangeListener(); static BluetoothAdapter* getInstance(); static bool isValidAddress(std::string &address); @@ -111,6 +114,7 @@ private: typedef std::map ConnectedSocketMapT; // bool mEnabled; + bool mVisible; ConnReqMultiMapT mConnReqMap; RegisteredUUIDMapT mRegisteredUUID; ConnectedSocketMapT mConnectedSocket; @@ -123,6 +127,7 @@ private: std::vector mDisappearedDevices; std::vector mFoundDevices; std::vector knownDevices; + Common::MultiCallbackUserDataPtr mChangeListener; }; typedef BluetoothAdapter* BluetoothAdapterPtr; diff --git a/src/Bluetooth/BluetoothCallback.cpp b/src/Bluetooth/BluetoothCallback.cpp new file mode 100644 index 0000000..a5088fc --- /dev/null +++ b/src/Bluetooth/BluetoothCallback.cpp @@ -0,0 +1,103 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include + +#include +#include +#include + +#include "BluetoothCallback.h" + + +using namespace DeviceAPI::Common; + +namespace DeviceAPI { +namespace Bluetooth { + + +class BluetoothCallbackData +{ +public: + BluetoothCallbackData(MultiCallbackUserDataPtr callback) + { + mCallback = callback; + mError = NULL; + }; + + BluetoothCallbackData(MultiCallbackUserDataPtr callback, Common::BasePlatformException *error) + { + mCallback = callback; + mError = error; + }; + + virtual ~BluetoothCallbackData() + { + if(mError) + delete mError; + }; + + MultiCallbackUserDataPtr mCallback; + Common::BasePlatformException *mError; +}; + +typedef BluetoothCallbackData* BluetoothCallbackDataPtr; + + +static Eina_Bool jobCompleteCB(void *userData){ + BluetoothCallbackDataPtr data = static_cast(userData); + + if(!data) { + LoggerW("BluetoothCallbackDataPtr is NULL"); + return false; + } + + if(!(data->mCallback)) { + LoggerW("MulticallbackUserData is NULL"); + delete data; + return false; + } + + if(data->mError == NULL) { // Success Callback + LoggerD("Success Callback"); + data->mCallback->invokeCallback("success"); + } + else { // Error Callback + LoggerD("BT_CB_ERROR"); + data->mCallback->invokeCallback("error", JSWebAPIErrorFactory::makeErrorObject(data->mCallback->getContext(), *(data->mError))); + } + + delete data; + return false; +} + +void BluetoothCallback::syncToAsyncSuccessCB(MultiCallbackUserDataPtr callback) +{ + BluetoothCallbackDataPtr data = new BluetoothCallbackData(callback); + ecore_idler_add(jobCompleteCB, data); +} + +void BluetoothCallback::syncToAsyncErrorCB(MultiCallbackUserDataPtr callback, Common::BasePlatformException *error) +{ + BluetoothCallbackDataPtr data = new BluetoothCallbackData(callback, error); + ecore_idler_add(jobCompleteCB, data); +} + + +} // Bluetooth +} // DeviceAPI + diff --git a/src/Bluetooth/BluetoothCallback.h b/src/Bluetooth/BluetoothCallback.h new file mode 100644 index 0000000..726a30c --- /dev/null +++ b/src/Bluetooth/BluetoothCallback.h @@ -0,0 +1,44 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef __TIZEN_BLUETOOTH_CALLBACK_H__ +#define __TIZEN_BLUETOOTH_CALLBACK_H__ + +#include +#include +#include + + +namespace DeviceAPI { +namespace Bluetooth { + + +class BluetoothCallback +{ +public: + static void syncToAsyncSuccessCB(DeviceAPI::Common::MultiCallbackUserDataPtr userData); + static void syncToAsyncErrorCB(DeviceAPI::Common::MultiCallbackUserDataPtr userData, Common::BasePlatformException *error); +}; + + +} // Bluetooth +} // DeviceAPI + + + +#endif // __TIZEN_BLUETOOTH_CALLBACK_H__ + diff --git a/src/Bluetooth/BluetoothCallbackUtil.h b/src/Bluetooth/BluetoothCallbackUtil.h index 610fd42..76926d6 100644 --- a/src/Bluetooth/BluetoothCallbackUtil.h +++ b/src/Bluetooth/BluetoothCallbackUtil.h @@ -73,7 +73,7 @@ public: if(mCBType == BT_CB_ERROR) delete mError; }; - + callbackTypeE mCBType; DeviceAPI::Common::MultiCallbackUserDataPtr mUserData; @@ -88,7 +88,7 @@ typedef BluetoothCallbackUserData* BluetoothCallbackUserDataPtr; class BluetoothCallbackUtil { -public: +public: static void syncToAsyncSuccessCallback(DeviceAPI::Common::MultiCallbackUserDataPtr userData); static void syncToAsyncErrorCallback(DeviceAPI::Common::MultiCallbackUserDataPtr userData, Common::BasePlatformException *error); static void syncToAsyncDeviceCallback(DeviceAPI::Common::MultiCallbackUserDataPtr userData, std::string &address); diff --git a/src/Bluetooth/BluetoothHealthApplication.cpp b/src/Bluetooth/BluetoothHealthApplication.cpp new file mode 100644 index 0000000..6832cb7 --- /dev/null +++ b/src/Bluetooth/BluetoothHealthApplication.cpp @@ -0,0 +1,102 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include "BluetoothHealthApplication.h" +#include "plugin_config.h" + +#include +#include +#include + +using namespace DeviceAPI::Common; + +namespace DeviceAPI { +namespace Bluetooth { + +BluetoothHealthApplication::BluetoothHealthApplication(std::string appID, std::string name, unsigned short dataType) +{ + mAppID = appID; + mName = name; + mDataType = dataType; + mIsRegistered = true; +} + +BluetoothHealthApplication::~BluetoothHealthApplication() +{ + if(mIsRegistered) + bt_hdp_unregister_sink_app(mAppID.c_str()); +} + +std::string BluetoothHealthApplication::getAppID() const +{ + return mAppID; +} + +unsigned short BluetoothHealthApplication::getDataType() const +{ + return mDataType; +} + +std::string BluetoothHealthApplication::getName() const +{ + return mName; +} + +bool BluetoothHealthApplication::setOnConnect(JSContextRef context, JSObjectRef onConnect) +{ + MultiCallbackUserDataPtr callback( + new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context))); + if(!callback){ + LoggerW("Can't create MultiCallbackUserData"); + return false; + } + callback->setCallback("onconnect", onConnect); + mOnConnect = callback; + + return mLocalProperty.setProperty(context, BLUETOOTH_HEALTH_APPLICATION_ONCONNECT, onConnect); +} + +MultiCallbackUserDataPtr BluetoothHealthApplication::getOnConnect() const +{ + return mOnConnect; +} + +JSValueRef BluetoothHealthApplication::getOnConnect(JSContextRef context) +{ + JSValueRef onConnect = mLocalProperty.getProperty(context, BLUETOOTH_HEALTH_APPLICATION_ONCONNECT); + if(onConnect == NULL) { + LoggerD("onconnect is null"); + return JSValueMakeNull(context); + } + + return onConnect; +} + +bool BluetoothHealthApplication::getRegistrationState() const +{ + return mIsRegistered; +} + +void BluetoothHealthApplication::setRegistrationState(bool isRegistered) +{ + mIsRegistered = isRegistered; +} + + +} // Bluetooth +} // DeviceAPI + diff --git a/src/Bluetooth/BluetoothHealthApplication.h b/src/Bluetooth/BluetoothHealthApplication.h new file mode 100644 index 0000000..3f549a6 --- /dev/null +++ b/src/Bluetooth/BluetoothHealthApplication.h @@ -0,0 +1,63 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef __TIZEN_BLUETOOTH_HEALTH_APPLICATION_H__ +#define __TIZEN_BLUETOOTH_HEALTH_APPLICATION_H__ + +#include + +#include +#include + +#include +#include + +namespace DeviceAPI { +namespace Bluetooth { + +class BluetoothHealthApplication +{ +public: + BluetoothHealthApplication(std::string appID, std::string name, unsigned short dataType); + virtual ~BluetoothHealthApplication(); + + std::string getAppID() const; + unsigned short getDataType() const; + std::string getName() const; + bool getRegistrationState() const; + void setRegistrationState(bool isRegistered); + Common::MultiCallbackUserDataPtr getOnConnect() const; + JSValueRef getOnConnect(JSContextRef context); + bool setOnConnect(JSContextRef context, JSObjectRef onConnect); + + +private: + std::string mAppID; + std::string mName; + bool mIsRegistered; + Common::MultiCallbackUserDataPtr mOnConnect; + unsigned short mDataType; + Common::PropertyBag mLocalProperty; +}; + +typedef boost::shared_ptr BluetoothHealthApplicationSharedPtr; + +} // Bluetooth +} // DeviceAPI + +#endif // __TIZEN_BLUETOOTH_HEALTH_APPLICATION_H__ + diff --git a/src/Bluetooth/BluetoothHealthChannel.cpp b/src/Bluetooth/BluetoothHealthChannel.cpp new file mode 100644 index 0000000..6fbd00c --- /dev/null +++ b/src/Bluetooth/BluetoothHealthChannel.cpp @@ -0,0 +1,142 @@ +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include +#include + +#include "BluetoothHealthChannel.h" +#include "JSBluetoothDevice.h" +#include "JSBluetoothHealthApplication.h" + +#include +#include + +using namespace DeviceAPI::Common; + +namespace DeviceAPI { +namespace Bluetooth { + +BluetoothHealthChannel::BluetoothHealthChannel(unsigned int channel, BluetoothDeviceSharedPtr remoteDevice, + bt_hdp_channel_type_e type, BluetoothHealthApplicationSharedPtr application) +{ + mChannel = channel; + mRemoteDevice = remoteDevice; + if(type == BT_HDP_CHANNEL_TYPE_RELIABLE) { + mChannelTypeStr = "RELIABLE"; + } + else { + mChannelTypeStr = "STREAMING"; + } + mChannelType = type; + mApp = application; + mIsConnected = true; +} + +BluetoothHealthChannel::~BluetoothHealthChannel() +{ + if(mIsConnected) { + bt_hdp_disconnect(mRemoteDevice->getAddress().c_str(), mChannel); + } +} + +bool BluetoothHealthChannel::getConnectionState() const +{ + return mIsConnected; +} + +void BluetoothHealthChannel::setConnectionState(bool isConnected) +{ + mIsConnected = isConnected; +} + +unsigned int BluetoothHealthChannel::getChannel() const +{ + return mChannel; +} + +std::string BluetoothHealthChannel::getChannelTypeStr() const +{ + return mChannelTypeStr; +} + +bt_hdp_channel_type_e BluetoothHealthChannel::getChannelType() const +{ + return mChannelType; +} + +JSValueRef BluetoothHealthChannel::getApp(JSContextRef context) +{ + return JSBluetoothHealthApplication::createJSObject(context, mApp); +} + +JSValueRef BluetoothHealthChannel::getPeer(JSContextRef context) +{ + return JSBluetoothDevice::createJSObject(context, mRemoteDevice); +} + +Common::MultiCallbackUserDataPtr BluetoothHealthChannel::getListener() const +{ + return mListener; +} + +unsigned long BluetoothHealthChannel::sendData(char* data, unsigned long size) +{ + unsigned long ret = 0; + TIME_TRACER_ITEM_BEGIN("sendData::bt_hdp_send_data", 1); + if(bt_hdp_send_data(mChannel, data, static_cast(size)) == BT_ERROR_NONE) { + TIME_TRACER_ITEM_END("sendData::bt_hdp_send_data", 1); + LoggerD("bt_hdp_send_data() succeeded"); + ret = size; + } + else { + throw UnknownException("Unknown error"); + } + + //delete data; + return ret; +} + +void BluetoothHealthChannel::close() +{ + if(!mIsConnected) { + LoggerD("Already disconnected"); + return; + } + + TIME_TRACER_ITEM_BEGIN("close::bt_hdp_disconnect", 1); + if(bt_hdp_disconnect(mRemoteDevice->getAddress().c_str(), mChannel) != BT_ERROR_NONE) { + LoggerE("bt_hdp_disconnect() failed"); + throw UnknownException("Unknown error"); + } + TIME_TRACER_ITEM_END("close::bt_hdp_disconnect", 1); + + mIsConnected = false; +} + +void BluetoothHealthChannel::setListener(Common::MultiCallbackUserDataPtr callback) +{ + mListener = callback; +} + +void BluetoothHealthChannel::unsetListener() +{ + mListener.reset(); +} + + +} // Bluetooth +} // DeviceAPI + diff --git a/src/Bluetooth/BluetoothHealthChannel.h b/src/Bluetooth/BluetoothHealthChannel.h new file mode 100644 index 0000000..d10d81f --- /dev/null +++ b/src/Bluetooth/BluetoothHealthChannel.h @@ -0,0 +1,69 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef __TIZEN_BLUETOOTH_HEALTH_CHANNEL_H__ +#define __TIZEN_BLUETOOTH_HEALTH_CHANNEL_H__ + +#include +#include +#include + +#include +#include "BluetoothDevice.h" +#include "BluetoothHealthApplication.h" + +namespace DeviceAPI { +namespace Bluetooth { + +class BluetoothHealthChannel +{ +public: + BluetoothHealthChannel(unsigned int channel, BluetoothDeviceSharedPtr remoteDevice, bt_hdp_channel_type_e type, BluetoothHealthApplicationSharedPtr application); + virtual ~BluetoothHealthChannel(); + + bool getConnectionState() const; + void setConnectionState(bool isConnected); + unsigned int getChannel() const; + std::string getChannelTypeStr() const; + bt_hdp_channel_type_e getChannelType() const; + JSValueRef getApp(JSContextRef context); + JSValueRef getPeer(JSContextRef context); + Common::MultiCallbackUserDataPtr getListener() const; + + unsigned long sendData(char* data, unsigned long size); + void close(); + void setListener(Common::MultiCallbackUserDataPtr callback); + void unsetListener(); + +private: + unsigned int mChannel; + bool mIsConnected; + std::string mChannelTypeStr; + bt_hdp_channel_type_e mChannelType; + BluetoothDeviceSharedPtr mRemoteDevice; + BluetoothHealthApplicationSharedPtr mApp; + + Common::MultiCallbackUserDataPtr mListener; +}; + +typedef BluetoothHealthChannel* BluetoothHealthChannelPtr; + +} // Bluetooth +} // DeviceAPI + +#endif // __TIZEN_BLUETOOTH_HEALTH_CHANNEL_H__ + diff --git a/src/Bluetooth/BluetoothHealthProfileHandler.cpp b/src/Bluetooth/BluetoothHealthProfileHandler.cpp new file mode 100644 index 0000000..c80049e --- /dev/null +++ b/src/Bluetooth/BluetoothHealthProfileHandler.cpp @@ -0,0 +1,397 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + + +#include +#include +#include +#include +#include + +#include "BluetoothHealthProfileHandler.h" +#include "BluetoothHealthProfileHandlerCallback.h" +#include "JSBluetoothHealthApplication.h" +#include "JSBluetoothDevice.h" +#include "JSBluetoothHealthChannel.h" +#include "BluetoothHealthChannel.h" + +using namespace DeviceAPI::Common; + +namespace DeviceAPI { +namespace Bluetooth { + +void BluetoothHealthProfileHandler::onConnected(int result, const char *remote_address, const char *app_id, + bt_hdp_channel_type_e type, unsigned int channel, void *userData) +{ + LoggerD("Enter"); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + + HealthProfileHandlerPtr object = static_cast(userData); + if(!object) { + LoggerW("userData is NULL"); + return; + } + + if(result != BT_ERROR_NONE) { + LoggerD("Not BT_ERROR_NONE"); + } + + LoggerD("Connected app: " << app_id); + LoggerD("Connected channel: " << channel); + + std::string appID(app_id); + RegisteredHealthAppMapT::iterator iter = object->mRegisteredHealthAppMap.find(appID); + if(iter == object->mRegisteredHealthAppMap.end()) { + LoggerW("This app is not registered"); + return; + } + BluetoothHealthApplicationSharedPtr application = iter->second; + + // call BluetoothHealthApplication.onconnect + if(result == BT_ERROR_NONE) { + Common::MultiCallbackUserDataPtr callback = application->getOnConnect(); + if(callback) { + bt_device_info_s *deviceInfo = NULL; + if(bt_adapter_get_bonded_device_info(remote_address, &deviceInfo) == BT_ERROR_NONE && + deviceInfo != NULL) { + BluetoothDeviceSharedPtr device(new BluetoothDevice(deviceInfo)); + bt_adapter_free_device_info(deviceInfo); + + LoggerD("invoke BluetoothHealthApplication.onconnect"); + BluetoothHealthChannelPtr healthChannel = new BluetoothHealthChannel(channel, device, type, application); + object->mConnectedSocketMap.insert(std::pair(channel, healthChannel)); + callback->invokeCallback("success", JSBluetoothHealthChannel::createJSObject(callback->getContext(), healthChannel)); + } + else { + LoggerE("Can't call BluetoothHealthApplication.onconnect because failed to get device info"); + } + } + else { + LoggerD("BluetoothHealthApplication.onconnect is not set"); + } + } + + // in case of connectToSource() + HealthConnReqMapT::iterator i = object->mHealthConnReqMap.find(application); + if(i != object->mHealthConnReqMap.end()) { + LoggerD("Requested connection"); + Common::MultiCallbackUserDataPtr callback = i->second->mUserData; + if(callback) { + if(result == BT_ERROR_NONE) { + BluetoothHealthChannelPtr healthChannel = new BluetoothHealthChannel(channel, i->second->mRemoteDevice, type, application); + //object->mConnectedSocketMap.insert(std::pair(channel, healthChannel)); + callback->invokeCallback("success", JSBluetoothHealthChannel::createJSObject(callback->getContext(), healthChannel)); + } + else { + LoggerE("Failed to establish a connection with health profile"); + callback->invokeCallback("error", + JSWebAPIErrorFactory::makeErrorObject(callback->getContext(), UnknownException("Failed to establish a connection with health profile"))); + } + } + + // Update mHealthConnReqMap + object->mHealthConnReqMap.erase(i); + } + else { + LoggerD("There is no connection request"); + } + + TIME_TRACER_ITEM_END(__FUNCTION__, 1); +} + +void BluetoothHealthProfileHandler::onDisconnected(int result, const char *remote_address, unsigned int channel, void *userData) +{ + LoggerD("Enter"); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + + HealthProfileHandlerPtr object = static_cast(userData); + if(!object) { + LoggerW("userData is NULL"); + return; + } + + LoggerD("Disconnected channel: " << channel); + HealthConnectedSocketMapT::iterator iter = object->mConnectedSocketMap.find(channel); + if(iter == object->mConnectedSocketMap.end()) { + LoggerW("Unexpected health disconnection event"); + return; + } + + if(result == BT_ERROR_NONE) { + BluetoothHealthChannelPtr healthChannel = iter->second; + object->mConnectedSocketMap.erase(iter); + + healthChannel->setConnectionState(false); + MultiCallbackUserDataPtr callback = healthChannel->getListener(); + if(callback) + callback->invokeCallback("onclose"); + } + else { + LoggerW("Failed to disconnect a connection"); + } + + TIME_TRACER_ITEM_END(__FUNCTION__, 1); +} + +void BluetoothHealthProfileHandler::onDataReceivedCB(unsigned int channel, const char *data, unsigned int size, void *userData) +{ + LoggerD("Enter"); + + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + + HealthProfileHandlerPtr object = static_cast(userData); + if(!object) { + LoggerW("userData is NULL"); + return; + } + + LoggerD("data channel: " << channel); + LoggerD("sent data size: " << size); + HealthConnectedSocketMapT::iterator iter = object->mConnectedSocketMap.find(channel); + if(iter == object->mConnectedSocketMap.end()) { + LoggerW("Unexpected health data received event"); + return; + } + + BluetoothHealthChannelPtr healthChannel = iter->second; + MultiCallbackUserDataPtr callback = healthChannel->getListener(); + if(callback) { + std::vector receivedData; + for(unsigned int i = 0; i < size; i++) { + receivedData.push_back(static_cast(data[i])); + } + callback->invokeCallback("onmessage", JSUtil::toJSValueRef_(callback->getContext(), receivedData)); + } + + TIME_TRACER_ITEM_END(__FUNCTION__, 1); +} + +BluetoothHealthProfileHandler* BluetoothHealthProfileHandler::getInstance() +{ + static BluetoothHealthProfileHandler instance; + return &instance; +} + +BluetoothHealthProfileHandler::BluetoothHealthProfileHandler() +{ + if(bt_hdp_set_connection_state_changed_cb(onConnected, onDisconnected, this) != BT_ERROR_NONE) { + LoggerE("bt_hdp_set_connection_state_changed_cb() failed"); + } + + if(bt_hdp_set_data_received_cb(onDataReceivedCB, this) != BT_ERROR_NONE) { + LoggerE("bt_hdp_set_data_received_cb() failed"); + } +} + +BluetoothHealthProfileHandler::~BluetoothHealthProfileHandler() +{ + // unset platform callback + bt_hdp_unset_connection_state_changed_cb(); + bt_hdp_unset_data_received_cb(); + + mHealthConnReqMap.clear(); + mConnectedSocketMap.clear(); + mRegisteredHealthAppMap.clear(); +} + +void BluetoothHealthProfileHandler::registerSinkApp(unsigned short dataType, std::string name, Common::MultiCallbackUserDataPtr callback) +{ + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + BluetoothHealthProfileHandlerCallback::syncToAsyncRegisterCB(callback, dataType, name); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); +} + +void BluetoothHealthProfileHandler::returnRegisteringSinkAppResult(unsigned short dataType, std::string name, Common::MultiCallbackUserDataPtr callback) +{ + LoggerD("Enter"); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + + char *app_id = NULL; + int ret = bt_hdp_register_sink_app(dataType, &app_id); + switch(ret) { + case BT_ERROR_NONE: + { + LoggerD("Registered app: " << app_id); + std::string appID(app_id); + free(app_id); + BluetoothHealthApplicationSharedPtr application(new BluetoothHealthApplication(appID, name, dataType)); + mRegisteredHealthAppMap.insert(std::pair(appID, application)); + if(callback) + callback->invokeCallback("success", JSBluetoothHealthApplication::createJSObject(callback->getContext(), application)); + break; + } + case BT_ERROR_NOT_ENABLED: + { + if(callback) { + callback->invokeCallback("error", + JSWebAPIErrorFactory::makeErrorObject(callback->getContext(), ServiceNotAvailableException("Bluetooth device is turned off"))); + } + break; + } + default: + { + if(callback) { + callback->invokeCallback("error", + JSWebAPIErrorFactory::makeErrorObject(callback->getContext(), UnknownException("Unknown error"))); + } + } + } + + TIME_TRACER_ITEM_END(__FUNCTION__, 1); +} + +/* +void BluetoothHealthProfileHandler::unregisterSinkApplication(JSObjectRef appObj, Common::MultiCallbackUserDataPtr callback) +{ + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + BluetoothHealthProfileHandlerCallback::syncToAsyncUnregisterCB(callback, appObj); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); +} + +void BluetoothHealthProfileHandler::returnUnregisteringResult(JSObjectRef appObj, Common::MultiCallbackUserDataPtr callback) +{ + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + + BluetoothHealthApplicationSharedPtr app = JSBluetoothHealthApplication::toBluetoothHealthApplication(appObj); + int ret = bt_hdp_unregister_sink_app(app->getAppID().c_str()); + switch(ret) { + case BT_ERROR_NONE: + { + //app->setRegistrationState(false); + BluetoothHealthProfileHandlerCallback::syncToAsyncSuccessCB(callback); + break; + } + case BT_ERROR_NOT_ENABLED: + { + ServiceNotAvailableException *error = new ServiceNotAvailableException("Bluetooth device is turned off"); + BluetoothHealthProfileHandlerCallback::syncToAsyncErrorCB(callback, error); + break; + } + default: + { + UnknownException *error = new UnknownException("Unknown error"); + BluetoothHealthProfileHandlerCallback::syncToAsyncErrorCB(callback, error); + } + } + + TIME_TRACER_ITEM_END(__FUNCTION__, 1); +} +*/ + +void BluetoothHealthProfileHandler::unregisterApp(std::string appID, Common::MultiCallbackUserDataPtr callback) +{ + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + BluetoothHealthProfileHandlerCallback::syncToAsyncUnregisterCB(callback, appID); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); +} + +void BluetoothHealthProfileHandler::returnUnregisteringAppResult(std::string appID, Common::MultiCallbackUserDataPtr callback) +{ + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + + RegisteredHealthAppMapT::iterator iter = mRegisteredHealthAppMap.find(appID); + BluetoothHealthApplicationSharedPtr application; + if(iter != mRegisteredHealthAppMap.end()) { + LoggerE("registered Health Application is found"); + application = iter->second; + } + else { + LoggerD("Already unregistered"); + if(callback) + callback->invokeCallback("success"); + return; + } + + int ret = bt_hdp_unregister_sink_app(appID.c_str()); + switch(ret) { + case BT_ERROR_NONE: + { + mRegisteredHealthAppMap.erase(iter); + application->setRegistrationState(false); + if(callback) + callback->invokeCallback("success"); + break; + } + case BT_ERROR_NOT_ENABLED: + { + if(callback) { + callback->invokeCallback("error", + JSWebAPIErrorFactory::makeErrorObject(callback->getContext(), ServiceNotAvailableException("Bluetooth device is turned off"))); + } + break; + } + default: + { + if(callback) { + callback->invokeCallback("error", + JSWebAPIErrorFactory::makeErrorObject(callback->getContext(), UnknownException("Unknown error"))); + } + } + } + + TIME_TRACER_ITEM_END(__FUNCTION__, 1); +} + +void BluetoothHealthProfileHandler::connectToSource(JSObjectRef remoteDeviceObj, JSObjectRef appObj, Common::MultiCallbackUserDataPtr callback) +{ + LoggerD("Enter"); + + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + + BluetoothDeviceSharedPtr device = JSBluetoothDevice::toBluetoothDevice(remoteDeviceObj); + BluetoothHealthApplicationSharedPtr app = JSBluetoothHealthApplication::toBluetoothHealthApplication(appObj); + LoggerD("address: " << device->getAddress().c_str()); + LoggerD("app ID: " << app->getAppID().c_str()); + int ret = bt_hdp_connect_to_source(device->getAddress().c_str(), app->getAppID().c_str()); + switch(ret) { + case BT_ERROR_NONE: + { + LoggerD("NONE"); + HealthConnReqPtr connReq = new HealthConnReq(device, callback); + mHealthConnReqMap.insert(std::pair(app, connReq)); + break; + } + case BT_ERROR_NOT_ENABLED: + { + LoggerD("Not Enabled"); + ServiceNotAvailableException *error = new ServiceNotAvailableException("Bluetooth device is turned off"); + BluetoothHealthProfileHandlerCallback::syncToAsyncErrorCB(callback, error); + break; + } + case BT_ERROR_INVALID_PARAMETER: + case BT_ERROR_REMOTE_DEVICE_NOT_BONDED: + { + LoggerD("invalid value"); + InvalidValuesException *error = new InvalidValuesException("Invalid value"); + BluetoothHealthProfileHandlerCallback::syncToAsyncErrorCB(callback, error); + break; + } + default: + { + LoggerD("Unknown error"); + UnknownException *error = new UnknownException("Unknown error"); + BluetoothHealthProfileHandlerCallback::syncToAsyncErrorCB(callback, error); + } + } + + TIME_TRACER_ITEM_END(__FUNCTION__, 1); +} + + +} // Bluetooth +} // DeviceAPI + diff --git a/src/Bluetooth/BluetoothHealthProfileHandler.h b/src/Bluetooth/BluetoothHealthProfileHandler.h new file mode 100644 index 0000000..e752805 --- /dev/null +++ b/src/Bluetooth/BluetoothHealthProfileHandler.h @@ -0,0 +1,89 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef __TIZEN_BLUETOOTH_ADAPTER_H__ +#define __TIZEN_HEALTH_PROFILE_HANDLER_H__ + +#include +#include +#include + +#include + +#include +#include +#include + +#include "BluetoothHealthChannel.h" +#include "BluetoothHealthApplication.h" +#include "BluetoothDevice.h" + + +namespace DeviceAPI { +namespace Bluetooth { + +class HealthConnReq +{ +public: + HealthConnReq(BluetoothDeviceSharedPtr remoteDevice, Common::MultiCallbackUserDataPtr userData) + { + mRemoteDevice = remoteDevice; + mUserData = userData; + }; + + BluetoothDeviceSharedPtr mRemoteDevice; + Common::MultiCallbackUserDataPtr mUserData; +}; +typedef HealthConnReq* HealthConnReqPtr; + +class BluetoothHealthProfileHandler +{ +public: + static BluetoothHealthProfileHandler* getInstance(); + void registerSinkApp(unsigned short dataType, std::string name, Common::MultiCallbackUserDataPtr callback); + void returnRegisteringSinkAppResult(unsigned short dataType, std::string name, Common::MultiCallbackUserDataPtr callback); +// void unregisterSinkApplication(JSObjectRef appObj, Common::MultiCallbackUserDataPtr callback); +// void returnUnregisteringResult(JSObjectRef appObj, Common::MultiCallbackUserDataPtr callback); + void unregisterApp(std::string appID, Common::MultiCallbackUserDataPtr callback); + void returnUnregisteringAppResult(std::string appID, Common::MultiCallbackUserDataPtr callback); + void connectToSource(JSObjectRef remoteDeviceObj, JSObjectRef appObj, Common::MultiCallbackUserDataPtr callback); + +private: + BluetoothHealthProfileHandler(); + virtual ~BluetoothHealthProfileHandler(); + + static void onConnected(int result, const char *remote_address, const char *app_id, + bt_hdp_channel_type_e type, unsigned int channel, void *userData); + static void onDisconnected(int result, const char *remote_address, unsigned int channel, void *userData); + static void onDataReceivedCB(unsigned int channel, const char *data, unsigned int size, void *userData); + + typedef std::map HealthConnReqMapT; + typedef std::map HealthConnectedSocketMapT; // + typedef std::map RegisteredHealthAppMapT; // + + HealthConnReqMapT mHealthConnReqMap; + HealthConnectedSocketMapT mConnectedSocketMap; + RegisteredHealthAppMapT mRegisteredHealthAppMap; +}; + +typedef BluetoothHealthProfileHandler* HealthProfileHandlerPtr; + +} // Bluetooth +} // DeviceAPI + +#endif // __TIZEN_HEALTH_PROFILE_HANDLER_H__ + diff --git a/src/Bluetooth/BluetoothHealthProfileHandlerCallback.cpp b/src/Bluetooth/BluetoothHealthProfileHandlerCallback.cpp new file mode 100644 index 0000000..aa8b3d1 --- /dev/null +++ b/src/Bluetooth/BluetoothHealthProfileHandlerCallback.cpp @@ -0,0 +1,116 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include + +#include +#include + +#include "BluetoothHealthProfileHandlerCallback.h" +#include "BluetoothHealthProfileHandler.h" + + +using namespace DeviceAPI::Common; + +namespace DeviceAPI { +namespace Bluetooth { + + +class HealthProfileHandlerCallbackData +{ +public: + HealthProfileHandlerCallbackData(MultiCallbackUserDataPtr callback, unsigned short dataType, std::string name) + { + mCallback = callback; + mDataType = dataType; + mName = name; + mIsRegistering = true; + }; + + HealthProfileHandlerCallbackData(MultiCallbackUserDataPtr callback, std::string appID) + { + mCallback = callback; + mAppID = appID; + mIsRegistering = false; + }; + + virtual ~HealthProfileHandlerCallbackData() + { + // Do nothing + }; + + MultiCallbackUserDataPtr mCallback; + unsigned short mDataType; + std::string mName; + std::string mAppID; + bool mIsRegistering; +}; + +typedef HealthProfileHandlerCallbackData* HealthProfileHandlerCallbackDataPtr; + + +static Eina_Bool idlerCallback(void *userData){ + HealthProfileHandlerCallbackDataPtr data = static_cast(userData); + + if(!data) { + LoggerW("BluetoothCallbackDataPtr is NULL"); + return false; + } + + if(!(data->mCallback)) { + LoggerW("MulticallbackUserData is NULL"); + delete data; + return false; + } + + if(data->mIsRegistering) { // registerSinkApplication + LoggerD("In case of registerSinkApplication"); + BluetoothHealthProfileHandler::getInstance()->returnRegisteringSinkAppResult(data->mDataType, data->mName, data->mCallback); + } + else { // unregisterSinkApplication + LoggerD("In case of unregisterSinkApplication"); + BluetoothHealthProfileHandler::getInstance()->returnUnregisteringAppResult(data->mAppID, data->mCallback); + } + + delete data; + return false; +} + +void BluetoothHealthProfileHandlerCallback::syncToAsyncRegisterCB(MultiCallbackUserDataPtr callback, unsigned short dataType, std::string name) +{ + HealthProfileHandlerCallbackDataPtr data = new HealthProfileHandlerCallbackData(callback, dataType, name); + ecore_idler_add(idlerCallback, data); +} + +/* +void BluetoothHealthProfileHandlerCallback::syncToAsyncUnregisterCB(MultiCallbackUserDataPtr callback, JSObjectRef application) +{ + HealthProfileHandlerCallbackDataPtr data = new HealthProfileHandlerCallbackData(callback, application); + ecore_idler_add(idlerCallback, data); +} +*/ +void BluetoothHealthProfileHandlerCallback::syncToAsyncUnregisterCB(MultiCallbackUserDataPtr callback, std::string appID) +{ + HealthProfileHandlerCallbackDataPtr data = new HealthProfileHandlerCallbackData(callback, appID); + ecore_idler_add(idlerCallback, data); +} + + +} // Bluetooth +} // DeviceAPI + + diff --git a/src/Bluetooth/BluetoothHealthProfileHandlerCallback.h b/src/Bluetooth/BluetoothHealthProfileHandlerCallback.h new file mode 100644 index 0000000..c86089e --- /dev/null +++ b/src/Bluetooth/BluetoothHealthProfileHandlerCallback.h @@ -0,0 +1,47 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef __TIZEN_HEALTH_PROFILE_HANDLER_CALLBACK_H__ +#define __TIZEN_HEALTH_PROFILE_HANDLER_CALLBACK_H__ + +#include +#include +#include + +#include "BluetoothCallback.h" + +namespace DeviceAPI { +namespace Bluetooth { + + +class BluetoothHealthProfileHandlerCallback : public BluetoothCallback +{ +public: + static void syncToAsyncRegisterCB(DeviceAPI::Common::MultiCallbackUserDataPtr callback, unsigned short dataType, std::string name); + //static void syncToAsyncUnregisterCB(DeviceAPI::Common::MultiCallbackUserDataPtr callback, JSObjectRef application); + static void syncToAsyncUnregisterCB(DeviceAPI::Common::MultiCallbackUserDataPtr callback, std::string appID); +}; + + +} // Bluetooth +} // DeviceAPI + + + +#endif // __TIZEN_HEALTH_PROFILE_HANDLER_CALLBACK_H__ + + diff --git a/src/Bluetooth/BluetoothServiceHandler.cpp b/src/Bluetooth/BluetoothServiceHandler.cpp index b1cafe4..7995611 100644 --- a/src/Bluetooth/BluetoothServiceHandler.cpp +++ b/src/Bluetooth/BluetoothServiceHandler.cpp @@ -24,6 +24,7 @@ #include "plugin_config.h" #include +#include using namespace DeviceAPI::Common; @@ -99,7 +100,7 @@ void BluetoothServiceHandler::setConnectionState(bool isConnected) mIsConnected = isConnected; } -bool BluetoothServiceHandler::getConnectionState() +bool BluetoothServiceHandler::getConnectionState() const { return mIsConnected; } @@ -107,7 +108,9 @@ bool BluetoothServiceHandler::getConnectionState() void BluetoothServiceHandler::unregister(MultiCallbackUserDataPtr userData) { if(BluetoothAdapter::getInstance()->getPowered() == true) { + TIME_TRACER_ITEM_BEGIN("unregister::bt_socket_destroy_rfcomm", 1); if(bt_socket_destroy_rfcomm(mRegisteredSocket) == BT_ERROR_NONE) { + TIME_TRACER_ITEM_END("unregister::bt_socket_destroy_rfcomm", 1); mIsRegistered = false; BluetoothAdapter::getInstance()->unregisterUUID(mUUID); BluetoothCallbackUtil::syncToAsyncSuccessCallback(userData); diff --git a/src/Bluetooth/BluetoothServiceHandler.h b/src/Bluetooth/BluetoothServiceHandler.h index 3f50010..189f5a2 100644 --- a/src/Bluetooth/BluetoothServiceHandler.h +++ b/src/Bluetooth/BluetoothServiceHandler.h @@ -37,7 +37,7 @@ public: std::string getUUID() const; std::string getName() const; int getRegisteredSocket() const; - bool getConnectionState(); + bool getConnectionState() const; Common::MultiCallbackUserDataPtr getOnConnect() const; JSValueRef getOnConnect(JSContextRef context); diff --git a/src/Bluetooth/BluetoothSocket.cpp b/src/Bluetooth/BluetoothSocket.cpp index e24644b..6e64919 100644 --- a/src/Bluetooth/BluetoothSocket.cpp +++ b/src/Bluetooth/BluetoothSocket.cpp @@ -24,6 +24,7 @@ #include "JSBluetoothDevice.h" #include +#include using namespace DeviceAPI::Common; @@ -179,15 +180,18 @@ JSValueRef BluetoothSocket::getOnError(JSContextRef context) unsigned long BluetoothSocket::writeData(char* data, unsigned long size) { unsigned long ret = 0; + TIME_TRACER_ITEM_BEGIN("writeData::bt_socket_send_data", 1); if(bt_socket_send_data(mConnectedSocket, data, static_cast(size)) == BT_ERROR_NONE) { + TIME_TRACER_ITEM_END("writeData::bt_socket_send_data", 1); LoggerD("bt_socket_send_data() succeeded"); ret = size; } else { + TIME_TRACER_ITEM_END("writeData::bt_socket_send_data", 1); throw UnknownException("Unknown error"); } - delete data; + //delete data; return ret; } @@ -212,11 +216,14 @@ void BluetoothSocket::close() LoggerD("Already disconnected"); return; } - + + TIME_TRACER_ITEM_BEGIN("close::bt_socket_disconnect_rfcomm", 1); if(bt_socket_disconnect_rfcomm(mConnectedSocket) != BT_ERROR_NONE) { + TIME_TRACER_ITEM_END("close::bt_socket_disconnect_rfcomm", 1); LoggerE("bt_socket_disconnect_rfcomm() failed"); throw UnknownException("Unknown error"); - } + } + TIME_TRACER_ITEM_END("close::bt_socket_disconnect_rfcomm", 1); mIsConnected = false; } diff --git a/src/Bluetooth/CMakeLists.txt b/src/Bluetooth/CMakeLists.txt index e64d8bf..c4bb7f7 100644 --- a/src/Bluetooth/CMakeLists.txt +++ b/src/Bluetooth/CMakeLists.txt @@ -21,6 +21,10 @@ SET(SRCS_IMPL JSBluetoothClassDeviceMinor.cpp JSBluetoothClassDeviceService.cpp JSBluetoothServiceHandler.cpp + JSBluetoothHealthApplication.cpp + JSBluetoothHealthChannel.cpp + JSBluetoothProfileHandler.cpp + JSBluetoothHealthProfileHandler.cpp BluetoothAdapter.cpp BluetoothDevice.cpp BluetoothSocket.cpp @@ -30,8 +34,12 @@ SET(SRCS_IMPL BluetoothClassDeviceService.cpp BluetoothServiceHandler.cpp BluetoothCallbackUtil.cpp + BluetoothCallback.cpp + BluetoothHealthApplication.cpp + BluetoothHealthChannel.cpp + BluetoothHealthProfileHandlerCallback.cpp + BluetoothHealthProfileHandler.cpp ) -# BluetoothManager.cpp INCLUDE_DIRECTORIES( ${INCLUDE_COMMON} diff --git a/src/Bluetooth/JSBluetoothAdapter.cpp b/src/Bluetooth/JSBluetoothAdapter.cpp index 221d792..b47aa52 100644 --- a/src/Bluetooth/JSBluetoothAdapter.cpp +++ b/src/Bluetooth/JSBluetoothAdapter.cpp @@ -24,6 +24,7 @@ #include "plugin_config.h" #include "JSBluetoothAdapter.h" #include "BluetoothAdapter.h" +#include "JSBluetoothHealthProfileHandler.h" #include #include @@ -73,6 +74,9 @@ JSStaticFunction JSBluetoothAdapter::m_function[] = { { BLUETOOTH_ADAPTER_API_CREATE_BONDING, createBonding, kJSPropertyAttributeNone }, { BLUETOOTH_ADAPTER_API_DESTROY_BONDING, destroyBonding, kJSPropertyAttributeNone }, { BLUETOOTH_ADAPTER_API_REGISTER_RFCOMMSERVICE_BY_UUID, registerRFCOMMServiceByUUID, kJSPropertyAttributeNone }, + { BLUETOOTH_ADAPTER_API_GET_BLUETOOTH_PROFILE_HANDLER, getBluetoothProfileHandler, kJSPropertyAttributeNone }, + { BLUETOOTH_ADAPTER_API_SET_CHANGE_LISTENER, setChangeListener, kJSPropertyAttributeNone }, + { BLUETOOTH_ADAPTER_API_UNSET_CHANGE_LISTENER, unsetChangeListener, kJSPropertyAttributeNone }, { 0, 0, 0 } }; @@ -141,10 +145,12 @@ JSValueRef JSBluetoothAdapter::setName(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); // Access Check + TIME_TRACER_ITEM_BEGIN("setName::ACE", 1); AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_SET_NAME); + TIME_TRACER_ITEM_END("setName::ACE", 1); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); try { @@ -165,7 +171,7 @@ JSValueRef JSBluetoothAdapter::setName(JSContextRef context, } BluetoothAdapter::getInstance()->setName(name, callback); - TIME_TRACER_ITEM_END(__FUNCTION__, 0); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); return JSValueMakeUndefined(context); } catch (const BasePlatformException &err) { @@ -183,10 +189,12 @@ JSValueRef JSBluetoothAdapter::setPowered(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); // Access Check + TIME_TRACER_ITEM_BEGIN("setPowered::ACE", 1); AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_SET_POWERED); + TIME_TRACER_ITEM_END("setPowered::ACE", 1); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); try { @@ -208,7 +216,7 @@ JSValueRef JSBluetoothAdapter::setPowered(JSContextRef context, } BluetoothAdapter::getInstance()->setPowered(state, callback); - TIME_TRACER_ITEM_END(__FUNCTION__, 0); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); return JSValueMakeUndefined(context); } catch (const BasePlatformException &err) { @@ -226,10 +234,12 @@ JSValueRef JSBluetoothAdapter::setVisible(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); // Access Check + TIME_TRACER_ITEM_BEGIN("setVisible::ACE", 1); AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_SET_VISIBLE); + TIME_TRACER_ITEM_END("setVisible::ACE", 1); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); try { @@ -254,7 +264,7 @@ JSValueRef JSBluetoothAdapter::setVisible(JSContextRef context, } BluetoothAdapter::getInstance()->setVisible(mode, timeout, callback); - TIME_TRACER_ITEM_END(__FUNCTION__, 0); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); return JSValueMakeUndefined(context); } catch (const BasePlatformException &err) { @@ -272,13 +282,17 @@ JSValueRef JSBluetoothAdapter::discoverDevices(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); // Access Check + TIME_TRACER_ITEM_BEGIN("discoverDevices::ACE", 1); AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_DISCOVER_DEVICES); + TIME_TRACER_ITEM_END("discoverDevices::ACE", 1); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); try { + TIME_TRACER_ITEM_BEGIN("discoverDevices::parameter", 1); + // Validate arguments ArgumentValidator validator(context, argumentCount, arguments); @@ -324,10 +338,11 @@ JSValueRef JSBluetoothAdapter::discoverDevices(JSContextRef context, callback->setCallback("error", errorCallback); } + TIME_TRACER_ITEM_END("discoverDevices::parameter", 1); // perform BluetoothAdapter::getInstance()->discoverDevices(callback); - TIME_TRACER_ITEM_END(__FUNCTION__, 0); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); return JSValueMakeUndefined(context); } catch (const BasePlatformException &err) { @@ -345,10 +360,12 @@ JSValueRef JSBluetoothAdapter::stopDiscovery(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); // Access Check + TIME_TRACER_ITEM_BEGIN("stopDiscovery::ACE", 1); AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_STOP_DISCOVERY); + TIME_TRACER_ITEM_END("stopDiscovery::ACE", 1); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); try { @@ -369,7 +386,7 @@ JSValueRef JSBluetoothAdapter::stopDiscovery(JSContextRef context, } BluetoothAdapter::getInstance()->stopDiscovery(callback); - TIME_TRACER_ITEM_END(__FUNCTION__, 0); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); return JSValueMakeUndefined(context); } catch (const BasePlatformException &err) { @@ -387,10 +404,12 @@ JSValueRef JSBluetoothAdapter::getKnownDevices(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); // Access Check + TIME_TRACER_ITEM_BEGIN("getKnownDevices::ACE", 1); AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_GET_KNOWN_DEVICES); + TIME_TRACER_ITEM_END("getKnownDevices::ACE", 1); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); try { @@ -411,7 +430,7 @@ JSValueRef JSBluetoothAdapter::getKnownDevices(JSContextRef context, } BluetoothAdapter::getInstance()->getKnownDevices(callback); - TIME_TRACER_ITEM_END(__FUNCTION__, 0); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); return JSValueMakeUndefined(context); } catch (const BasePlatformException &err) { @@ -429,10 +448,12 @@ JSValueRef JSBluetoothAdapter::getDevice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); // Access Check + TIME_TRACER_ITEM_BEGIN("getDevice::ACE", 1); AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_GET_DEVICE); + TIME_TRACER_ITEM_END("getDevice::ACE", 1); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); try { @@ -454,7 +475,7 @@ JSValueRef JSBluetoothAdapter::getDevice(JSContextRef context, } BluetoothAdapter::getInstance()->getDevice(address, callback); - TIME_TRACER_ITEM_END(__FUNCTION__, 0); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); return JSValueMakeUndefined(context); } catch (const BasePlatformException &err) { @@ -472,10 +493,12 @@ JSValueRef JSBluetoothAdapter::createBonding(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); // Access Check + TIME_TRACER_ITEM_BEGIN("createBonding::ACE", 1); AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_CREATE_BONDING); + TIME_TRACER_ITEM_END("createBonding::ACE", 1); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); try { @@ -497,7 +520,7 @@ JSValueRef JSBluetoothAdapter::createBonding(JSContextRef context, } BluetoothAdapter::getInstance()->createBonding(address, callback); - TIME_TRACER_ITEM_END(__FUNCTION__, 0); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); return JSValueMakeUndefined(context); } catch (const BasePlatformException &err) { @@ -515,10 +538,12 @@ JSValueRef JSBluetoothAdapter::destroyBonding(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); // Access Check + TIME_TRACER_ITEM_BEGIN("destroyBonding::ACE", 1); AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_DESTROY_BONDING); + TIME_TRACER_ITEM_END("destroyBonding::ACE", 1); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); try { @@ -540,7 +565,7 @@ JSValueRef JSBluetoothAdapter::destroyBonding(JSContextRef context, } BluetoothAdapter::getInstance()->destroyBonding(address, callback); - TIME_TRACER_ITEM_END(__FUNCTION__, 0); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); return JSValueMakeUndefined(context); } catch (const BasePlatformException &err) { @@ -558,10 +583,12 @@ JSValueRef JSBluetoothAdapter::registerRFCOMMServiceByUUID(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); // Access Check + TIME_TRACER_ITEM_BEGIN("registerRFCOMMServiceByUUID::ACE", 1); AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_ADAPTER_API_REGISTER_RFCOMMSERVICE_BY_UUID); + TIME_TRACER_ITEM_END("registerRFCOMMServiceByUUID::ACE", 1); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); try { @@ -584,7 +611,7 @@ JSValueRef JSBluetoothAdapter::registerRFCOMMServiceByUUID(JSContextRef context, } BluetoothAdapter::getInstance()->registerRFCOMMServiceByUUID(uuid, name, callback); - TIME_TRACER_ITEM_END(__FUNCTION__, 0); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); return JSValueMakeUndefined(context); } catch (const BasePlatformException &err) { @@ -595,6 +622,123 @@ JSValueRef JSBluetoothAdapter::registerRFCOMMServiceByUUID(JSContextRef context, } } +JSValueRef JSBluetoothAdapter::getBluetoothProfileHandler(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LoggerD("Enter"); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + + try { + // Validate arguments + ArgumentValidator validator(context, argumentCount, arguments); + std::string type = validator.toString(0); // profileType + + // perform + JSObjectRef profileHandler; + bool isCorrectParameter = false; + if(type.compare("HEALTH") == 0) { + isCorrectParameter = true; + profileHandler = JSBluetoothHealthProfileHandler::createJSObject(context); + } + TIME_TRACER_ITEM_END(__FUNCTION__, 1); + + if(!isCorrectParameter) { + throw InvalidValuesException("Invalid Value"); + } + + return profileHandler; + } catch (const BasePlatformException &err) { + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.registerRFCOMMServiceByUUID()."); + return JSWebAPIErrorFactory::postException(context, exception, err); + } +} + +JSValueRef JSBluetoothAdapter::setChangeListener(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LoggerD("Enter"); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + + try { + // Validate arguments + ArgumentValidator validator(context, argumentCount, arguments); + JSObjectRef changeCallbackObj = validator.toCallbackObject(0, false, "onstatechanged", "onnamechanged", "onvisibilitychanged", NULL); + + MultiCallbackUserDataPtr callback( + new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context))); + if(!callback){ + LoggerW("Can't create MultiMultiCallbackUserData"); + } + else { + // onstatechanged + JSValueRef onstatechangedValue = JSUtil::getProperty(context , changeCallbackObj, "onstatechanged"); + if(!JSValueIsUndefined(context, onstatechangedValue)) { + LoggerD("There is a onstatechanged()"); + callback->setCallback("onstatechanged", JSUtil::JSValueToObject(context, onstatechangedValue)); + } + + // onnamechanged + JSValueRef onnamechangedValue = JSUtil::getProperty(context , changeCallbackObj, "onnamechanged"); + if(!JSValueIsUndefined(context, onnamechangedValue)) { + LoggerD("There is a onnamechanged()"); + callback->setCallback("onnamechanged", JSUtil::JSValueToObject(context, onnamechangedValue)); + } + + // onvisibilitychanged + JSValueRef onvisibilitychangedValue = JSUtil::getProperty(context , changeCallbackObj, "onvisibilitychanged"); + if(!JSValueIsUndefined(context, onvisibilitychangedValue)) { + LoggerD("There is a onvisibilitychanged()"); + callback->setCallback("onvisibilitychanged", JSUtil::JSValueToObject(context, onvisibilitychangedValue)); + } + } + + // perform + BluetoothAdapter::getInstance()->setChangeListener(callback); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); + + return JSValueMakeUndefined(context); + } catch (const BasePlatformException &err) { + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.registerRFCOMMServiceByUUID()."); + return JSWebAPIErrorFactory::postException(context, exception, err); + } +} + +JSValueRef JSBluetoothAdapter::unsetChangeListener(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LoggerD("Enter"); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + + try { + // perform + BluetoothAdapter::getInstance()->unsetChangeListener(); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); + + return JSValueMakeUndefined(context); + } catch (const BasePlatformException &err) { + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.registerRFCOMMServiceByUUID()."); + return JSWebAPIErrorFactory::postException(context, exception, err); + } +} + } // Bluetooth } // DeviceAPI diff --git a/src/Bluetooth/JSBluetoothAdapter.h b/src/Bluetooth/JSBluetoothAdapter.h index 161892b..72c56e9 100644 --- a/src/Bluetooth/JSBluetoothAdapter.h +++ b/src/Bluetooth/JSBluetoothAdapter.h @@ -118,6 +118,27 @@ private: const JSValueRef arguments[], JSValueRef* exception); + static JSValueRef getBluetoothProfileHandler(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + + static JSValueRef setChangeListener(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + + static JSValueRef unsetChangeListener(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + /** * This member variable contains the values which has to be passed * when the this class is embedded into JS Engine. diff --git a/src/Bluetooth/JSBluetoothClass.cpp b/src/Bluetooth/JSBluetoothClass.cpp index 2f1e97b..ecc8168 100644 --- a/src/Bluetooth/JSBluetoothClass.cpp +++ b/src/Bluetooth/JSBluetoothClass.cpp @@ -137,10 +137,12 @@ JSValueRef JSBluetoothClass::hasService(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); // Access Check + TIME_TRACER_ITEM_BEGIN("hasService::ACE", 1); AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_CLASS_API_HAS_SERVICE); + TIME_TRACER_ITEM_END("hasService::ACE", 1); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); try { @@ -153,9 +155,10 @@ JSValueRef JSBluetoothClass::hasService(JSContextRef context, ArgumentValidator validator(context, argumentCount, arguments); unsigned long service = validator.toULong(0); // uuid - TIME_TRACER_ITEM_END(__FUNCTION__, 0); + JSValueRef result = JSUtil::toJSValueRef(context, priv->mClass->hasService(service)); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); - return JSUtil::toJSValueRef(context, priv->mClass->hasService(service)); + return result; } catch (const BasePlatformException &err) { return JSWebAPIErrorFactory::postException(context, exception, err); } catch (...) { diff --git a/src/Bluetooth/JSBluetoothDevice.cpp b/src/Bluetooth/JSBluetoothDevice.cpp index 4283313..8b5a4aa 100644 --- a/src/Bluetooth/JSBluetoothDevice.cpp +++ b/src/Bluetooth/JSBluetoothDevice.cpp @@ -94,6 +94,12 @@ JSObjectRef JSBluetoothDevice::createJSObject(JSContextRef context, BluetoothDev return JSObjectMake(context, getClassRef(), static_cast(holder)); } +BluetoothDeviceSharedPtr JSBluetoothDevice::toBluetoothDevice(JSObjectRef deviceObj) +{ + BluetoothDeviceHolderPtr priv = static_cast(JSObjectGetPrivate(deviceObj)); + return priv->mDevice; +} + void JSBluetoothDevice::initialize(JSContextRef context, JSObjectRef object) { // Do nothing @@ -154,10 +160,12 @@ JSValueRef JSBluetoothDevice::connectToServiceByUUID(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); // Access Check + TIME_TRACER_ITEM_BEGIN("connectToServiceByUUID::ACE", 1); AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_DEVICE_API_CONNECT_TO_SERVICE_BY_UUID); + TIME_TRACER_ITEM_END("connectToServiceByUUID::ACE", 1); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); try { @@ -185,7 +193,7 @@ JSValueRef JSBluetoothDevice::connectToServiceByUUID(JSContextRef context, } BluetoothAdapter::getInstance()->connectToServiceByUUID(remoteAddress, uuid, callback); - TIME_TRACER_ITEM_END(__FUNCTION__, 0); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); return JSValueMakeUndefined(context); } catch (const BasePlatformException &err) { diff --git a/src/Bluetooth/JSBluetoothDevice.h b/src/Bluetooth/JSBluetoothDevice.h index 7d6acf1..d14630c 100644 --- a/src/Bluetooth/JSBluetoothDevice.h +++ b/src/Bluetooth/JSBluetoothDevice.h @@ -39,6 +39,7 @@ public: static const JSClassDefinition* getClassInfo(); static const JSClassRef getClassRef(); static JSObjectRef createJSObject(JSContextRef context, BluetoothDeviceSharedPtr device); + static BluetoothDeviceSharedPtr toBluetoothDevice(JSObjectRef deviceObj); private: diff --git a/src/Bluetooth/JSBluetoothHealthApplication.cpp b/src/Bluetooth/JSBluetoothHealthApplication.cpp new file mode 100644 index 0000000..0ff1f30 --- /dev/null +++ b/src/Bluetooth/JSBluetoothHealthApplication.cpp @@ -0,0 +1,244 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include + +#include +#include +#include +#include +#include + +#include "plugin_config.h" +#include "JSBluetoothHealthApplication.h" +#include "BluetoothHealthProfileHandler.h" + +#include +#include + +using namespace WrtDeviceApis::Commons; +using namespace DeviceAPI::Common; + +namespace DeviceAPI { +namespace Bluetooth { + +JSClassDefinition JSBluetoothHealthApplication::m_classInfo = { + 0, + kJSClassAttributeNone, + "BluetoothHealthApplication", + NULL, //ParentClass + m_property, //StaticValues + m_function, //StaticFunctions + initialize, //Initialize + finalize, //Finalize + NULL, //HasProperty, + NULL, //GetProperty, + NULL, //SetProperty, + NULL, //DeleteProperty, + NULL, //GetPropertyNames, + NULL, //CallAsFunction, + NULL, //CallAsConstructor, + NULL, //HasInstance, + NULL //ConvertToType +}; + +JSStaticValue JSBluetoothHealthApplication::m_property[] = { + { BLUETOOTH_HEALTH_APPLICATION_DATA_TYPE, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete }, + { BLUETOOTH_HEALTH_APPLICATION_NAME, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete }, + { BLUETOOTH_HEALTH_APPLICATION_ONCONNECT, getProperty, setProperty, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete }, + //{ BLUETOOTH_HEALTH_APPLICATION_IS_REGISTERED, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete }, + { 0, 0, 0, 0 } +}; + +JSStaticFunction JSBluetoothHealthApplication::m_function[] = { + { BLUETOOTH_HEALTH_APPLICATION_API_UNREGISTER, unregister, kJSPropertyAttributeNone }, + { 0, 0, 0 } +}; + +JSClassRef JSBluetoothHealthApplication::m_jsClassRef = JSClassCreate(JSBluetoothHealthApplication::getClassInfo()); + +const JSClassRef JSBluetoothHealthApplication::getClassRef() +{ + if (!m_jsClassRef) { + m_jsClassRef = JSClassCreate(&m_classInfo); + } + return m_jsClassRef; +} + +const JSClassDefinition* JSBluetoothHealthApplication::getClassInfo() +{ + return &m_classInfo; +} + +JSObjectRef JSBluetoothHealthApplication::createJSObject(JSContextRef context, BluetoothHealthApplicationSharedPtr app) +{ + BluetoothHealthApplicationHolderPtr holder = new BluetoothHealthApplicationHolder(app); + return JSObjectMake(context, getClassRef(), static_cast(holder)); +} + +BluetoothHealthApplicationSharedPtr JSBluetoothHealthApplication::toBluetoothHealthApplication(JSObjectRef appObj) +{ + BluetoothHealthApplicationHolderPtr priv = static_cast(JSObjectGetPrivate(appObj)); + return priv->mApp; +} + +void JSBluetoothHealthApplication::initialize(JSContextRef context, JSObjectRef object) +{ + // Do nothing +} + +void JSBluetoothHealthApplication::finalize(JSObjectRef object) +{ + BluetoothHealthApplicationHolderPtr priv = static_cast(JSObjectGetPrivate(object)); + if (priv) { + JSObjectSetPrivate(object, NULL); + delete priv; + } +} + +JSValueRef JSBluetoothHealthApplication::getProperty(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) +{ + try { + BluetoothHealthApplicationHolderPtr priv = static_cast(JSObjectGetPrivate(object)); + if (!priv) { + throw TypeMismatchException("Private object is NULL"); + } + + if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_HEALTH_APPLICATION_DATA_TYPE)) { + return JSValueMakeNumber(context, priv->mApp->getDataType()); + } + else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_HEALTH_APPLICATION_NAME)) { + return JSUtil::toJSValueRef(context, priv->mApp->getName()); + } + else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_HEALTH_APPLICATION_ONCONNECT)) { + return JSUtil::toJSValueRef(context, priv->mApp->getOnConnect()); + } + /* + else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_HEALTH_APPLICATION_IS_REGISTERED)) { + return JSUtil::toJSValueRef(context, priv->mApp->getRegistrationState()); + } + */ + } catch (const BasePlatformException &err) { + LoggerW("Getting property is failed: " << err.getMessage().c_str()); + } + + return NULL; +} + +bool JSBluetoothHealthApplication::setProperty(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef value, + JSValueRef* exception) +{ + try { + BluetoothHealthApplicationHolderPtr priv = static_cast(JSObjectGetPrivate(object)); + if (!priv) { + throw TypeMismatchException("Private object is NULL"); + } + + if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_HEALTH_APPLICATION_ONCONNECT)) { + JSObjectRef object = NULL; + if(!JSValueIsNull(context, value)) { + if(!JSValueIsObject(context, value)) { + throw TypeMismatchException("Value is not Object"); + } + + JSValueRef ex = NULL; + object = JSValueToObject(context, value, &ex); + if(ex){ + throw TypeMismatchException("Can't convert to Object"); + } + + if(!JSObjectIsFunction(context, object)) { + throw TypeMismatchException("Not function"); + } + } + else { + LoggerD("onconnect() is NULL"); + } + + return priv->mApp->setOnConnect(context, object); + } + } catch (const BasePlatformException &err) { + JSWebAPIErrorFactory::postException(context, exception, err); + } + + return false; +} + + +JSValueRef JSBluetoothHealthApplication::unregister(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LoggerD("Enter"); + + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + + // Access Check + /* + TIME_TRACER_ITEM_BEGIN("unregister::ACE", 1); + AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_HEALTH_APPLICATION_API_UNREGISTER); + TIME_TRACER_ITEM_END("unregister::ACE", 1); + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + */ + + try { + BluetoothHealthApplicationHolderPtr priv = static_cast(JSObjectGetPrivate(thisObject)); + if (!priv) { + throw TypeMismatchException("Private object is NULL"); + } + + ArgumentValidator validator(context, argumentCount, arguments); + JSObjectRef successCallback = validator.toFunction(0, true); // successCallback + JSObjectRef errorCallback = validator.toFunction(1, true); // errorCallback + + // perform + MultiCallbackUserDataPtr callback( + new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context))); + if(!callback){ + LoggerW("Can't create MultiCallbackUserData"); + } + else { + callback->setCallback("success", successCallback); + callback->setCallback("error", errorCallback); + } + + BluetoothHealthProfileHandler::getInstance()->unregisterApp(priv->mApp->getAppID(), callback); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); + + return JSValueMakeUndefined(context); + } catch (const BasePlatformException &err) { + TIME_TRACER_ITEM_END(__FUNCTION__, 1); + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.setName()."); + return JSWebAPIErrorFactory::postException(context, exception, err); + } +} + + +} // Bluetooth +} // DeviceAPI + diff --git a/src/Bluetooth/JSBluetoothHealthApplication.h b/src/Bluetooth/JSBluetoothHealthApplication.h new file mode 100644 index 0000000..c44f405 --- /dev/null +++ b/src/Bluetooth/JSBluetoothHealthApplication.h @@ -0,0 +1,103 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef __TIZEN_JS_BLUETOOTH_HEALTH_APPLICATION_H__ +#define __TIZEN_JS_BLUETOOTH_HEALTH_APPLICATION_H__ + +#include + +#include "BluetoothHealthApplication.h" + +namespace DeviceAPI { +namespace Bluetooth { + +class BluetoothHealthApplicationHolder +{ +public: + BluetoothHealthApplicationHolder(BluetoothHealthApplicationSharedPtr app) {mApp = app;} + BluetoothHealthApplicationSharedPtr mApp; +}; +typedef BluetoothHealthApplicationHolder* BluetoothHealthApplicationHolderPtr; + +class JSBluetoothHealthApplication +{ +public: + static const JSClassDefinition* getClassInfo(); + static const JSClassRef getClassRef(); + static JSObjectRef createJSObject(JSContextRef context, BluetoothHealthApplicationSharedPtr app); + static BluetoothHealthApplicationSharedPtr toBluetoothHealthApplication(JSObjectRef appObj); + +private: + + /** + * The callback invoked when an object is first created. + */ + static void initialize(JSContextRef context, + JSObjectRef object); + + /** + * The callback invoked when an object is finalized. + */ + static void finalize(JSObjectRef object); + + static JSValueRef getProperty(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception); + + static bool setProperty(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef value, + JSValueRef* exception); + + static JSValueRef unregister(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + + /** + * This member variable contains the values which has to be passed + * when the this class is embedded into JS Engine. + */ + static JSClassDefinition m_classInfo; + + /** + * This structure describes a statically declared function property. + */ + static JSStaticFunction m_function[]; + + /** + * This member variable contains the initialization values for the + * properties of this class. The values are given according to + * the data structure JSPropertySpec + */ + static JSStaticValue m_property[]; + + static JSClassRef m_jsClassRef; +}; + + +} // Bluetooth +} // DeviceAPI + +#endif // __TIZEN_JS_BLUETOOTH_HEALTH_APPLICATION_H__ + + + diff --git a/src/Bluetooth/JSBluetoothHealthChannel.cpp b/src/Bluetooth/JSBluetoothHealthChannel.cpp new file mode 100644 index 0000000..a6e30ac --- /dev/null +++ b/src/Bluetooth/JSBluetoothHealthChannel.cpp @@ -0,0 +1,334 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include + +#include +#include +#include +#include +#include +#include + +#include "plugin_config.h" +#include "JSBluetoothHealthChannel.h" +#include "BluetoothHealthProfileHandler.h" + +#include +#include + +using namespace WrtDeviceApis::Commons; +using namespace DeviceAPI::Common; + +namespace DeviceAPI { +namespace Bluetooth { + +JSClassDefinition JSBluetoothHealthChannel::m_classInfo = { + 0, + kJSClassAttributeNone, + "BluetoothHealthChannel", + NULL, //ParentClass + m_property, //StaticValues + m_function, //StaticFunctions + initialize, //Initialize + finalize, //Finalize + NULL, //HasProperty, + NULL, //GetProperty, + NULL, //SetProperty, + NULL, //DeleteProperty, + NULL, //GetPropertyNames, + NULL, //CallAsFunction, + NULL, //CallAsConstructor, + NULL, //HasInstance, + NULL //ConvertToType +}; + +JSStaticValue JSBluetoothHealthChannel::m_property[] = { + { BLUETOOTH_HEALTH_CHANNEL_PEER, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete }, + { BLUETOOTH_HEALTH_CHANNEL_TYPE, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete }, + { BLUETOOTH_HEALTH_CHANNEL_APP, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete }, + { BLUETOOTH_HEALTH_CHANNEL_IS_CONNECTED, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeDontDelete }, + { 0, 0, 0, 0 } +}; + +JSStaticFunction JSBluetoothHealthChannel::m_function[] = { + { BLUETOOTH_HEALTH_CHANNEL_API_SEND_DATA, sendData, kJSPropertyAttributeNone }, + { BLUETOOTH_HEALTH_CHANNEL_API_CLOSE, close, kJSPropertyAttributeNone }, + { BLUETOOTH_HEALTH_CHANNEL_API_SET_LISTENER, setListener, kJSPropertyAttributeNone }, + { BLUETOOTH_HEALTH_CHANNEL_API_UNSET_LISTENER, unsetListener, kJSPropertyAttributeNone }, + { 0, 0, 0 } +}; + +JSClassRef JSBluetoothHealthChannel::m_jsClassRef = JSClassCreate(JSBluetoothHealthChannel::getClassInfo()); + +const JSClassRef JSBluetoothHealthChannel::getClassRef() +{ + if (!m_jsClassRef) { + m_jsClassRef = JSClassCreate(&m_classInfo); + } + return m_jsClassRef; +} + +const JSClassDefinition* JSBluetoothHealthChannel::getClassInfo() +{ + return &m_classInfo; +} + +JSObjectRef JSBluetoothHealthChannel::createJSObject(JSContextRef context, BluetoothHealthChannelPtr channel) +{ + return JSObjectMake(context, getClassRef(), static_cast(channel)); +} + +void JSBluetoothHealthChannel::initialize(JSContextRef context, JSObjectRef object) +{ + // do nothing +} + +void JSBluetoothHealthChannel::finalize(JSObjectRef object) +{ + BluetoothHealthChannelPtr priv = static_cast(JSObjectGetPrivate(object)); + if (priv) { + JSObjectSetPrivate(object, NULL); + delete priv; + } +} + +JSValueRef JSBluetoothHealthChannel::getProperty(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) +{ + try { + BluetoothHealthChannelPtr priv = static_cast(JSObjectGetPrivate(object)); + if (!priv) { + throw TypeMismatchException("Private object is NULL"); + } + + if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_HEALTH_CHANNEL_PEER)) { + return priv->getPeer(context); + } + else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_HEALTH_CHANNEL_TYPE)) { + return JSUtil::toJSValueRef(context, priv->getChannelTypeStr()); + } + else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_HEALTH_CHANNEL_APP)) { + return priv->getApp(context); + } + else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_HEALTH_CHANNEL_IS_CONNECTED)) { + return JSUtil::toJSValueRef(context, priv->getConnectionState()); + } + } catch (const BasePlatformException &err) { + LoggerW("Getting property is failed: " << err.getMessage().c_str()); + } + + return NULL; +} + +JSValueRef JSBluetoothHealthChannel::sendData(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LoggerD("Enter"); + + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);; + + // Access Check + /* + TIME_TRACER_ITEM_BEGIN("sendData::ACE", 1);; + AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_HEALTH_CHANNEL_API_SEND_DATA); + TIME_TRACER_ITEM_END("sendData::ACE", 1);; + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + */ + + try { + // Private Object + BluetoothHealthChannelPtr priv = static_cast(JSObjectGetPrivate(thisObject)); + if (!priv) { + throw DeviceAPI::Common::UnknownException("Private object is NULL."); + } + + ArgumentValidator validator(context, argumentCount, arguments); + + JSObjectRef dataArrayObj = validator.toArrayObject(0); // data + size_t size = JSGetArrayLength(context, dataArrayObj); + char *buffer = new char[size]; + for(size_t i = 0; i < size; ++i) { + JSValueRef element = JSGetArrayElement(context, dataArrayObj, i); + buffer[i] = static_cast(JSUtil::JSValueToByte(context, element)); + } + + JSValueRef result = JSUtil::toJSValueRef(context, priv->sendData(buffer, size)); + delete buffer; + TIME_TRACER_ITEM_END(__FUNCTION__, 1);; + + return result; + } catch (const BasePlatformException &err) { + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error"); + return JSWebAPIErrorFactory::postException(context, exception, err); + } +} + +JSValueRef JSBluetoothHealthChannel::close(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LoggerD("Enter"); + + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);; + + // Access Check + /* + TIME_TRACER_ITEM_BEGIN("close::ACE", 1);; + AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_HEALTH_CHANNEL_API_CLOSE); + TIME_TRACER_ITEM_END("close::ACE", 1);; + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + */ + + try { + // Private Object + BluetoothHealthChannelPtr priv = static_cast(JSObjectGetPrivate(thisObject)); + if (!priv) { + throw DeviceAPI::Common::UnknownException("Private object is NULL."); + } + + priv->close(); + TIME_TRACER_ITEM_END(__FUNCTION__, 1);; + + return JSValueMakeUndefined(context); + } catch (const BasePlatformException &err) { + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error"); + return JSWebAPIErrorFactory::postException(context, exception, err); + } +} + +JSValueRef JSBluetoothHealthChannel::setListener(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LoggerD("Enter"); + + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);; + + // Access Check + /* + TIME_TRACER_ITEM_BEGIN("setListener::ACE", 1);; + AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_HEALTH_CHANNEL_API_SET_LISTENER); + TIME_TRACER_ITEM_END("setListener::ACE", 1);; + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + */ + + try { + // Private Object + BluetoothHealthChannelPtr priv = static_cast(JSObjectGetPrivate(thisObject)); + if (!priv) { + throw DeviceAPI::Common::UnknownException("Private object is NULL."); + } + + // Validate arguments + ArgumentValidator validator(context, argumentCount, arguments); + + // successCallback + JSObjectRef successCallback = validator.toCallbackObject(0, false, "onmessage", "onclose", NULL); + + MultiCallbackUserDataPtr callback( + new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context))); + if(!callback){ + LoggerW("Can't create MultiMultiCallbackUserData"); + } + else { + // onmessage + JSValueRef onmessageValue = JSUtil::getProperty(context , successCallback, "onmessage"); + if(!JSValueIsUndefined(context, onmessageValue)) { + LoggerD("There is a onmessage()"); + callback->setCallback("onmessage", JSUtil::JSValueToObject(context, onmessageValue)); + } + + // onclose + JSValueRef oncloseValue = JSUtil::getProperty(context , successCallback, "onclose"); + if(!JSValueIsUndefined(context, oncloseValue)) { + LoggerD("There is a onclose()"); + callback->setCallback("onclose", JSUtil::JSValueToObject(context, oncloseValue)); + } + } + + priv->setListener(callback); + TIME_TRACER_ITEM_END(__FUNCTION__, 1);; + + return JSValueMakeUndefined(context); + } catch (const BasePlatformException &err) { + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error"); + return JSWebAPIErrorFactory::postException(context, exception, err); + } +} + +JSValueRef JSBluetoothHealthChannel::unsetListener(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LoggerD("Enter"); + + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);; + + // Access Check + /* + TIME_TRACER_ITEM_BEGIN("unsetListener::ACE", 1);; + AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_HEALTH_CHANNEL_API_UNSET_LISTENER); + TIME_TRACER_ITEM_END("unsetListener::ACE", 1);; + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + */ + + try { + // Private Object + BluetoothHealthChannelPtr priv = static_cast(JSObjectGetPrivate(thisObject)); + if (!priv) { + throw DeviceAPI::Common::UnknownException("Private object is NULL."); + } + + priv->unsetListener(); + TIME_TRACER_ITEM_END(__FUNCTION__, 1);; + + return JSValueMakeUndefined(context); + } catch (const BasePlatformException &err) { + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error"); + return JSWebAPIErrorFactory::postException(context, exception, err); + } +} + + + +} // Bluetooth +} // DeviceAPI + diff --git a/src/Bluetooth/JSBluetoothHealthChannel.h b/src/Bluetooth/JSBluetoothHealthChannel.h new file mode 100644 index 0000000..a217353 --- /dev/null +++ b/src/Bluetooth/JSBluetoothHealthChannel.h @@ -0,0 +1,110 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef __TIZEN_JS_BLUETOOTH_HEALTH_CHANNEL_H__ +#define __TIZEN_JS_BLUETOOTH_HEALTH_CHANNEL_H__ + +#include + +#include "BluetoothHealthChannel.h" + +namespace DeviceAPI { +namespace Bluetooth { + +class JSBluetoothHealthChannel +{ +public: + static const JSClassDefinition* getClassInfo(); + static const JSClassRef getClassRef(); + static JSObjectRef createJSObject(JSContextRef context, BluetoothHealthChannelPtr channel); + +private: + + /** + * The callback invoked when an object is first created. + */ + static void initialize(JSContextRef context, + JSObjectRef object); + + /** + * The callback invoked when an object is finalized. + */ + static void finalize(JSObjectRef object); + + static JSValueRef getProperty(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception); + + static JSValueRef close(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + + static JSValueRef sendData(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + + static JSValueRef setListener(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + + static JSValueRef unsetListener(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + + /** + * This member variable contains the values which has to be passed + * when the this class is embedded into JS Engine. + */ + static JSClassDefinition m_classInfo; + + /** + * This structure describes a statically declared function property. + */ + static JSStaticFunction m_function[]; + + /** + * This member variable contains the initialization values for the + * properties of this class. The values are given according to + * the data structure JSPropertySpec + */ + static JSStaticValue m_property[]; + + static JSClassRef m_jsClassRef; +}; + + +} // Bluetooth +} // DeviceAPI + +#endif // __TIZEN_JS_BLUETOOTH_HEALTH_CHANNEL_H__ + + + + diff --git a/src/Bluetooth/JSBluetoothHealthProfileHandler.cpp b/src/Bluetooth/JSBluetoothHealthProfileHandler.cpp new file mode 100644 index 0000000..95101d2 --- /dev/null +++ b/src/Bluetooth/JSBluetoothHealthProfileHandler.cpp @@ -0,0 +1,208 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include + +#include +#include +#include + +#include "plugin_config.h" +#include "JSBluetoothHealthProfileHandler.h" +#include "JSBluetoothProfileHandler.h" +#include "JSBluetoothHealthApplication.h" +#include "JSBluetoothDevice.h" +#include "BluetoothHealthProfileHandler.h" + +#include +#include + +using namespace WrtDeviceApis::Commons; +using namespace DeviceAPI::Common; + +namespace DeviceAPI { +namespace Bluetooth { + +JSClassDefinition JSBluetoothHealthProfileHandler::m_classInfo = { + 0, + kJSClassAttributeNone, + "BluetoothHealthProfileHandler", + JSBluetoothProfileHandler::getClassRef(), //ParentClass + NULL, //StaticValues + m_function, //StaticFunctions + initialize, //Initialize + finalize, //Finalize + NULL, //HasProperty, + NULL, //GetProperty, + NULL, //SetProperty, + NULL, //DeleteProperty, + NULL, //GetPropertyNames, + NULL, //CallAsFunction, + NULL, //CallAsConstructor, + NULL, //HasInstance, + NULL //ConvertToType +}; + +JSStaticFunction JSBluetoothHealthProfileHandler::m_function[] = { + { BLUETOOTH_HEALTH_PROFILE_HANDLER_API_REGISTER_SINK_APPLICATION, registerSinkApplication, kJSPropertyAttributeNone }, + { BLUETOOTH_HEALTH_PROFILE_HANDLER_API_CONNECT_TO_SOURCE, connectToSource, kJSPropertyAttributeNone }, + { 0, 0, 0 } +}; + +JSClassRef JSBluetoothHealthProfileHandler::m_jsClassRef = JSClassCreate(JSBluetoothHealthProfileHandler::getClassInfo()); + +const JSClassRef JSBluetoothHealthProfileHandler::getClassRef() +{ + if (!m_jsClassRef) { + m_jsClassRef = JSClassCreate(&m_classInfo); + } + return m_jsClassRef; +} + +const JSClassDefinition* JSBluetoothHealthProfileHandler::getClassInfo() +{ + return &m_classInfo; +} + +JSObjectRef JSBluetoothHealthProfileHandler::createJSObject(JSContextRef context) +{ + return JSObjectMake(context, getClassRef(), NULL); +} + +void JSBluetoothHealthProfileHandler::initialize(JSContextRef context, JSObjectRef object) +{ + // do nothing +} + + +void JSBluetoothHealthProfileHandler::finalize(JSObjectRef object) +{ + // do nothing +} + +JSValueRef JSBluetoothHealthProfileHandler::registerSinkApplication(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LoggerD("Enter"); + + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + + // Access Check + /* + TIME_TRACER_ITEM_BEGIN("registerSinkApplication::ACE", 1); + AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_HEALTH_PROFILE_HANDLER_API_REGISTER_SINK_APPLICATION); + TIME_TRACER_ITEM_END("registerSinkApplication::ACE", 1); + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + */ + + try { + ArgumentValidator validator(context, argumentCount, arguments); + unsigned short dataType = static_cast(validator.toULong(0)); // dataType + std::string name = validator.toString(1); // name + JSObjectRef successCallback = validator.toFunction(2); // successCallback + JSObjectRef errorCallback = validator.toFunction(3, true); // errorCallback + + // perform + MultiCallbackUserDataPtr callback( + new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context))); + if(!callback){ + LoggerW("Can't create MultiCallbackUserData"); + } + else { + callback->setCallback("success", successCallback); + callback->setCallback("error", errorCallback); + } + + BluetoothHealthProfileHandler::getInstance()->registerSinkApp(dataType, name, callback); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); + + return JSValueMakeUndefined(context); + } catch (const BasePlatformException &err) { + TIME_TRACER_ITEM_END(__FUNCTION__, 1); + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.setName()."); + return JSWebAPIErrorFactory::postException(context, exception, err); + } +} + +JSValueRef JSBluetoothHealthProfileHandler::connectToSource(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LoggerD("Enter"); + + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); + + // Access Check + /* + TIME_TRACER_ITEM_BEGIN("setName::ACE", 1); + AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_HEALTH_PROFILE_HANDLER_API_CONNECT_TO_SOURCE); + TIME_TRACER_ITEM_END("setName::ACE", 1); + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + */ + + try { + ArgumentValidator validator(context, argumentCount, arguments); + JSObjectRef remoteObj = validator.toObject(0); // remoteDevice + if(!JSValueIsObjectOfClass(context, remoteObj, JSBluetoothDevice::getClassRef())) { + throw TypeMismatchException("remoteDevice is not a BluetoothDevice object"); + } + + JSObjectRef appObj = validator.toObject(1); // application + if(!JSValueIsObjectOfClass(context, appObj, JSBluetoothHealthApplication::getClassRef())) { + throw TypeMismatchException("application is not a BluetoothHealthApplication object"); + } + + JSObjectRef successCallback = validator.toFunction(2); // successCallback + JSObjectRef errorCallback = validator.toFunction(3, true); // errorCallback + + // perform + MultiCallbackUserDataPtr callback( + new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context))); + if(!callback){ + LoggerW("Can't create MultiCallbackUserData"); + } + else { + callback->setCallback("success", successCallback); + callback->setCallback("error", errorCallback); + } + + BluetoothHealthProfileHandler::getInstance()->connectToSource(remoteObj, appObj, callback); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); + + return JSValueMakeUndefined(context); + } catch (const BasePlatformException &err) { + TIME_TRACER_ITEM_END(__FUNCTION__, 1); + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.setName()."); + return JSWebAPIErrorFactory::postException(context, exception, err); + } +} + + +} // Bluetooth +} // DeviceAPI + diff --git a/src/Bluetooth/JSBluetoothHealthProfileHandler.h b/src/Bluetooth/JSBluetoothHealthProfileHandler.h new file mode 100644 index 0000000..dddf037 --- /dev/null +++ b/src/Bluetooth/JSBluetoothHealthProfileHandler.h @@ -0,0 +1,80 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef __TIZEN_JS_HEALTH_PROFILE_HANDLER_H__ +#define __TIZEN_JS_HEALTH_PROFILE_HANDLER_H__ + +#include + +namespace DeviceAPI { +namespace Bluetooth { + +class JSBluetoothHealthProfileHandler +{ +public: + static const JSClassDefinition* getClassInfo(); + static const JSClassRef getClassRef(); + static JSObjectRef createJSObject(JSContextRef context); + +private: + + /** + * The callback invoked when an object is first created. + */ + static void initialize(JSContextRef context, + JSObjectRef object); + + /** + * The callback invoked when an object is finalized. + */ + static void finalize(JSObjectRef object); + + static JSValueRef registerSinkApplication(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + + static JSValueRef connectToSource(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + + /** + * This member variable contains the values which has to be passed + * when the this class is embedded into JS Engine. + */ + static JSClassDefinition m_classInfo; + + /** + * This structure describes a statically declared function property. + */ + static JSStaticFunction m_function[]; + + static JSClassRef m_jsClassRef; +}; + + +} // Bluetooth +} // DeviceAPI + +#endif // __TIZEN_JS_HEALTH_PROFILE_HANDLER_H__ + + diff --git a/src/Bluetooth/JSBluetoothManager.cpp b/src/Bluetooth/JSBluetoothManager.cpp index 2c6db3c..fcc0d60 100644 --- a/src/Bluetooth/JSBluetoothManager.cpp +++ b/src/Bluetooth/JSBluetoothManager.cpp @@ -22,13 +22,13 @@ #include #include #include +#include #include "plugin_config.h" #include "JSBluetoothManager.h" #include "JSBluetoothClassDeviceMajor.h" #include "JSBluetoothClassDeviceMinor.h" #include "JSBluetoothClassDeviceService.h" -//#include "BluetoothManager.h" #include "JSBluetoothAdapter.h" #include "BluetoothAdapter.h" @@ -146,15 +146,23 @@ JSValueRef JSBluetoothManager::getDefaultAdapter(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + TIME_TRACER_ITEM_BEGIN("getDefaultAdapter", 1); // Access Check + TIME_TRACER_ITEM_BEGIN("getDefaultAdapter::ACE", 1); AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_MANAGER_API_GET_DEFAULT_ADAPTER); + TIME_TRACER_ITEM_END("getDefaultAdapter::ACE", 1); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); try { - TIME_TRACER_ITEM_END(__FUNCTION__, 0); - return JSBluetoothAdapter::createJSObject(context); + JSObjectRef adapter = JSBluetoothAdapter::createJSObject(context); + + if(bt_initialize() != BT_ERROR_NONE) { + LoggerE("bt_initialize() failed"); + } + + TIME_TRACER_ITEM_END("getDefaultAdapter", 1); + return adapter; } catch (const BasePlatformException &err) { return JSWebAPIErrorFactory::postException(context, exception, err); diff --git a/src/Bluetooth/JSBluetoothProfileHandler.cpp b/src/Bluetooth/JSBluetoothProfileHandler.cpp new file mode 100644 index 0000000..28fe6fb --- /dev/null +++ b/src/Bluetooth/JSBluetoothProfileHandler.cpp @@ -0,0 +1,114 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include + +#include +#include +#include +#include + +#include "plugin_config.h" +#include "JSBluetoothProfileHandler.h" +#include "JSBluetoothHealthProfileHandler.h" + +#include +#include + +using namespace WrtDeviceApis::Commons; +using namespace DeviceAPI::Common; + +namespace DeviceAPI { +namespace Bluetooth { + +JSClassDefinition JSBluetoothProfileHandler::m_classInfo = { + 0, + kJSClassAttributeNone, + "BluetoothProfileHandler", + NULL, //ParentClass + m_property, //StaticValues + NULL, //StaticFunctions + initialize, //Initialize + finalize, //Finalize + NULL, //HasProperty, + NULL, //GetProperty, + NULL, //SetProperty, + NULL, //DeleteProperty, + NULL, //GetPropertyNames, + NULL, //CallAsFunction, + NULL, //CallAsConstructor, + NULL, //HasInstance, + NULL //ConvertToType +}; + +JSStaticValue JSBluetoothProfileHandler::m_property[] = { + { BLUETOOTH_PROFILE_TYPE, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete}, + { 0, 0, 0, 0 } +}; + +JSClassRef JSBluetoothProfileHandler::m_jsClassRef = JSClassCreate(JSBluetoothProfileHandler::getClassInfo()); + +const JSClassRef JSBluetoothProfileHandler::getClassRef() +{ + if (!m_jsClassRef) { + m_jsClassRef = JSClassCreate(&m_classInfo); + } + return m_jsClassRef; +} + +const JSClassDefinition* JSBluetoothProfileHandler::getClassInfo() +{ + return &m_classInfo; +} + +void JSBluetoothProfileHandler::initialize(JSContextRef context, JSObjectRef object) +{ + // Do nothing +} + +void JSBluetoothProfileHandler::finalize(JSObjectRef object) +{ + // Do nothing +} + +JSValueRef JSBluetoothProfileHandler::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { + LoggerD("Enter"); + try { + if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_PROFILE_TYPE)) { + if(object) { + if(JSValueIsObjectOfClass(context, object, JSBluetoothHealthProfileHandler::getClassRef())) { + std::string profileType("HEALTH"); + LoggerD("profileType: " << profileType.c_str()); + return JSUtil::toJSValueRef(context, profileType); + } + } + else { + LoggerE("object is NULL"); + } + } + } catch (const BasePlatformException &err) { + LoggerW("Getting property is failed" << err.getMessage().c_str()); + } + + return NULL; +} + + + +} // Bluetooth +} // DeviceAPI + diff --git a/src/Bluetooth/JSBluetoothProfileHandler.h b/src/Bluetooth/JSBluetoothProfileHandler.h new file mode 100644 index 0000000..d493731 --- /dev/null +++ b/src/Bluetooth/JSBluetoothProfileHandler.h @@ -0,0 +1,68 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef __TIZEN_JS_BLUETOOTH_PROFILE_HANDLER_H__ +#define __TIZEN_JS_BLUETOOTH_PROFILE_HANDLER_H__ + +#include + +namespace DeviceAPI { +namespace Bluetooth { + +class JSBluetoothProfileHandler +{ +public: + static const JSClassDefinition* getClassInfo(); + static const JSClassRef getClassRef(); + +private: + + /** + * The callback invoked when an object is first created. + */ + static void initialize(JSContextRef context, + JSObjectRef object); + + /** + * The callback invoked when an object is finalized. + */ + static void finalize(JSObjectRef object); + + static JSValueRef getProperty(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception); + + /** + * This member variable contains the values which has to be passed + * when the this class is embedded into JS Engine. + */ + static JSClassDefinition m_classInfo; + + static JSStaticValue m_property[]; + + static JSClassRef m_jsClassRef; + +}; + + + +} // Bluetooth +} // DeviceAPI + +#endif // __TIZEN_JS_BLUETOOTH_PROFILE_HANDLER_H__ + diff --git a/src/Bluetooth/JSBluetoothServiceHandler.cpp b/src/Bluetooth/JSBluetoothServiceHandler.cpp index 0398771..bf207f6 100644 --- a/src/Bluetooth/JSBluetoothServiceHandler.cpp +++ b/src/Bluetooth/JSBluetoothServiceHandler.cpp @@ -182,10 +182,12 @@ JSValueRef JSBluetoothServiceHandler::unregister(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1); // Access Check + TIME_TRACER_ITEM_BEGIN("unregister::ACE", 1); AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_SERVICE_HANDLER_API_UNREGISTER); + TIME_TRACER_ITEM_END("unregister::ACE", 1); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); try { @@ -211,7 +213,7 @@ JSValueRef JSBluetoothServiceHandler::unregister(JSContextRef context, } priv->unregister(callback); - TIME_TRACER_ITEM_END(__FUNCTION__, 0); + TIME_TRACER_ITEM_END(__FUNCTION__, 1); return JSValueMakeUndefined(context); } catch (const BasePlatformException &err) { diff --git a/src/Bluetooth/JSBluetoothSocket.cpp b/src/Bluetooth/JSBluetoothSocket.cpp index 577b281..4f93a48 100644 --- a/src/Bluetooth/JSBluetoothSocket.cpp +++ b/src/Bluetooth/JSBluetoothSocket.cpp @@ -249,10 +249,12 @@ JSValueRef JSBluetoothSocket::writeData(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);; // Access Check + TIME_TRACER_ITEM_BEGIN("writeData::ACE", 1);; AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_SOCKET_API_WRITE_DATA); + TIME_TRACER_ITEM_END("writeData::ACE", 1);; TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); try { @@ -271,9 +273,12 @@ JSValueRef JSBluetoothSocket::writeData(JSContextRef context, JSValueRef element = JSGetArrayElement(context, dataArrayObj, i); buffer[i] = static_cast(JSUtil::JSValueToByte(context, element)); } - TIME_TRACER_ITEM_END(__FUNCTION__, 0); - return JSUtil::toJSValueRef(context, priv->writeData(buffer, size)); + JSValueRef result = JSUtil::toJSValueRef(context, priv->writeData(buffer, size)); + delete buffer; + TIME_TRACER_ITEM_END(__FUNCTION__, 1);; + + return result; } catch (const BasePlatformException &err) { return JSWebAPIErrorFactory::postException(context, exception, err); } catch (...) { @@ -289,10 +294,12 @@ JSValueRef JSBluetoothSocket::readData(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);; // Access Check + TIME_TRACER_ITEM_BEGIN("readData::ACE", 1);; AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_SOCKET_API_READ_DATA); + TIME_TRACER_ITEM_END("readData::ACE", 1);; TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); try { @@ -303,7 +310,7 @@ JSValueRef JSBluetoothSocket::readData(JSContextRef context, } std::vector data = priv->readData(); - TIME_TRACER_ITEM_END(__FUNCTION__, 0); + TIME_TRACER_ITEM_END(__FUNCTION__, 1);; return JSUtil::toJSValueRef_(context, data); } catch (const BasePlatformException &err) { @@ -321,10 +328,12 @@ JSValueRef JSBluetoothSocket::close(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0); + TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);; // Access Check + TIME_TRACER_ITEM_BEGIN("close::ACE", 1);; AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_SOCKET_API_CLOSE); + TIME_TRACER_ITEM_END("close::ACE", 1);; TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); try { @@ -335,7 +344,7 @@ JSValueRef JSBluetoothSocket::close(JSContextRef context, } priv->close(); - TIME_TRACER_ITEM_END(__FUNCTION__, 0); + TIME_TRACER_ITEM_END(__FUNCTION__, 1);; return JSValueMakeUndefined(context); } catch (const BasePlatformException &err) { diff --git a/src/Bluetooth/plugin_config.cpp b/src/Bluetooth/plugin_config.cpp index 05fb079..dbab123 100644 --- a/src/Bluetooth/plugin_config.cpp +++ b/src/Bluetooth/plugin_config.cpp @@ -26,11 +26,14 @@ #define BLUETOOTH_FEATURE_API_GAP "http://tizen.org/privilege/bluetooth.gap" #define BLUETOOTH_FEATURE_API_SPP "http://tizen.org/privilege/bluetooth.spp" #define BLUETOOTH_FEATURE_API_MANAGER "http://tizen.org/privilege/bluetoothmanager" +#define BLUETOOTH_FEATURE_API_HDP "http://tizen.org/privilege/bluetooth.health" #define BLUETOOTH_DEVICE_CAP_ADMIN "bluetooth.admin" #define BLUETOOTH_DEVICE_CAP_GAP "bluetooth.gap" #define BLUETOOTH_DEVICE_CAP_SPP "bluetooth.spp" #define BLUETOOTH_DEVICE_CAP_MANAGER "bluetoothmanager" +#define BLUETOOTH_DEVICE_CAP_HDP "bluetooth.health" + using namespace WrtDeviceApis::Commons; @@ -66,6 +69,10 @@ static FunctionMapping createBluetoothFunctions() ACE_CREATE_DEVICE_CAP(DEVICE_CAP_BLUETOOTH_MANAGER, BLUETOOTH_DEVICE_CAP_MANAGER); ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_BLUETOOTH_MANAGER); ACE_ADD_DEVICE_CAP(DEVICE_LIST_BLUETOOTH_MANAGER, DEVICE_CAP_BLUETOOTH_MANAGER); + + ACE_CREATE_DEVICE_CAP(DEVICE_CAP_BLUETOOTH_HDP, BLUETOOTH_DEVICE_CAP_HDP); + ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_BLUETOOTH_HDP); + ACE_ADD_DEVICE_CAP(DEVICE_LIST_BLUETOOTH_HDP, DEVICE_CAP_BLUETOOTH_HDP); /** @@ -88,6 +95,10 @@ static FunctionMapping createBluetoothFunctions() ACE_ADD_API_FEATURE(BLUETOOTH_FEATURES_BLUETOOTH_MANAGER, FEATURE_MANAGER); ACE_ADD_API_FEATURE(BLUETOOTH_FEATURES_BLUETOOTH_MANAGER, FEATURE_ADMIN); // for backward compatibility + ACE_CREATE_FEATURE(FEATURE_HDP, BLUETOOTH_FEATURE_API_HDP); + ACE_CREATE_FEATURE_LIST(BLUETOOTH_FEATURES_BLUETOOTH_HDP); + ACE_ADD_API_FEATURE(BLUETOOTH_FEATURES_BLUETOOTH_HDP, FEATURE_HDP); + /** * Functions @@ -138,6 +149,28 @@ static FunctionMapping createBluetoothFunctions() BLUETOOTH_ADAPTER_API_SET_VISIBLE, setVisibleFunc)); + // setChangeListener() + AceFunction setChangeListenerFunc = ACE_CREATE_FUNCTION( + FUNCTION_BLUETOOTH_ADAPTER_API_SET_CHANGE_LISTENER, + BLUETOOTH_ADAPTER_API_SET_CHANGE_LISTENER, + BLUETOOTH_FEATURES_BLUETOOTH_ADMIN, + DEVICE_LIST_BLUETOOTH_ADMIN); + + BluetoothMapping.insert(std::make_pair( + BLUETOOTH_ADAPTER_API_SET_CHANGE_LISTENER, + setChangeListenerFunc)); + + // unsetChangeListener() + AceFunction unsetChangeListenerFunc = ACE_CREATE_FUNCTION( + FUNCTION_BLUETOOTH_ADAPTER_API_UNSET_CHANGE_LISTENER, + BLUETOOTH_ADAPTER_API_UNSET_CHANGE_LISTENER, + BLUETOOTH_FEATURES_BLUETOOTH_ADMIN, + DEVICE_LIST_BLUETOOTH_ADMIN); + + BluetoothMapping.insert(std::make_pair( + BLUETOOTH_ADAPTER_API_UNSET_CHANGE_LISTENER, + unsetChangeListenerFunc)); + // discoverDevices() AceFunction discoverDevicesFunc = ACE_CREATE_FUNCTION( FUNCTION_BLUETOOTH_ADAPTER_API_DISCOVER_DEVICES, @@ -281,6 +314,83 @@ static FunctionMapping createBluetoothFunctions() BLUETOOTH_SERVICE_HANDLER_API_UNREGISTER, unregisterFunc)); + // registerSinkApplication() + AceFunction registerSinkApplicationFunc = ACE_CREATE_FUNCTION( + FUNCTION_BLUETOOTH_HEALTH_PROFILE_HANDLER_API_REGISTER_SINK_APPLICATION, + BLUETOOTH_HEALTH_PROFILE_HANDLER_API_REGISTER_SINK_APPLICATION, + BLUETOOTH_FEATURES_BLUETOOTH_HDP, + DEVICE_LIST_BLUETOOTH_HDP); + + BluetoothMapping.insert(std::make_pair( + BLUETOOTH_HEALTH_PROFILE_HANDLER_API_REGISTER_SINK_APPLICATION, + registerSinkApplicationFunc)); + + // connectToSource() + AceFunction connectToSourceFunc = ACE_CREATE_FUNCTION( + FUNCTION_BLUETOOTH_HEALTH_PROFILE_HANDLER_API_CONNECT_TO_SOURCE, + BLUETOOTH_HEALTH_PROFILE_HANDLER_API_CONNECT_TO_SOURCE, + BLUETOOTH_FEATURES_BLUETOOTH_HDP, + DEVICE_LIST_BLUETOOTH_HDP); + + BluetoothMapping.insert(std::make_pair( + BLUETOOTH_HEALTH_PROFILE_HANDLER_API_CONNECT_TO_SOURCE, + connectToSourceFunc)); + + // unregister() + AceFunction unregisterHDPFunc = ACE_CREATE_FUNCTION( + FUNCTION_BLUETOOTH_HEALTH_APPLICATION_API_UNREGISTER, + BLUETOOTH_HEALTH_APPLICATION_API_UNREGISTER, + BLUETOOTH_FEATURES_BLUETOOTH_HDP, + DEVICE_LIST_BLUETOOTH_HDP); + + BluetoothMapping.insert(std::make_pair( + BLUETOOTH_HEALTH_APPLICATION_API_UNREGISTER, + unregisterHDPFunc)); + + // close() + AceFunction closeHDPFunc = ACE_CREATE_FUNCTION( + FUNCTION_BLUETOOTH_HEALTH_CHANNEL_API_CLOSE, + BLUETOOTH_HEALTH_CHANNEL_API_CLOSE, + BLUETOOTH_FEATURES_BLUETOOTH_HDP, + DEVICE_LIST_BLUETOOTH_HDP); + + BluetoothMapping.insert(std::make_pair( + BLUETOOTH_HEALTH_CHANNEL_API_CLOSE, + closeHDPFunc)); + + // sendData() + AceFunction sendDataFunc = ACE_CREATE_FUNCTION( + FUNCTION_BLUETOOTH_HEALTH_CHANNEL_API_SEND_DATA, + BLUETOOTH_HEALTH_CHANNEL_API_SEND_DATA, + BLUETOOTH_FEATURES_BLUETOOTH_HDP, + DEVICE_LIST_BLUETOOTH_HDP); + + BluetoothMapping.insert(std::make_pair( + BLUETOOTH_HEALTH_CHANNEL_API_SEND_DATA, + sendDataFunc)); + + // setListener() + AceFunction setListenerFunc = ACE_CREATE_FUNCTION( + FUNCTION_BLUETOOTH_HEALTH_CHANNEL_API_SET_LISTENER, + BLUETOOTH_HEALTH_CHANNEL_API_SET_LISTENER, + BLUETOOTH_FEATURES_BLUETOOTH_HDP, + DEVICE_LIST_BLUETOOTH_HDP); + + BluetoothMapping.insert(std::make_pair( + BLUETOOTH_HEALTH_CHANNEL_API_SET_LISTENER, + setListenerFunc)); + + // unsetListener() + AceFunction unsetListenerFunc = ACE_CREATE_FUNCTION( + FUNCTION_BLUETOOTH_HEALTH_CHANNEL_API_UNSET_LISTENER, + BLUETOOTH_HEALTH_CHANNEL_API_UNSET_LISTENER, + BLUETOOTH_FEATURES_BLUETOOTH_HDP, + DEVICE_LIST_BLUETOOTH_HDP); + + BluetoothMapping.insert(std::make_pair( + BLUETOOTH_HEALTH_CHANNEL_API_UNSET_LISTENER, + unsetListenerFunc)); + return BluetoothMapping; } diff --git a/src/Bluetooth/plugin_config.h b/src/Bluetooth/plugin_config.h index 3930c9f..13b4cbc 100644 --- a/src/Bluetooth/plugin_config.h +++ b/src/Bluetooth/plugin_config.h @@ -19,11 +19,8 @@ #ifndef _BLUETOOTH_PLUGIN_CONFIG_H_ #define _BLUETOOTH_PLUGIN_CONFIG_H_ -#include #include -#include - namespace DeviceAPI { namespace Bluetooth { @@ -55,6 +52,15 @@ namespace Bluetooth { #define BLUETOOTH_SERVICE_HANDLER_NAME "name" #define BLUETOOTH_SERVICE_HANDLER_IS_CONNECTED "isConnected" #define BLUETOOTH_SERVICE_HANDLER_ONCONNECT "onconnect" +#define BLUETOOTH_PROFILE_TYPE "profileType" +#define BLUETOOTH_HEALTH_APPLICATION_DATA_TYPE "dataType" +#define BLUETOOTH_HEALTH_APPLICATION_NAME "name" +#define BLUETOOTH_HEALTH_APPLICATION_ONCONNECT "onconnect" +#define BLUETOOTH_HEALTH_CHANNEL_PEER "peer" +#define BLUETOOTH_HEALTH_CHANNEL_TYPE "channelType" +#define BLUETOOTH_HEALTH_CHANNEL_APP "application" +#define BLUETOOTH_HEALTH_CHANNEL_IS_CONNECTED "isConnected" + // functions #define BLUETOOTH_MANAGER_API_GET_DEFAULT_ADAPTER "getDefaultAdapter" @@ -68,12 +74,23 @@ namespace Bluetooth { #define BLUETOOTH_ADAPTER_API_CREATE_BONDING "createBonding" #define BLUETOOTH_ADAPTER_API_DESTROY_BONDING "destroyBonding" #define BLUETOOTH_ADAPTER_API_REGISTER_RFCOMMSERVICE_BY_UUID "registerRFCOMMServiceByUUID" +#define BLUETOOTH_ADAPTER_API_GET_BLUETOOTH_PROFILE_HANDLER "getBluetoothProfileHandler" +#define BLUETOOTH_ADAPTER_API_SET_CHANGE_LISTENER "setChangeListener" +#define BLUETOOTH_ADAPTER_API_UNSET_CHANGE_LISTENER "unsetChangeListener" #define BLUETOOTH_DEVICE_API_CONNECT_TO_SERVICE_BY_UUID "connectToServiceByUUID" #define BLUETOOTH_SOCKET_API_WRITE_DATA "writeData" #define BLUETOOTH_SOCKET_API_READ_DATA "readData" #define BLUETOOTH_SOCKET_API_CLOSE "close" #define BLUETOOTH_CLASS_API_HAS_SERVICE "hasService" #define BLUETOOTH_SERVICE_HANDLER_API_UNREGISTER "unregister" +#define BLUETOOTH_HEALTH_PROFILE_HANDLER_API_REGISTER_SINK_APPLICATION "registerSinkApplication" +#define BLUETOOTH_HEALTH_APPLICATION_API_UNREGISTER "unregister" +#define BLUETOOTH_HEALTH_PROFILE_HANDLER_API_CONNECT_TO_SOURCE "connectToSource" +#define BLUETOOTH_HEALTH_CHANNEL_API_SEND_DATA "sendData" +#define BLUETOOTH_HEALTH_CHANNEL_API_SET_LISTENER "setListener" +#define BLUETOOTH_HEALTH_CHANNEL_API_UNSET_LISTENER "unsetListener" +#define BLUETOOTH_HEALTH_CHANNEL_API_CLOSE "close" + DECLARE_FUNCTION_GETTER(Bluetooth); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5f0f009..d6f2871 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,4 +64,5 @@ add_plugin( Bookmark SecureElement DataSync + WebSetting ) diff --git a/src/Calendar/JSCalendarItemProperties.cpp b/src/Calendar/JSCalendarItemProperties.cpp index 28c912e..2d3f0b6 100755 --- a/src/Calendar/JSCalendarItemProperties.cpp +++ b/src/Calendar/JSCalendarItemProperties.cpp @@ -79,7 +79,7 @@ JSStaticValue JSCalendarItemProperties::m_property[] = { // Item Properties { TIZEN_CALENDAR_ITEM_DESCRIPTION, getPropertyDescription, setPropertyDescription, kJSPropertyAttributeNone }, { TIZEN_CALENDAR_ITEM_SUMMARY, getPropertySummary, setPropertySummary, kJSPropertyAttributeNone }, - { TIZEN_CALENDAR_ITEM_START_DATE, getPropertyStartTime, setPropertyStartTime, kJSPropertyAttributeNone }, + { TIZEN_CALENDAR_ITEM_START_DATE, getPropertyStartDate, setPropertyStartDate, kJSPropertyAttributeNone }, { TIZEN_CALENDAR_ITEM_LOCATION, getPropertyLocation, setPropertyLocation, kJSPropertyAttributeNone }, { TIZEN_CALENDAR_ITEM_GEOLOCATION, getPropertyGeolocation, setPropertyGeolocation, kJSPropertyAttributeNone }, { TIZEN_CALENDAR_ITEM_ORGANIZER, getPropertyOrganizer, setPropertyOrganizer, kJSPropertyAttributeNone }, @@ -419,33 +419,34 @@ bool JSCalendarItemProperties::setPropertySummary(JSContextRef context, return true; } -JSValueRef JSCalendarItemProperties::getPropertyStartTime(JSContextRef context, +JSValueRef JSCalendarItemProperties::getPropertyStartDate(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { Try { - CalendarItemPropertiesPrivObject *privateObject = - static_cast(JSObjectGetPrivate(object)); + CalendarItemPropertiesPrivObject *privateObject = static_cast(JSObjectGetPrivate(object)); + TimeUtilConverter timeConverter(context); - CalendarEventPtr event = privateObject->getObject(); + CalendarEventPtr item = privateObject->getObject(); - LoggerI("start time before converted to TZDate: "<getStartTime()<<", time zone: "<getTimeZone()); - if (UNDEFINED_TIME==event->getStartTime()) { + LoggerI("start time before converted to TZDate: "<getStartTime()<<", time zone: "<getTimeZone()); + if (UNDEFINED_TIME==item->getStartTime()) { return JSValueMakeUndefined(context); } else { - return timeConverter.toJSValueRefTZDate((double)(event->getStartTime()*1000.0), event->getTimeZone()); + return timeConverter.toJSValueRefTZDate((double)(item->getStartTime()*1000.0), item->getTimeZone()); } } Catch(Exception) { LoggerW("Exception: "<<_rethrown_exception.GetMessage()); } + return JSValueMakeUndefined(context); } -bool JSCalendarItemProperties::setPropertyStartTime(JSContextRef context, +bool JSCalendarItemProperties::setPropertyStartDate(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, @@ -457,19 +458,15 @@ bool JSCalendarItemProperties::setPropertyStartTime(JSContextRef context, ThrowMsg(ConversionException, "Wrong parameter type."); } - CalendarEventPtr event = getPrivateObject(object); - TimeUtilConverter converter(context); - std::time_t duration = event->getEndTime() - event->getStartTime(); - if (duration<0) { - duration = 0; - } + CalendarEventPtr item = getPrivateObject(object); + TimeUtilConverter timeConverter(context); + + long long int startTime = (long long int) (timeConverter.getTimeInMilliseconds(value)/1000); + item->setStartTime(startTime); - long long int startTime = (long long int) (converter.getTimeInMilliseconds(value)/1000); - event->setStartTime(startTime); - event->setEndTime(startTime + duration); + std::string timeZone = timeConverter.getPropertiesInTZDate(value).timezone; + item->setTimeZone(timeZone); - std::string timeZone = converter.getPropertiesInTZDate(value).timezone; - event->setTimeZone(timeZone); return true; } Catch(Exception) @@ -846,7 +843,7 @@ bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context, { Try { - CalendarEventPtr event = getPrivateObject(object); + CalendarEventPtr item = getPrivateObject(object); TimeUtilConverter timeUtilConverter(context); DurationPropertiesPtr duration = timeUtilConverter.getDuration(value); @@ -858,7 +855,26 @@ bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context, } LoggerD("length: "<setDuration(duration); + item->setDuration(duration); + + // Adjust the endDate because the endDate has priority over duration when saving the item. + long long int endDate; + if( DeviceAPI::Time::SECONDS_UNIT==unit ) { + endDate = item->getStartTime() + length; + } else if ( DeviceAPI::Time::MINUTES_UNIT==unit ) { + endDate = item->getStartTime() + length*60; + } else if ( DeviceAPI::Time::HOURS_UNIT==unit ) { + endDate = item->getStartTime() + length*60*60; + } else if ( DeviceAPI::Time::DAYS_UNIT==unit ) { + endDate = item->getStartTime() + length*24*60*60; + } else if ( DeviceAPI::Time::MSECS_UNIT==unit ) { + endDate = item->getStartTime() + length/1000; + } else { + LoggerW("Wrong duration unit: "<setEndTime(endDate); + LoggerD("Set the endDate from the duration: "< getColumns() { return m_columns;} std::string getResultSetPath() { return m_resultSetPath;} - std::string getErrorMsg() { return m_errorMsg;} + std::string getErrorMsg() { + if (m_errorMsg) + return m_errorMsg; + else + return ""; + } void setReqId(const unsigned int & reqId) { m_reqId = reqId;} void setWhere(const std::string& where) { m_where = where; } @@ -68,7 +80,13 @@ public: void setNumberPerPage(const std::string &number) { m_numberPerPage = number;} void setColumns(const std::vector& columns) { m_columns = columns;} void setResultSetPath(const std::string& path) { m_resultSetPath = path;} - void setErrorMsg(const std::string& msg) { m_errorMsg = msg;} + void setErrorMsg(const std::string& msg) { + if (msg.size() > 0) { + m_errorMsg = new char[msg.size() + 1]; + msg.copy(m_errorMsg, 0, msg.size() - 1); + m_errorMsg[msg.size()] = NULL; + } + } }; typedef DPL::SharedPtr EventSelectPtr; diff --git a/src/Download/JSDownloadRequest.cpp b/src/Download/JSDownloadRequest.cpp index 4bda4f0..b04bf63 100644 --- a/src/Download/JSDownloadRequest.cpp +++ b/src/Download/JSDownloadRequest.cpp @@ -179,11 +179,8 @@ JSObjectRef JSDownloadRequest::constructor(JSContextRef context, try { std::string networkType = validator.toString(3, true, "ALL"); if (networkType.compare("CELLULAR") && networkType.compare("WIFI") && networkType.compare("ALL")) { - delete priv; - TypeMismatchException err("networkType is invalid."); - JSObjectRef errObj = JSWebAPIErrorFactory::makeErrorObject(context, err); - *exception = errObj; - return errObj; + networkType = "ALL"; + LOGW("networkType is invalid. 'ALL' type is set."); } priv->setNetworkType(networkType); } catch (const BasePlatformException& err) { diff --git a/src/MessagePort/MessagePortManagerProxy.cpp b/src/MessagePort/MessagePortManagerProxy.cpp index a9a398e..85200e2 100644 --- a/src/MessagePort/MessagePortManagerProxy.cpp +++ b/src/MessagePort/MessagePortManagerProxy.cpp @@ -316,6 +316,8 @@ void MessagePortManagerProxy::messagePortMessageCb(int id, const char* remote_ap MessagePortDataItemMapPtr dataItemMap = MessagePortUtilitySingleton::Instance().getDataItemMap(data); localMessagePort->OnMessageReceived(dataItemMap, remoteMessagePort); + + MessagePortUtilitySingleton::Instance().releaseBundle(data); } // private static diff --git a/src/Notification/JSStatusNotification.cpp b/src/Notification/JSStatusNotification.cpp index 4fdadd1..bd00cd7 100755 --- a/src/Notification/JSStatusNotification.cpp +++ b/src/Notification/JSStatusNotification.cpp @@ -346,7 +346,23 @@ JSObjectRef JSStatusNotification::constructor(JSContextRef context, JSValueRef appIdValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_APP_ID); if (!JSValueIsUndefined(context, appIdValue)) priv->setApplicationId(JSUtil::JSValueToString(context, appIdValue)); - + + //Light + JSValueRef lightValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_LIGHT); + LoggerI("Light :" << JSUtil::JSValueToString(context, lightValue)); + if (!JSValueIsUndefined(context, lightValue)) + priv->setLight(JSUtil::JSValueToString(context, lightValue)); + + //onTime + JSValueRef onTimeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_LIGHT_ONTIME); + if (!JSValueIsUndefined(context, onTimeValue)) + priv->setLightOnTime(JSUtil::JSValueToLong(context, onTimeValue)); + + //offTime + JSValueRef offTimeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_LIGHT_OFFTIME); + if (!JSValueIsUndefined(context, offTimeValue)) + priv->setLightOffTime(JSUtil::JSValueToLong(context, offTimeValue)); + //progressType NotificationProgressType progressType = NOTI_PROGRESS_TYPE_PERCENTAGE; @@ -632,6 +648,21 @@ StatusNotification* JSStatusNotification::getPrivateObject(JSContextRef context, JSValueRef appId = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_APP_ID); if (!JSValueIsNull(context, appId)) priv->setApplicationId(JSUtil::JSValueToString(context, appId)); + + // light + JSValueRef light = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_LIGHT); + if (!JSValueIsNull(context, light)) + priv->setLight(JSUtil::JSValueToString(context, light)); + + // onTime + JSValueRef onTime = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_LIGHT_ONTIME); + if (!JSValueIsNull(context, onTime)) + priv->setLightOnTime(JSUtil::JSValueToLong(context, onTime)); + + // offTime + JSValueRef offTime = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_LIGHT_OFFTIME); + if (!JSValueIsNull(context, offTime)) + priv->setLightOffTime(JSUtil::JSValueToLong(context, offTime)); #if 0 // progressType @@ -803,6 +834,16 @@ void JSStatusNotification::setPrivateObject(JSContextRef context, JSObjectRef ob else JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_ID, JSValueMakeNull(context), kJSPropertyAttributeNone); + //Light + JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT, + JSUtil::toJSValueRef(context, priv->getLight()), kJSPropertyAttributeNone); + + JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT_ONTIME, + JSUtil::toJSValueRef(context, priv->getLightOnTime()), kJSPropertyAttributeNone); + + JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT_OFFTIME, + JSUtil::toJSValueRef(context, priv->getLightOffTime()), kJSPropertyAttributeNone); + #if 0 // progressType & Value LoggerI("Progress Type=" << priv->getProgressType()); diff --git a/src/Notification/StatusNotification.cpp b/src/Notification/StatusNotification.cpp index f9e61ad..96789c0 100755 --- a/src/Notification/StatusNotification.cpp +++ b/src/Notification/StatusNotification.cpp @@ -1764,6 +1764,145 @@ service_h StatusNotification::getService() } +std::string StatusNotification::getLight() +{ + LoggerI("get Light handle: " << m_notiHandle); + if (m_notiHandle) + { + int ledColor = 0; + notification_led_op_e type = NOTIFICATION_LED_OP_ON; + if (notification_get_led(m_notiHandle, &type, &ledColor) != NOTIFICATION_ERROR_NONE) + { + throw UnknownException("get notification Content error"); + } + + //ledColor = ledColor | 0xff000000; + std::stringstream stream; + if (NOTIFICATION_LED_OP_OFF != type) + { + stream << std::hex << ledColor; + } + + return stream.str(); + } + else + { + throw UnknownException("notification handle is null"); + } +} + +void StatusNotification::setLight(std::string color) +{ + LoggerI("set Light handle: " << m_notiHandle); + LoggerI("led Color : " << color); + if (m_notiHandle) + { + + std::stringstream stream; + int ledColor = 0; + notification_led_op_e type = NOTIFICATION_LED_OP_ON; + + stream << std::hex << color; + LoggerI("LedColor = " << stream.str()); + stream >> ledColor; + LoggerI("LedColor = " << ledColor); + + if (notification_set_led(m_notiHandle, NOTIFICATION_LED_OP_ON_CUSTOM_COLOR, ledColor) != NOTIFICATION_ERROR_NONE) + { + throw UnknownException("set notification led "); + } + } + else + { + throw UnknownException("notification handle is null"); + } +} + +unsigned long StatusNotification::getLightOnTime() +{ + LoggerI("get Light on Time handle: " << m_notiHandle); + if (m_notiHandle) + { + int onTime = 0; + int offTime = 0; + + if (notification_get_led_time_period(m_notiHandle, &onTime, &offTime ) != NOTIFICATION_ERROR_NONE) + { + throw UnknownException("set notification led "); + } + LoggerI("onTime " << onTime); + + return (unsigned long) onTime; + } + else + { + throw UnknownException("notification handle is null"); + } +} + +void StatusNotification::setLightOnTime(unsigned long time) +{ + LoggerI("set Light on Time handle: " << m_notiHandle); + LoggerI("itme = " << time); + if (m_notiHandle) + { + int offTime = getLightOffTime(); + + if (notification_set_led_time_period(m_notiHandle, time, offTime ) != NOTIFICATION_ERROR_NONE) + { + throw UnknownException("set notification led "); + } + + } + else + { + throw UnknownException("notification handle is null"); + } +} + +unsigned long StatusNotification::getLightOffTime() +{ + + LoggerI("get Light on Time handle: " << m_notiHandle); + if (m_notiHandle) + { + int onTime = 0; + int offTime = 0; + + if (notification_get_led_time_period(m_notiHandle, &onTime, &offTime ) != NOTIFICATION_ERROR_NONE) + { + throw UnknownException("set notification led "); + } + LoggerI("offTime " << offTime); + + return offTime; + } + else + { + throw UnknownException("notification handle is null"); + } + +} + +void StatusNotification::setLightOffTime(unsigned long time) +{ + LoggerI("set Light off Time handle: " << m_notiHandle); + LoggerI("time = " << time); + if (m_notiHandle) + { + int onTime = getLightOnTime(); + + if (notification_set_led_time_period(m_notiHandle, onTime, time ) != NOTIFICATION_ERROR_NONE) + { + throw UnknownException("set notification led "); + } + } + else + { + throw UnknownException("notification handle is null"); + } +} + //Detail Info void StatusNotification::loadDetailInfos() { diff --git a/src/Notification/StatusNotification.h b/src/Notification/StatusNotification.h index 96c8e79..408330f 100755 --- a/src/Notification/StatusNotification.h +++ b/src/Notification/StatusNotification.h @@ -146,6 +146,15 @@ public: void setApplicationId(const std::string& appId); std::string getApplicationId(); + std::string getLight(); + void setLight(std::string color); + + unsigned long getLightOnTime(); + void setLightOnTime(unsigned long onTime); + + unsigned long getLightOffTime(); + void setLightOffTime(unsigned long offTime); + void* getNotificationHandle(); void setNotificationHandle(void *handle); diff --git a/src/Notification/plugin_config.h b/src/Notification/plugin_config.h index 71dd44c..076af11 100755 --- a/src/Notification/plugin_config.h +++ b/src/Notification/plugin_config.h @@ -44,6 +44,9 @@ namespace Notification { #define STATUS_NOTIFICATION_VIBRATION "vibration" #define STATUS_NOTIFICATION_APP_CONTROL "appControl" #define STATUS_NOTIFICATION_APP_ID "appId" +#define STATUS_NOTIFICATION_LIGHT "ledColor" +#define STATUS_NOTIFICATION_LIGHT_ONTIME "ledOnTime" +#define STATUS_NOTIFICATION_LIGHT_OFFTIME "ledOffTime" #define STATUS_NOTIFICATION_PROGRESS_TYPE "progressType" #define STATUS_NOTIFICATION_PROGRESS_VALUE "progressValue" #define NOTIFICATION_DETAIL_INFO_MAIN_TEXT "mainText" @@ -69,4 +72,4 @@ DECLARE_FUNCTION_GETTER(Notification); } } -#endif // _NOTIFICATION_PLUGIN_CONFIG_H_ \ No newline at end of file +#endif // _NOTIFICATION_PLUGIN_CONFIG_H_ diff --git a/src/Systeminfo/CMakeLists.txt b/src/Systeminfo/CMakeLists.txt index 53f8287..4ff3261 100755 --- a/src/Systeminfo/CMakeLists.txt +++ b/src/Systeminfo/CMakeLists.txt @@ -9,7 +9,6 @@ PKG_CHECK_MODULES(platform_pkgs_systeminfo REQUIRED capi-system-runtime-info capi-system-sensor sensor - pkgmgr-info tapi ) diff --git a/src/Systeminfo/JSDeviceCapabilitiesInfo.cpp b/src/Systeminfo/JSDeviceCapabilitiesInfo.cpp index 4c837d9..b6cf382 100755 --- a/src/Systeminfo/JSDeviceCapabilitiesInfo.cpp +++ b/src/Systeminfo/JSDeviceCapabilitiesInfo.cpp @@ -29,6 +29,9 @@ #include "plugin_config.h" #include +#define MAXBUFSIZE 256 +#define DEVICE_PROFILE "MOBILE" + namespace DeviceAPI { namespace Systeminfo { using namespace WrtDeviceApis::CommonsJavaScript; @@ -105,6 +108,7 @@ const char* DEVICE_CAPABILITIES_SECURE_ELEMENT = "secureElement"; const char* DEVICE_CAPABILITIES_NATIVE_OSP_COMPATIBLE = "nativeOspCompatible"; const char* DEVICE_CAPABILITIES_INPUT_KEY_BACK = "inputKeyBack"; const char* DEVICE_CAPABILITIES_INPUT_KEY_OPTION = "inputKeyMenu"; +const char* DEVICE_CAPABILITIES_PROFILE = "profile"; } JSClassRef JSDeviceCapabilitiesInfo::m_classRef = NULL; @@ -199,6 +203,7 @@ JSStaticValue JSDeviceCapabilitiesInfo::m_properties[] = { { DEVICE_CAPABILITIES_NATIVE_OSP_COMPATIBLE, getProperty, NULL, kJSPropertyAttributeReadOnly }, { DEVICE_CAPABILITIES_INPUT_KEY_BACK, getProperty, NULL, kJSPropertyAttributeReadOnly }, { DEVICE_CAPABILITIES_INPUT_KEY_OPTION, getProperty, NULL, kJSPropertyAttributeReadOnly }, + { DEVICE_CAPABILITIES_PROFILE, getProperty, NULL, kJSPropertyAttributeReadOnly }, { 0, 0, 0, 0 } }; @@ -798,7 +803,10 @@ JSValueRef JSDeviceCapabilitiesInfo::getProperty(JSContextRef context, JSObjectR } else { return JSValueMakeUndefined(context); } - return convert.toJSValueRef(deviceCapabilitiesInfo->inputKeyMenu); + return convert.toJSValueRef(deviceCapabilitiesInfo->inputKeyMenu); + } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_PROFILE)) { + deviceCapabilitiesInfo->profile = DEVICE_PROFILE; + return convert.toJSValueRef(deviceCapabilitiesInfo->profile); } } Catch(Exception) diff --git a/src/Systeminfo/JSDeviceOrientationInfo.cpp b/src/Systeminfo/JSDeviceOrientationInfo.cpp old mode 100644 new mode 100755 index ffaee4f..b6c843a --- a/src/Systeminfo/JSDeviceOrientationInfo.cpp +++ b/src/Systeminfo/JSDeviceOrientationInfo.cpp @@ -26,6 +26,7 @@ using namespace WrtDeviceApis::Commons; namespace { const char* DEVICEORIENTATION_STATUS_PROPERTY = "status"; +const char* DEVICEORIENTATION_IS_AUTOROTATION_PROPERTY = "isAutoRotation"; } JSClassRef JSDeviceOrientationInfo::m_classRef = NULL; @@ -52,6 +53,7 @@ JSClassDefinition JSDeviceOrientationInfo::m_classInfo = { JSStaticValue JSDeviceOrientationInfo::m_properties[] = { { DEVICEORIENTATION_STATUS_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly }, + { DEVICEORIENTATION_IS_AUTOROTATION_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly }, { 0, 0, 0, 0 } }; @@ -108,6 +110,8 @@ JSValueRef JSDeviceOrientationInfo::getProperty(JSContextRef context, JSObjectRe if (JSStringIsEqualToUTF8CString(propertyName, DEVICEORIENTATION_STATUS_PROPERTY)) { return convert.toJSValueRef(deviceOrientationInfo->status); + } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICEORIENTATION_IS_AUTOROTATION_PROPERTY)) { + return convert.toJSValueRef(deviceOrientationInfo->isAutoRotation); } } Catch(Exception) diff --git a/src/Systeminfo/Systeminfo.cpp b/src/Systeminfo/Systeminfo.cpp index eeb804f..3ef6e01 100755 --- a/src/Systeminfo/Systeminfo.cpp +++ b/src/Systeminfo/Systeminfo.cpp @@ -65,6 +65,14 @@ void DisplayValueCallback(keynode_t *node, void* event_ptr) } } +void OrientationValueVconfCallback(keynode_t *node, void *event_ptr) +{ + LoggerD("enter"); + if(event_ptr) { + ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DEVICE_ORIENTATION); + } +} + void NetworkTypeValueCallback(connection_type_e type, void* event_ptr) { if(event_ptr) { @@ -97,7 +105,6 @@ static Eina_Bool CpuValueCallback(void* event_ptr) void OrientationValueCallback(unsigned int event_type, sensor_event_data_t *event , void *event_ptr) { - LoggerD("enter"); if(event_ptr) { ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DEVICE_ORIENTATION); } @@ -105,7 +112,6 @@ void OrientationValueCallback(unsigned int event_type, sensor_event_data_t *even void localeChangedCallback(runtime_info_key_e key, void* event_ptr) { - LoggerD("enter"); if(event_ptr) { ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_LOCALE); } @@ -299,6 +305,7 @@ void Systeminfo::clearWatch(const long id) break; case WATCH_TYPE_DEVICE_ORIENTATION: if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) { + vconf_ignore_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, OrientationValueVconfCallback); int state = sf_unregister_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK); if (state < 0) { LoggerD("sf_unregister_event fail to gather data\n"); @@ -530,6 +537,7 @@ void Systeminfo::OnRequestReceived(const EventWatchSysteminfoPtr& event) case WATCH_TYPE_DEVICE_ORIENTATION: LoggerD("regist sensor"); if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) { + vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, OrientationValueVconfCallback, (void *)this); int state = sf_register_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK, NULL, OrientationValueCallback, (void *)this); if (state < 0) { LoggerD("sensor_register_cb fail to gather data"); @@ -1423,6 +1431,15 @@ PROPERTY_GET_SYSTEMINFO_DEFINITION(DeviceOrientation) { unsigned long rotation = 0; int handleOrientaion = 0; + int isAutoRotation = 0; + + if (vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &isAutoRotation) == 0) { + if (isAutoRotation) { + deviceOrientation->isAutoRotation = true; + } else { + deviceOrientation->isAutoRotation = false; + } + } handleOrientaion = sf_connect(ACCELEROMETER_SENSOR); LoggerD("handleOrientaion : " << handleOrientaion); diff --git a/src/Systeminfo/SysteminfoListener.cpp b/src/Systeminfo/SysteminfoListener.cpp index 287d13f..e0b33a4 100644 --- a/src/Systeminfo/SysteminfoListener.cpp +++ b/src/Systeminfo/SysteminfoListener.cpp @@ -34,8 +34,8 @@ SysteminfoListener& SysteminfoListener::getInstance() } SysteminfoListener::SysteminfoListener() : - EventGetSysteminfoAnswerReceiver(WrtDeviceApis::Commons::ThreadEnum::NULL_THREAD), - EventWatchSysteminfoAnswerReceiver(WrtDeviceApis::Commons::ThreadEnum::NULL_THREAD) + EventGetSysteminfoAnswerReceiver(WrtDeviceApis::Commons::ThreadEnum::SYSTEMINFO_THREAD), + EventWatchSysteminfoAnswerReceiver(WrtDeviceApis::Commons::ThreadEnum::SYSTEMINFO_THREAD) { } diff --git a/src/Systeminfo/SysteminfoPropertyInfo.h b/src/Systeminfo/SysteminfoPropertyInfo.h index 6aeff39..726ae2a 100755 --- a/src/Systeminfo/SysteminfoPropertyInfo.h +++ b/src/Systeminfo/SysteminfoPropertyInfo.h @@ -106,6 +106,7 @@ struct DeviceCapabilitiesProperties bool nativeOspCompatible; bool inputKeyBack; bool inputKeyMenu; + std::string profile; DeviceCapabilitiesProperties() : bluetooth(false), @@ -176,7 +177,8 @@ struct DeviceCapabilitiesProperties secureElement(false), nativeOspCompatible(false), inputKeyBack(false), - inputKeyMenu(false) + inputKeyMenu(false), + profile("") { } }; @@ -340,9 +342,11 @@ struct SIMProperties struct DeviceOrientationProperties { std::string status; + bool isAutoRotation; DeviceOrientationProperties() : - status("") + status(""), + isAutoRotation(false) { } }; diff --git a/src/WebSetting/CMakeLists.txt b/src/WebSetting/CMakeLists.txt new file mode 100755 index 0000000..a9fdb8d --- /dev/null +++ b/src/WebSetting/CMakeLists.txt @@ -0,0 +1,48 @@ + +SET(TARGET_NAME ${websetting_target}) +SET(DESTINATION_NAME ${websetting_dest}) +SET(TARGET_IMPL_NAME ${websetting_impl}) + +#PKG_CHECK_MODULES(websetting REQUIRED [.. required package name ..]) + +INCLUDE_DIRECTORIES( + ${INCLUDE_COMMON} + ${websetting_INCLUDE_DIRS} +) + +SET(CMAKE_INSTALL_RPATH + ${CMAKE_INSTALL_RPATH} + ${CMAKE_INSTALL_PREFIX}/${DESTINATION_LIB_PREFIX}/${tizen_dest} + ${CMAKE_INSTALL_PREFIX}/${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME} +) + +SET(SRCS_IMPL + JSWebSettingManager.cpp + WebSettingManager.cpp +) + +ADD_LIBRARY(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL}) + +TARGET_LINK_LIBRARIES(${TARGET_IMPL_NAME} + ${LIBS_COMMON} + ${tizen_impl} + ${websetting_LIBRARIES} +) + +SET(SRCS + plugin_config.cpp + plugin_initializer.cpp +) + +ADD_LIBRARY(${TARGET_NAME} SHARED ${SRCS}) + +TARGET_LINK_LIBRARIES(${TARGET_NAME} + ${TARGET_IMPL_NAME} +) + +INSTALL(TARGETS ${TARGET_NAME} ${TARGET_IMPL_NAME} LIBRARY DESTINATION ${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME}) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME}) +INSTALL( + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${DESTINATION_HEADER_PREFIX}/websetting + FILES_MATCHING PATTERN "*.h" PATTERN "CMakeFiles" EXCLUDE +) diff --git a/src/WebSetting/JSWebSettingManager.cpp b/src/WebSetting/JSWebSettingManager.cpp new file mode 100755 index 0000000..90d45d5 --- /dev/null +++ b/src/WebSetting/JSWebSettingManager.cpp @@ -0,0 +1,191 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include + +#include +#include +#include +#include +#include +#include + +#include "plugin_config.h" + +#include "JSWebSettingManager.h" + +using namespace WrtDeviceApis::Commons; +using namespace DeviceAPI::Common; + +namespace DeviceAPI { +namespace WebSetting { + +JSClassDefinition JSWebSettingManager::m_classInfo = { + 0, + kJSClassAttributeNone, + "WebSettingManager", + NULL, //ParentClass + NULL, //StaticValues + m_function, //StaticFunctions + initialize, //Initialize + finalize, //Finalize + NULL, //HasProperty, + NULL, //GetProperty, + NULL, //SetProperty, + NULL, //DeleteProperty, + NULL, //GetPropertyNames, + NULL, //CallAsFunction, + NULL, //CallAsConstructor, + NULL, //HasInstance, + NULL //ConvertToType +}; + +JSStaticFunction JSWebSettingManager::m_function[] = { + { WEB_SETTING_MANAGER_API_SET_USER_AGENT_STRING, setUserAgentString, kJSPropertyAttributeNone }, + { WEB_SETTING_MANAGER_API_REMOVE_ALL_COOKIES, removeAllCookies, kJSPropertyAttributeNone }, + { 0, 0, 0 } +}; + +JSClassRef JSWebSettingManager::m_jsClassRef = JSClassCreate(JSWebSettingManager::getClassInfo()); + +const JSClassRef JSWebSettingManager::getClassRef() +{ + if (!m_jsClassRef) { + m_jsClassRef = JSClassCreate(&m_classInfo); + } + return m_jsClassRef; +} + +const JSClassDefinition* JSWebSettingManager::getClassInfo() +{ + return &m_classInfo; +} + +void JSWebSettingManager::initialize(JSContextRef context, JSObjectRef object) +{ + if (!JSObjectGetPrivate(object)) { + WebSettingManager *priv = new WebSettingManager(); + if (!JSObjectSetPrivate(object, static_cast(priv))) { + delete priv; + } + } +} + +void JSWebSettingManager::finalize(JSObjectRef object) +{ + WebSettingManager *priv = static_cast(JSObjectGetPrivate(object)); + if (priv) { + JSObjectSetPrivate(object, NULL); + delete priv; + } +} + +JSValueRef JSWebSettingManager::setUserAgentString(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + try { + // Private Object + WebSettingManager *priv = static_cast(JSObjectGetPrivate(thisObject)); + if (!priv) { + throw TypeMismatchException("Private object is NULL."); + } + ArgumentValidator validator(context, argumentCount, arguments); + MultiCallbackUserDataPtr callbacks(new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context))); + + // userAgent + std::string userAgent = validator.toString(0); + + // successCallback + JSObjectRef successCallbackObj = validator.toFunction(1, true); + if (successCallbackObj) + { + callbacks->setCallback("onsuccess", successCallbackObj); + } + + // errorCallback + JSObjectRef errorCallbackObj = validator.toFunction(2, true); + + if (errorCallbackObj) + { + callbacks->setCallback("onerror", errorCallbackObj); + } + + priv->setUserAgentString(userAgent, callbacks); + return JSValueMakeUndefined(context); + } catch (const BasePlatformException &err) { + LoggerE("%s: %s", err.getName().c_str(), err.getMessage().c_str()); + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error in WebSettingManager.setUserAgentString()."); + LoggerE("%s: %s", err.getName().c_str(), err.getMessage().c_str()); + return JSWebAPIErrorFactory::postException(context, exception, err); + } +} + +JSValueRef JSWebSettingManager::removeAllCookies(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + //TODO: Need to implement ACE check + //AceSecurityStatus status = WEB_SETTING_CHECK_ACCESS(WEB_SETTING_MANAGER_API_REMOVE_ALL_COOKIES); + //TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + + try { + // Private Object + WebSettingManager *priv = static_cast(JSObjectGetPrivate(thisObject)); + if (!priv) { + throw TypeMismatchException("Private object is NULL."); + } + + ArgumentValidator validator(context, argumentCount, arguments); + MultiCallbackUserDataPtr callbacks(new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context))); + + // successCallback + JSObjectRef successCallbackObj = validator.toFunction(0, true); + if (successCallbackObj) + { + callbacks->setCallback("onsuccess", successCallbackObj); + } + + // errorCallback + JSObjectRef errorCallbackObj = validator.toFunction(1, true); + if (errorCallbackObj) + { + callbacks->setCallback("onerror", errorCallbackObj); + } + priv->removeAllCookies(callbacks); + return JSValueMakeUndefined(context); + } catch (const BasePlatformException &err) { + LoggerE("%s: %s", err.getName().c_str(), err.getMessage().c_str()); + return JSWebAPIErrorFactory::postException(context, exception, err); + } catch (...) { + DeviceAPI::Common::UnknownException err("Unknown Error in WebSettingManager.removeAllCookies()."); + LoggerE("%s: %s", err.getName().c_str(), err.getMessage().c_str()); + return JSWebAPIErrorFactory::postException(context, exception, err); + } +} + + +} // WebSetting +} // DeviceAPI diff --git a/src/WebSetting/JSWebSettingManager.h b/src/WebSetting/JSWebSettingManager.h new file mode 100644 index 0000000..0733ca8 --- /dev/null +++ b/src/WebSetting/JSWebSettingManager.h @@ -0,0 +1,86 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef __TIZEN_JS_WEB_SETTING_MANAGER_H__ +#define __TIZEN_JS_WEB_SETTING_MANAGER_H__ + +#include + +#include "WebSettingManager.h" + +namespace DeviceAPI { +namespace WebSetting { + +class JSWebSettingManager +{ +public: + static const JSClassDefinition* getClassInfo(); + static const JSClassRef getClassRef(); +private: + + /** + * The callback invoked when an object is first created. + */ + static void initialize(JSContextRef context, + JSObjectRef object); + + /** + * The callback invoked when an object is finalized. + */ + static void finalize(JSObjectRef object); + + static JSValueRef setUserAgentString(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + + static JSValueRef removeAllCookies(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + + /** + * This member variable contains the values which has to be passed + * when the this class is embedded into JS Engine. + */ + static JSClassDefinition m_classInfo; + + /** + * This structure describes a statically declared function property. + */ + static JSStaticFunction m_function[]; + + /** + * This member variable contains the initialization values for the + * properties of this class. The values are given according to + * the data structure JSPropertySpec + */ + static JSStaticValue m_property[]; + + static JSClassRef m_jsClassRef; +}; + + + +} // WebSetting +} // DeviceAPI + +#endif // __TIZEN_JS_DOWNLOAD_MANAGER_H__ diff --git a/src/WebSetting/WebSettingManager.cpp b/src/WebSetting/WebSettingManager.cpp new file mode 100755 index 0000000..f056fdf --- /dev/null +++ b/src/WebSetting/WebSettingManager.cpp @@ -0,0 +1,113 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include +#include +#include "WebSettingManager.h" +#include +#include +#include +#include +#include + + +namespace DeviceAPI { +namespace WebSetting { + +WebSettingManager::WebSettingManager() +{ +} + +WebSettingManager::~WebSettingManager() +{ +} + +static gboolean asyncUserAgentStringResult(void *data) +{ + LoggerD("[asyncUserAgentStringResult] entered in Mainloop"); + + WebSettingManager* object = static_cast(data); + if(object == NULL) + { + //TBD : JSWebAPIErrorFactory::postException(context, exception, err); + LoggerD("[asyncUserAgentStringResult] User data is NULL"); + return true; + } + + MultiCallbackUserDataPtr callback = (MultiCallbackUserDataPtr)object->mSetUserAgentCallbacks; + + if (callback) + { + JSContextRef context = callback->getContext(); + callback->invokeCallback("onsuccess"); + } + + return false; +} + +static gboolean asyncRemoveAllCookiesResult(void *data) +{ + LoggerD("[asyncRemoveAllCookiesResult] entered in Mainloop"); + + WebSettingManager* object = static_cast(data); + if(object == NULL) + { + //TBD : JSWebAPIErrorFactory::postException(context, exception, err); + LoggerD("[asyncRemoveAllCookiesResult] User data is NULL"); + return true; + } + + MultiCallbackUserDataPtr callback = (MultiCallbackUserDataPtr)object->mRemoveAllCookiesCallbacks; + if (callback) + { + JSContextRef context = callback->getContext(); + callback->invokeCallback("onsuccess"); + } + + return false; +} + +static void checkSetUserAgentString(void *data, Ecore_Thread *thread) +{ + LoggerD("WebSettingManager::checkUserAgentString"); + g_idle_add(asyncUserAgentStringResult, data); +} + +static void checkRemoveAllCookies(void *data, Ecore_Thread *thread) +{ + LoggerD("WebSettingManager::checkRemoveAllCookies"); + g_idle_add(asyncRemoveAllCookiesResult, data); +} + +void WebSettingManager::setUserAgentString(std::string userAgent, MultiCallbackUserDataPtr callbacks) +{ + LoggerD("WebSetting:setUserAgentString: " << userAgent); + mSetUserAgentCallbacks = callbacks; + ecore_thread_run(checkSetUserAgentString, NULL, NULL, this); + //throw UnknownException("Not Implemented."); +} + +void WebSettingManager::removeAllCookies(MultiCallbackUserDataPtr callbacks) +{ + LoggerD("WebSetting:removeAllCookies: "); + mRemoveAllCookiesCallbacks = callbacks; + ecore_thread_run(checkRemoveAllCookies, NULL, NULL, this); + //throw UnknownException("Not Implemented."); +} + +} // WebSetting +} // DeviceAPI diff --git a/src/WebSetting/WebSettingManager.h b/src/WebSetting/WebSettingManager.h new file mode 100755 index 0000000..b859614 --- /dev/null +++ b/src/WebSetting/WebSettingManager.h @@ -0,0 +1,50 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef __TIZEN_WEB_SETTING_MANAGER_H__ +#define __TIZEN_WEB_SETTING_MANAGER_H__ + +#include + +#include "WebSettingTypes.h" + +using namespace DeviceAPI::Common; + +namespace DeviceAPI { +namespace WebSetting { + +class WebSettingManager +{ +public: + WebSettingManager(); + virtual ~WebSettingManager(); + + void setUserAgentString(std::string userAgent, MultiCallbackUserDataPtr callbacks); + + void removeAllCookies(MultiCallbackUserDataPtr callbacks); + + Common::MultiCallbackUserDataPtr mSetUserAgentCallbacks; + + Common::MultiCallbackUserDataPtr mRemoveAllCookiesCallbacks; + +private: +}; + +} // WebSetting +} // DeviceAPI + +#endif // __TIZEN_WEB_SETTING_MANAGER_H__ \ No newline at end of file diff --git a/src/WebSetting/WebSettingTypes.h b/src/WebSetting/WebSettingTypes.h new file mode 100644 index 0000000..a25c897 --- /dev/null +++ b/src/WebSetting/WebSettingTypes.h @@ -0,0 +1,32 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef _WEB_SETTING_TYPES_H_ +#define _WEB_SETTING_TYPES_H_ + +#include +#include +#include + +namespace DeviceAPI { +namespace WebSetting { + + +} // WebSetting +} // DeviceAPI + +#endif // _WEB_SETTING_TYPES_H_ diff --git a/src/WebSetting/config.xml b/src/WebSetting/config.xml new file mode 100644 index 0000000..377b37f --- /dev/null +++ b/src/WebSetting/config.xml @@ -0,0 +1,15 @@ + + + + libwrt-plugins-tizen-websetting.so + websetting.install.uri + SAMSUNG plugin group + SAMSUNG certificate authority + AAAABBBBCCCCDDDEEEE0000 + + + http://tizen.org/privilege/websetting + websetting + + + \ No newline at end of file diff --git a/src/WebSetting/plugin_config.cpp b/src/WebSetting/plugin_config.cpp new file mode 100644 index 0000000..9a3ed7f --- /dev/null +++ b/src/WebSetting/plugin_config.cpp @@ -0,0 +1,44 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + + +#include +#include +#include +#include + +#include "plugin_config.h" + +using namespace WrtDeviceApis::Commons; + +namespace DeviceAPI { +namespace WebSetting { + +static FunctionMapping createWebSettingFunctions(); +static FunctionMapping WebSettingFunctions = createWebSettingFunctions(); + +DEFINE_FUNCTION_GETTER(WebSetting, WebSettingFunctions); + +static FunctionMapping createWebSettingFunctions() +{ + FunctionMapping webSettingMapping; + // TODO: implement here + return webSettingMapping; +} + +} // WebSetting +} // DeviceAPI diff --git a/src/WebSetting/plugin_config.h b/src/WebSetting/plugin_config.h new file mode 100644 index 0000000..9443546 --- /dev/null +++ b/src/WebSetting/plugin_config.h @@ -0,0 +1,46 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + + +#ifndef _WEB_SETTING_PLUGIN_CONFIG_H_ +#define _WEB_SETTING_PLUGIN_CONFIG_H_ + +#include +#include + +#include + +namespace DeviceAPI { +namespace WebSetting { + +// attributes + +// functions +#define WEB_SETTING_MANAGER_API_SET_USER_AGENT_STRING "setUserAgentString" +#define WEB_SETTING_MANAGER_API_REMOVE_ALL_COOKIES "removeAllCookies" + +DECLARE_FUNCTION_GETTER(WebSetting); + +#define WEB_SETTING_CHECK_ACCESS(functionName) \ + aceCheckAccess >( \ + getWebSettingFunctionData, \ + functionName) + +} +} + +#endif // _WEB_SETTING_PLUGIN_CONFIG_H_ \ No newline at end of file diff --git a/src/WebSetting/plugin_initializer.cpp b/src/WebSetting/plugin_initializer.cpp new file mode 100755 index 0000000..85a702b --- /dev/null +++ b/src/WebSetting/plugin_initializer.cpp @@ -0,0 +1,81 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + + +#include +#include + +#include + +#include "JSWebSettingManager.h" + +#include + +using namespace WrtDeviceApis; +using namespace WrtDeviceApis::Commons; +using namespace DeviceAPI::Common; + +namespace DeviceAPI { +namespace WebSetting { + + +void on_widget_start_callback(int widgetId) +{ + LoggerD("[Tizen\\WebSetting] on_widget_start_callback (%d)", widgetId); + try { + WrtAccessSingleton::Instance().initialize(widgetId); + } catch (...) { + LoggerE("WrtAccess initialization failed"); + } +} + +void on_widget_stop_callback(int widgetId) +{ + LoggerD("[Tizen\\WebSetting] on_widget_stop_callback (%d)", widgetId); + try { + WrtAccessSingleton::Instance().deinitialize(widgetId); + } catch (...) { + LoggerE("WrtAccess deinitialization failed"); + } +} + +void on_frame_load_callback(const void * context) +{ + LoggerD("[Tizen\\WebSetting] on_frame_load_callback (%p)", context); + GlobalContextManager::getInstance()->addGlobalContext(static_cast(context)); +} + +void on_frame_unload_callback(const void * context) +{ + LoggerD("[Tizen\\WebSetting] on_frame_unload_callback (%p)", context); + GlobalContextManager::getInstance()->removeGlobalContext(static_cast(context)); +} + +PLUGIN_ON_WIDGET_START(on_widget_start_callback) +PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback) +PLUGIN_ON_FRAME_LOAD(on_frame_load_callback) +PLUGIN_ON_FRAME_UNLOAD(on_frame_unload_callback) + +PLUGIN_CLASS_MAP_BEGIN +PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, + "websetting", + (js_class_template_getter)JSWebSettingManager::getClassRef, + NULL) +PLUGIN_CLASS_MAP_END + +} // WebSetting +} // DeviceAPI -- 2.7.4