Skip to content

Commit

Permalink
jsonrpc: add Input.ExecuteAction
Browse files Browse the repository at this point in the history
  • Loading branch information
Montellese committed Jul 10, 2012
1 parent 15de540 commit f87c0b0
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 0 deletions.
9 changes: 9 additions & 0 deletions xbmc/input/ButtonTranslator.cpp
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions xbmc/input/ButtonTranslator.h
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions xbmc/interfaces/json-rpc/InputOperations.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions xbmc/interfaces/json-rpc/InputOperations.h
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions xbmc/interfaces/json-rpc/JSONRPC.cpp
Expand Up @@ -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"
Expand All @@ -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++)
Expand Down
1 change: 1 addition & 0 deletions xbmc/interfaces/json-rpc/JSONServiceDescription.cpp
Expand Up @@ -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 },
Expand Down
10 changes: 10 additions & 0 deletions xbmc/interfaces/json-rpc/ServiceDescription.h
Expand Up @@ -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\","
Expand Down
10 changes: 10 additions & 0 deletions xbmc/interfaces/json-rpc/methods.json
Expand Up @@ -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",
Expand Down

0 comments on commit f87c0b0

Please sign in to comment.