[TVInputDevice] Stub
authorMariusz Polasinski <m.polasinski@samsung.com>
Mon, 29 Dec 2014 12:29:38 +0000 (13:29 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Wed, 4 Feb 2015 08:05:01 +0000 (17:05 +0900)
[Verification]
Code complies without error
Methods are visible in node (and returns hardcoded values)

Change-Id: Id5bd9cb20141cf4f63f69ba5eebe69b801a6b4b8
Signed-off-by: Mariusz Polasinski <m.polasinski@samsung.com>
src/tvinputdevice/tvinputdevice.gyp
src/tvinputdevice/tvinputdevice_api.js [new file with mode: 0644]
src/tvinputdevice/tvinputdevice_extension.cc [new file with mode: 0644]
src/tvinputdevice/tvinputdevice_extension.h [new file with mode: 0644]
src/tvinputdevice/tvinputdevice_instance.cc [new file with mode: 0644]
src/tvinputdevice/tvinputdevice_instance.h [new file with mode: 0644]
src/tvinputdevice/tvinputdevice_key.cc [new file with mode: 0644]
src/tvinputdevice/tvinputdevice_key.h [new file with mode: 0644]
src/tvinputdevice/tvinputdevice_manager.cc [new file with mode: 0755]
src/tvinputdevice/tvinputdevice_manager.h [new file with mode: 0755]

index 5ed68ef25c095e8e141a118a01086cfa02872ea7..c0201fa1e001e5b35002ad6b3c6255ca19875143 100644 (file)
@@ -7,6 +7,15 @@
       'target_name': 'tizen_tvinputdevice',
       'type': 'loadable_module',
       'sources': [
+        'tvinputdevice_api.js',
+        'tvinputdevice_extension.cc',
+        'tvinputdevice_extension.h',
+        'tvinputdevice_instance.cc',
+        'tvinputdevice_instance.h',
+        'tvinputdevice_key.cc',
+        'tvinputdevice_key.h',
+        'tvinputdevice_manager.cc',
+        'tvinputdevice_manager.h'
       ],
       'includes': [
         '../common/pkg-config.gypi',
diff --git a/src/tvinputdevice/tvinputdevice_api.js b/src/tvinputdevice/tvinputdevice_api.js
new file mode 100644 (file)
index 0000000..5e549e1
--- /dev/null
@@ -0,0 +1,120 @@
+/* global xwalk, extension, tizen */
+
+// 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.
+
+
+var native = new xwalk.utils.NativeManager(extension);
+var validator = xwalk.utils.validator;
+var types = validator.Types;
+
+
+function InputDeviceKey(dict) {
+  for (var key in dict) {
+    if (dict.hasOwnProperty(key)) {
+      Object.defineProperty(this, key, {
+        value: dict[key],
+        enumerable: true
+      });
+    }
+  }
+  Object.freeze(this);
+}
+
+
+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
+ */
+function TVInputDeviceManager() {
+  if (!(this instanceof TVInputDeviceManager)) {
+    throw new TypeError;
+  }
+}
+
+
+/**
+ * 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);
+  }
+  return dictListToInputDeviceKeyList(native.getResultObject(ret));
+};
+
+
+/**
+ * Returns information about the key which has the given name.
+ * @param {!string} keyName  The key name
+ * @return {object} Key object
+ */
+TVInputDeviceManager.prototype.getKey = function(keyName) {
+  var args = validator.validateArgs(arguments, [
+    {name: 'keyName', type: types.STRING}
+  ]);
+
+  var ret = native.callSync('TVInputDeviceManager_getKey', {
+    keyName: args.keyName
+  });
+
+  if (native.isFailure(ret)) {
+    throw native.getErrorObject(ret);
+  }
+  return native.getResultObject(ret);
+};
+
+
+/**
+ * Registers an input device key to receive DOM keyboard event when it is pressed or released.
+ * @param {!string} keyName  The key name
+ */
+TVInputDeviceManager.prototype.registerKey = function(keyName) {
+  var args = validator.validateArgs(arguments, [
+    {name: 'keyName', type: types.STRING}
+  ]);
+
+  var ret = native.callSync('TVInputDeviceManager_registerKey', {
+    keyName: args.keyName
+  });
+
+  if (native.isFailure(ret)) {
+    throw native.getErrorObject(ret);
+  }
+};
+
+
+/**
+ * Unregisters an input device key.
+ * @param {!string} keyName  The key name
+ */
+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 (native.isFailure(ret)) {
+    throw native.getErrorObject(ret);
+  }
+};
+
+
+// Exports
+exports = new TVInputDeviceManager();
diff --git a/src/tvinputdevice/tvinputdevice_extension.cc b/src/tvinputdevice/tvinputdevice_extension.cc
new file mode 100644 (file)
index 0000000..8256147
--- /dev/null
@@ -0,0 +1,35 @@
+// 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[];
+
+namespace extension {
+namespace tvinputdevice {
+
+TVInputDeviceExtension::TVInputDeviceExtension() {
+    SetExtensionName("tizen.tvinputdevice");
+    SetJavaScriptAPI(kSource_tvinputdevice_api);
+}
+
+TVInputDeviceExtension::~TVInputDeviceExtension() {}
+
+TVInputDeviceManager& TVInputDeviceExtension::manager() {
+    // Initialize API on first request
+    return TVInputDeviceManager::getInstance();
+}
+
+common::Instance* TVInputDeviceExtension::CreateInstance() {
+    return new TVInputDeviceInstance;
+}
+
+}  // namespace tvinputdevice
+}  // namespace extension
+
+common::Extension* CreateExtension() {
+    return new extension::tvinputdevice::TVInputDeviceExtension;
+}
diff --git a/src/tvinputdevice/tvinputdevice_extension.h b/src/tvinputdevice/tvinputdevice_extension.h
new file mode 100644 (file)
index 0000000..a136efb
--- /dev/null
@@ -0,0 +1,29 @@
+// 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 {
+
+class TVInputDeviceExtension : public common::Extension {
+ public:
+    TVInputDeviceExtension();
+    virtual ~TVInputDeviceExtension();
+
+    TVInputDeviceManager& manager();
+
+ private:
+    virtual common::Instance* CreateInstance();
+};
+
+}  // namespace tvinputdevice
+}  // namespace extension
+
+#endif  // SRC_TVINPUTDEVICE_TVINPUTDEVICE_EXTENSION_H_
+
diff --git a/src/tvinputdevice/tvinputdevice_instance.cc b/src/tvinputdevice/tvinputdevice_instance.cc
new file mode 100644 (file)
index 0000000..8d991cb
--- /dev/null
@@ -0,0 +1,85 @@
+// 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 <functional>
+#include <string>
+#include <vector>
+
+#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
diff --git a/src/tvinputdevice/tvinputdevice_instance.h b/src/tvinputdevice/tvinputdevice_instance.h
new file mode 100644 (file)
index 0000000..2d9f1a9
--- /dev/null
@@ -0,0 +1,32 @@
+// 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_INSTANCE_H_
+#define SRC_TVINPUTDEVICE_TVINPUTDEVICE_INSTANCE_H_
+
+#include "common/picojson.h"
+#include "common/extension.h"
+
+#include "tvinputdevice/tvinputdevice_manager.h"
+
+namespace extension {
+namespace tvinputdevice {
+
+class TVInputDeviceInstance : public common::ParsedInstance {
+ public:
+    TVInputDeviceInstance();
+    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
+}  // namespace extension
+
+#endif  // SRC_TVINPUTDEVICE_TVINPUTDEVICE_INSTANCE_H_
diff --git a/src/tvinputdevice/tvinputdevice_key.cc b/src/tvinputdevice/tvinputdevice_key.cc
new file mode 100644 (file)
index 0000000..42882c0
--- /dev/null
@@ -0,0 +1,48 @@
+// 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 "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
new file mode 100644 (file)
index 0000000..4cdbd62
--- /dev/null
@@ -0,0 +1,39 @@
+// 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_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
new file mode 100755 (executable)
index 0000000..e121394
--- /dev/null
@@ -0,0 +1,78 @@
+// 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 <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
new file mode 100755 (executable)
index 0000000..723fa5f
--- /dev/null
@@ -0,0 +1,41 @@
+// 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_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();
+
+ private:
+    TVInputDeviceManager();
+    virtual ~TVInputDeviceManager();
+
+    void setSupportedKeys();
+    std::vector<InputDeviceKeyPtr> m_availableKeys;
+
+    void cleanSupportedKeys();
+};
+
+}  // namespace tvinputdevice
+}  // namespace extension
+
+#endif  // SRC_TVINPUTDEVICE_TVINPUTDEVICE_MANAGER_H_