diff options
author | montellese <montellese@xbmc.org> | 2012-05-26 14:25:23 +0200 |
---|---|---|
committer | montellese <montellese@xbmc.org> | 2012-07-10 15:44:33 +0200 |
commit | f87c0b0c45a6a50ac98b41148dae01fe3e24be21 (patch) | |
tree | e5fd3134e14bbdd40f9fc76a25d0bdcf43f34c46 | |
parent | 15de54024b43a1340ac5605cda11e60d435b1677 (diff) |
jsonrpc: add Input.ExecuteAction
-rw-r--r-- | xbmc/input/ButtonTranslator.cpp | 9 | ||||
-rw-r--r-- | xbmc/input/ButtonTranslator.h | 3 | ||||
-rw-r--r-- | xbmc/interfaces/json-rpc/InputOperations.cpp | 10 | ||||
-rw-r--r-- | xbmc/interfaces/json-rpc/InputOperations.h | 1 | ||||
-rw-r--r-- | xbmc/interfaces/json-rpc/JSONRPC.cpp | 6 | ||||
-rw-r--r-- | xbmc/interfaces/json-rpc/JSONServiceDescription.cpp | 1 | ||||
-rw-r--r-- | xbmc/interfaces/json-rpc/ServiceDescription.h | 10 | ||||
-rw-r--r-- | xbmc/interfaces/json-rpc/methods.json | 10 |
8 files changed, 50 insertions, 0 deletions
diff --git a/xbmc/input/ButtonTranslator.cpp b/xbmc/input/ButtonTranslator.cpp index 1aa4e16007..022074855e 100644 --- a/xbmc/input/ButtonTranslator.cpp +++ b/xbmc/input/ButtonTranslator.cpp @@ -845,6 +845,15 @@ bool CButtonTranslator::TranslateJoystickString(int window, const char* szDevice } #endif +void CButtonTranslator::GetActions(std::vector<std::string> &actionList) +{ + unsigned int size = sizeof(actions) / sizeof(ActionMapping); + actionList.clear(); + actionList.reserve(size); + for (unsigned int index = 0; index < size; index++) + actionList.push_back(actions[index].name); +} + CAction CButtonTranslator::GetAction(int window, const CKey &key, bool fallback) { CStdString strAction; diff --git a/xbmc/input/ButtonTranslator.h b/xbmc/input/ButtonTranslator.h index d48c543b42..a8ba512e04 100644 --- a/xbmc/input/ButtonTranslator.h +++ b/xbmc/input/ButtonTranslator.h @@ -25,6 +25,7 @@ #pragma once #include <map> +#include <vector> #include "system.h" // for HAS_EVENT_SERVER, HAS_SDL_JOYSTICK, HAS_LIRC #ifdef HAS_EVENT_SERVER @@ -69,6 +70,8 @@ public: /// clears the maps void Clear(); + static void GetActions(std::vector<std::string> &actionList); + CAction GetAction(int window, const CKey &key, bool fallback = true); /*! \brief Translate between a window name and it's id diff --git a/xbmc/interfaces/json-rpc/InputOperations.cpp b/xbmc/interfaces/json-rpc/InputOperations.cpp index be918643b4..44603a45de 100644 --- a/xbmc/interfaces/json-rpc/InputOperations.cpp +++ b/xbmc/interfaces/json-rpc/InputOperations.cpp @@ -24,6 +24,7 @@ #include "guilib/GUIAudioManager.h" #include "guilib/GUIWindow.h" #include "guilib/GUIWindowManager.h" +#include "input/ButtonTranslator.h" #include "input/XBMC_keyboard.h" #include "input/XBMC_vkeys.h" #include "threads/SingleLock.h" @@ -109,6 +110,15 @@ JSONRPC_STATUS CInputOperations::SendText(const CStdString &method, ITransportLa return ACK; } +JSONRPC_STATUS CInputOperations::ExecuteAction(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) +{ + int action; + if (!CButtonTranslator::TranslateActionString(parameterObject["action"].asString().c_str(), action)) + return InvalidParams; + + return SendAction(action); +} + JSONRPC_STATUS CInputOperations::Left(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result) { return SendKey(XBMCVK_LEFT); diff --git a/xbmc/interfaces/json-rpc/InputOperations.h b/xbmc/interfaces/json-rpc/InputOperations.h index 69d19b9aff..00f2b80baf 100644 --- a/xbmc/interfaces/json-rpc/InputOperations.h +++ b/xbmc/interfaces/json-rpc/InputOperations.h @@ -33,6 +33,7 @@ namespace JSONRPC static CKey GetKey(); static JSONRPC_STATUS SendText(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result); + static JSONRPC_STATUS ExecuteAction(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result); static JSONRPC_STATUS Left(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result); static JSONRPC_STATUS Right(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result); diff --git a/xbmc/interfaces/json-rpc/JSONRPC.cpp b/xbmc/interfaces/json-rpc/JSONRPC.cpp index f4379529ee..31278b323a 100644 --- a/xbmc/interfaces/json-rpc/JSONRPC.cpp +++ b/xbmc/interfaces/json-rpc/JSONRPC.cpp @@ -23,6 +23,7 @@ #include "JSONRPC.h" #include "ServiceDescription.h" +#include "input/ButtonTranslator.h" #include "interfaces/AnnouncementManager.h" #include "settings/AdvancedSettings.h" #include "utils/log.h" @@ -39,6 +40,11 @@ void CJSONRPC::Initialize() if (m_initialized) return; + // Add some types/enums at runtime + vector<string> inputActions; + CButtonTranslator::GetActions(inputActions); + CJSONServiceDescription::AddEnum("Input.Action", inputActions); + unsigned int size = sizeof(JSONRPC_SERVICE_TYPES) / sizeof(char*); for (unsigned int index = 0; index < size; index++) diff --git a/xbmc/interfaces/json-rpc/JSONServiceDescription.cpp b/xbmc/interfaces/json-rpc/JSONServiceDescription.cpp index afda077dd7..ebb63a0a19 100644 --- a/xbmc/interfaces/json-rpc/JSONServiceDescription.cpp +++ b/xbmc/interfaces/json-rpc/JSONServiceDescription.cpp @@ -163,6 +163,7 @@ JsonRpcMethodMap CJSONServiceDescription::m_methodMaps[] = { // Input operations { "Input.SendText", CInputOperations::SendText }, + { "Input.ExecuteAction", CInputOperations::ExecuteAction }, { "Input.Left", CInputOperations::Left }, { "Input.Right", CInputOperations::Right }, { "Input.Down", CInputOperations::Down }, diff --git a/xbmc/interfaces/json-rpc/ServiceDescription.h b/xbmc/interfaces/json-rpc/ServiceDescription.h index 0f612d15e4..8d209ac5ae 100644 --- a/xbmc/interfaces/json-rpc/ServiceDescription.h +++ b/xbmc/interfaces/json-rpc/ServiceDescription.h @@ -2339,6 +2339,16 @@ namespace JSONRPC "]," "\"returns\": \"string\"" "}", + "\"Input.ExecuteAction\": {" + "\"type\": \"method\"," + "\"description\": \"Execute a specific action\"," + "\"transport\": \"Response\"," + "\"permission\": \"Navigate\"," + "\"params\": [" + "{ \"name\": \"action\", \"$ref\": \"Input.Action\", \"required\": true }" + "]," + "\"returns\": \"string\"" + "}", "\"Input.Left\": {" "\"type\": \"method\"," "\"description\": \"Navigate left in GUI\"," diff --git a/xbmc/interfaces/json-rpc/methods.json b/xbmc/interfaces/json-rpc/methods.json index ef5df2d18d..570a80adca 100644 --- a/xbmc/interfaces/json-rpc/methods.json +++ b/xbmc/interfaces/json-rpc/methods.json @@ -1474,6 +1474,16 @@ ], "returns": "string" }, + "Input.ExecuteAction": { + "type": "method", + "description": "Execute a specific action", + "transport": "Response", + "permission": "Navigate", + "params": [ + { "name": "action", "$ref": "Input.Action", "required": true } + ], + "returns": "string" + }, "Input.Left": { "type": "method", "description": "Navigate left in GUI", |