'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',
--- /dev/null
+/* 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();
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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_
+
--- /dev/null
+// 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
--- /dev/null
+// 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_
--- /dev/null
+// 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
--- /dev/null
+// 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_
--- /dev/null
+// 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
--- /dev/null
+// 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_