Update change log and spec for wrt-plugins-tizen_0.4.44
authorDongjin Choi <milkelf.choi@samsung.com>
Sun, 23 Jun 2013 18:44:23 +0000 (03:44 +0900)
committerDongjin Choi <milkelf.choi@samsung.com>
Sun, 23 Jun 2013 18:44:23 +0000 (03:44 +0900)
[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

80 files changed:
packaging/wrt-plugins-tizen.spec
pkgconfigs/wrt-plugins-tizen-websetting.pc.in [new file with mode: 0755]
src/Application/ApplicationConverter.cpp
src/Application/ApplicationConverter.h
src/Application/ApplicationManager.cpp
src/Application/ApplicationManager.h
src/Application/ApplicationMetaData.cpp [new file with mode: 0644]
src/Application/ApplicationMetaData.h [new file with mode: 0644]
src/Application/CMakeLists.txt
src/Application/JSApplicationManager.cpp
src/Application/JSApplicationManager.h
src/Application/JSApplicationMetaData.cpp [new file with mode: 0644]
src/Application/JSApplicationMetaData.h [new file with mode: 0644]
src/Application/JSRequestedApplicationControl.cpp
src/Application/config.xml
src/Application/plugin_config.cpp
src/Application/plugin_config.h
src/Bluetooth/BluetoothAdapter.cpp
src/Bluetooth/BluetoothAdapter.h
src/Bluetooth/BluetoothCallback.cpp [new file with mode: 0644]
src/Bluetooth/BluetoothCallback.h [new file with mode: 0644]
src/Bluetooth/BluetoothCallbackUtil.h
src/Bluetooth/BluetoothHealthApplication.cpp [new file with mode: 0644]
src/Bluetooth/BluetoothHealthApplication.h [new file with mode: 0644]
src/Bluetooth/BluetoothHealthChannel.cpp [new file with mode: 0644]
src/Bluetooth/BluetoothHealthChannel.h [new file with mode: 0644]
src/Bluetooth/BluetoothHealthProfileHandler.cpp [new file with mode: 0644]
src/Bluetooth/BluetoothHealthProfileHandler.h [new file with mode: 0644]
src/Bluetooth/BluetoothHealthProfileHandlerCallback.cpp [new file with mode: 0644]
src/Bluetooth/BluetoothHealthProfileHandlerCallback.h [new file with mode: 0644]
src/Bluetooth/BluetoothServiceHandler.cpp
src/Bluetooth/BluetoothServiceHandler.h
src/Bluetooth/BluetoothSocket.cpp
src/Bluetooth/CMakeLists.txt
src/Bluetooth/JSBluetoothAdapter.cpp
src/Bluetooth/JSBluetoothAdapter.h
src/Bluetooth/JSBluetoothClass.cpp
src/Bluetooth/JSBluetoothDevice.cpp
src/Bluetooth/JSBluetoothDevice.h
src/Bluetooth/JSBluetoothHealthApplication.cpp [new file with mode: 0644]
src/Bluetooth/JSBluetoothHealthApplication.h [new file with mode: 0644]
src/Bluetooth/JSBluetoothHealthChannel.cpp [new file with mode: 0644]
src/Bluetooth/JSBluetoothHealthChannel.h [new file with mode: 0644]
src/Bluetooth/JSBluetoothHealthProfileHandler.cpp [new file with mode: 0644]
src/Bluetooth/JSBluetoothHealthProfileHandler.h [new file with mode: 0644]
src/Bluetooth/JSBluetoothManager.cpp
src/Bluetooth/JSBluetoothProfileHandler.cpp [new file with mode: 0644]
src/Bluetooth/JSBluetoothProfileHandler.h [new file with mode: 0644]
src/Bluetooth/JSBluetoothServiceHandler.cpp
src/Bluetooth/JSBluetoothSocket.cpp
src/Bluetooth/plugin_config.cpp
src/Bluetooth/plugin_config.h
src/CMakeLists.txt
src/Calendar/JSCalendarItemProperties.cpp
src/Calendar/JSCalendarItemProperties.h
src/Contact/ContactObjectA2PConverter.cpp
src/DataControl/DataControlAsyncCallbackManager.h
src/DataControl/EventSelect.h
src/Download/JSDownloadRequest.cpp
src/MessagePort/MessagePortManagerProxy.cpp
src/Notification/JSStatusNotification.cpp
src/Notification/StatusNotification.cpp
src/Notification/StatusNotification.h
src/Notification/plugin_config.h
src/Systeminfo/CMakeLists.txt
src/Systeminfo/JSDeviceCapabilitiesInfo.cpp
src/Systeminfo/JSDeviceOrientationInfo.cpp [changed mode: 0644->0755]
src/Systeminfo/Systeminfo.cpp
src/Systeminfo/SysteminfoListener.cpp
src/Systeminfo/SysteminfoPropertyInfo.h
src/WebSetting/CMakeLists.txt [new file with mode: 0755]
src/WebSetting/JSWebSettingManager.cpp [new file with mode: 0755]
src/WebSetting/JSWebSettingManager.h [new file with mode: 0644]
src/WebSetting/WebSettingManager.cpp [new file with mode: 0755]
src/WebSetting/WebSettingManager.h [new file with mode: 0755]
src/WebSetting/WebSettingTypes.h [new file with mode: 0644]
src/WebSetting/config.xml [new file with mode: 0644]
src/WebSetting/plugin_config.cpp [new file with mode: 0644]
src/WebSetting/plugin_config.h [new file with mode: 0644]
src/WebSetting/plugin_initializer.cpp [new file with mode: 0755]

index 89e6274..57d58a9 100755 (executable)
@@ -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 (executable)
index 0000000..e7346e1
--- /dev/null
@@ -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}
index 849aacb..02318b1 100644 (file)
@@ -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) {
index 033ef63..a62bde0 100755 (executable)
@@ -27,6 +27,7 @@
 #include "ApplicationControlData.h"
 #include "ApplicationControl.h"
 #include "ApplicationCert.h"
+#include "ApplicationMetaData.h"
 #include "Application.h"
 #include <Export.h>
 
@@ -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);
index 47ce3b8..75d11d4 100644 (file)
@@ -28,7 +28,6 @@
 #include "ApplicationContext.h"
 #include "ApplicationControlData.h"
 #include "ApplicationControl.h"
-#include "ApplicationCert.h"
 #include "Application.h"
 
 #include <app.h>
@@ -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)
 {
index 8640820..b50125a 100644 (file)
@@ -30,6 +30,7 @@
 #include "ApplicationContext.h"
 #include "ApplicationInformation.h"
 #include "ApplicationCert.h"
+#include "ApplicationMetaData.h"
 
 //#include <app_manager.h>
 #include <app_service.h>
@@ -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 (file)
index 0000000..2711e8d
--- /dev/null
@@ -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 (file)
index 0000000..60e3b29
--- /dev/null
@@ -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 <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+namespace DeviceAPI {
+namespace Application {
+
+class ApplicationMetaData;
+typedef DPL::SharedPtr<ApplicationMetaData> ApplicationMetaDataPtr;
+
+typedef std::vector<ApplicationMetaDataPtr> ApplicationMetaDataArray;
+typedef DPL::SharedPtr<ApplicationMetaDataArray> 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
index 3a2dddf..78b69ff 100644 (file)
@@ -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})
index 8d3138c..b0b5893 100644 (file)
@@ -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);
index 3f28d1d..c7826d0 100644 (file)
@@ -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 (file)
index 0000000..8abeb0e
--- /dev/null
@@ -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 <cassert>
+#include <memory>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Converter.h>
+
+//#include <Commons/Exception.h>
+#include <JSWebAPIErrorFactory.h>
+
+#include "ApplicationMetaData.h"
+#include "JSApplicationMetaData.h"
+#include <Export.h>
+#include <Logger.h>
+
+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<JSApplicationMetaDataPriv*>(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<JSApplicationMetaDataPriv*>(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 (file)
index 0000000..e58aa36
--- /dev/null
@@ -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 <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <dpl/shared_ptr.h>
+
+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<ApplicationMetaDataPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> 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
index 6d4a45e..5b59cf7 100644 (file)
 
 #include <cassert>
 #include <memory>
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/JSDOMExceptionFactory.h>
-#include <CommonsJavaScript/PrivateObject.h>
-#include <CommonsJavaScript/JSUtils.h>
+
 #include <SecurityExceptions.h>
-#include <Commons/Exception.h>
-#include <JSWebAPIErrorFactory.h>
+#include <JSWebAPIError.h>
+#include <ArgumentValidator.h>
 
 #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<JSRequestedApplicationControlPriv*>(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<ApplicationControlDataPtr> resultArray;
-               if (argumentCount > 0) {
-                       resultArray = converter->toApplicationControlDataArray(arguments[0]);
+               JSObjectRef dataArrayObj = validator.toArrayObject(0, true);
+               std::vector<ApplicationControlDataPtr> 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<JSRequestedApplicationControlPriv*>(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);
+    }
 }
 
 }
index 022f496..415b85d 100755 (executable)
         <name>http://tizen.org/privilege/application.read</name>
         <device-capability>appmanager.certificate</device-capability>
     </api-feature>
+
+    <api-feature>
+        <name>http://tizen.org/privilege/application.info</name>
+        <device-capability>application.info</device-capability>
+    </api-feature>
     
 </plugin-properties>
index 291d57b..636a017 100755 (executable)
@@ -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
index 0e44e7e..0cfd8fb 100755 (executable)
@@ -47,6 +47,7 @@
 #define APPLICATION_FUNCTION_API_REPLY_RESULT                                  "replyResult"\r
 #define APPLICATION_FUNCTION_API_REPLY_FAILURE                                 "replyFailure"\r
 #define APPLICATION_FUNCTION_API_GET_APP_SHARED_URI                            "getAppSharedURI"\r
+#define APPLICATION_FUNCTION_API_GET_APP_META_DATA                             "getAppMetaData"\r
 #define APPLICATION_FUNCTION_API_SET_USER_AGENT                                        "setUserAgent"\r
 \r
 namespace DeviceAPI {\r
index 8ea4789..09b970c 100644 (file)
@@ -21,6 +21,7 @@
 #include <JSWebAPIErrorFactory.h>
 #include <system_info.h>
 #include <JSUtil.h>
+#include <TimeTracer.h>
 
 #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<BluetoothAdapterPtr>(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<BluetoothAdapterPtr>(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<MultiCallbackUserDataPtr>(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<BluetoothAdapterPtr>(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<BluetoothAdapterPtr>(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<BluetoothAdapterPtr>(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<BluetoothAdapterPtr>(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(&current , &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<std::string, BluetoothConnReqPtr>(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);
 }
 
 
index 604ced4..8b573e0 100644 (file)
@@ -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<int, BluetoothSocketPtr> ConnectedSocketMapT;   // <socketFD, BluetoothSocketPtr>
 
     bool mEnabled;
+    bool mVisible;
     ConnReqMultiMapT mConnReqMap;
     RegisteredUUIDMapT mRegisteredUUID;
     ConnectedSocketMapT mConnectedSocket;
@@ -123,6 +127,7 @@ private:
     std::vector<std::string> mDisappearedDevices;
     std::vector<BluetoothDeviceSharedPtr> mFoundDevices;
     std::vector<BluetoothDeviceSharedPtr> knownDevices;
+    Common::MultiCallbackUserDataPtr mChangeListener;
 };
 
 typedef BluetoothAdapter* BluetoothAdapterPtr;
diff --git a/src/Bluetooth/BluetoothCallback.cpp b/src/Bluetooth/BluetoothCallback.cpp
new file mode 100644 (file)
index 0000000..a5088fc
--- /dev/null
@@ -0,0 +1,103 @@
+//\r
+// Tizen Web Device API\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#include <Ecore.h>\r
+\r
+#include <JSUtil.h>\r
+#include <JSWebAPIErrorFactory.h>\r
+#include <Logger.h>\r
+\r
+#include "BluetoothCallback.h"\r
+\r
+\r
+using namespace DeviceAPI::Common;\r
+\r
+namespace DeviceAPI {\r
+namespace Bluetooth {\r
+\r
+\r
+class BluetoothCallbackData\r
+{\r
+public:\r
+    BluetoothCallbackData(MultiCallbackUserDataPtr callback)\r
+    {\r
+        mCallback = callback;\r
+        mError = NULL;\r
+    };\r
+\r
+    BluetoothCallbackData(MultiCallbackUserDataPtr callback, Common::BasePlatformException *error)\r
+    {\r
+        mCallback = callback;\r
+        mError = error;\r
+    };    \r
+\r
+    virtual ~BluetoothCallbackData()\r
+    {\r
+        if(mError)\r
+            delete mError;\r
+    };\r
+\r
+    MultiCallbackUserDataPtr mCallback;\r
+    Common::BasePlatformException *mError;\r
+};\r
+\r
+typedef BluetoothCallbackData* BluetoothCallbackDataPtr;\r
+\r
+\r
+static Eina_Bool jobCompleteCB(void *userData){\r
+    BluetoothCallbackDataPtr data = static_cast<BluetoothCallbackDataPtr>(userData);\r
+\r
+    if(!data) {\r
+        LoggerW("BluetoothCallbackDataPtr is NULL");\r
+        return false;\r
+    }\r
+\r
+    if(!(data->mCallback)) {\r
+        LoggerW("MulticallbackUserData is NULL");\r
+        delete data;\r
+        return false;            \r
+    }\r
+\r
+    if(data->mError == NULL) {  // Success Callback\r
+        LoggerD("Success Callback");\r
+        data->mCallback->invokeCallback("success");    \r
+    }\r
+    else {  // Error Callback\r
+        LoggerD("BT_CB_ERROR");\r
+        data->mCallback->invokeCallback("error", JSWebAPIErrorFactory::makeErrorObject(data->mCallback->getContext(), *(data->mError)));    \r
+    }\r
+\r
+    delete data;\r
+    return false;\r
+}\r
+\r
+void BluetoothCallback::syncToAsyncSuccessCB(MultiCallbackUserDataPtr callback)\r
+{\r
+    BluetoothCallbackDataPtr data = new BluetoothCallbackData(callback);\r
+    ecore_idler_add(jobCompleteCB, data);\r
+}\r
+\r
+void BluetoothCallback::syncToAsyncErrorCB(MultiCallbackUserDataPtr callback, Common::BasePlatformException *error)\r
+{\r
+    BluetoothCallbackDataPtr data = new BluetoothCallbackData(callback, error);\r
+    ecore_idler_add(jobCompleteCB, data);\r
+}\r
+\r
+\r
+} // Bluetooth\r
+} // DeviceAPI\r
+\r
diff --git a/src/Bluetooth/BluetoothCallback.h b/src/Bluetooth/BluetoothCallback.h
new file mode 100644 (file)
index 0000000..726a30c
--- /dev/null
@@ -0,0 +1,44 @@
+//\r
+// Tizen Web Device API\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#ifndef __TIZEN_BLUETOOTH_CALLBACK_H__\r
+#define __TIZEN_BLUETOOTH_CALLBACK_H__\r
+\r
+#include <string>\r
+#include <MultiCallbackUserData.h>\r
+#include <PlatformException.h>\r
+\r
+\r
+namespace DeviceAPI {\r
+namespace Bluetooth {\r
+\r
+\r
+class BluetoothCallback\r
+{\r
+public:\r
+    static void syncToAsyncSuccessCB(DeviceAPI::Common::MultiCallbackUserDataPtr userData);\r
+    static void syncToAsyncErrorCB(DeviceAPI::Common::MultiCallbackUserDataPtr userData, Common::BasePlatformException *error);\r
+};\r
+\r
+\r
+} // Bluetooth\r
+} // DeviceAPI\r
+\r
+\r
+\r
+#endif // __TIZEN_BLUETOOTH_CALLBACK_H__\r
+\r
index 610fd42..76926d6 100644 (file)
@@ -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 (file)
index 0000000..6832cb7
--- /dev/null
@@ -0,0 +1,102 @@
+//\r
+// Tizen Web Device API\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#include "BluetoothHealthApplication.h"\r
+#include "plugin_config.h"\r
+\r
+#include <bluetooth.h>\r
+#include <Logger.h>\r
+#include <GlobalContextManager.h>\r
+\r
+using namespace DeviceAPI::Common;\r
+\r
+namespace DeviceAPI {\r
+namespace Bluetooth {\r
+\r
+BluetoothHealthApplication::BluetoothHealthApplication(std::string appID, std::string name, unsigned short dataType)\r
+{\r
+    mAppID = appID;\r
+    mName = name;\r
+    mDataType = dataType;\r
+    mIsRegistered = true;\r
+}\r
+\r
+BluetoothHealthApplication::~BluetoothHealthApplication()\r
+{\r
+    if(mIsRegistered)\r
+        bt_hdp_unregister_sink_app(mAppID.c_str());\r
+}\r
+\r
+std::string BluetoothHealthApplication::getAppID() const\r
+{\r
+    return mAppID;\r
+}\r
+\r
+unsigned short BluetoothHealthApplication::getDataType() const\r
+{\r
+    return mDataType;\r
+}\r
+\r
+std::string BluetoothHealthApplication::getName() const\r
+{\r
+    return mName;\r
+}\r
+\r
+bool BluetoothHealthApplication::setOnConnect(JSContextRef context, JSObjectRef onConnect)\r
+{\r
+    MultiCallbackUserDataPtr callback(\r
+            new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));\r
+    if(!callback){\r
+        LoggerW("Can't create MultiCallbackUserData");\r
+        return false;\r
+    }    \r
+    callback->setCallback("onconnect", onConnect);\r
+    mOnConnect = callback;\r
+\r
+    return mLocalProperty.setProperty(context, BLUETOOTH_HEALTH_APPLICATION_ONCONNECT, onConnect);\r
+}\r
+\r
+MultiCallbackUserDataPtr BluetoothHealthApplication::getOnConnect() const\r
+{\r
+    return mOnConnect;\r
+}\r
+\r
+JSValueRef BluetoothHealthApplication::getOnConnect(JSContextRef context)\r
+{\r
+    JSValueRef onConnect = mLocalProperty.getProperty(context, BLUETOOTH_HEALTH_APPLICATION_ONCONNECT);\r
+    if(onConnect == NULL) {\r
+        LoggerD("onconnect is null");\r
+        return JSValueMakeNull(context);\r
+    }\r
+    \r
+    return onConnect;\r
+}\r
+\r
+bool BluetoothHealthApplication::getRegistrationState() const\r
+{\r
+    return mIsRegistered;\r
+}\r
+\r
+void BluetoothHealthApplication::setRegistrationState(bool isRegistered)\r
+{\r
+    mIsRegistered = isRegistered;\r
+}\r
+\r
+\r
+} // Bluetooth\r
+} // DeviceAPI\r
+\r
diff --git a/src/Bluetooth/BluetoothHealthApplication.h b/src/Bluetooth/BluetoothHealthApplication.h
new file mode 100644 (file)
index 0000000..3f549a6
--- /dev/null
@@ -0,0 +1,63 @@
+//\r
+// Tizen Web Device API\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#ifndef __TIZEN_BLUETOOTH_HEALTH_APPLICATION_H__\r
+#define __TIZEN_BLUETOOTH_HEALTH_APPLICATION_H__\r
+\r
+#include <string>\r
+\r
+#include <JavaScriptCore/JavaScript.h>\r
+#include <boost/shared_ptr.hpp>\r
+\r
+#include <MultiCallbackUserData.h>\r
+#include <PropertyBag.h>\r
+\r
+namespace DeviceAPI {\r
+namespace Bluetooth {\r
+\r
+class BluetoothHealthApplication\r
+{\r
+public:\r
+    BluetoothHealthApplication(std::string appID, std::string name, unsigned short dataType);\r
+    virtual ~BluetoothHealthApplication();\r
+\r
+    std::string getAppID() const;\r
+    unsigned short getDataType() const;\r
+    std::string getName() const;    \r
+    bool getRegistrationState() const;\r
+    void setRegistrationState(bool isRegistered);\r
+    Common::MultiCallbackUserDataPtr getOnConnect() const;\r
+    JSValueRef getOnConnect(JSContextRef context);\r
+    bool setOnConnect(JSContextRef context, JSObjectRef onConnect);\r
+\r
+\r
+private:\r
+    std::string mAppID;\r
+    std::string mName;\r
+    bool mIsRegistered;\r
+    Common::MultiCallbackUserDataPtr mOnConnect;    \r
+    unsigned short mDataType;\r
+    Common::PropertyBag mLocalProperty;    \r
+};\r
+\r
+typedef boost::shared_ptr<BluetoothHealthApplication> BluetoothHealthApplicationSharedPtr;\r
+\r
+} // Bluetooth\r
+} // DeviceAPI\r
+\r
+#endif // __TIZEN_BLUETOOTH_HEALTH_APPLICATION_H__\r
+\r
diff --git a/src/Bluetooth/BluetoothHealthChannel.cpp b/src/Bluetooth/BluetoothHealthChannel.cpp
new file mode 100644 (file)
index 0000000..6fbd00c
--- /dev/null
@@ -0,0 +1,142 @@
+// Tizen Web Device API\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#include <GlobalContextManager.h>\r
+#include <PlatformException.h>\r
+\r
+#include "BluetoothHealthChannel.h"\r
+#include "JSBluetoothDevice.h"\r
+#include "JSBluetoothHealthApplication.h"\r
+\r
+#include <Logger.h>\r
+#include <TimeTracer.h>\r
+\r
+using namespace DeviceAPI::Common;\r
+\r
+namespace DeviceAPI {\r
+namespace Bluetooth {\r
+\r
+BluetoothHealthChannel::BluetoothHealthChannel(unsigned int channel, BluetoothDeviceSharedPtr remoteDevice, \r
+        bt_hdp_channel_type_e type, BluetoothHealthApplicationSharedPtr application)\r
+{\r
+    mChannel = channel;\r
+    mRemoteDevice = remoteDevice;\r
+    if(type == BT_HDP_CHANNEL_TYPE_RELIABLE) {\r
+        mChannelTypeStr = "RELIABLE";\r
+    }\r
+    else {\r
+        mChannelTypeStr = "STREAMING";\r
+    }\r
+    mChannelType = type;\r
+    mApp = application;\r
+    mIsConnected = true;\r
+}\r
+\r
+BluetoothHealthChannel::~BluetoothHealthChannel()\r
+{\r
+    if(mIsConnected) {\r
+        bt_hdp_disconnect(mRemoteDevice->getAddress().c_str(), mChannel);\r
+    }\r
+}\r
+\r
+bool BluetoothHealthChannel::getConnectionState() const\r
+{\r
+    return mIsConnected;\r
+}\r
+\r
+void BluetoothHealthChannel::setConnectionState(bool isConnected)\r
+{\r
+    mIsConnected = isConnected;\r
+}\r
+\r
+unsigned int BluetoothHealthChannel::getChannel() const\r
+{\r
+    return mChannel;\r
+}\r
+\r
+std::string BluetoothHealthChannel::getChannelTypeStr() const\r
+{\r
+    return mChannelTypeStr;\r
+}\r
+\r
+bt_hdp_channel_type_e BluetoothHealthChannel::getChannelType() const\r
+{\r
+    return mChannelType;\r
+}\r
+\r
+JSValueRef BluetoothHealthChannel::getApp(JSContextRef context)\r
+{\r
+    return JSBluetoothHealthApplication::createJSObject(context, mApp);\r
+}\r
+\r
+JSValueRef BluetoothHealthChannel::getPeer(JSContextRef context)\r
+{\r
+    return JSBluetoothDevice::createJSObject(context, mRemoteDevice);\r
+}\r
+\r
+Common::MultiCallbackUserDataPtr BluetoothHealthChannel::getListener() const\r
+{\r
+    return mListener;\r
+}\r
+\r
+unsigned long BluetoothHealthChannel::sendData(char* data, unsigned long size)\r
+{\r
+    unsigned long ret = 0;\r
+    TIME_TRACER_ITEM_BEGIN("sendData::bt_hdp_send_data", 1);\r
+    if(bt_hdp_send_data(mChannel, data, static_cast<unsigned int>(size)) == BT_ERROR_NONE) {\r
+        TIME_TRACER_ITEM_END("sendData::bt_hdp_send_data", 1);\r
+        LoggerD("bt_hdp_send_data() succeeded");\r
+        ret = size;\r
+    }\r
+    else {\r
+        throw UnknownException("Unknown error");\r
+    }\r
+\r
+    //delete data;\r
+    return ret;\r
+}\r
+\r
+void BluetoothHealthChannel::close()\r
+{\r
+    if(!mIsConnected) {\r
+        LoggerD("Already disconnected");\r
+        return;\r
+    }\r
+\r
+    TIME_TRACER_ITEM_BEGIN("close::bt_hdp_disconnect", 1);\r
+    if(bt_hdp_disconnect(mRemoteDevice->getAddress().c_str(), mChannel) != BT_ERROR_NONE) {\r
+        LoggerE("bt_hdp_disconnect() failed");\r
+        throw UnknownException("Unknown error");\r
+    }\r
+    TIME_TRACER_ITEM_END("close::bt_hdp_disconnect", 1);\r
+\r
+    mIsConnected = false;\r
+}\r
+\r
+void BluetoothHealthChannel::setListener(Common::MultiCallbackUserDataPtr callback)\r
+{\r
+    mListener = callback;\r
+}\r
+\r
+void BluetoothHealthChannel::unsetListener()\r
+{\r
+    mListener.reset();\r
+}\r
+\r
+\r
+} // Bluetooth\r
+} // DeviceAPI\r
+\r
diff --git a/src/Bluetooth/BluetoothHealthChannel.h b/src/Bluetooth/BluetoothHealthChannel.h
new file mode 100644 (file)
index 0000000..d10d81f
--- /dev/null
@@ -0,0 +1,69 @@
+//\r
+// Tizen Web Device API\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#ifndef __TIZEN_BLUETOOTH_HEALTH_CHANNEL_H__\r
+#define __TIZEN_BLUETOOTH_HEALTH_CHANNEL_H__\r
+\r
+#include <string>\r
+#include <bluetooth.h>\r
+#include <JavaScriptCore/JavaScript.h>\r
+\r
+#include <MultiCallbackUserData.h>\r
+#include "BluetoothDevice.h"\r
+#include "BluetoothHealthApplication.h"\r
+\r
+namespace DeviceAPI {\r
+namespace Bluetooth {\r
+\r
+class BluetoothHealthChannel\r
+{\r
+public:\r
+    BluetoothHealthChannel(unsigned int channel, BluetoothDeviceSharedPtr remoteDevice, bt_hdp_channel_type_e type, BluetoothHealthApplicationSharedPtr application);\r
+    virtual ~BluetoothHealthChannel();\r
+\r
+    bool getConnectionState() const;\r
+    void setConnectionState(bool isConnected);\r
+    unsigned int getChannel() const;\r
+    std::string getChannelTypeStr() const;\r
+    bt_hdp_channel_type_e getChannelType() const;\r
+    JSValueRef getApp(JSContextRef context);\r
+    JSValueRef getPeer(JSContextRef context);    \r
+    Common::MultiCallbackUserDataPtr getListener() const;\r
+    \r
+    unsigned long sendData(char* data, unsigned long size);\r
+    void close();\r
+    void setListener(Common::MultiCallbackUserDataPtr callback);\r
+    void unsetListener();    \r
+\r
+private:\r
+    unsigned int mChannel;\r
+    bool mIsConnected;\r
+    std::string mChannelTypeStr;\r
+    bt_hdp_channel_type_e mChannelType;\r
+    BluetoothDeviceSharedPtr mRemoteDevice;\r
+    BluetoothHealthApplicationSharedPtr mApp;\r
+\r
+    Common::MultiCallbackUserDataPtr mListener;\r
+};\r
+\r
+typedef BluetoothHealthChannel* BluetoothHealthChannelPtr;\r
+\r
+} // Bluetooth\r
+} // DeviceAPI\r
+\r
+#endif // __TIZEN_BLUETOOTH_HEALTH_CHANNEL_H__\r
+\r
diff --git a/src/Bluetooth/BluetoothHealthProfileHandler.cpp b/src/Bluetooth/BluetoothHealthProfileHandler.cpp
new file mode 100644 (file)
index 0000000..c80049e
--- /dev/null
@@ -0,0 +1,397 @@
+//\r
+// Tizen Web Device API\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+\r
+#include <Logger.h>\r
+#include <JSWebAPIErrorFactory.h>\r
+#include <system_info.h>\r
+#include <JSUtil.h>\r
+#include <TimeTracer.h>\r
+\r
+#include "BluetoothHealthProfileHandler.h"\r
+#include "BluetoothHealthProfileHandlerCallback.h"\r
+#include "JSBluetoothHealthApplication.h"\r
+#include "JSBluetoothDevice.h"\r
+#include "JSBluetoothHealthChannel.h"\r
+#include "BluetoothHealthChannel.h"\r
+\r
+using namespace DeviceAPI::Common;\r
+\r
+namespace DeviceAPI {\r
+namespace Bluetooth {\r
+\r
+void BluetoothHealthProfileHandler::onConnected(int result, const char *remote_address, const char *app_id, \r
+        bt_hdp_channel_type_e type, unsigned int channel, void *userData)\r
+{\r
+    LoggerD("Enter");\r
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);\r
+\r
+    HealthProfileHandlerPtr object = static_cast<HealthProfileHandlerPtr>(userData);\r
+    if(!object) {\r
+        LoggerW("userData is NULL");\r
+        return;\r
+    }\r
+\r
+    if(result != BT_ERROR_NONE) {\r
+        LoggerD("Not BT_ERROR_NONE");\r
+    }\r
+\r
+    LoggerD("Connected app: " << app_id);\r
+    LoggerD("Connected channel: " << channel);\r
+\r
+    std::string appID(app_id);\r
+    RegisteredHealthAppMapT::iterator iter = object->mRegisteredHealthAppMap.find(appID);\r
+    if(iter == object->mRegisteredHealthAppMap.end()) {\r
+        LoggerW("This app is not registered");\r
+        return;        \r
+    }\r
+    BluetoothHealthApplicationSharedPtr application = iter->second;\r
+\r
+    //  call BluetoothHealthApplication.onconnect\r
+    if(result == BT_ERROR_NONE) {\r
+        Common::MultiCallbackUserDataPtr callback = application->getOnConnect();\r
+        if(callback) {\r
+            bt_device_info_s *deviceInfo = NULL;\r
+            if(bt_adapter_get_bonded_device_info(remote_address, &deviceInfo) == BT_ERROR_NONE &&\r
+                    deviceInfo != NULL) {            \r
+                BluetoothDeviceSharedPtr device(new BluetoothDevice(deviceInfo));\r
+                bt_adapter_free_device_info(deviceInfo);\r
+            \r
+                LoggerD("invoke BluetoothHealthApplication.onconnect");\r
+                BluetoothHealthChannelPtr healthChannel = new BluetoothHealthChannel(channel, device, type, application);                            \r
+                object->mConnectedSocketMap.insert(std::pair<unsigned int, BluetoothHealthChannelPtr>(channel, healthChannel));\r
+                callback->invokeCallback("success", JSBluetoothHealthChannel::createJSObject(callback->getContext(), healthChannel));        \r
+            }\r
+            else {\r
+                LoggerE("Can't call BluetoothHealthApplication.onconnect because failed to get device info");\r
+            }\r
+        }\r
+        else {\r
+            LoggerD("BluetoothHealthApplication.onconnect is not set");\r
+        }\r
+    }\r
+\r
+    // in case of connectToSource()\r
+    HealthConnReqMapT::iterator i = object->mHealthConnReqMap.find(application);\r
+    if(i != object->mHealthConnReqMap.end()) {\r
+        LoggerD("Requested connection");\r
+        Common::MultiCallbackUserDataPtr callback = i->second->mUserData;\r
+        if(callback) {\r
+            if(result == BT_ERROR_NONE) {\r
+                BluetoothHealthChannelPtr healthChannel = new BluetoothHealthChannel(channel, i->second->mRemoteDevice, type, application);                            \r
+                //object->mConnectedSocketMap.insert(std::pair<unsigned int, BluetoothHealthChannelPtr>(channel, healthChannel));\r
+                callback->invokeCallback("success", JSBluetoothHealthChannel::createJSObject(callback->getContext(), healthChannel));               \r
+            }\r
+            else {\r
+                LoggerE("Failed to establish a connection with health profile");\r
+                callback->invokeCallback("error", \r
+                        JSWebAPIErrorFactory::makeErrorObject(callback->getContext(), UnknownException("Failed to establish a connection with health profile")));\r
+            }     \r
+        }       \r
+\r
+        // Update mHealthConnReqMap\r
+        object->mHealthConnReqMap.erase(i);            \r
+    }\r
+    else {\r
+        LoggerD("There is no connection request");\r
+    }    \r
+\r
+    TIME_TRACER_ITEM_END(__FUNCTION__, 1);\r
+}\r
+\r
+void BluetoothHealthProfileHandler::onDisconnected(int result, const char *remote_address, unsigned int channel, void *userData)\r
+{\r
+    LoggerD("Enter");\r
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);\r
+\r
+    HealthProfileHandlerPtr object = static_cast<HealthProfileHandlerPtr>(userData);\r
+    if(!object) {\r
+        LoggerW("userData is NULL");\r
+        return;\r
+    }\r
+\r
+    LoggerD("Disconnected channel: " << channel);\r
+    HealthConnectedSocketMapT::iterator iter = object->mConnectedSocketMap.find(channel);\r
+    if(iter == object->mConnectedSocketMap.end()) {\r
+        LoggerW("Unexpected health disconnection event");\r
+        return;\r
+    }\r
+\r
+    if(result == BT_ERROR_NONE) {\r
+        BluetoothHealthChannelPtr healthChannel = iter->second;\r
+        object->mConnectedSocketMap.erase(iter);\r
+\r
+        healthChannel->setConnectionState(false);\r
+        MultiCallbackUserDataPtr callback = healthChannel->getListener();\r
+        if(callback)\r
+            callback->invokeCallback("onclose");        \r
+    }\r
+    else {\r
+        LoggerW("Failed to disconnect a connection");\r
+    }\r
+    \r
+    TIME_TRACER_ITEM_END(__FUNCTION__, 1);\r
+}\r
+\r
+void BluetoothHealthProfileHandler::onDataReceivedCB(unsigned int channel, const char *data, unsigned int size, void *userData)\r
+{\r
+    LoggerD("Enter");\r
+\r
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);\r
+\r
+    HealthProfileHandlerPtr object = static_cast<HealthProfileHandlerPtr>(userData);\r
+    if(!object) {\r
+        LoggerW("userData is NULL");\r
+        return;\r
+    }\r
+\r
+    LoggerD("data channel: " << channel);\r
+    LoggerD("sent data size: " << size);\r
+    HealthConnectedSocketMapT::iterator iter = object->mConnectedSocketMap.find(channel);\r
+    if(iter == object->mConnectedSocketMap.end()) {\r
+        LoggerW("Unexpected health data received event");\r
+        return;\r
+    }\r
+\r
+    BluetoothHealthChannelPtr healthChannel = iter->second;\r
+    MultiCallbackUserDataPtr callback = healthChannel->getListener();        \r
+    if(callback) {\r
+        std::vector<signed char> receivedData;\r
+        for(unsigned int i = 0; i < size; i++) {\r
+            receivedData.push_back(static_cast<signed char>(data[i]));\r
+        }\r
+        callback->invokeCallback("onmessage", JSUtil::toJSValueRef_(callback->getContext(), receivedData));\r
+    }\r
+    \r
+    TIME_TRACER_ITEM_END(__FUNCTION__, 1);\r
+}\r
+\r
+BluetoothHealthProfileHandler* BluetoothHealthProfileHandler::getInstance()\r
+{\r
+    static BluetoothHealthProfileHandler instance;\r
+    return &instance;\r
+}\r
+\r
+BluetoothHealthProfileHandler::BluetoothHealthProfileHandler()\r
+{\r
+    if(bt_hdp_set_connection_state_changed_cb(onConnected, onDisconnected, this) != BT_ERROR_NONE) {\r
+        LoggerE("bt_hdp_set_connection_state_changed_cb() failed");\r
+    }\r
+\r
+    if(bt_hdp_set_data_received_cb(onDataReceivedCB, this) != BT_ERROR_NONE) {\r
+        LoggerE("bt_hdp_set_data_received_cb() failed");\r
+    }    \r
+}\r
+\r
+BluetoothHealthProfileHandler::~BluetoothHealthProfileHandler()\r
+{\r
+    // unset platform callback\r
+    bt_hdp_unset_connection_state_changed_cb();\r
+    bt_hdp_unset_data_received_cb();\r
+\r
+    mHealthConnReqMap.clear();\r
+    mConnectedSocketMap.clear();\r
+    mRegisteredHealthAppMap.clear();    \r
+}\r
+\r
+void BluetoothHealthProfileHandler::registerSinkApp(unsigned short dataType, std::string name, Common::MultiCallbackUserDataPtr callback)\r
+{\r
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);\r
+    BluetoothHealthProfileHandlerCallback::syncToAsyncRegisterCB(callback, dataType, name);\r
+    TIME_TRACER_ITEM_END(__FUNCTION__, 1);    \r
+}\r
+\r
+void BluetoothHealthProfileHandler::returnRegisteringSinkAppResult(unsigned short dataType, std::string name, Common::MultiCallbackUserDataPtr callback)\r
+{\r
+    LoggerD("Enter");\r
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);\r
+    \r
+    char *app_id = NULL;\r
+    int ret = bt_hdp_register_sink_app(dataType, &app_id);\r
+    switch(ret) {\r
+        case BT_ERROR_NONE:\r
+        {\r
+            LoggerD("Registered app: " << app_id);\r
+            std::string appID(app_id);\r
+            free(app_id);\r
+            BluetoothHealthApplicationSharedPtr application(new BluetoothHealthApplication(appID, name, dataType));\r
+            mRegisteredHealthAppMap.insert(std::pair<std::string, BluetoothHealthApplicationSharedPtr>(appID, application));\r
+            if(callback)\r
+                callback->invokeCallback("success", JSBluetoothHealthApplication::createJSObject(callback->getContext(), application));\r
+            break;\r
+        }\r
+        case BT_ERROR_NOT_ENABLED:\r
+        {\r
+            if(callback) {\r
+                callback->invokeCallback("error", \r
+                        JSWebAPIErrorFactory::makeErrorObject(callback->getContext(), ServiceNotAvailableException("Bluetooth device is turned off")));            \r
+            }\r
+            break;\r
+        }\r
+        default:\r
+        {\r
+            if(callback) {\r
+                callback->invokeCallback("error", \r
+                        JSWebAPIErrorFactory::makeErrorObject(callback->getContext(), UnknownException("Unknown error")));            \r
+            }\r
+        }\r
+    }\r
+    \r
+    TIME_TRACER_ITEM_END(__FUNCTION__, 1); \r
+}\r
+\r
+/*\r
+void BluetoothHealthProfileHandler::unregisterSinkApplication(JSObjectRef appObj, Common::MultiCallbackUserDataPtr callback)\r
+{\r
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);\r
+    BluetoothHealthProfileHandlerCallback::syncToAsyncUnregisterCB(callback, appObj);\r
+    TIME_TRACER_ITEM_END(__FUNCTION__, 1);    \r
+}\r
+\r
+void BluetoothHealthProfileHandler::returnUnregisteringResult(JSObjectRef appObj, Common::MultiCallbackUserDataPtr callback)\r
+{\r
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);\r
+    \r
+    BluetoothHealthApplicationSharedPtr app = JSBluetoothHealthApplication::toBluetoothHealthApplication(appObj);\r
+    int ret = bt_hdp_unregister_sink_app(app->getAppID().c_str());\r
+    switch(ret) {\r
+        case BT_ERROR_NONE:\r
+        {\r
+            //app->setRegistrationState(false);\r
+            BluetoothHealthProfileHandlerCallback::syncToAsyncSuccessCB(callback);\r
+            break;\r
+        }\r
+        case BT_ERROR_NOT_ENABLED:\r
+        {\r
+            ServiceNotAvailableException *error =  new ServiceNotAvailableException("Bluetooth device is turned off");\r
+            BluetoothHealthProfileHandlerCallback::syncToAsyncErrorCB(callback, error);\r
+            break;\r
+        }\r
+        default:\r
+        {\r
+            UnknownException *error = new UnknownException("Unknown error");\r
+            BluetoothHealthProfileHandlerCallback::syncToAsyncErrorCB(callback, error);\r
+        }        \r
+    }\r
+    \r
+    TIME_TRACER_ITEM_END(__FUNCTION__, 1); \r
+}\r
+*/\r
+\r
+void BluetoothHealthProfileHandler::unregisterApp(std::string appID, Common::MultiCallbackUserDataPtr callback)\r
+{\r
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);\r
+    BluetoothHealthProfileHandlerCallback::syncToAsyncUnregisterCB(callback, appID);\r
+    TIME_TRACER_ITEM_END(__FUNCTION__, 1);    \r
+}\r
+\r
+void BluetoothHealthProfileHandler::returnUnregisteringAppResult(std::string appID, Common::MultiCallbackUserDataPtr callback)\r
+{\r
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);  \r
+\r
+    RegisteredHealthAppMapT::iterator iter = mRegisteredHealthAppMap.find(appID);\r
+    BluetoothHealthApplicationSharedPtr application;\r
+    if(iter != mRegisteredHealthAppMap.end()) {\r
+        LoggerE("registered Health Application is found");\r
+        application = iter->second;    \r
+    }\r
+    else {\r
+        LoggerD("Already unregistered");\r
+        if(callback)\r
+            callback->invokeCallback("success");\r
+        return;\r
+    }    \r
+\r
+    int ret = bt_hdp_unregister_sink_app(appID.c_str());\r
+    switch(ret) {\r
+        case BT_ERROR_NONE:\r
+        {\r
+            mRegisteredHealthAppMap.erase(iter);\r
+            application->setRegistrationState(false);\r
+            if(callback)\r
+                callback->invokeCallback("success");           \r
+            break;\r
+        }\r
+        case BT_ERROR_NOT_ENABLED:\r
+        {\r
+            if(callback) {\r
+                callback->invokeCallback("error", \r
+                        JSWebAPIErrorFactory::makeErrorObject(callback->getContext(), ServiceNotAvailableException("Bluetooth device is turned off")));            \r
+            }\r
+            break;\r
+        }\r
+        default:\r
+        {\r
+            if(callback) {\r
+                callback->invokeCallback("error", \r
+                        JSWebAPIErrorFactory::makeErrorObject(callback->getContext(), UnknownException("Unknown error")));            \r
+            }\r
+        }        \r
+    }\r
+    \r
+    TIME_TRACER_ITEM_END(__FUNCTION__, 1); \r
+}\r
+\r
+void BluetoothHealthProfileHandler::connectToSource(JSObjectRef remoteDeviceObj, JSObjectRef appObj, Common::MultiCallbackUserDataPtr callback)\r
+{\r
+    LoggerD("Enter");\r
+    \r
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);\r
+\r
+    BluetoothDeviceSharedPtr device = JSBluetoothDevice::toBluetoothDevice(remoteDeviceObj);\r
+    BluetoothHealthApplicationSharedPtr app = JSBluetoothHealthApplication::toBluetoothHealthApplication(appObj);\r
+    LoggerD("address: " << device->getAddress().c_str());\r
+    LoggerD("app ID: " << app->getAppID().c_str());    \r
+    int ret = bt_hdp_connect_to_source(device->getAddress().c_str(), app->getAppID().c_str());\r
+    switch(ret) {\r
+        case BT_ERROR_NONE:\r
+        {\r
+            LoggerD("NONE");\r
+            HealthConnReqPtr connReq = new HealthConnReq(device, callback);\r
+            mHealthConnReqMap.insert(std::pair<BluetoothHealthApplicationSharedPtr, HealthConnReqPtr>(app, connReq));            \r
+            break;\r
+        }\r
+        case BT_ERROR_NOT_ENABLED:\r
+        {\r
+            LoggerD("Not Enabled");\r
+            ServiceNotAvailableException *error =  new ServiceNotAvailableException("Bluetooth device is turned off");\r
+            BluetoothHealthProfileHandlerCallback::syncToAsyncErrorCB(callback, error);\r
+            break;\r
+        }\r
+        case BT_ERROR_INVALID_PARAMETER:\r
+        case BT_ERROR_REMOTE_DEVICE_NOT_BONDED:\r
+        {\r
+            LoggerD("invalid value");\r
+            InvalidValuesException *error = new InvalidValuesException("Invalid value");\r
+            BluetoothHealthProfileHandlerCallback::syncToAsyncErrorCB(callback, error);\r
+            break;\r
+        }\r
+        default:\r
+        {\r
+            LoggerD("Unknown error");\r
+            UnknownException *error = new UnknownException("Unknown error");\r
+            BluetoothHealthProfileHandlerCallback::syncToAsyncErrorCB(callback, error);\r
+        }        \r
+    }\r
+\r
+    TIME_TRACER_ITEM_END(__FUNCTION__, 1); \r
+}\r
+\r
+\r
+} // Bluetooth\r
+} // DeviceAPI\r
+\r
diff --git a/src/Bluetooth/BluetoothHealthProfileHandler.h b/src/Bluetooth/BluetoothHealthProfileHandler.h
new file mode 100644 (file)
index 0000000..e752805
--- /dev/null
@@ -0,0 +1,89 @@
+//\r
+// Tizen Web Device API\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#ifndef __TIZEN_BLUETOOTH_ADAPTER_H__\r
+#define __TIZEN_HEALTH_PROFILE_HANDLER_H__\r
+\r
+#include <string>\r
+#include <map>\r
+#include <vector>\r
+\r
+#include <JavaScriptCore/JavaScript.h>\r
+\r
+#include <MultiCallbackUserData.h>\r
+#include <PlatformException.h>\r
+#include <bluetooth.h>\r
+\r
+#include "BluetoothHealthChannel.h"\r
+#include "BluetoothHealthApplication.h"\r
+#include "BluetoothDevice.h"\r
+\r
+\r
+namespace DeviceAPI {\r
+namespace Bluetooth {\r
+\r
+class HealthConnReq\r
+{\r
+public:\r
+    HealthConnReq(BluetoothDeviceSharedPtr remoteDevice, Common::MultiCallbackUserDataPtr userData) \r
+    {\r
+        mRemoteDevice = remoteDevice;\r
+        mUserData = userData;\r
+    };\r
+    \r
+    BluetoothDeviceSharedPtr mRemoteDevice;\r
+    Common::MultiCallbackUserDataPtr mUserData;\r
+};\r
+typedef HealthConnReq* HealthConnReqPtr;\r
+\r
+class BluetoothHealthProfileHandler\r
+{\r
+public:    \r
+    static BluetoothHealthProfileHandler* getInstance();    \r
+    void registerSinkApp(unsigned short dataType, std::string name, Common::MultiCallbackUserDataPtr callback);\r
+    void returnRegisteringSinkAppResult(unsigned short dataType, std::string name, Common::MultiCallbackUserDataPtr callback);\r
+//    void unregisterSinkApplication(JSObjectRef appObj, Common::MultiCallbackUserDataPtr callback);\r
+//    void returnUnregisteringResult(JSObjectRef appObj, Common::MultiCallbackUserDataPtr callback);\r
+    void unregisterApp(std::string appID, Common::MultiCallbackUserDataPtr callback);\r
+    void returnUnregisteringAppResult(std::string appID, Common::MultiCallbackUserDataPtr callback);\r
+    void connectToSource(JSObjectRef remoteDeviceObj, JSObjectRef appObj, Common::MultiCallbackUserDataPtr callback);\r
+    \r
+private:  \r
+    BluetoothHealthProfileHandler();\r
+    virtual ~BluetoothHealthProfileHandler();\r
+\r
+    static void onConnected(int result, const char *remote_address, const char *app_id,\r
+            bt_hdp_channel_type_e type, unsigned int channel, void *userData);\r
+    static void onDisconnected(int result, const char *remote_address, unsigned int channel, void *userData);\r
+    static void onDataReceivedCB(unsigned int channel, const char *data, unsigned int size, void *userData);\r
+\r
+    typedef std::map<BluetoothHealthApplicationSharedPtr, HealthConnReqPtr> HealthConnReqMapT;\r
+    typedef std::map<unsigned int, BluetoothHealthChannelPtr> HealthConnectedSocketMapT;    // <channel, BluetoothHealthChannelPtr>\r
+    typedef std::map<std::string, BluetoothHealthApplicationSharedPtr> RegisteredHealthAppMapT; // <app_id, BluetoothHealthApplicationSharedPtr>\r
+    \r
+    HealthConnReqMapT mHealthConnReqMap;\r
+    HealthConnectedSocketMapT mConnectedSocketMap;\r
+    RegisteredHealthAppMapT mRegisteredHealthAppMap;\r
+};\r
+\r
+typedef BluetoothHealthProfileHandler* HealthProfileHandlerPtr;\r
+\r
+} // Bluetooth\r
+} // DeviceAPI\r
+\r
+#endif // __TIZEN_HEALTH_PROFILE_HANDLER_H__\r
+\r
diff --git a/src/Bluetooth/BluetoothHealthProfileHandlerCallback.cpp b/src/Bluetooth/BluetoothHealthProfileHandlerCallback.cpp
new file mode 100644 (file)
index 0000000..aa8b3d1
--- /dev/null
@@ -0,0 +1,116 @@
+//\r
+// Tizen Web Device API\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#include <Ecore.h>\r
+\r
+#include <JSUtil.h>\r
+#include <Logger.h>\r
+\r
+#include "BluetoothHealthProfileHandlerCallback.h"\r
+#include "BluetoothHealthProfileHandler.h"\r
+\r
+\r
+using namespace DeviceAPI::Common;\r
+\r
+namespace DeviceAPI {\r
+namespace Bluetooth {\r
+\r
+\r
+class HealthProfileHandlerCallbackData\r
+{\r
+public:\r
+    HealthProfileHandlerCallbackData(MultiCallbackUserDataPtr callback, unsigned short dataType, std::string name)\r
+    {\r
+        mCallback = callback;\r
+        mDataType = dataType;\r
+        mName = name;\r
+        mIsRegistering = true;\r
+    };\r
+\r
+    HealthProfileHandlerCallbackData(MultiCallbackUserDataPtr callback, std::string appID)\r
+    {\r
+        mCallback = callback;\r
+        mAppID = appID;\r
+        mIsRegistering = false;\r
+    };    \r
+\r
+    virtual ~HealthProfileHandlerCallbackData()\r
+    {\r
+        // Do nothing\r
+    };\r
+\r
+    MultiCallbackUserDataPtr mCallback;\r
+    unsigned short mDataType;\r
+    std::string mName;\r
+    std::string mAppID;\r
+    bool mIsRegistering;\r
+};\r
+\r
+typedef HealthProfileHandlerCallbackData* HealthProfileHandlerCallbackDataPtr;\r
+\r
+\r
+static Eina_Bool idlerCallback(void *userData){\r
+    HealthProfileHandlerCallbackDataPtr data = static_cast<HealthProfileHandlerCallbackDataPtr>(userData);\r
+\r
+    if(!data) {\r
+        LoggerW("BluetoothCallbackDataPtr is NULL");\r
+        return false;\r
+    }\r
+\r
+    if(!(data->mCallback)) {\r
+        LoggerW("MulticallbackUserData is NULL");\r
+        delete data;\r
+        return false;            \r
+    }\r
+\r
+    if(data->mIsRegistering) {  // registerSinkApplication\r
+        LoggerD("In case of registerSinkApplication");\r
+        BluetoothHealthProfileHandler::getInstance()->returnRegisteringSinkAppResult(data->mDataType, data->mName, data->mCallback);\r
+    }\r
+    else {  // unregisterSinkApplication\r
+        LoggerD("In case of unregisterSinkApplication");\r
+        BluetoothHealthProfileHandler::getInstance()->returnUnregisteringAppResult(data->mAppID, data->mCallback);\r
+    }\r
+\r
+    delete data;\r
+    return false;\r
+}\r
+\r
+void BluetoothHealthProfileHandlerCallback::syncToAsyncRegisterCB(MultiCallbackUserDataPtr callback, unsigned short dataType, std::string name)\r
+{\r
+    HealthProfileHandlerCallbackDataPtr data = new HealthProfileHandlerCallbackData(callback, dataType, name);\r
+    ecore_idler_add(idlerCallback, data);\r
+}\r
+\r
+/*\r
+void BluetoothHealthProfileHandlerCallback::syncToAsyncUnregisterCB(MultiCallbackUserDataPtr callback, JSObjectRef application)\r
+{\r
+    HealthProfileHandlerCallbackDataPtr data = new HealthProfileHandlerCallbackData(callback, application);\r
+    ecore_idler_add(idlerCallback, data);\r
+}\r
+*/\r
+void BluetoothHealthProfileHandlerCallback::syncToAsyncUnregisterCB(MultiCallbackUserDataPtr callback, std::string appID)\r
+{\r
+    HealthProfileHandlerCallbackDataPtr data = new HealthProfileHandlerCallbackData(callback, appID);\r
+    ecore_idler_add(idlerCallback, data);\r
+}\r
+\r
+\r
+} // Bluetooth\r
+} // DeviceAPI\r
+\r
+\r
diff --git a/src/Bluetooth/BluetoothHealthProfileHandlerCallback.h b/src/Bluetooth/BluetoothHealthProfileHandlerCallback.h
new file mode 100644 (file)
index 0000000..c86089e
--- /dev/null
@@ -0,0 +1,47 @@
+//\r
+// Tizen Web Device API\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#ifndef __TIZEN_HEALTH_PROFILE_HANDLER_CALLBACK_H__\r
+#define __TIZEN_HEALTH_PROFILE_HANDLER_CALLBACK_H__\r
+\r
+#include <string>\r
+#include <MultiCallbackUserData.h>\r
+#include <JavaScriptCore/JavaScript.h>\r
+\r
+#include "BluetoothCallback.h"\r
+\r
+namespace DeviceAPI {\r
+namespace Bluetooth {\r
+\r
+\r
+class BluetoothHealthProfileHandlerCallback : public BluetoothCallback\r
+{\r
+public:\r
+    static void syncToAsyncRegisterCB(DeviceAPI::Common::MultiCallbackUserDataPtr callback, unsigned short dataType, std::string name);\r
+    //static void syncToAsyncUnregisterCB(DeviceAPI::Common::MultiCallbackUserDataPtr callback, JSObjectRef application);\r
+    static void syncToAsyncUnregisterCB(DeviceAPI::Common::MultiCallbackUserDataPtr callback, std::string appID);\r
+};\r
+\r
+\r
+} // Bluetooth\r
+} // DeviceAPI\r
+\r
+\r
+\r
+#endif // __TIZEN_HEALTH_PROFILE_HANDLER_CALLBACK_H__\r
+\r
+\r
index b1cafe4..7995611 100644 (file)
@@ -24,6 +24,7 @@
 #include "plugin_config.h"
 
 #include <Logger.h>
+#include <TimeTracer.h>
 
 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);
index 3f50010..189f5a2 100644 (file)
@@ -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);
 
index e24644b..6e64919 100644 (file)
@@ -24,6 +24,7 @@
 #include "JSBluetoothDevice.h"
 
 #include <Logger.h>
+#include <TimeTracer.h>
 
 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<int>(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;
 }
index e64d8bf..c4bb7f7 100644 (file)
@@ -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}
index 221d792..b47aa52 100644 (file)
@@ -24,6 +24,7 @@
 #include "plugin_config.h"
 #include "JSBluetoothAdapter.h"
 #include "BluetoothAdapter.h"
+#include "JSBluetoothHealthProfileHandler.h"
 
 #include <TimeTracer.h>
 #include <Logger.h>
@@ -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
index 161892b..72c56e9 100644 (file)
@@ -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.
index 2f1e97b..ecc8168 100644 (file)
@@ -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 (...) {
index 4283313..8b5a4aa 100644 (file)
@@ -94,6 +94,12 @@ JSObjectRef JSBluetoothDevice::createJSObject(JSContextRef context, BluetoothDev
     return JSObjectMake(context, getClassRef(), static_cast<void*>(holder));
 }
 
+BluetoothDeviceSharedPtr JSBluetoothDevice::toBluetoothDevice(JSObjectRef deviceObj)
+{
+    BluetoothDeviceHolderPtr priv = static_cast<BluetoothDeviceHolderPtr>(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) {
index 7d6acf1..d14630c 100644 (file)
@@ -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 (file)
index 0000000..0ff1f30
--- /dev/null
@@ -0,0 +1,244 @@
+//\r
+// Tizen Web Device API\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#include <SecurityExceptions.h>\r
+\r
+#include <JSUtil.h>\r
+#include <ArgumentValidator.h>\r
+#include <GlobalContextManager.h>\r
+#include <PlatformException.h>\r
+#include <MultiCallbackUserData.h>\r
+\r
+#include "plugin_config.h"\r
+#include "JSBluetoothHealthApplication.h"\r
+#include "BluetoothHealthProfileHandler.h"\r
+\r
+#include <TimeTracer.h>\r
+#include <Logger.h>\r
+\r
+using namespace WrtDeviceApis::Commons;\r
+using namespace DeviceAPI::Common;\r
+\r
+namespace DeviceAPI {\r
+namespace Bluetooth {\r
+\r
+JSClassDefinition JSBluetoothHealthApplication::m_classInfo = {\r
+    0,\r
+    kJSClassAttributeNone,\r
+    "BluetoothHealthApplication",\r
+    NULL, //ParentClass\r
+    m_property, //StaticValues\r
+    m_function, //StaticFunctions\r
+    initialize, //Initialize\r
+    finalize, //Finalize\r
+    NULL, //HasProperty,\r
+    NULL, //GetProperty,\r
+    NULL, //SetProperty,\r
+    NULL, //DeleteProperty,\r
+    NULL, //GetPropertyNames,\r
+    NULL, //CallAsFunction,\r
+    NULL, //CallAsConstructor,\r
+    NULL, //HasInstance,\r
+    NULL //ConvertToType\r
+};\r
+\r
+JSStaticValue JSBluetoothHealthApplication::m_property[] = {\r
+    { BLUETOOTH_HEALTH_APPLICATION_DATA_TYPE, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },\r
+    { BLUETOOTH_HEALTH_APPLICATION_NAME, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },\r
+    { BLUETOOTH_HEALTH_APPLICATION_ONCONNECT, getProperty, setProperty, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },\r
+    //{ BLUETOOTH_HEALTH_APPLICATION_IS_REGISTERED, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },\r
+    { 0, 0, 0, 0 }\r
+};\r
+\r
+JSStaticFunction JSBluetoothHealthApplication::m_function[] = {\r
+    { BLUETOOTH_HEALTH_APPLICATION_API_UNREGISTER, unregister, kJSPropertyAttributeNone },\r
+    { 0, 0, 0 }\r
+};\r
+\r
+JSClassRef JSBluetoothHealthApplication::m_jsClassRef = JSClassCreate(JSBluetoothHealthApplication::getClassInfo());\r
+\r
+const JSClassRef JSBluetoothHealthApplication::getClassRef()\r
+{\r
+    if (!m_jsClassRef) {\r
+        m_jsClassRef = JSClassCreate(&m_classInfo);\r
+    }\r
+    return m_jsClassRef;\r
+}\r
+\r
+const JSClassDefinition* JSBluetoothHealthApplication::getClassInfo()\r
+{\r
+    return &m_classInfo;\r
+}\r
+\r
+JSObjectRef JSBluetoothHealthApplication::createJSObject(JSContextRef context, BluetoothHealthApplicationSharedPtr app)\r
+{\r
+    BluetoothHealthApplicationHolderPtr holder = new BluetoothHealthApplicationHolder(app);\r
+    return JSObjectMake(context, getClassRef(), static_cast<void*>(holder));\r
+}\r
+\r
+BluetoothHealthApplicationSharedPtr JSBluetoothHealthApplication::toBluetoothHealthApplication(JSObjectRef appObj)\r
+{\r
+    BluetoothHealthApplicationHolderPtr priv = static_cast<BluetoothHealthApplicationHolderPtr>(JSObjectGetPrivate(appObj));\r
+    return priv->mApp;\r
+}\r
+\r
+void JSBluetoothHealthApplication::initialize(JSContextRef context, JSObjectRef object)\r
+{\r
+    // Do nothing\r
+}\r
+\r
+void JSBluetoothHealthApplication::finalize(JSObjectRef object)\r
+{\r
+    BluetoothHealthApplicationHolderPtr priv = static_cast<BluetoothHealthApplicationHolderPtr>(JSObjectGetPrivate(object));\r
+    if (priv) {\r
+        JSObjectSetPrivate(object, NULL);\r
+        delete priv;\r
+    }\r
+}\r
+\r
+JSValueRef JSBluetoothHealthApplication::getProperty(JSContextRef context,\r
+        JSObjectRef object,\r
+        JSStringRef propertyName,\r
+        JSValueRef* exception)\r
+{\r
+    try {\r
+        BluetoothHealthApplicationHolderPtr priv = static_cast<BluetoothHealthApplicationHolderPtr>(JSObjectGetPrivate(object));\r
+        if (!priv) {\r
+            throw TypeMismatchException("Private object is NULL");\r
+        }\r
+\r
+        if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_HEALTH_APPLICATION_DATA_TYPE)) {\r
+            return JSValueMakeNumber(context, priv->mApp->getDataType());\r
+        }\r
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_HEALTH_APPLICATION_NAME)) {\r
+            return JSUtil::toJSValueRef(context, priv->mApp->getName());\r
+        }\r
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_HEALTH_APPLICATION_ONCONNECT)) {\r
+            return JSUtil::toJSValueRef(context, priv->mApp->getOnConnect());\r
+        }        \r
+        /*\r
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_HEALTH_APPLICATION_IS_REGISTERED)) {\r
+            return JSUtil::toJSValueRef(context, priv->mApp->getRegistrationState());\r
+        }\r
+        */\r
+    } catch (const BasePlatformException &err) {\r
+        LoggerW("Getting property is failed: " << err.getMessage().c_str());\r
+    }\r
+\r
+    return NULL;\r
+}\r
+\r
+bool JSBluetoothHealthApplication::setProperty(JSContextRef context,\r
+        JSObjectRef object,\r
+        JSStringRef propertyName,\r
+        JSValueRef value,\r
+        JSValueRef* exception)\r
+{\r
+    try {\r
+        BluetoothHealthApplicationHolderPtr priv = static_cast<BluetoothHealthApplicationHolderPtr>(JSObjectGetPrivate(object));\r
+        if (!priv) {\r
+            throw TypeMismatchException("Private object is NULL");\r
+        }\r
+        \r
+        if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_HEALTH_APPLICATION_ONCONNECT)) {\r
+            JSObjectRef object = NULL;\r
+            if(!JSValueIsNull(context, value)) {\r
+                if(!JSValueIsObject(context, value)) {\r
+                    throw TypeMismatchException("Value is not Object");\r
+                }\r
+\r
+                JSValueRef ex = NULL;\r
+                object = JSValueToObject(context, value, &ex);\r
+                if(ex){\r
+                    throw TypeMismatchException("Can't convert to Object");\r
+                }                \r
+\r
+                if(!JSObjectIsFunction(context, object)) {\r
+                    throw TypeMismatchException("Not function");\r
+                }\r
+            }\r
+            else {\r
+                LoggerD("onconnect() is NULL");\r
+            }\r
+            \r
+            return priv->mApp->setOnConnect(context, object);\r
+        }\r
+    } catch (const BasePlatformException &err) {\r
+        JSWebAPIErrorFactory::postException(context, exception, err);\r
+    }\r
+\r
+    return false;\r
+}\r
+\r
+\r
+JSValueRef JSBluetoothHealthApplication::unregister(JSContextRef context,\r
+    JSObjectRef object,\r
+    JSObjectRef thisObject,\r
+    size_t argumentCount,\r
+    const JSValueRef arguments[],\r
+    JSValueRef* exception)\r
+{\r
+    LoggerD("Enter");\r
+\r
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);\r
+    \r
+    // Access Check\r
+    /*\r
+    TIME_TRACER_ITEM_BEGIN("unregister::ACE", 1);\r
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_HEALTH_APPLICATION_API_UNREGISTER);\r
+    TIME_TRACER_ITEM_END("unregister::ACE", 1);\r
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);\r
+    */\r
+\r
+    try {\r
+        BluetoothHealthApplicationHolderPtr priv = static_cast<BluetoothHealthApplicationHolderPtr>(JSObjectGetPrivate(thisObject));\r
+        if (!priv) {\r
+            throw TypeMismatchException("Private object is NULL");\r
+        }\r
+\r
+        ArgumentValidator validator(context, argumentCount, arguments);\r
+        JSObjectRef successCallback = validator.toFunction(0, true);  // successCallback  \r
+        JSObjectRef errorCallback = validator.toFunction(1, true);  // errorCallback\r
+\r
+        // perform\r
+        MultiCallbackUserDataPtr callback(\r
+                new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));\r
+        if(!callback){\r
+            LoggerW("Can't create MultiCallbackUserData");\r
+        }\r
+        else {\r
+            callback->setCallback("success", successCallback);\r
+            callback->setCallback("error", errorCallback);\r
+        }      \r
+        \r
+        BluetoothHealthProfileHandler::getInstance()->unregisterApp(priv->mApp->getAppID(), callback);\r
+        TIME_TRACER_ITEM_END(__FUNCTION__, 1);\r
+        \r
+        return JSValueMakeUndefined(context);    \r
+    } catch (const BasePlatformException &err) {\r
+        TIME_TRACER_ITEM_END(__FUNCTION__, 1);    \r
+        return JSWebAPIErrorFactory::postException(context, exception, err);\r
+    } catch (...) {\r
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.setName().");\r
+        return JSWebAPIErrorFactory::postException(context, exception, err);\r
+    }    \r
+}\r
+\r
+\r
+} // Bluetooth\r
+} // DeviceAPI\r
+\r
diff --git a/src/Bluetooth/JSBluetoothHealthApplication.h b/src/Bluetooth/JSBluetoothHealthApplication.h
new file mode 100644 (file)
index 0000000..c44f405
--- /dev/null
@@ -0,0 +1,103 @@
+//\r
+// Tizen Web Device API\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#ifndef __TIZEN_JS_BLUETOOTH_HEALTH_APPLICATION_H__\r
+#define __TIZEN_JS_BLUETOOTH_HEALTH_APPLICATION_H__\r
+\r
+#include <JavaScriptCore/JavaScript.h>\r
+\r
+#include "BluetoothHealthApplication.h"\r
+\r
+namespace DeviceAPI {\r
+namespace Bluetooth {\r
+\r
+class BluetoothHealthApplicationHolder\r
+{\r
+public:\r
+    BluetoothHealthApplicationHolder(BluetoothHealthApplicationSharedPtr app) {mApp = app;}\r
+    BluetoothHealthApplicationSharedPtr mApp; \r
+};\r
+typedef BluetoothHealthApplicationHolder* BluetoothHealthApplicationHolderPtr;\r
+\r
+class JSBluetoothHealthApplication\r
+{\r
+public:\r
+    static const JSClassDefinition* getClassInfo();\r
+    static const JSClassRef getClassRef();\r
+    static JSObjectRef createJSObject(JSContextRef context, BluetoothHealthApplicationSharedPtr app);\r
+    static BluetoothHealthApplicationSharedPtr toBluetoothHealthApplication(JSObjectRef appObj);\r
+    \r
+private:\r
+\r
+    /**\r
+     * The callback invoked when an object is first created.\r
+     */\r
+    static void initialize(JSContextRef context,\r
+            JSObjectRef object);\r
+\r
+    /**\r
+     * The callback invoked when an object is finalized.\r
+     */\r
+    static void finalize(JSObjectRef object);\r
+\r
+    static JSValueRef getProperty(JSContextRef context,\r
+            JSObjectRef object,\r
+            JSStringRef propertyName,\r
+            JSValueRef* exception);\r
+\r
+    static bool setProperty(JSContextRef context,\r
+            JSObjectRef object,\r
+            JSStringRef propertyName,\r
+            JSValueRef value,\r
+            JSValueRef* exception);\r
+\r
+    static JSValueRef unregister(JSContextRef context,\r
+        JSObjectRef object,\r
+        JSObjectRef thisObject,\r
+        size_t argumentCount,\r
+        const JSValueRef arguments[],\r
+        JSValueRef* exception);\r
+\r
+    /**\r
+     * This member variable contains the values which has to be passed\r
+     * when the this class is embedded into JS Engine.\r
+     */\r
+    static JSClassDefinition m_classInfo;\r
+\r
+    /**\r
+     * This structure describes a statically declared function property.\r
+     */\r
+    static JSStaticFunction m_function[];\r
+\r
+    /**\r
+     * This member variable contains the initialization values for the\r
+     * properties of this class. The values are given according to\r
+     * the data structure JSPropertySpec\r
+     */\r
+    static JSStaticValue m_property[];\r
+\r
+    static JSClassRef m_jsClassRef;\r
+};\r
+\r
+\r
+} // Bluetooth\r
+} // DeviceAPI\r
+\r
+#endif // __TIZEN_JS_BLUETOOTH_HEALTH_APPLICATION_H__\r
+\r
+\r
+\r
diff --git a/src/Bluetooth/JSBluetoothHealthChannel.cpp b/src/Bluetooth/JSBluetoothHealthChannel.cpp
new file mode 100644 (file)
index 0000000..a6e30ac
--- /dev/null
@@ -0,0 +1,334 @@
+//\r
+// Tizen Web Device API\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#include <vector>\r
+\r
+#include <SecurityExceptions.h>\r
+#include <JSUtil.h>\r
+#include <ArgumentValidator.h>\r
+#include <GlobalContextManager.h>\r
+#include <PlatformException.h>\r
+#include <MultiCallbackUserData.h>\r
+\r
+#include "plugin_config.h"\r
+#include "JSBluetoothHealthChannel.h"\r
+#include "BluetoothHealthProfileHandler.h"\r
+\r
+#include <TimeTracer.h>\r
+#include <Logger.h>\r
+\r
+using namespace WrtDeviceApis::Commons;\r
+using namespace DeviceAPI::Common;\r
+\r
+namespace DeviceAPI {\r
+namespace Bluetooth {\r
+\r
+JSClassDefinition JSBluetoothHealthChannel::m_classInfo = {\r
+    0,\r
+    kJSClassAttributeNone,\r
+    "BluetoothHealthChannel",\r
+    NULL, //ParentClass\r
+    m_property, //StaticValues\r
+    m_function, //StaticFunctions\r
+    initialize, //Initialize\r
+    finalize, //Finalize\r
+    NULL, //HasProperty,\r
+    NULL, //GetProperty,\r
+    NULL, //SetProperty,\r
+    NULL, //DeleteProperty,\r
+    NULL, //GetPropertyNames,\r
+    NULL, //CallAsFunction,\r
+    NULL, //CallAsConstructor,\r
+    NULL, //HasInstance,\r
+    NULL //ConvertToType\r
+};\r
+\r
+JSStaticValue JSBluetoothHealthChannel::m_property[] = {\r
+    { BLUETOOTH_HEALTH_CHANNEL_PEER, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },\r
+    { BLUETOOTH_HEALTH_CHANNEL_TYPE, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },\r
+    { BLUETOOTH_HEALTH_CHANNEL_APP, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete },\r
+    { BLUETOOTH_HEALTH_CHANNEL_IS_CONNECTED, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeDontDelete },\r
+    { 0, 0, 0, 0 }\r
+};\r
+\r
+JSStaticFunction JSBluetoothHealthChannel::m_function[] = {\r
+    { BLUETOOTH_HEALTH_CHANNEL_API_SEND_DATA, sendData, kJSPropertyAttributeNone },\r
+    { BLUETOOTH_HEALTH_CHANNEL_API_CLOSE, close, kJSPropertyAttributeNone },\r
+    { BLUETOOTH_HEALTH_CHANNEL_API_SET_LISTENER, setListener, kJSPropertyAttributeNone },\r
+    { BLUETOOTH_HEALTH_CHANNEL_API_UNSET_LISTENER, unsetListener, kJSPropertyAttributeNone },    \r
+    { 0, 0, 0 }\r
+};\r
+\r
+JSClassRef JSBluetoothHealthChannel::m_jsClassRef = JSClassCreate(JSBluetoothHealthChannel::getClassInfo());\r
+\r
+const JSClassRef JSBluetoothHealthChannel::getClassRef()\r
+{\r
+    if (!m_jsClassRef) {\r
+        m_jsClassRef = JSClassCreate(&m_classInfo);\r
+    }\r
+    return m_jsClassRef;\r
+}\r
+\r
+const JSClassDefinition* JSBluetoothHealthChannel::getClassInfo()\r
+{\r
+    return &m_classInfo;\r
+}\r
+\r
+JSObjectRef JSBluetoothHealthChannel::createJSObject(JSContextRef context, BluetoothHealthChannelPtr channel)\r
+{\r
+    return JSObjectMake(context, getClassRef(), static_cast<void*>(channel));\r
+}\r
+\r
+void JSBluetoothHealthChannel::initialize(JSContextRef context, JSObjectRef object)\r
+{\r
+    // do nothing\r
+}\r
+\r
+void JSBluetoothHealthChannel::finalize(JSObjectRef object)\r
+{\r
+    BluetoothHealthChannelPtr priv = static_cast<BluetoothHealthChannelPtr>(JSObjectGetPrivate(object));\r
+    if (priv) {\r
+        JSObjectSetPrivate(object, NULL);\r
+        delete priv;\r
+    }\r
+}\r
+\r
+JSValueRef JSBluetoothHealthChannel::getProperty(JSContextRef context,\r
+        JSObjectRef object,\r
+        JSStringRef propertyName,\r
+        JSValueRef* exception)\r
+{\r
+    try {\r
+        BluetoothHealthChannelPtr priv = static_cast<BluetoothHealthChannelPtr>(JSObjectGetPrivate(object));\r
+        if (!priv) {\r
+            throw TypeMismatchException("Private object is NULL");\r
+        }\r
+\r
+        if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_HEALTH_CHANNEL_PEER)) {\r
+            return priv->getPeer(context);\r
+        }\r
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_HEALTH_CHANNEL_TYPE)) {\r
+            return JSUtil::toJSValueRef(context, priv->getChannelTypeStr());\r
+        }\r
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_HEALTH_CHANNEL_APP)) {\r
+            return priv->getApp(context);\r
+        }\r
+        else if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_HEALTH_CHANNEL_IS_CONNECTED)) {\r
+            return JSUtil::toJSValueRef(context, priv->getConnectionState());\r
+        }\r
+    } catch (const BasePlatformException &err) {\r
+        LoggerW("Getting property is failed: " << err.getMessage().c_str());\r
+    }\r
+\r
+    return NULL;\r
+}\r
+\r
+JSValueRef JSBluetoothHealthChannel::sendData(JSContextRef context,\r
+        JSObjectRef object,\r
+        JSObjectRef thisObject,\r
+        size_t argumentCount,\r
+        const JSValueRef arguments[],\r
+        JSValueRef* exception)\r
+{\r
+    LoggerD("Enter");\r
+\r
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);;\r
+\r
+    // Access Check\r
+    /*\r
+    TIME_TRACER_ITEM_BEGIN("sendData::ACE", 1);;\r
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_HEALTH_CHANNEL_API_SEND_DATA);\r
+    TIME_TRACER_ITEM_END("sendData::ACE", 1);;\r
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);\r
+    */\r
+\r
+    try {\r
+        // Private Object\r
+        BluetoothHealthChannelPtr priv = static_cast<BluetoothHealthChannelPtr>(JSObjectGetPrivate(thisObject));\r
+        if (!priv) {\r
+            throw DeviceAPI::Common::UnknownException("Private object is NULL.");\r
+        }\r
+    \r
+        ArgumentValidator validator(context, argumentCount, arguments);\r
+\r
+        JSObjectRef dataArrayObj  = validator.toArrayObject(0);  // data\r
+        size_t size = JSGetArrayLength(context, dataArrayObj);\r
+        char *buffer = new char[size];\r
+        for(size_t i = 0; i < size; ++i) {\r
+            JSValueRef element = JSGetArrayElement(context, dataArrayObj, i);\r
+            buffer[i] = static_cast<char>(JSUtil::JSValueToByte(context, element));\r
+        }\r
+\r
+        JSValueRef result = JSUtil::toJSValueRef(context, priv->sendData(buffer, size));\r
+        delete buffer;\r
+        TIME_TRACER_ITEM_END(__FUNCTION__, 1);;\r
+\r
+        return result;\r
+    } catch (const BasePlatformException &err) {\r
+        return JSWebAPIErrorFactory::postException(context, exception, err);\r
+    } catch (...) {\r
+        DeviceAPI::Common::UnknownException err("Unknown Error");\r
+        return JSWebAPIErrorFactory::postException(context, exception, err);\r
+    }\r
+}\r
+\r
+JSValueRef JSBluetoothHealthChannel::close(JSContextRef context,\r
+        JSObjectRef object,\r
+        JSObjectRef thisObject,\r
+        size_t argumentCount,\r
+        const JSValueRef arguments[],\r
+        JSValueRef* exception)\r
+{\r
+    LoggerD("Enter");\r
+\r
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);;\r
+    \r
+    // Access Check\r
+    /*\r
+    TIME_TRACER_ITEM_BEGIN("close::ACE", 1);;\r
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_HEALTH_CHANNEL_API_CLOSE);\r
+    TIME_TRACER_ITEM_END("close::ACE", 1);;\r
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);\r
+    */\r
+\r
+    try {\r
+        // Private Object\r
+        BluetoothHealthChannelPtr priv = static_cast<BluetoothHealthChannelPtr>(JSObjectGetPrivate(thisObject));\r
+        if (!priv) {\r
+            throw DeviceAPI::Common::UnknownException("Private object is NULL.");\r
+        }\r
+\r
+        priv->close();\r
+        TIME_TRACER_ITEM_END(__FUNCTION__, 1);;\r
+        \r
+        return JSValueMakeUndefined(context);\r
+    } catch (const BasePlatformException &err) {\r
+        return JSWebAPIErrorFactory::postException(context, exception, err);\r
+    } catch (...) {\r
+        DeviceAPI::Common::UnknownException err("Unknown Error");\r
+        return JSWebAPIErrorFactory::postException(context, exception, err);\r
+    }\r
+}\r
+\r
+JSValueRef JSBluetoothHealthChannel::setListener(JSContextRef context,\r
+        JSObjectRef object,\r
+        JSObjectRef thisObject,\r
+        size_t argumentCount,\r
+        const JSValueRef arguments[],\r
+        JSValueRef* exception)\r
+{\r
+    LoggerD("Enter");\r
+\r
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);;\r
+    \r
+    // Access Check\r
+    /*\r
+    TIME_TRACER_ITEM_BEGIN("setListener::ACE", 1);;\r
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_HEALTH_CHANNEL_API_SET_LISTENER);\r
+    TIME_TRACER_ITEM_END("setListener::ACE", 1);;\r
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);\r
+    */\r
+\r
+    try {\r
+        // Private Object\r
+        BluetoothHealthChannelPtr priv = static_cast<BluetoothHealthChannelPtr>(JSObjectGetPrivate(thisObject));\r
+        if (!priv) {\r
+            throw DeviceAPI::Common::UnknownException("Private object is NULL.");\r
+        }\r
+\r
+        // Validate arguments\r
+        ArgumentValidator validator(context, argumentCount, arguments);\r
+\r
+        // successCallback\r
+        JSObjectRef successCallback = validator.toCallbackObject(0, false, "onmessage", "onclose", NULL);\r
+\r
+        MultiCallbackUserDataPtr callback(\r
+                new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));\r
+        if(!callback){\r
+            LoggerW("Can't create MultiMultiCallbackUserData");\r
+        }\r
+        else {\r
+            // onmessage\r
+            JSValueRef onmessageValue = JSUtil::getProperty(context , successCallback, "onmessage");\r
+            if(!JSValueIsUndefined(context, onmessageValue)) {\r
+                LoggerD("There is a onmessage()");\r
+                callback->setCallback("onmessage", JSUtil::JSValueToObject(context, onmessageValue));\r
+            }\r
+            \r
+            // onclose\r
+            JSValueRef oncloseValue = JSUtil::getProperty(context , successCallback, "onclose");\r
+            if(!JSValueIsUndefined(context, oncloseValue)) {\r
+                LoggerD("There is a onclose()");\r
+                callback->setCallback("onclose", JSUtil::JSValueToObject(context, oncloseValue));\r
+            }\r
+        }\r
+\r
+        priv->setListener(callback);\r
+        TIME_TRACER_ITEM_END(__FUNCTION__, 1);;\r
+        \r
+        return JSValueMakeUndefined(context);\r
+    } catch (const BasePlatformException &err) {\r
+        return JSWebAPIErrorFactory::postException(context, exception, err);\r
+    } catch (...) {\r
+        DeviceAPI::Common::UnknownException err("Unknown Error");\r
+        return JSWebAPIErrorFactory::postException(context, exception, err);\r
+    }\r
+}\r
+\r
+JSValueRef JSBluetoothHealthChannel::unsetListener(JSContextRef context,\r
+        JSObjectRef object,\r
+        JSObjectRef thisObject,\r
+        size_t argumentCount,\r
+        const JSValueRef arguments[],\r
+        JSValueRef* exception)\r
+{\r
+    LoggerD("Enter");\r
+\r
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);;\r
+    \r
+    // Access Check\r
+    /*\r
+    TIME_TRACER_ITEM_BEGIN("unsetListener::ACE", 1);;\r
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_HEALTH_CHANNEL_API_UNSET_LISTENER);\r
+    TIME_TRACER_ITEM_END("unsetListener::ACE", 1);;\r
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);\r
+    */\r
+\r
+    try {\r
+        // Private Object\r
+        BluetoothHealthChannelPtr priv = static_cast<BluetoothHealthChannelPtr>(JSObjectGetPrivate(thisObject));\r
+        if (!priv) {\r
+            throw DeviceAPI::Common::UnknownException("Private object is NULL.");\r
+        }\r
+\r
+        priv->unsetListener();\r
+        TIME_TRACER_ITEM_END(__FUNCTION__, 1);;\r
+        \r
+        return JSValueMakeUndefined(context);\r
+    } catch (const BasePlatformException &err) {\r
+        return JSWebAPIErrorFactory::postException(context, exception, err);\r
+    } catch (...) {\r
+        DeviceAPI::Common::UnknownException err("Unknown Error");\r
+        return JSWebAPIErrorFactory::postException(context, exception, err);\r
+    }\r
+}\r
+\r
+\r
+\r
+} // Bluetooth\r
+} // DeviceAPI\r
+\r
diff --git a/src/Bluetooth/JSBluetoothHealthChannel.h b/src/Bluetooth/JSBluetoothHealthChannel.h
new file mode 100644 (file)
index 0000000..a217353
--- /dev/null
@@ -0,0 +1,110 @@
+//\r
+// Tizen Web Device API\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#ifndef __TIZEN_JS_BLUETOOTH_HEALTH_CHANNEL_H__\r
+#define __TIZEN_JS_BLUETOOTH_HEALTH_CHANNEL_H__\r
+\r
+#include <JavaScriptCore/JavaScript.h>\r
+\r
+#include "BluetoothHealthChannel.h"\r
+\r
+namespace DeviceAPI {\r
+namespace Bluetooth {\r
+\r
+class JSBluetoothHealthChannel\r
+{\r
+public:\r
+    static const JSClassDefinition* getClassInfo();\r
+    static const JSClassRef getClassRef();\r
+    static JSObjectRef createJSObject(JSContextRef context, BluetoothHealthChannelPtr channel);\r
+    \r
+private:\r
+\r
+    /**\r
+     * The callback invoked when an object is first created.\r
+     */\r
+    static void initialize(JSContextRef context,\r
+            JSObjectRef object);\r
+\r
+    /**\r
+     * The callback invoked when an object is finalized.\r
+     */\r
+    static void finalize(JSObjectRef object);\r
+\r
+    static JSValueRef getProperty(JSContextRef context,\r
+            JSObjectRef object,\r
+            JSStringRef propertyName,\r
+            JSValueRef* exception);\r
+\r
+    static JSValueRef close(JSContextRef context,\r
+        JSObjectRef object,\r
+        JSObjectRef thisObject,\r
+        size_t argumentCount,\r
+        const JSValueRef arguments[],\r
+        JSValueRef* exception);\r
+\r
+    static JSValueRef sendData(JSContextRef context,\r
+        JSObjectRef object,\r
+        JSObjectRef thisObject,\r
+        size_t argumentCount,\r
+        const JSValueRef arguments[],\r
+        JSValueRef* exception);\r
+\r
+    static JSValueRef setListener(JSContextRef context,\r
+        JSObjectRef object,\r
+        JSObjectRef thisObject,\r
+        size_t argumentCount,\r
+        const JSValueRef arguments[],\r
+        JSValueRef* exception);\r
+\r
+    static JSValueRef unsetListener(JSContextRef context,\r
+        JSObjectRef object,\r
+        JSObjectRef thisObject,\r
+        size_t argumentCount,\r
+        const JSValueRef arguments[],\r
+        JSValueRef* exception);\r
+\r
+    /**\r
+     * This member variable contains the values which has to be passed\r
+     * when the this class is embedded into JS Engine.\r
+     */\r
+    static JSClassDefinition m_classInfo;\r
+\r
+    /**\r
+     * This structure describes a statically declared function property.\r
+     */\r
+    static JSStaticFunction m_function[];\r
+\r
+    /**\r
+     * This member variable contains the initialization values for the\r
+     * properties of this class. The values are given according to\r
+     * the data structure JSPropertySpec\r
+     */\r
+    static JSStaticValue m_property[];\r
+\r
+    static JSClassRef m_jsClassRef;\r
+};\r
+\r
+\r
+} // Bluetooth\r
+} // DeviceAPI\r
+\r
+#endif // __TIZEN_JS_BLUETOOTH_HEALTH_CHANNEL_H__\r
+\r
+\r
+\r
+\r
diff --git a/src/Bluetooth/JSBluetoothHealthProfileHandler.cpp b/src/Bluetooth/JSBluetoothHealthProfileHandler.cpp
new file mode 100644 (file)
index 0000000..95101d2
--- /dev/null
@@ -0,0 +1,208 @@
+//\r
+// Tizen Web Device API\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#include <SecurityExceptions.h>\r
+\r
+#include <JSUtil.h>\r
+#include <ArgumentValidator.h>\r
+#include <GlobalContextManager.h>\r
+\r
+#include "plugin_config.h"\r
+#include "JSBluetoothHealthProfileHandler.h"\r
+#include "JSBluetoothProfileHandler.h"\r
+#include "JSBluetoothHealthApplication.h"\r
+#include "JSBluetoothDevice.h"\r
+#include "BluetoothHealthProfileHandler.h"\r
+\r
+#include <TimeTracer.h>\r
+#include <Logger.h>\r
+\r
+using namespace WrtDeviceApis::Commons;\r
+using namespace DeviceAPI::Common;\r
+\r
+namespace DeviceAPI {\r
+namespace Bluetooth {\r
+\r
+JSClassDefinition JSBluetoothHealthProfileHandler::m_classInfo = {\r
+    0,\r
+    kJSClassAttributeNone,\r
+    "BluetoothHealthProfileHandler",\r
+    JSBluetoothProfileHandler::getClassRef(), //ParentClass\r
+    NULL, //StaticValues\r
+    m_function, //StaticFunctions\r
+    initialize, //Initialize\r
+    finalize, //Finalize\r
+    NULL, //HasProperty,\r
+    NULL, //GetProperty,\r
+    NULL, //SetProperty,\r
+    NULL, //DeleteProperty,\r
+    NULL, //GetPropertyNames,\r
+    NULL, //CallAsFunction,\r
+    NULL, //CallAsConstructor,\r
+    NULL, //HasInstance,\r
+    NULL //ConvertToType\r
+};\r
+\r
+JSStaticFunction JSBluetoothHealthProfileHandler::m_function[] = {\r
+    { BLUETOOTH_HEALTH_PROFILE_HANDLER_API_REGISTER_SINK_APPLICATION, registerSinkApplication, kJSPropertyAttributeNone },\r
+    { BLUETOOTH_HEALTH_PROFILE_HANDLER_API_CONNECT_TO_SOURCE, connectToSource, kJSPropertyAttributeNone },\r
+    { 0, 0, 0 }\r
+};\r
+\r
+JSClassRef JSBluetoothHealthProfileHandler::m_jsClassRef = JSClassCreate(JSBluetoothHealthProfileHandler::getClassInfo());\r
+\r
+const JSClassRef JSBluetoothHealthProfileHandler::getClassRef()\r
+{\r
+    if (!m_jsClassRef) {\r
+        m_jsClassRef = JSClassCreate(&m_classInfo);\r
+    }\r
+    return m_jsClassRef;\r
+}\r
+\r
+const JSClassDefinition* JSBluetoothHealthProfileHandler::getClassInfo()\r
+{\r
+    return &m_classInfo;\r
+}\r
+\r
+JSObjectRef JSBluetoothHealthProfileHandler::createJSObject(JSContextRef context)\r
+{\r
+    return JSObjectMake(context, getClassRef(), NULL);\r
+}\r
+\r
+void JSBluetoothHealthProfileHandler::initialize(JSContextRef context, JSObjectRef object)\r
+{\r
+    // do nothing\r
+}\r
+\r
+\r
+void JSBluetoothHealthProfileHandler::finalize(JSObjectRef object)\r
+{\r
+    // do nothing\r
+}\r
+\r
+JSValueRef JSBluetoothHealthProfileHandler::registerSinkApplication(JSContextRef context,\r
+    JSObjectRef object,\r
+    JSObjectRef thisObject,\r
+    size_t argumentCount,\r
+    const JSValueRef arguments[],\r
+    JSValueRef* exception)\r
+{\r
+    LoggerD("Enter");\r
+    \r
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);\r
+    \r
+    // Access Check\r
+    /*\r
+    TIME_TRACER_ITEM_BEGIN("registerSinkApplication::ACE", 1);\r
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_HEALTH_PROFILE_HANDLER_API_REGISTER_SINK_APPLICATION);\r
+    TIME_TRACER_ITEM_END("registerSinkApplication::ACE", 1);\r
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);\r
+    */\r
+\r
+    try {\r
+        ArgumentValidator validator(context, argumentCount, arguments);        \r
+        unsigned short dataType = static_cast<unsigned short>(validator.toULong(0));  // dataType\r
+        std::string name = validator.toString(1);  // name\r
+        JSObjectRef successCallback = validator.toFunction(2);  // successCallback  \r
+        JSObjectRef errorCallback = validator.toFunction(3, true);  // errorCallback\r
+\r
+        // perform\r
+        MultiCallbackUserDataPtr callback(\r
+                new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));\r
+        if(!callback){\r
+            LoggerW("Can't create MultiCallbackUserData");\r
+        }\r
+        else {\r
+            callback->setCallback("success", successCallback);\r
+            callback->setCallback("error", errorCallback);\r
+        }      \r
+        \r
+        BluetoothHealthProfileHandler::getInstance()->registerSinkApp(dataType, name, callback);\r
+        TIME_TRACER_ITEM_END(__FUNCTION__, 1);\r
+        \r
+        return JSValueMakeUndefined(context);\r
+    } catch (const BasePlatformException &err) {\r
+        TIME_TRACER_ITEM_END(__FUNCTION__, 1);    \r
+        return JSWebAPIErrorFactory::postException(context, exception, err);\r
+    } catch (...) {\r
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.setName().");\r
+        return JSWebAPIErrorFactory::postException(context, exception, err);\r
+    }    \r
+}\r
+\r
+JSValueRef JSBluetoothHealthProfileHandler::connectToSource(JSContextRef context,\r
+    JSObjectRef object,\r
+    JSObjectRef thisObject,\r
+    size_t argumentCount,\r
+    const JSValueRef arguments[],\r
+    JSValueRef* exception)\r
+{\r
+    LoggerD("Enter");\r
+    \r
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 1);\r
+    \r
+    // Access Check\r
+    /*\r
+    TIME_TRACER_ITEM_BEGIN("setName::ACE", 1);\r
+    AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(BLUETOOTH_HEALTH_PROFILE_HANDLER_API_CONNECT_TO_SOURCE);\r
+    TIME_TRACER_ITEM_END("setName::ACE", 1);\r
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);\r
+    */\r
+\r
+    try {\r
+        ArgumentValidator validator(context, argumentCount, arguments);\r
+        JSObjectRef remoteObj = validator.toObject(0);  // remoteDevice        \r
+        if(!JSValueIsObjectOfClass(context, remoteObj, JSBluetoothDevice::getClassRef())) {\r
+            throw TypeMismatchException("remoteDevice is not a BluetoothDevice object");\r
+        }\r
+\r
+        JSObjectRef appObj = validator.toObject(1);  // application\r
+        if(!JSValueIsObjectOfClass(context, appObj, JSBluetoothHealthApplication::getClassRef())) {\r
+            throw TypeMismatchException("application is not a BluetoothHealthApplication object");\r
+        }\r
+\r
+        JSObjectRef successCallback = validator.toFunction(2);  // successCallback  \r
+        JSObjectRef errorCallback = validator.toFunction(3, true);  // errorCallback\r
+\r
+        // perform\r
+        MultiCallbackUserDataPtr callback(\r
+                new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context)));\r
+        if(!callback){\r
+            LoggerW("Can't create MultiCallbackUserData");\r
+        }\r
+        else {\r
+            callback->setCallback("success", successCallback);\r
+            callback->setCallback("error", errorCallback);\r
+        }      \r
+\r
+        BluetoothHealthProfileHandler::getInstance()->connectToSource(remoteObj, appObj, callback);\r
+        TIME_TRACER_ITEM_END(__FUNCTION__, 1);\r
+        \r
+        return JSValueMakeUndefined(context);    \r
+    } catch (const BasePlatformException &err) {\r
+        TIME_TRACER_ITEM_END(__FUNCTION__, 1);    \r
+        return JSWebAPIErrorFactory::postException(context, exception, err);\r
+    } catch (...) {\r
+        DeviceAPI::Common::UnknownException err("Unknown Error in BluetoothAdapter.setName().");\r
+        return JSWebAPIErrorFactory::postException(context, exception, err);\r
+    }    \r
+}\r
+\r
+\r
+} // Bluetooth\r
+} // DeviceAPI\r
+\r
diff --git a/src/Bluetooth/JSBluetoothHealthProfileHandler.h b/src/Bluetooth/JSBluetoothHealthProfileHandler.h
new file mode 100644 (file)
index 0000000..dddf037
--- /dev/null
@@ -0,0 +1,80 @@
+//\r
+// Tizen Web Device API\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#ifndef __TIZEN_JS_HEALTH_PROFILE_HANDLER_H__\r
+#define __TIZEN_JS_HEALTH_PROFILE_HANDLER_H__\r
+\r
+#include <JavaScriptCore/JavaScript.h>\r
+\r
+namespace DeviceAPI {\r
+namespace Bluetooth {\r
+\r
+class JSBluetoothHealthProfileHandler\r
+{\r
+public:\r
+    static const JSClassDefinition* getClassInfo();\r
+    static const JSClassRef getClassRef();\r
+    static JSObjectRef createJSObject(JSContextRef context);\r
+    \r
+private:\r
+\r
+    /**\r
+     * The callback invoked when an object is first created.\r
+     */\r
+    static void initialize(JSContextRef context,\r
+            JSObjectRef object);\r
+\r
+    /**\r
+     * The callback invoked when an object is finalized.\r
+     */\r
+    static void finalize(JSObjectRef object);\r
+\r
+    static JSValueRef registerSinkApplication(JSContextRef context,\r
+        JSObjectRef object,\r
+        JSObjectRef thisObject,\r
+        size_t argumentCount,\r
+        const JSValueRef arguments[],\r
+        JSValueRef* exception);\r
+\r
+    static JSValueRef connectToSource(JSContextRef context,\r
+        JSObjectRef object,\r
+        JSObjectRef thisObject,\r
+        size_t argumentCount,\r
+        const JSValueRef arguments[],\r
+        JSValueRef* exception);\r
+\r
+    /**\r
+     * This member variable contains the values which has to be passed\r
+     * when the this class is embedded into JS Engine.\r
+     */\r
+    static JSClassDefinition m_classInfo;\r
+\r
+    /**\r
+     * This structure describes a statically declared function property.\r
+     */\r
+    static JSStaticFunction m_function[];\r
+\r
+    static JSClassRef m_jsClassRef;\r
+};\r
+\r
+\r
+} // Bluetooth\r
+} // DeviceAPI\r
+\r
+#endif // __TIZEN_JS_HEALTH_PROFILE_HANDLER_H__\r
+\r
+\r
index 2c6db3c..fcc0d60 100644 (file)
 #include <GlobalContextManager.h>
 #include <PlatformException.h>
 #include <PropertyBag.h>
+#include <bluetooth.h>
 
 #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 (file)
index 0000000..28fe6fb
--- /dev/null
@@ -0,0 +1,114 @@
+//\r
+// Tizen Web Device API\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#include <SecurityExceptions.h>\r
+\r
+#include <JSUtil.h>\r
+#include <ArgumentValidator.h>\r
+#include <GlobalContextManager.h>\r
+#include <PlatformException.h>\r
+\r
+#include "plugin_config.h"\r
+#include "JSBluetoothProfileHandler.h"\r
+#include "JSBluetoothHealthProfileHandler.h"\r
+\r
+#include <TimeTracer.h>\r
+#include <Logger.h>\r
+\r
+using namespace WrtDeviceApis::Commons;\r
+using namespace DeviceAPI::Common;\r
+\r
+namespace DeviceAPI {\r
+namespace Bluetooth {\r
+\r
+JSClassDefinition JSBluetoothProfileHandler::m_classInfo = {\r
+    0,\r
+    kJSClassAttributeNone,\r
+    "BluetoothProfileHandler",\r
+    NULL, //ParentClass\r
+    m_property, //StaticValues\r
+    NULL, //StaticFunctions\r
+    initialize, //Initialize\r
+    finalize, //Finalize\r
+    NULL, //HasProperty,\r
+    NULL, //GetProperty,\r
+    NULL, //SetProperty,\r
+    NULL, //DeleteProperty,\r
+    NULL, //GetPropertyNames,\r
+    NULL, //CallAsFunction,\r
+    NULL, //CallAsConstructor,\r
+    NULL, //HasInstance,\r
+    NULL //ConvertToType\r
+};\r
+\r
+JSStaticValue JSBluetoothProfileHandler::m_property[] = {\r
+    { BLUETOOTH_PROFILE_TYPE, getProperty, NULL, kJSPropertyAttributeNone|kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete},\r
+    { 0, 0, 0, 0 }\r
+};\r
+\r
+JSClassRef JSBluetoothProfileHandler::m_jsClassRef = JSClassCreate(JSBluetoothProfileHandler::getClassInfo());\r
+\r
+const JSClassRef JSBluetoothProfileHandler::getClassRef()\r
+{\r
+    if (!m_jsClassRef) {\r
+        m_jsClassRef = JSClassCreate(&m_classInfo);\r
+    }\r
+    return m_jsClassRef;\r
+}\r
+\r
+const JSClassDefinition* JSBluetoothProfileHandler::getClassInfo()\r
+{\r
+    return &m_classInfo;\r
+}\r
+\r
+void JSBluetoothProfileHandler::initialize(JSContextRef context, JSObjectRef object)\r
+{\r
+    // Do nothing\r
+}\r
+\r
+void JSBluetoothProfileHandler::finalize(JSObjectRef object)\r
+{\r
+    // Do nothing\r
+}\r
+\r
+JSValueRef JSBluetoothProfileHandler::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) {\r
+    LoggerD("Enter");\r
+    try {\r
+        if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_PROFILE_TYPE)) {\r
+            if(object) {\r
+                if(JSValueIsObjectOfClass(context, object, JSBluetoothHealthProfileHandler::getClassRef())) {\r
+                    std::string profileType("HEALTH");\r
+                    LoggerD("profileType: " << profileType.c_str());\r
+                    return JSUtil::toJSValueRef(context, profileType);\r
+                }\r
+            }\r
+            else {\r
+                LoggerE("object is NULL");\r
+            }\r
+        }\r
+    } catch (const BasePlatformException &err) {\r
+        LoggerW("Getting property is failed" << err.getMessage().c_str());\r
+    }\r
+\r
+    return NULL;\r
+}\r
+\r
+\r
+\r
+} // Bluetooth\r
+} // DeviceAPI\r
+\r
diff --git a/src/Bluetooth/JSBluetoothProfileHandler.h b/src/Bluetooth/JSBluetoothProfileHandler.h
new file mode 100644 (file)
index 0000000..d493731
--- /dev/null
@@ -0,0 +1,68 @@
+//\r
+// Tizen Web Device API\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+#ifndef __TIZEN_JS_BLUETOOTH_PROFILE_HANDLER_H__\r
+#define __TIZEN_JS_BLUETOOTH_PROFILE_HANDLER_H__\r
+\r
+#include <JavaScriptCore/JavaScript.h>\r
+\r
+namespace DeviceAPI {\r
+namespace Bluetooth {\r
+\r
+class JSBluetoothProfileHandler\r
+{\r
+public:\r
+    static const JSClassDefinition* getClassInfo();\r
+    static const JSClassRef getClassRef();\r
+\r
+private:\r
+\r
+    /**\r
+     * The callback invoked when an object is first created.\r
+     */\r
+    static void initialize(JSContextRef context,\r
+            JSObjectRef object);\r
+\r
+    /**\r
+     * The callback invoked when an object is finalized.\r
+     */\r
+    static void finalize(JSObjectRef object);\r
+\r
+    static JSValueRef getProperty(JSContextRef context,\r
+            JSObjectRef object,\r
+            JSStringRef propertyName,\r
+            JSValueRef* exception);\r
+\r
+    /**\r
+     * This member variable contains the values which has to be passed\r
+     * when the this class is embedded into JS Engine.\r
+     */\r
+    static JSClassDefinition m_classInfo;\r
+\r
+    static JSStaticValue m_property[];\r
+\r
+    static JSClassRef m_jsClassRef;\r
+\r
+};\r
+\r
+\r
+\r
+} // Bluetooth\r
+} // DeviceAPI\r
+\r
+#endif // __TIZEN_JS_BLUETOOTH_PROFILE_HANDLER_H__\r
+\r
index 0398771..bf207f6 100644 (file)
@@ -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) {
index 577b281..4f93a48 100644 (file)
@@ -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<char>(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<signed char> 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) {
index 05fb079..dbab123 100644 (file)
 #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;
 }
 
index 3930c9f..13b4cbc 100644 (file)
 #ifndef _BLUETOOTH_PLUGIN_CONFIG_H_
 #define _BLUETOOTH_PLUGIN_CONFIG_H_
 
-#include <string>
 #include <Commons/FunctionDeclaration.h>
 
-#include <Logger.h>
-
 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);
 
index 5f0f009..d6f2871 100755 (executable)
@@ -64,4 +64,5 @@ add_plugin(
        Bookmark
        SecureElement
        DataSync
+       WebSetting
 )
index 28c912e..2d3f0b6 100755 (executable)
@@ -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<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
+        CalendarItemPropertiesPrivObject *privateObject = static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
+
         TimeUtilConverter timeConverter(context);
-        CalendarEventPtr event = privateObject->getObject();
+        CalendarEventPtr item = privateObject->getObject();
 
-        LoggerI("start time before converted to TZDate: "<<event->getStartTime()<<", time zone: "<<event->getTimeZone());
-        if (UNDEFINED_TIME==event->getStartTime()) {
+        LoggerI("start time before converted to TZDate: "<<item->getStartTime()<<", time zone: "<<item->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: "<<length<< ", unit:" <<unit);
-               event->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: "<<unit);
+                       return true;
+        }
+               item->setEndTime(endDate);
+               LoggerD("Set the endDate from the duration: "<<endDate);
 
         return true;
     }
index 6b9279e..793a124 100755 (executable)
@@ -136,11 +136,11 @@ class JSCalendarItemProperties
             JSStringRef propertyName,
             JSValueRef value,
             JSValueRef* exception);
-    static JSValueRef getPropertyStartTime(JSContextRef context,
+    static JSValueRef getPropertyStartDate(JSContextRef context,
             JSObjectRef object,
             JSStringRef propertyName,
             JSValueRef* exception);
-    static bool setPropertyStartTime(JSContextRef context,
+    static bool setPropertyStartDate(JSContextRef context,
             JSObjectRef object,
             JSStringRef propertyName,
             JSValueRef value,
index 832540c..f9e825b 100755 (executable)
@@ -150,12 +150,14 @@ void ContactObjectA2PConverter::importBaseInfoValue()
        }
        else
        {
+               bool is_first = false;
                errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.image, 0, &child_record);
                if(errorCode != CONTACTS_ERROR_NONE || child_record == NULL)
                {
                        errorCode = contacts_record_create(_contacts_image._uri, &child_record);
                        if(errorCode != CONTACTS_ERROR_NONE)
                                ThrowMsg(UnknownException, "creating name value B (errorCode:" << errorCode << ")");
+                       is_first = true;
                }
 
                contacts_record_get_str_p(child_record, _contacts_image.path, &oldValueStr);
@@ -180,6 +182,8 @@ void ContactObjectA2PConverter::importBaseInfoValue()
                                ThrowMsg(PlatformException, "importing photoURI E (err:" <<     errorCode);
                        }
                }
+
+               if(is_first)
                contacts_record_add_child_record(m_platformContact, _contacts_contact.image, child_record);
        }
 
index 3ffba37..eb09449 100755 (executable)
@@ -100,7 +100,7 @@ public:
                        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "same id exist");
                }
 
-//             LoggerD(key << " : " << std::hex << data);
+               LoggerD("Add OK ReqId : " << key);
 
                DPL::Mutex::ScopedLock lock(&m_mutex);          
                m_callbackSQLUserDataMap[key] = data;
@@ -110,6 +110,7 @@ public:
        {
                if (m_callbackSQLUserDataMap.find(key) == m_callbackSQLUserDataMap.end())
                {
+                       LoggerD("Fail ReqId : " << key);
                        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "there is no key");
                }
                
index c50e09e..ae928d8 100644 (file)
@@ -38,7 +38,8 @@ private :
        std::string m_page;
        std::string m_numberPerPage;
        std::string m_resultSetPath;
-       std::string m_errorMsg;
+       char *m_errorMsg;
+       
 public:
        EventSelect() {
                LoggerD("entered"); 
@@ -48,9 +49,15 @@ public:
                m_page = "";
                m_numberPerPage = "";
                m_resultSetPath = "";
-               m_errorMsg = "";                
+
+               m_errorMsg = NULL;
+       }
+       ~EventSelect() { 
+               if (m_errorMsg) {
+                       delete[] m_errorMsg;
+                       m_errorMsg = NULL;
+               }
        }
-       ~EventSelect() { }
 
        unsigned int getReqId() { return m_reqId; }
        std::string getWhere() { return m_where; }
@@ -59,7 +66,12 @@ public:
        std::string getNumerPerPage() { return m_numberPerPage; }
        std::vector<std::string> 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<std::string>& 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<EventSelect> EventSelectPtr;
index 4bda4f0..b04bf63 100644 (file)
@@ -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) {
index a9a398e..85200e2 100644 (file)
@@ -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
index 4fdadd1..bd00cd7 100755 (executable)
@@ -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());
index f9e61ad..96789c0 100755 (executable)
@@ -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()
 {
index 96c8e79..408330f 100755 (executable)
@@ -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);
 
index 71dd44c..076af11 100755 (executable)
@@ -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_
index 53f8287..4ff3261 100755 (executable)
@@ -9,7 +9,6 @@ PKG_CHECK_MODULES(platform_pkgs_systeminfo REQUIRED
        capi-system-runtime-info
        capi-system-sensor
        sensor
-       pkgmgr-info
        tapi
 )
 
index 4c837d9..b6cf382 100755 (executable)
@@ -29,6 +29,9 @@
 #include "plugin_config.h"
 #include <Logger.h>
 
+#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)
old mode 100644 (file)
new mode 100755 (executable)
index ffaee4f..b6c843a
@@ -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)
index eeb804f..3ef6e01 100755 (executable)
@@ -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);
index 287d13f..e0b33a4 100644 (file)
@@ -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)
 {
 }
 
index 6aeff39..726ae2a 100755 (executable)
@@ -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 (executable)
index 0000000..a9fdb8d
--- /dev/null
@@ -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 (executable)
index 0000000..90d45d5
--- /dev/null
@@ -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 <SecurityExceptions.h>
+
+#include <JSUtil.h>
+#include <JSWebAPIError.h>
+#include <ArgumentValidator.h>
+#include <GlobalContextManager.h>
+#include <MultiCallbackUserData.h>
+#include <PlatformException.h>
+
+#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<void*>(priv))) {
+            delete priv;
+        }
+    }
+}
+
+void JSWebSettingManager::finalize(JSObjectRef object)
+{
+    WebSettingManager *priv = static_cast<WebSettingManager*>(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<WebSettingManager*>(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<WebSettingManager*>(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 (file)
index 0000000..0733ca8
--- /dev/null
@@ -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 <JavaScriptCore/JavaScript.h>
+
+#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 (executable)
index 0000000..f056fdf
--- /dev/null
@@ -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 <PlatformException.h>
+#include <Logger.h>
+#include "WebSettingManager.h"
+#include <glib.h>
+#include <Ecore.h>
+#include <JSUtil.h>
+#include <JSWebAPIError.h>
+#include <PlatformException.h>
+
+
+namespace DeviceAPI {
+namespace WebSetting {
+
+WebSettingManager::WebSettingManager()
+{
+}
+
+WebSettingManager::~WebSettingManager()
+{
+}
+
+static gboolean asyncUserAgentStringResult(void *data)
+{
+    LoggerD("[asyncUserAgentStringResult] entered in Mainloop");
+
+    WebSettingManager* object = static_cast<WebSettingManager*>(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<WebSettingManager*>(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 (executable)
index 0000000..b859614
--- /dev/null
@@ -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 <MultiCallbackUserData.h>
+
+#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 (file)
index 0000000..a25c897
--- /dev/null
@@ -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 <string>
+#include <vector>
+#include <map>
+
+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 (file)
index 0000000..377b37f
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+    <library-name>libwrt-plugins-tizen-websetting.so</library-name>
+    <feature-install-uri>websetting.install.uri</feature-install-uri>
+    <feature-key-cn>SAMSUNG plugin group</feature-key-cn>
+    <feature-root-cn>SAMSUNG certificate authority</feature-root-cn>
+    <feature-root-fingerprint>AAAABBBBCCCCDDDEEEE0000</feature-root-fingerprint>
+
+    <api-feature>
+        <name>http://tizen.org/privilege/websetting</name>
+        <device-capability>websetting</device-capability>
+    </api-feature>
+
+</plugin-properties>
\ No newline at end of file
diff --git a/src/WebSetting/plugin_config.cpp b/src/WebSetting/plugin_config.cpp
new file mode 100644 (file)
index 0000000..9a3ed7f
--- /dev/null
@@ -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 <Commons/FunctionDefinition.h>
+#include <Commons/FunctionDeclaration.h>
+#include <Commons/Exception.h>
+#include <map>
+
+#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 (file)
index 0000000..9443546
--- /dev/null
@@ -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 <string>
+#include <Commons/FunctionDeclaration.h>
+
+#include <Logger.h>
+
+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<AceFunctionGetter, DefaultArgsVerifier<> >( \
+    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 (executable)
index 0000000..85a702b
--- /dev/null
@@ -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 <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+
+#include <GlobalContextManager.h>
+
+#include "JSWebSettingManager.h"
+
+#include <Logger.h>
+
+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<JSContextRef>(context));
+}
+
+void on_frame_unload_callback(const void * context)
+{
+    LoggerD("[Tizen\\WebSetting] on_frame_unload_callback (%p)", context);
+    GlobalContextManager::getInstance()->removeGlobalContext(static_cast<JSContextRef>(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