From: Piotr Czaja Date: Wed, 24 Jun 2015 13:14:20 +0000 (+0200) Subject: [TV][InputDevice] Adding synchronous call for registering and unregistering keys X-Git-Tag: submit/tizen/20150702.103311^2~2^2~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=546054801b3b8a2dcb445a9c06e674875d832db3;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [TV][InputDevice] Adding synchronous call for registering and unregistering keys Change-Id: Ic330564dab503907ce67850cd6ffbb615e475b05 Signed-off-by: Piotr Czaja --- diff --git a/src/tvinputdevice/tvinputdevice.gyp b/src/tvinputdevice/tvinputdevice.gyp index d404756d..9bd3ab0c 100644 --- a/src/tvinputdevice/tvinputdevice.gyp +++ b/src/tvinputdevice/tvinputdevice.gyp @@ -14,11 +14,7 @@ 'tvinputdevice_extension.cc', 'tvinputdevice_extension.h', 'tvinputdevice_instance.cc', - 'tvinputdevice_instance.h', - 'tvinputdevice_key.cc', - 'tvinputdevice_key.h', - 'tvinputdevice_manager.cc', - 'tvinputdevice_manager.h' + 'tvinputdevice_instance.h' ], 'includes': [ '../common/pkg-config.gypi', diff --git a/src/tvinputdevice/tvinputdevice_api.js b/src/tvinputdevice/tvinputdevice_api.js index f4deb54c..0c58d8f4 100644 --- a/src/tvinputdevice/tvinputdevice_api.js +++ b/src/tvinputdevice/tvinputdevice_api.js @@ -17,9 +17,19 @@ var native = new xwalk.utils.NativeManager(extension); var validator = xwalk.utils.validator; var types = validator.Types; +var map = { + "VolumeUp": { + keyName: "XF86AudioRaiseVolume", + keyCode: 447 + }, + "VolumeDown": { + keyName: "XF86AudioLowerVolume", + keyCode: 448 + }, +}; -function InputDeviceKey(dict) { +function TVInputDeviceKey(dict) { for (var key in dict) { if (dict.hasOwnProperty(key)) { Object.defineProperty(this, key, { @@ -32,16 +42,6 @@ function InputDeviceKey(dict) { } -function dictListToInputDeviceKeyList(list) { - var result = [], listLength = list.length; - for (var i = 0; i < listLength; ++i) { - result.push(new InputDeviceKey(list[i])); - } - return result; -} - - - /** * This class provides access to the API functionalities through the tizen.tvinputdevice interface. * @constructor @@ -52,17 +52,20 @@ function TVInputDeviceManager() { } } - /** * Retrieves the list of keys can be registered with the registerKey() method. * @return {array} Array of keys */ TVInputDeviceManager.prototype.getSupportedKeys = function() { - var ret = native.callSync('TVInputDeviceManager_getSupportedKeys'); - if (native.isFailure(ret)) { - throw native.getErrorObject(ret); + + var re = []; + for (var key in map) { + if (map.hasOwnProperty(key)) { + re.push(new TVInputDeviceKey({name: key, code: map[key].keyCode})); + } } - return dictListToInputDeviceKeyList(native.getResultObject(ret)); + + return re; }; @@ -76,14 +79,13 @@ TVInputDeviceManager.prototype.getKey = function(keyName) { {name: 'keyName', type: types.STRING} ]); - var ret = native.callSync('TVInputDeviceManager_getKey', { - keyName: args.keyName - }); - - if (native.isFailure(ret)) { - throw native.getErrorObject(ret); + if (!map[args.keyName]) { + throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, + 'Parameter "keyName" is invalid.'); } - return native.getResultObject(ret); + + return new TVInputDeviceKey( { name: args.keyName, code: map[args.keyName].keyCode } ); + }; @@ -95,10 +97,12 @@ TVInputDeviceManager.prototype.registerKey = function(keyName) { var args = validator.validateArgs(arguments, [ {name: 'keyName', type: types.STRING} ]); + if (!map[args.keyName]) { + throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, + 'Parameter "keyName" is invalid.'); + } - var ret = native.callSync('TVInputDeviceManager_registerKey', { - keyName: args.keyName - }); + var ret = native.sendRuntimeSyncMessage('tizen://api/inputdevice/registerKey',map[args.keyName].keyName); if (native.isFailure(ret)) { throw native.getErrorObject(ret); @@ -114,10 +118,13 @@ TVInputDeviceManager.prototype.unregisterKey = function(keyName) { var args = validator.validateArgs(arguments, [ {name: 'keyName', type: types.STRING} ]); - - var ret = native.callSync('TVInputDeviceManager_unregisterKey', { - keyName: args.keyName - }); + + if (!map[args.keyName]) { + throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, + 'Parameter "keyName" is invalid.'); + } + + var ret = native.sendRuntimeSyncMessage('tizen://api/inputdevice/unregisterKey',map[args.keyName].keyName); if (native.isFailure(ret)) { throw native.getErrorObject(ret); diff --git a/src/tvinputdevice/tvinputdevice_extension.cc b/src/tvinputdevice/tvinputdevice_extension.cc index 05016149..e007872f 100644 --- a/src/tvinputdevice/tvinputdevice_extension.cc +++ b/src/tvinputdevice/tvinputdevice_extension.cc @@ -1,21 +1,9 @@ -/* - * 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 "tvinputdevice/tvinputdevice_extension.h" -#include "tvinputdevice/tvinputdevice_instance.h" +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "../tvinputdevice/tvinputdevice_extension.h" +#include "../tvinputdevice/tvinputdevice_instance.h" // This will be generated from tvinputdevice_api.js extern const char kSource_tvinputdevice_api[]; @@ -30,11 +18,6 @@ TVInputDeviceExtension::TVInputDeviceExtension() { TVInputDeviceExtension::~TVInputDeviceExtension() {} -TVInputDeviceManager& TVInputDeviceExtension::manager() { - // Initialize API on first request - return TVInputDeviceManager::getInstance(); -} - common::Instance* TVInputDeviceExtension::CreateInstance() { return new TVInputDeviceInstance; } diff --git a/src/tvinputdevice/tvinputdevice_extension.h b/src/tvinputdevice/tvinputdevice_extension.h index b82ec23b..8a633f15 100644 --- a/src/tvinputdevice/tvinputdevice_extension.h +++ b/src/tvinputdevice/tvinputdevice_extension.h @@ -1,24 +1,11 @@ -/* - * 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. - */ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. #ifndef SRC_TVINPUTDEVICE_TVINPUTDEVICE_EXTENSION_H_ #define SRC_TVINPUTDEVICE_TVINPUTDEVICE_EXTENSION_H_ #include "common/extension.h" -#include "tvinputdevice/tvinputdevice_manager.h" namespace extension { namespace tvinputdevice { @@ -28,8 +15,6 @@ class TVInputDeviceExtension : public common::Extension { TVInputDeviceExtension(); virtual ~TVInputDeviceExtension(); - TVInputDeviceManager& manager(); - private: virtual common::Instance* CreateInstance(); }; diff --git a/src/tvinputdevice/tvinputdevice_instance.cc b/src/tvinputdevice/tvinputdevice_instance.cc index f78fc98e..fe926ca4 100644 --- a/src/tvinputdevice/tvinputdevice_instance.cc +++ b/src/tvinputdevice/tvinputdevice_instance.cc @@ -14,84 +14,21 @@ * limitations under the License. */ -#include -#include -#include +#include "../tvinputdevice/tvinputdevice_instance.h" #include "common/logger.h" -#include "tvinputdevice/tvinputdevice_instance.h" -#include "tvinputdevice/tvinputdevice_manager.h" namespace extension { namespace tvinputdevice { TVInputDeviceInstance::TVInputDeviceInstance() { LOGD("Enter"); - using std::placeholders::_1; - using std::placeholders::_2; - #define REGISTER_SYNC(c, x) \ - RegisterSyncHandler(c, std::bind(&TVInputDeviceInstance::x, this, _1, _2)); - REGISTER_SYNC("TVInputDeviceManager_getSupportedKeys", getSupportedKeys); - REGISTER_SYNC("TVInputDeviceManager_getKey", getKey); - REGISTER_SYNC("TVInputDeviceManager_registerKey", registerKey); - REGISTER_SYNC("TVInputDeviceManager_unregisterKey", unregisterKey); - #undef REGISTER_SYNC } TVInputDeviceInstance::~TVInputDeviceInstance() { LOGD("Enter"); } -picojson::value TVInputDeviceInstance::inputDeviceKeyToJson( - const InputDeviceKeyPtr keyPtr) { - LOGD("Enter"); - picojson::value::object keyMap; - keyMap.insert( - std::make_pair("name", - picojson::value(keyPtr->getName()))); - keyMap.insert( - std::make_pair("code", - picojson::value(static_cast(keyPtr->getCode())))); - return picojson::value(keyMap); -} - -void TVInputDeviceInstance::getSupportedKeys(const picojson::value& args, - picojson::object& out) { - LOGD("Enter"); - std::vector inputDeviceKeys = - TVInputDeviceManager::getInstance().getSupportedKeys(); - picojson::value::array picjsonValuesArray; - for (auto it = inputDeviceKeys.begin(); it != inputDeviceKeys.end(); ++it) { - picjsonValuesArray.push_back(inputDeviceKeyToJson(*it)); - } - ReportSuccess(picojson::value(picjsonValuesArray), out); -} - -void TVInputDeviceInstance::getKey(const picojson::value& args, - picojson::object& out) { - LOGD("Enter"); - std::string keyName = args.get("keyName").get(); - InputDeviceKeyPtr keyPtr = - TVInputDeviceManager::getInstance().getKey(keyName); - ReportSuccess(inputDeviceKeyToJson(keyPtr), out); -} - -void TVInputDeviceInstance::registerKey(const picojson::value& args, - picojson::object& out) { - LOGD("Enter"); - std::string keyName = args.get("keyName").get(); - TVInputDeviceManager::getInstance().registerKey(keyName); - ReportSuccess(out); -} - -void TVInputDeviceInstance::unregisterKey(const picojson::value& args, - picojson::object& out) { - LOGD("Enter"); - std::string keyName = args.get("keyName").get(); - TVInputDeviceManager::getInstance().unregisterKey(keyName); - ReportSuccess(out); -} - } // namespace tvinputdevice } // namespace extension diff --git a/src/tvinputdevice/tvinputdevice_instance.h b/src/tvinputdevice/tvinputdevice_instance.h index 45eab858..d48248e1 100644 --- a/src/tvinputdevice/tvinputdevice_instance.h +++ b/src/tvinputdevice/tvinputdevice_instance.h @@ -20,7 +20,6 @@ #include "common/picojson.h" #include "common/extension.h" -#include "tvinputdevice/tvinputdevice_manager.h" namespace extension { namespace tvinputdevice { @@ -31,11 +30,6 @@ class TVInputDeviceInstance : public common::ParsedInstance { virtual ~TVInputDeviceInstance(); private: - picojson::value inputDeviceKeyToJson(const InputDeviceKeyPtr keyPtr); - void getSupportedKeys(const picojson::value& args, picojson::object& out); - void getKey(const picojson::value& args, picojson::object& out); - void registerKey(const picojson::value& args, picojson::object& out); - void unregisterKey(const picojson::value& args, picojson::object& out); }; } // namespace tvinputdevice diff --git a/src/tvinputdevice/tvinputdevice_key.cc b/src/tvinputdevice/tvinputdevice_key.cc deleted file mode 100644 index c655279e..00000000 --- a/src/tvinputdevice/tvinputdevice_key.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 "common/logger.h" -#include "common/platform_exception.h" - -#include "tvinputdevice/tvinputdevice_key.h" - -namespace extension { -namespace tvinputdevice { - -InputDeviceKey::InputDeviceKey(): - m_code(0), m_name("") { - LOGD("Enter"); -} - -InputDeviceKey::InputDeviceKey(std::string name, int32_t code): - m_name(name), m_code(code) { - LOGD("Key Name %s", m_name.c_str() ); -} - -InputDeviceKey::~InputDeviceKey() { - LOGD("Enter"); -} - -std::string InputDeviceKey::getName() const { - LOGD("Enter"); - LOGD("Key Name %s", m_name.c_str() ); - return m_name; -} - -void InputDeviceKey::setName(std::string name) { - LOGD("Key Name %s", name.c_str() ); - m_name = name; -} - -int32_t InputDeviceKey::getCode() const { - return m_code; -} - -void InputDeviceKey::setCode(int32_t code) { - m_code = code; -} - - -} // namespace tvinputdevice -} // namespace extension diff --git a/src/tvinputdevice/tvinputdevice_key.h b/src/tvinputdevice/tvinputdevice_key.h deleted file mode 100644 index 1fd4d9c8..00000000 --- a/src/tvinputdevice/tvinputdevice_key.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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 SRC_TVINPUTDEVICE_TVINPUTDEVICE_KEY_H_ -#define SRC_TVINPUTDEVICE_TVINPUTDEVICE_KEY_H_ - -#include -#include -#include - -namespace extension { -namespace tvinputdevice { - -class InputDeviceKey { - public: - InputDeviceKey(); - - InputDeviceKey(std::string name, int32_t code); - - virtual ~InputDeviceKey(); - - std::string getName() const; - void setName(std::string name); - - int32_t getCode() const; - void setCode(int32_t code); - - private: - std::string m_name; - int32_t m_code; -}; - -typedef std::shared_ptr InputDeviceKeyPtr; - -} // namespace tvinputdevice -} // namespace extension - -#endif // SRC_TVINPUTDEVICE_TVINPUTDEVICE_KEY_H_ diff --git a/src/tvinputdevice/tvinputdevice_manager.cc b/src/tvinputdevice/tvinputdevice_manager.cc deleted file mode 100755 index fa0344b8..00000000 --- a/src/tvinputdevice/tvinputdevice_manager.cc +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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/logger.h" -#include "common/platform_exception.h" - -#include "tvinputdevice/tvinputdevice_manager.h" - -namespace extension { -namespace tvinputdevice { - -using common::UnknownException; -using common::InvalidValuesException; - -TVInputDeviceManager::TVInputDeviceManager() { - LOGD("Enter"); - setSupportedKeys(); -} - -TVInputDeviceManager::~TVInputDeviceManager() { - LOGD("Enter"); - cleanSupportedKeys(); -} - -TVInputDeviceManager& TVInputDeviceManager::getInstance() { - LOGD("Enter"); - static TVInputDeviceManager instance; - return instance; -} - -void TVInputDeviceManager::cleanSupportedKeys() { - LOGD("Enter"); - m_availableKeys.clear(); -} - -void TVInputDeviceManager::setSupportedKeys() { - LOGD("Entered"); - cleanSupportedKeys(); - InputDeviceKeyPtr key(new InputDeviceKey()); - m_availableKeys.push_back(key); -} - -InputDeviceKeyPtr TVInputDeviceManager::getKey( - std::string const& keyName) const { - LOGD("Enter"); - auto it = std::find_if(m_availableKeys.begin(), m_availableKeys.end(), - [ keyName ](InputDeviceKeyPtr _pKey)->bool{ - if (_pKey->getName() == keyName) { - return true; - } else { - return false; - } - }); - - if (it != m_availableKeys.end()) { - return *it; - } else { - return NULL; - } -} -void TVInputDeviceManager::registerKey(std::string const& keyName) const { - LOGD("Enter"); -} -void TVInputDeviceManager::unregisterKey(std::string const& keyName) const { - LOGD("Enter"); -} - -std::vector TVInputDeviceManager::getSupportedKeys() const { - LOGD("Enter"); - return m_availableKeys; -} - -} // namespace tvinputdevice -} // namespace extension diff --git a/src/tvinputdevice/tvinputdevice_manager.h b/src/tvinputdevice/tvinputdevice_manager.h deleted file mode 100755 index 874a0c93..00000000 --- a/src/tvinputdevice/tvinputdevice_manager.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 SRC_TVINPUTDEVICE_TVINPUTDEVICE_MANAGER_H_ -#define SRC_TVINPUTDEVICE_TVINPUTDEVICE_MANAGER_H_ - -#include -#include - -#include "tvinputdevice/tvinputdevice_key.h" - -namespace extension { -namespace tvinputdevice { - -class TVInputDeviceManager { - public: - InputDeviceKeyPtr getKey(std::string const& keyName) const; - - void registerKey(std::string const& keyName) const; - - void unregisterKey(std::string const& keyName) const; - - std::vector getSupportedKeys() const; - - static TVInputDeviceManager& getInstance(); - - virtual ~TVInputDeviceManager(); - - private: - TVInputDeviceManager(); - - void setSupportedKeys(); - std::vector m_availableKeys; - - void cleanSupportedKeys(); -}; - -} // namespace tvinputdevice -} // namespace extension - -#endif // SRC_TVINPUTDEVICE_TVINPUTDEVICE_MANAGER_H_