[TV][InputDevice] Adding synchronous call for registering and unregistering keys
authorPiotr Czaja <p.czaja@samsung.com>
Wed, 24 Jun 2015 13:14:20 +0000 (15:14 +0200)
committerPiotr Czaja <p.czaja@samsung.com>
Fri, 26 Jun 2015 09:16:58 +0000 (11:16 +0200)
Change-Id: Ic330564dab503907ce67850cd6ffbb615e475b05
Signed-off-by: Piotr Czaja <p.czaja@samsung.com>
src/tvinputdevice/tvinputdevice.gyp
src/tvinputdevice/tvinputdevice_api.js
src/tvinputdevice/tvinputdevice_extension.cc
src/tvinputdevice/tvinputdevice_extension.h
src/tvinputdevice/tvinputdevice_instance.cc
src/tvinputdevice/tvinputdevice_instance.h
src/tvinputdevice/tvinputdevice_key.cc [deleted file]
src/tvinputdevice/tvinputdevice_key.h [deleted file]
src/tvinputdevice/tvinputdevice_manager.cc [deleted file]
src/tvinputdevice/tvinputdevice_manager.h [deleted file]

index d404756d624d5054ea6783ffce235dd3dc98f70a..9bd3ab0c5f2f8b2c0264ebce3b34819cc87e39c4 100644 (file)
         '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',
index f4deb54c3d4dbb1f1e19ddd49affb8ae08c4d902..0c58d8f4dae9fe459e06748dd390384c68dea628 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) {
+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);
index 050161497ee17620b87889c8382d38ed83cfe98b..e007872f45e619504072678a410d2192bf28545a 100644 (file)
@@ -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;
 }
index b82ec23b67603bd042b45abc3ea4f416ffe8e2d0..8a633f15b095e85c8a86cde855542dc5a9148bcf 100644 (file)
@@ -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();
 };
index f78fc98eb81b4204ab5dd9496e90b5b1c679d72b..fe926ca4b5f3312fc9689b72ffcf9ff58222f05f 100644 (file)
  *    limitations under the License.
  */
  
-#include <functional>
-#include <string>
-#include <vector>
 
+#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<double>(keyPtr->getCode()))));
-    return picojson::value(keyMap);
-}
-
-void TVInputDeviceInstance::getSupportedKeys(const picojson::value& args,
-        picojson::object& out) {
-    LOGD("Enter");
-    std::vector<InputDeviceKeyPtr> 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<std::string>();
-    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<std::string>();
-    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<std::string>();
-    TVInputDeviceManager::getInstance().unregisterKey(keyName);
-    ReportSuccess(out);
-}
-
 }  // namespace tvinputdevice
 }  // namespace extension
index 45eab85813f43144d7cf6885379f7c5fe977a6b4..d48248e1e58ead63f2d2035151beb1f3fc5c6db7 100644 (file)
@@ -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 (file)
index c655279..0000000
+++ /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 (file)
index 1fd4d9c..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_TVINPUTDEVICE_TVINPUTDEVICE_KEY_H_
-#define SRC_TVINPUTDEVICE_TVINPUTDEVICE_KEY_H_
-
-#include <sys/types.h>
-#include <string>
-#include <memory>
-
-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<InputDeviceKey> 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 (executable)
index fa0344b..0000000
+++ /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 <sys/types.h>
-#include <algorithm>
-
-#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<InputDeviceKeyPtr> 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 (executable)
index 874a0c9..0000000
+++ /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 <vector>
-#include <string>
-
-#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<InputDeviceKeyPtr> getSupportedKeys() const;
-
-    static TVInputDeviceManager& getInstance();
-
-    virtual ~TVInputDeviceManager();
-
- private:
-    TVInputDeviceManager();
-
-    void setSupportedKeys();
-    std::vector<InputDeviceKeyPtr> m_availableKeys;
-
-    void cleanSupportedKeys();
-};
-
-}  // namespace tvinputdevice
-}  // namespace extension
-
-#endif  // SRC_TVINPUTDEVICE_TVINPUTDEVICE_MANAGER_H_