From: Lukasz Foniok Date: Thu, 14 May 2015 12:53:00 +0000 (+0200) Subject: [InputDevice] Implementation moved to java script X-Git-Tag: submit/tizen/20150702.103311^2~1^2~50 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=26c389b1083e4965f280256db95e783f90513149;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [InputDevice] Implementation moved to java script [Verification] tizen.inputdevice.getSupportedKeys() tizen.inputdevice.getKeyName("VolumeUp") tizen.inputdevice.registerKey("VolumeUp") tizen.inputdevice.unregisterKey("VolumeUp") Change-Id: Ic952a24dab39be5fd66f9d101f0c7f0aa47ea243 Signed-off-by: Lukasz Foniok --- diff --git a/src/inputdevice/inputdevice.gyp b/src/inputdevice/inputdevice.gyp index 8d5a9947..77a76b07 100644 --- a/src/inputdevice/inputdevice.gyp +++ b/src/inputdevice/inputdevice.gyp @@ -14,11 +14,7 @@ 'inputdevice_extension.cc', 'inputdevice_extension.h', 'inputdevice_instance.cc', - 'inputdevice_instance.h', - 'inputdevice_key.cc', - 'inputdevice_key.h', - 'inputdevice_manager.cc', - 'inputdevice_manager.h' + 'inputdevice_instance.h' ], 'includes': [ '../common/pkg-config.gypi', diff --git a/src/inputdevice/inputdevice_api.js b/src/inputdevice/inputdevice_api.js index 4e194571..d689b6e2 100644 --- a/src/inputdevice/inputdevice_api.js +++ b/src/inputdevice/inputdevice_api.js @@ -17,6 +17,16 @@ 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) { @@ -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 InputDeviceManager() { } } - /** * Retrieves the list of keys can be registered with the registerKey() method. * @return {array} Array of keys */ InputDeviceManager.prototype.getSupportedKeys = function() { - var ret = native.callSync('InputDeviceManager_getSupportedKeys'); - if (native.isFailure(ret)) { - throw native.getErrorObject(ret); + + var re = []; + for (var key in map) { + if (map.hasOwnProperty(key)) { + re.push(new InputDeviceKey({name: key, code: map[key].keyCode})); + } } - return dictListToInputDeviceKeyList(native.getResultObject(ret)); + + return re; }; @@ -76,14 +79,13 @@ InputDeviceManager.prototype.getKey = function(keyName) { {name: 'keyName', type: types.STRING} ]); - var ret = native.callSync('InputDeviceManager_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 InputDeviceKey( { name: args.keyName, code: map[args.keyName].keyCode } ); + }; @@ -95,8 +97,12 @@ InputDeviceManager.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.sendRuntimeSyncMessage('tizen://api/inputdevice/registerKey',args.keyName); + var ret = native.sendRuntimeSyncMessage('tizen://api/inputdevice/registerKey',map[args.keyName].keyName); if (native.isFailure(ret)) { throw native.getErrorObject(ret); @@ -113,7 +119,12 @@ InputDeviceManager.prototype.unregisterKey = function(keyName) { {name: 'keyName', type: types.STRING} ]); - var ret = native.sendRuntimeSyncMessage('tizen://api/inputdevice/unregisterKey',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/inputdevice/inputdevice_extension.cc b/src/inputdevice/inputdevice_extension.cc index f078dbe7..cf59eab9 100644 --- a/src/inputdevice/inputdevice_extension.cc +++ b/src/inputdevice/inputdevice_extension.cc @@ -3,7 +3,6 @@ // found in the LICENSE file. #include "../inputdevice/inputdevice_extension.h" - #include "../inputdevice/inputdevice_instance.h" // This will be generated from inputdevice_api.js @@ -19,11 +18,6 @@ InputDeviceExtension::InputDeviceExtension() { InputDeviceExtension::~InputDeviceExtension() {} -InputDeviceManager& InputDeviceExtension::manager() { - // Initialize API on first request - return InputDeviceManager::getInstance(); -} - common::Instance* InputDeviceExtension::CreateInstance() { return new InputDeviceInstance; } diff --git a/src/inputdevice/inputdevice_extension.h b/src/inputdevice/inputdevice_extension.h index 0b07f282..ae38eadd 100644 --- a/src/inputdevice/inputdevice_extension.h +++ b/src/inputdevice/inputdevice_extension.h @@ -5,7 +5,6 @@ #ifndef SRC_INPUTDEVICE_INPUTDEVICE_EXTENSION_H_ #define SRC_INPUTDEVICE_INPUTDEVICE_EXTENSION_H_ -#include "../inputdevice/inputdevice_manager.h" #include "common/extension.h" namespace extension { @@ -16,8 +15,6 @@ class InputDeviceExtension : public common::Extension { InputDeviceExtension(); virtual ~InputDeviceExtension(); - InputDeviceManager& manager(); - private: virtual common::Instance* CreateInstance(); }; diff --git a/src/inputdevice/inputdevice_instance.cc b/src/inputdevice/inputdevice_instance.cc index 5d48e2c5..d5b7fc41 100644 --- a/src/inputdevice/inputdevice_instance.cc +++ b/src/inputdevice/inputdevice_instance.cc @@ -14,12 +14,8 @@ * limitations under the License. */ -#include -#include -#include #include "../inputdevice/inputdevice_instance.h" -#include "../inputdevice/inputdevice_manager.h" #include "common/logger.h" @@ -28,52 +24,11 @@ namespace inputdevice { InputDeviceInstance::InputDeviceInstance() { LOGD("Enter"); - using std::placeholders::_1; - using std::placeholders::_2; - #define REGISTER_SYNC(c, x) \ - RegisterSyncHandler(c, std::bind(&InputDeviceInstance::x, this, _1, _2)); - REGISTER_SYNC("TVInputDeviceManager_getSupportedKeys", getSupportedKeys); - REGISTER_SYNC("TVInputDeviceManager_getKey", getKey); - #undef REGISTER_SYNC } InputDeviceInstance::~InputDeviceInstance() { LOGD("Enter"); } -picojson::value InputDeviceInstance::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 InputDeviceInstance::getSupportedKeys(const picojson::value& args, - picojson::object& out) { - LOGD("Enter"); - std::vector inputDeviceKeys = - InputDeviceManager::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 InputDeviceInstance::getKey(const picojson::value& args, - picojson::object& out) { - LOGD("Enter"); - std::string keyName = args.get("keyName").get(); - InputDeviceKeyPtr keyPtr = - InputDeviceManager::getInstance().getKey(keyName); - ReportSuccess(inputDeviceKeyToJson(keyPtr), out); -} - } // namespace inputdevice } // namespace extension diff --git a/src/inputdevice/inputdevice_instance.h b/src/inputdevice/inputdevice_instance.h index 7f976cdd..c09b16a5 100644 --- a/src/inputdevice/inputdevice_instance.h +++ b/src/inputdevice/inputdevice_instance.h @@ -17,7 +17,6 @@ #ifndef SRC_INPUTDEVICE_INPUTDEVICE_INSTANCE_H_ #define SRC_INPUTDEVICE_INPUTDEVICE_INSTANCE_H_ -#include "../inputdevice/inputdevice_manager.h" #include "common/picojson.h" #include "common/extension.h" @@ -31,9 +30,6 @@ class InputDeviceInstance : public common::ParsedInstance { virtual ~InputDeviceInstance(); 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); }; } // namespace inputdevice diff --git a/src/inputdevice/inputdevice_key.cc b/src/inputdevice/inputdevice_key.cc deleted file mode 100644 index 0b4332dc..00000000 --- a/src/inputdevice/inputdevice_key.cc +++ /dev/null @@ -1,61 +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 "../inputdevice/inputdevice_key.h" -#include "common/logger.h" -#include "common/platform_exception.h" - - -namespace extension { -namespace inputdevice { - -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 inputdevice -} // namespace extension diff --git a/src/inputdevice/inputdevice_key.h b/src/inputdevice/inputdevice_key.h deleted file mode 100644 index e6111b3a..00000000 --- a/src/inputdevice/inputdevice_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_INPUTDEVICE_INPUTDEVICE_KEY_H_ -#define SRC_INPUTDEVICE_INPUTDEVICE_KEY_H_ - -#include -#include -#include - -namespace extension { -namespace inputdevice { - -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 inputdevice -} // namespace extension - -#endif // SRC_INPUTDEVICE_INPUTDEVICE_KEY_H_ diff --git a/src/inputdevice/inputdevice_manager.cc b/src/inputdevice/inputdevice_manager.cc deleted file mode 100755 index 82dc0a5f..00000000 --- a/src/inputdevice/inputdevice_manager.cc +++ /dev/null @@ -1,85 +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 "../inputdevice/inputdevice_manager.h" -#include -#include - -#include "common/logger.h" -#include "common/platform_exception.h" - - -namespace extension { -namespace inputdevice { - -using common::UnknownException; -using common::InvalidValuesException; - -InputDeviceManager::InputDeviceManager() { - LOGD("Enter"); - setSupportedKeys(); -} - -InputDeviceManager::~InputDeviceManager() { - LOGD("Enter"); - cleanSupportedKeys(); -} - -InputDeviceManager& InputDeviceManager::getInstance() { - LOGD("Enter"); - static InputDeviceManager instance; - return instance; -} - -void InputDeviceManager::cleanSupportedKeys() { - LOGD("Enter"); - m_availableKeys.clear(); -} - -void InputDeviceManager::setSupportedKeys() { - LOGD("Entered"); - cleanSupportedKeys(); - InputDeviceKeyPtr key(new InputDeviceKey()); - m_availableKeys.push_back(key); -} - -InputDeviceKeyPtr InputDeviceManager::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; - } -} - -std::vector InputDeviceManager::getSupportedKeys() const { - LOGD("Enter"); - return m_availableKeys; -} - -} // namespace inputdevice -} // namespace extension diff --git a/src/inputdevice/inputdevice_manager.h b/src/inputdevice/inputdevice_manager.h deleted file mode 100755 index f089ed12..00000000 --- a/src/inputdevice/inputdevice_manager.h +++ /dev/null @@ -1,50 +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_INPUTDEVICE_INPUTDEVICE_MANAGER_H_ -#define SRC_INPUTDEVICE_INPUTDEVICE_MANAGER_H_ - -#include -#include - -#include "../inputdevice/inputdevice_key.h" - -namespace extension { -namespace inputdevice { - -class InputDeviceManager { - public: - InputDeviceKeyPtr getKey(std::string const& keyName) const; - - std::vector getSupportedKeys() const; - - static InputDeviceManager& getInstance(); - - virtual ~InputDeviceManager(); - - private: - InputDeviceManager(); - - void setSupportedKeys(); - std::vector m_availableKeys; - - void cleanSupportedKeys(); -}; - -} // namespace inputdevice -} // namespace extension - -#endif // SRC_INPUTDEVICE_INPUTDEVICE_MANAGER_H_