[InputDevice] Implementation moved to java script
authorLukasz Foniok <l.foniok@samsung.com>
Thu, 14 May 2015 12:53:00 +0000 (14:53 +0200)
committerpius lee <pius.lee@samsung.com>
Tue, 30 Jun 2015 04:33:50 +0000 (13:33 +0900)
[Verification]
tizen.inputdevice.getSupportedKeys()
tizen.inputdevice.getKeyName("VolumeUp")
tizen.inputdevice.registerKey("VolumeUp")
tizen.inputdevice.unregisterKey("VolumeUp")

Change-Id: Ic952a24dab39be5fd66f9d101f0c7f0aa47ea243
Signed-off-by: Lukasz Foniok <l.foniok@samsung.com>
src/inputdevice/inputdevice.gyp
src/inputdevice/inputdevice_api.js
src/inputdevice/inputdevice_extension.cc
src/inputdevice/inputdevice_extension.h
src/inputdevice/inputdevice_instance.cc
src/inputdevice/inputdevice_instance.h
src/inputdevice/inputdevice_key.cc [deleted file]
src/inputdevice/inputdevice_key.h [deleted file]
src/inputdevice/inputdevice_manager.cc [deleted file]
src/inputdevice/inputdevice_manager.h [deleted file]

index 8d5a99474324d072a99c1a050905a32da1eef465..77a76b07a3dcb724b68482e693fea2c89439146b 100644 (file)
         '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',
index 4e194571f79449b9d0ec03b37c6425a67a7f28b4..d689b6e2a5ddaaf2be40f5f5c22bce46880b8ddb 100644 (file)
 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);
index f078dbe74eeb362800fb58ef90632b8e870ccb95..cf59eab9fa0542954348c36fc9667c8062498cf8 100644 (file)
@@ -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;
 }
index 0b07f282414a2700eb8ccd0f31379767a07ecd5a..ae38eaddb34a308c5971743aa3f183b4787796e8 100644 (file)
@@ -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();
 };
index 5d48e2c5b43536e82f4d2af5221033044c86b6ea..d5b7fc416fc5001cbb44cd1370d103f69e996e3a 100644 (file)
  *    limitations under the License.
  */
  
-#include <functional>
-#include <string>
-#include <vector>
 
 #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<double>(keyPtr->getCode()))));
-    return picojson::value(keyMap);
-}
-
-void InputDeviceInstance::getSupportedKeys(const picojson::value& args,
-        picojson::object& out) {
-    LOGD("Enter");
-    std::vector<InputDeviceKeyPtr> 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<std::string>();
-    InputDeviceKeyPtr keyPtr =
-            InputDeviceManager::getInstance().getKey(keyName);
-    ReportSuccess(inputDeviceKeyToJson(keyPtr), out);
-}
-
 }  // namespace inputdevice
 }  // namespace extension
index 7f976cdd7b4a5f1a2c16e00c31edf58b7355daf8..c09b16a5bb8ad154d5e3a0353f1b6381efb398cd 100644 (file)
@@ -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 (file)
index 0b4332d..0000000
+++ /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 (file)
index e6111b3..0000000
+++ /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 <sys/types.h>
-#include <string>
-#include <memory>
-
-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<InputDeviceKey> 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 (executable)
index 82dc0a5..0000000
+++ /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 <sys/types.h>
-#include <algorithm>
-
-#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<InputDeviceKeyPtr> 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 (executable)
index f089ed1..0000000
+++ /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 <vector>
-#include <string>
-
-#include "../inputdevice/inputdevice_key.h"
-
-namespace extension {
-namespace inputdevice {
-
-class InputDeviceManager {
- public:
-    InputDeviceKeyPtr getKey(std::string const& keyName) const;
-
-    std::vector<InputDeviceKeyPtr> getSupportedKeys() const;
-
-    static InputDeviceManager& getInstance();
-
-    virtual ~InputDeviceManager();
-
- private:
-    InputDeviceManager();
-
-    void setSupportedKeys();
-    std::vector<InputDeviceKeyPtr> m_availableKeys;
-
-    void cleanSupportedKeys();
-};
-
-}  // namespace inputdevice
-}  // namespace extension
-
-#endif  // SRC_INPUTDEVICE_INPUTDEVICE_MANAGER_H_