Permalink
Browse files

jsonrpc: add Input.ExecuteAction

  • Loading branch information...
Montellese committed May 26, 2012
1 parent 15de540 commit f87c0b0c45a6a50ac98b41148dae01fe3e24be21
@@ -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;
@@ -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 @@ class CButtonTranslator
/// 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
@@ -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 &parameterObject, 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 &parameterObject, CVariant &result)
{
return SendKey(XBMCVK_LEFT);
@@ -33,6 +33,7 @@ namespace JSONRPC
static CKey GetKey();
static JSONRPC_STATUS SendText(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS ExecuteAction(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS Left(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS Right(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
@@ -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++)
@@ -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 },
@@ -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\","
@@ -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",

0 comments on commit f87c0b0

Please sign in to comment.