'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',
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 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
}
}
-
/**
* 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;
};
{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 } );
+
};
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);
{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);
// found in the LICENSE file.
#include "../inputdevice/inputdevice_extension.h"
-
#include "../inputdevice/inputdevice_instance.h"
// This will be generated from inputdevice_api.js
InputDeviceExtension::~InputDeviceExtension() {}
-InputDeviceManager& InputDeviceExtension::manager() {
- // Initialize API on first request
- return InputDeviceManager::getInstance();
-}
-
common::Instance* InputDeviceExtension::CreateInstance() {
return new InputDeviceInstance;
}
#ifndef SRC_INPUTDEVICE_INPUTDEVICE_EXTENSION_H_
#define SRC_INPUTDEVICE_INPUTDEVICE_EXTENSION_H_
-#include "../inputdevice/inputdevice_manager.h"
#include "common/extension.h"
namespace extension {
InputDeviceExtension();
virtual ~InputDeviceExtension();
- InputDeviceManager& manager();
-
private:
virtual common::Instance* CreateInstance();
};
* limitations under the License.
*/
-#include <functional>
-#include <string>
-#include <vector>
#include "../inputdevice/inputdevice_instance.h"
-#include "../inputdevice/inputdevice_manager.h"
#include "common/logger.h"
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
#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"
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
+++ /dev/null
-/*
- * 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
+++ /dev/null
-/*
- * 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_
+++ /dev/null
-/*
- * 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
+++ /dev/null
-/*
- * 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_