From f57bc28fce1662684f57543b8a19169fcb390e8a Mon Sep 17 00:00:00 2001 From: Jakub Skowron Date: Mon, 25 Apr 2016 13:36:43 +0200 Subject: [PATCH] [Feedback] Implement new module plugin Note: It wasn't tested sufficiently. 'feedback_is_supported_pattern' Native function returns 'false' status for all system pre-defined patterns and types. Tested on: [Version] Model=Tizen3/Mobile; Build=tizen-mobile_20160121.1; Change-Id: I405eefa24892f6bdfbebbb55af9c3ec1a5f36af0 Signed-off-by: Piotr Czaja Signed-off-by: Jakub Skowron --- packaging/webapi-plugins.spec | 8 ++ src/feedback/feedback.gyp | 32 +++++ src/feedback/feedback_api.js | 185 ++++++++++++++++++++++++++++ src/feedback/feedback_extension.cc | 37 ++++++ src/feedback/feedback_extension.h | 31 +++++ src/feedback/feedback_instance.cc | 111 +++++++++++++++++ src/feedback/feedback_instance.h | 48 ++++++++ src/feedback/feedback_manager.cc | 191 +++++++++++++++++++++++++++++ src/feedback/feedback_manager.h | 63 ++++++++++ src/tizen-wrt.gyp | 7 ++ 10 files changed, 713 insertions(+) create mode 100644 src/feedback/feedback.gyp create mode 100755 src/feedback/feedback_api.js create mode 100755 src/feedback/feedback_extension.cc create mode 100755 src/feedback/feedback_extension.h create mode 100755 src/feedback/feedback_instance.cc create mode 100755 src/feedback/feedback_instance.h create mode 100644 src/feedback/feedback_manager.cc create mode 100644 src/feedback/feedback_manager.h diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index d8676073..b6e2475c 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -51,6 +51,7 @@ Source0: %{name}-%{version}.tar.gz %define tizen_feature_datasync_support 0 %define tizen_feature_download_support 1 %define tizen_feature_exif_support 1 +%define tizen_feature_feedback_support 1 %define tizen_feature_filesystem_support 1 %define tizen_feature_fm_radio_support 1 %if 0%{?tizen_is_emulator} @@ -151,6 +152,7 @@ Source0: %{name}-%{version}.tar.gz %define tizen_feature_download_support 0 %endif %define tizen_feature_exif_support 1 +%define tizen_feature_feedback_support 1 %define tizen_feature_filesystem_support 1 %define tizen_feature_fm_radio_support 0 %define tizen_feature_ham_support 1 @@ -231,6 +233,7 @@ Source0: %{name}-%{version}.tar.gz %define tizen_feature_datasync_support 0 %define tizen_feature_download_support 1 %define tizen_feature_exif_support 1 +%define tizen_feature_feedback_support 0 %define tizen_feature_filesystem_support 1 %define tizen_feature_fm_radio_support 0 %define tizen_feature_ham_support 0 @@ -399,6 +402,10 @@ BuildRequires: pkgconfig(capi-network-nfc) BuildRequires: pkgconfig(capi-media-radio) %endif +%if 0%{?tizen_feature_feedback_support} +BuildRequires: pkgconfig(feedback) +%endif + %if 0%{?tizen_feature_se_support} BuildRequires: pkgconfig(smartcard-service) BuildRequires: pkgconfig(smartcard-service-common) @@ -463,6 +470,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_datacontrol_support=%{?tizen_feature_d GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_datasync_support=%{?tizen_feature_datasync_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_download_support=%{?tizen_feature_download_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_exif_support=%{?tizen_feature_exif_support}" +GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_feedback_support=%{?tizen_feature_feedback_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_filesystem_support=%{?tizen_feature_filesystem_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_fm_radio_support=%{?tizen_feature_fm_radio_support}" GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ham_support=%{?tizen_feature_ham_support}" diff --git a/src/feedback/feedback.gyp b/src/feedback/feedback.gyp new file mode 100644 index 00000000..b45c463a --- /dev/null +++ b/src/feedback/feedback.gyp @@ -0,0 +1,32 @@ +{ + 'includes':[ + '../common/common.gypi', + ], + 'targets': [ + { + 'target_name': 'tizen_feedback', + 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], + 'sources': [ + 'feedback_api.js', + 'feedback_extension.cc', + 'feedback_extension.h', + 'feedback_instance.cc', + 'feedback_instance.h', + 'feedback_manager.cc', + 'feedback_manager.h' + ], + 'conditions': [ + ['tizen == 1', { + 'variables': { + 'packages': [ + 'feedback' + ] + }, + }], + ], + }, + ], +} diff --git a/src/feedback/feedback_api.js b/src/feedback/feedback_api.js new file mode 100755 index 00000000..5f09d0f8 --- /dev/null +++ b/src/feedback/feedback_api.js @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +var validator_ = xwalk.utils.validator; +var types_ = validator_.Types; +var type_ = xwalk.utils.type; +var native_ = new xwalk.utils.NativeManager(extension); + +var ExceptionMap = { + 'UnknownError' : WebAPIException.UNKNOWN_ERR, + 'TypeMismatchError' : WebAPIException.TYPE_MISMATCH_ERR, + 'InvalidValuesError' : WebAPIException.INVALID_VALUES_ERR, + 'IOError' : WebAPIException.IO_ERR, + 'ServiceNotAvailableError' : WebAPIException.SERVICE_NOT_AVAILABLE_ERR, + 'SecurityError' : WebAPIException.SECURITY_ERR, + 'NetworkError' : WebAPIException.NETWORK_ERR, + 'NotSupportedError' : WebAPIException.NOT_SUPPORTED_ERR, + 'NotFoundError' : WebAPIException.NOT_FOUND_ERR, + 'InvalidAccessError' : WebAPIException.INVALID_ACCESS_ERR, + 'AbortError' : WebAPIException.ABORT_ERR, + 'QuotaExceededError' : WebAPIException.QUOTA_EXCEEDED_ERR +}; + +function callNative(cmd, args) { + var json = {'cmd': cmd, 'args': args}; + var argjson = JSON.stringify(json); + var resultString = extension.internal.sendSyncMessage(argjson); + var result = JSON.parse(resultString); + + if (typeof result !== 'object') { + throw new WebAPIException(WebAPIException.UNKNOWN_ERR); + } + + if (result['status'] == 'success') { + if (result['result']) { + return result['result']; + } + return true; + } + else if (result['status'] == 'error') { + var err = result['error']; + if (err) { + if (ExceptionMap[err.name]) { + throw new WebAPIException(ExceptionMap[err.name], err.message); + } else { + throw new WebAPIException(WebAPIException.UNKNOWN_ERR, err.message); + } + } + return false; + } +} + +function SetReadOnlyProperty(obj, n, v) { + Object.defineProperty(obj, n, {value: v, writable: false}); +} + +var FeedbackType = { + TYPE_SOUND: 'TYPE_SOUND', + TYPE_VIBRATION: 'TYPE_VIBRATION', + NONE: 'NONE' +} + +var FeedbackPattern = { + TAP: 'TAP', + SIP: 'SIP', + KEY0: 'KEY0', + KEY1: 'KEY1', + KEY2: 'KEY2', + KEY3: 'KEY3', + KEY4: 'KEY4', + KEY5: 'KEY5', + KEY6: 'KEY6', + KEY7: 'KEY7', + KEY8: 'KEY8', + KEY9: 'KEY9', + KEY_STAR: 'KEY_STAR', + KEY_SHARP: 'KEY_SHARP', + KEY_BACK: 'KEY_BACK', + HOLD: 'HOLD', + HW_TAP: 'HW_TAP', + HW_HOLD: 'HW_HOLD', + MESSAGE: 'MESSAGE', + EMAIL: 'EMAIL', + WAKEUP: 'WAKEUP', + SCHEDULE: 'SCHEDULE', + TIMER: 'TIMER', + GENERAL: 'GENERAL', + POWERON: 'POWERON', + POWEROFF: 'POWEROFF', + CHARGERCONN: 'CHARGERCONN', + CHARGING_ERROR: 'CHARGING_ERROR', + FULLCHARGED: 'FULLCHARGED', + LOWBATT: 'LOWBATT', + LOCK: 'LOCK', + UNLOCK: 'UNLOCK', + VIBRATION_ON: 'VIBRATION_ON', + SILENT_OFF: 'SILENT_OFF', + BT_CONNECTED: 'BT_CONNECTED', + BT_DISCONNECTED: 'BT_DISCONNECTED', + LIST_REORDER: 'LIST_REORDER', + LIST_SLIDER: 'LIST_SLIDER', + VOLUME_KEY: 'VOLUME_KEY' + }; + +function FeedbackManager() { + // constructor of FeedbackManager +} + + +FeedbackManager.prototype.isPatternSupported = function(pattern, type) { + var args = validator_.validateArgs(arguments, [ + {name: 'pattern', type: types_.ENUM, values: Object.keys(FeedbackPattern)}, + {name: 'type', type: types_.ENUM, values: Object.keys(FeedbackType)}, + ]); + + if ('' === args.pattern) { + throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, + 'Pattern name cannot be empty.'); + } + + if ('' === args.type) { + throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, + 'Pattern type name cannot be empty.'); + } + + var result = callNative('FeedbackManager_isPatternSupported', args); + + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } + return native_.getResultObject(result); +}; + +FeedbackManager.prototype.play = function(pattern, type) { + var args = validator_.validateArgs(arguments, [ + {name: 'pattern', type: types_.ENUM, values: Object.keys(FeedbackPattern)}, + {name: 'type', type: types_.ENUM, values: Object.keys(FeedbackType), 'optional' : true}, + ]); + + if ('' === args.pattern) { + throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, + 'Pattern name cannot be empty.'); + } + if ('' === args.type) { + throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, + 'Pattern type name cannot be empty.'); + } + + var nativeParam = { + 'pattern': args.pattern, + 'type': args.type ? args.type : 'any' + }; + + var result = callNative('FeedbackManager_play', nativeParam); + + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } + return; +}; + +FeedbackManager.prototype.stop = function() { + native_.removeListener(TAG_LISTENER); + + var result = callNative('FeedbackManager_stop'); + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } + return; +}; + +exports = new FeedbackManager(); diff --git a/src/feedback/feedback_extension.cc b/src/feedback/feedback_extension.cc new file mode 100755 index 00000000..7e686eac --- /dev/null +++ b/src/feedback/feedback_extension.cc @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 "feedback/feedback_extension.h" + +#include "feedback/feedback_instance.h" + +// This will be generated from feedback_api.js +extern const char kSource_feedback_api[]; + +common::Extension* CreateExtension() { + return new FeedbackExtension; +} + +FeedbackExtension::FeedbackExtension() { + SetExtensionName("tizen.feedback"); + SetJavaScriptAPI(kSource_feedback_api); +} + +FeedbackExtension::~FeedbackExtension() {} + +common::Instance* FeedbackExtension::CreateInstance() { + return new extension::feedback::FeedbackInstance; +} diff --git a/src/feedback/feedback_extension.h b/src/feedback/feedback_extension.h new file mode 100755 index 00000000..f115a899 --- /dev/null +++ b/src/feedback/feedback_extension.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 FEEDBACK_FEEDBACK_EXTENSION_H_ +#define FEEDBACK_FEEDBACK_EXTENSION_H_ + +#include "common/extension.h" + +class FeedbackExtension : public common::Extension { + public: + FeedbackExtension(); + virtual ~FeedbackExtension(); + + private: + virtual common::Instance* CreateInstance(); +}; + +#endif // FEEDBACK_FEEDBACK_EXTENSION_H_ diff --git a/src/feedback/feedback_instance.cc b/src/feedback/feedback_instance.cc new file mode 100755 index 00000000..65de61c8 --- /dev/null +++ b/src/feedback/feedback_instance.cc @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 "feedback/feedback_instance.h" +#include "feedback_manager.h" + +#include +#include + +#include "common/picojson.h" +#include "common/logger.h" +#include "common/picojson.h" +#include "common/platform_exception.h" +#include "common/platform_result.h" +#include "common/tools.h" + +namespace extension { +namespace feedback { + +using namespace common; + +using common::TypeMismatchException; +using common::InvalidValuesException; +using common::UnknownException; +using common::NotFoundException; +using common::QuotaExceededException; + +FeedbackInstance::FeedbackInstance() + : m_feedbackMapsPtr(new FeedbackMaps), + m_feedbackManagerPtr(new FeedbackManager(this->m_feedbackMapsPtr)) + { + LoggerD("Enter"); + using std::placeholders::_1; + using std::placeholders::_2; + #define REGISTER_SYNC(c, x) \ + RegisterSyncHandler(c, std::bind(&FeedbackInstance::x, this, _1, _2)); + REGISTER_SYNC("FeedbackManager_isPatternSupported", + IsPatternSupported); + REGISTER_SYNC("FeedbackManager_play", + Play); + REGISTER_SYNC("FeedbackManager_stop", + Stop); + #undef REGISTER_SYNC +} + +FeedbackInstance::~FeedbackInstance() { + LoggerD("Enter"); +} + +void FeedbackInstance::IsPatternSupported + (const picojson::value& args, picojson::object& out) { + LoggerD("Enter"); + + const auto pattern = args.get("pattern").get(); + const auto type = args.get("type").get(); + + bool patternStatus = false; + PlatformResult result = + m_feedbackManagerPtr->isPatternSupported(pattern, type, &patternStatus); + if (result.IsSuccess()) { + ReportSuccess(picojson::value(patternStatus), out); + } else { + LogAndReportError(result, &out); + } +} + +void FeedbackInstance::Play + (const picojson::value& args, picojson::object& out) { + LoggerD("Enter"); + + const auto pattern = args.get("pattern").get(); + const auto type = args.get("type").get(); + + PlatformResult result = + m_feedbackManagerPtr->play(pattern, type); + if (result.IsSuccess()) { + ReportSuccess(out); + } else { + LogAndReportError(result, &out); + } +} + +void FeedbackInstance::Stop + (const picojson::value& args, picojson::object& out) { + LoggerD("Enter"); + PlatformResult result = + m_feedbackManagerPtr->stop(); + if (result.IsSuccess()) { + ReportSuccess(out); + } else { + LogAndReportError(result, &out); + } +} + +#undef CHECK_EXIST + +} // namespace messageport +} // namespace extension diff --git a/src/feedback/feedback_instance.h b/src/feedback/feedback_instance.h new file mode 100755 index 00000000..98f4bda4 --- /dev/null +++ b/src/feedback/feedback_instance.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 FEEDBACK_FEEDBACK_INSTANCE_H_ +#define FEEDBACK_FEEDBACK_INSTANCE_H_ + +#include "common/extension.h" +#include + +namespace extension { +namespace feedback { + +class FeedbackMaps; +class FeedbackManager; + +class FeedbackInstance : public common::ParsedInstance { + public: + FeedbackInstance(); + virtual ~FeedbackInstance(); + + private: + std::shared_ptr m_feedbackMapsPtr; + std::unique_ptr m_feedbackManagerPtr; + void IsPatternSupported + (const picojson::value& args, picojson::object& out); + void Play + (const picojson::value& args, picojson::object& out); + void Stop + (const picojson::value& args, picojson::object& out); +}; + +} // namespace feedback +} // namespace extension + +#endif // FEEDBACK_FEEDBACK_INSTANCE_H_ diff --git a/src/feedback/feedback_manager.cc b/src/feedback/feedback_manager.cc new file mode 100644 index 00000000..381ecb54 --- /dev/null +++ b/src/feedback/feedback_manager.cc @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "common/assert.h" +#include "common/converter.h" +#include "common/extension.h" +#include "common/logger.h" +#include "common/platform_exception.h" +#include "common/picojson.h" +#include "common/platform_result.h" +#include "common/tools.h" + +using namespace common; +using namespace std; +using common::tools::ReportError; + +namespace extension { +namespace feedback { + +FeedbackMaps::FeedbackMaps() : + mTypeMap{ + {"TYPE_SOUND", FEEDBACK_TYPE_SOUND}, + {"TYPE_VIBRATION", FEEDBACK_TYPE_VIBRATION} + }, + mPatternMap{ + {"TAP", FEEDBACK_PATTERN_TAP}, + {"SIP", FEEDBACK_PATTERN_SIP}, + {"KEY0", FEEDBACK_PATTERN_KEY0}, + {"KEY1", FEEDBACK_PATTERN_KEY1}, + {"KEY2", FEEDBACK_PATTERN_KEY2}, + {"KEY3", FEEDBACK_PATTERN_KEY3}, + {"KEY4", FEEDBACK_PATTERN_KEY4}, + {"KEY5", FEEDBACK_PATTERN_KEY5}, + {"KEY6", FEEDBACK_PATTERN_KEY6}, + {"KEY7", FEEDBACK_PATTERN_KEY7}, + {"KEY8", FEEDBACK_PATTERN_KEY8}, + {"KEY9", FEEDBACK_PATTERN_KEY9}, + {"KEY_STAR", FEEDBACK_PATTERN_KEY_STAR}, + {"KEY_SHARP", FEEDBACK_PATTERN_KEY_SHARP}, + {"KEY_BACK", FEEDBACK_PATTERN_KEY_BACK}, + {"HOLD", FEEDBACK_PATTERN_HOLD}, + {"HW_TAP", FEEDBACK_PATTERN_HW_TAP}, + {"HW_HOLD", FEEDBACK_PATTERN_HW_HOLD}, + {"MESSAGE", FEEDBACK_PATTERN_MESSAGE}, + {"EMAIL", FEEDBACK_PATTERN_EMAIL}, + {"WAKEUP", FEEDBACK_PATTERN_WAKEUP}, + {"SCHEDULE", FEEDBACK_PATTERN_SCHEDULE}, + {"TIMER", FEEDBACK_PATTERN_TIMER}, + {"GENERAL", FEEDBACK_PATTERN_GENERAL}, + {"POWERON", FEEDBACK_PATTERN_POWERON}, + {"POWEROFF", FEEDBACK_PATTERN_POWEROFF}, + {"CHARGERCONN", FEEDBACK_PATTERN_CHARGERCONN}, + {"CHARGING_ERROR", FEEDBACK_PATTERN_CHARGING_ERROR}, + {"FULLCHARGED", FEEDBACK_PATTERN_FULLCHARGED}, + {"LOWBATT", FEEDBACK_PATTERN_LOWBATT}, + {"LOCK", FEEDBACK_PATTERN_LOCK}, + {"UNLOCK", FEEDBACK_PATTERN_UNLOCK}, + {"VIBRATION_ON", FEEDBACK_PATTERN_VIBRATION_ON}, + {"SILENT_OFF", FEEDBACK_PATTERN_SILENT_OFF}, + {"BT_CONNECTED", FEEDBACK_PATTERN_BT_CONNECTED}, + {"BT_DISCONNECTED", FEEDBACK_PATTERN_BT_DISCONNECTED}, + {"LIST_REORDER", FEEDBACK_PATTERN_LIST_REORDER}, + {"LIST_SLIDER", FEEDBACK_PATTERN_LIST_SLIDER}, + {"VOLUME_KEY", FEEDBACK_PATTERN_VOLUME_KEY} + } +{}; + +FeedbackMaps::~FeedbackMaps() +{} + +feedback_pattern_e const & FeedbackMaps::getPatternFromMap(const std::string& pattern) { + return mPatternMap[pattern]; +} + +feedback_type_e const & FeedbackMaps::getTypeFromMap(const std::string& type) { + return mTypeMap[type]; +} + +FeedbackManager::FeedbackManager(std::shared_ptr maps) + : m_feedbackMapsPtr(maps) +{ + LoggerD("Entered"); + // feedback API initialization + int ret = feedback_initialize(); + if(ret != FEEDBACK_ERROR_NONE) { + LoggerE("Could not initialize Feedback Manager, error: %d", ret); + } + +} + +FeedbackManager::~FeedbackManager() { + LoggerD("Entered"); + + // feedback library deinitialization + int ret = feedback_deinitialize(); + if(ret != FEEDBACK_ERROR_NONE) { + LoggerE("Could not deinitialize Feedback Manager, error: %d", ret); + } +} + +common::PlatformResult +FeedbackManager::isPatternSupported(const std::string &pattern, const std::string &type, bool* patternStatus) { + LoggerD("Entered"); + int ret = feedback_is_supported_pattern( + m_feedbackMapsPtr->getTypeFromMap(type), + m_feedbackMapsPtr->getPatternFromMap(pattern), + patternStatus + ); + if(ret != FEEDBACK_ERROR_NONE) { + LoggerE("isPatternSupported failed: %d", ret); + return CodeToResult(ret, getFeedbackErrorMessage(ret).c_str()); + } + return PlatformResult(ErrorCode::NO_ERROR); +} + +common::PlatformResult FeedbackManager::play(const std::string &pattern, const std::string &type) { + LoggerD("Entered"); + int ret = 0; + if(type == "any") { + ret = feedback_play(m_feedbackMapsPtr->getPatternFromMap(pattern)); + } else { + ret = feedback_play_type(m_feedbackMapsPtr->getTypeFromMap(type), + m_feedbackMapsPtr->getPatternFromMap(pattern)); + } + if(ret != FEEDBACK_ERROR_NONE) { + LoggerE("play failed: %d", ret); + return CodeToResult(ret, getFeedbackErrorMessage(ret).c_str()); + } + return PlatformResult(ErrorCode::NO_ERROR); +} + +common::PlatformResult FeedbackManager::stop() { + LoggerD("Entered"); + int ret = feedback_stop(); + if(ret != FEEDBACK_ERROR_NONE && ret != FEEDBACK_ERROR_NOT_SUPPORTED) { + LoggerE("stop failed: %d", ret); + return CodeToResult(ret, getFeedbackErrorMessage(ret).c_str()); + } + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult FeedbackManager::CodeToResult(const int errorCode, + const std::string& message) { + LoggerD("Entered"); + switch(errorCode) { + case FEEDBACK_ERROR_INVALID_PARAMETER: + return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, message); + case FEEDBACK_ERROR_OPERATION_FAILED: + return LogAndCreateResult(ErrorCode::SECURITY_ERR, message); + case FEEDBACK_ERROR_NOT_SUPPORTED: + return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, message); + case FEEDBACK_ERROR_NOT_INITIALIZED: + default: + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, message); + } +} + +const std::string FeedbackManager::getFeedbackErrorMessage(const int error_code) { + LoggerD("Error code : %d", error_code); + switch(error_code) { + case FEEDBACK_ERROR_OPERATION_FAILED: + return "Operation not permitted"; + case FEEDBACK_ERROR_INVALID_PARAMETER: + return "Invalid parameter"; + case FEEDBACK_ERROR_NOT_SUPPORTED: + return "Not supported device"; + case FEEDBACK_ERROR_NOT_INITIALIZED: + return "Not initialized"; + default: + return "UnknownError"; + } +} + +}// feedback +}// extension diff --git a/src/feedback/feedback_manager.h b/src/feedback/feedback_manager.h new file mode 100644 index 00000000..471ab7c3 --- /dev/null +++ b/src/feedback/feedback_manager.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 FEEDBACK_MANAGER_H_ +#define FEEDBACK_MANAGER_H_ + +#include "common/picojson.h" +#include "common/platform_result.h" + +#include +#include +#include + +namespace extension { +namespace feedback { + +using stringPatternMap = std::map; +using stringTypeMap = std::map; + +class FeedbackMaps { + public: + FeedbackMaps(); + virtual ~FeedbackMaps(); + feedback_pattern_e const & getPatternFromMap(const std::string& pattern); + feedback_type_e const & getTypeFromMap(const std::string& type); + private: + stringTypeMap mTypeMap; + stringPatternMap mPatternMap; +}; + +class FeedbackManager { + public: + FeedbackManager(std::shared_ptr maps); + virtual ~FeedbackManager(); + + common::PlatformResult isPatternSupported( + const std::string &pattern, const std::string &type, bool* patternStatus); + common::PlatformResult play(const std::string &pattern, const std::string &type); + common::PlatformResult stop(); + private: + const std::string getFeedbackErrorMessage(const int error_code); + common::PlatformResult CodeToResult( + const int errorCode, const std::string& message); + std::shared_ptr m_feedbackMapsPtr; +}; + +} // feedback +} // extension + +#endif // FEEDBACK_MANAGER_H_ diff --git a/src/tizen-wrt.gyp b/src/tizen-wrt.gyp index 4d2a4837..336485e5 100755 --- a/src/tizen-wrt.gyp +++ b/src/tizen-wrt.gyp @@ -119,6 +119,13 @@ ], }, ], + [ + 'tizen_feature_feedback_support==1', { + 'dependencies': [ + 'feedback/feedback.gyp:*', + ], + }, + ], [ 'tizen_feature_filesystem_support==1', { 'dependencies': [ -- 2.34.1