Skip to content

Commit

Permalink
jsonrpc: move GetInfoLabels and GetInfoBooleans from System to XBMC n…
Browse files Browse the repository at this point in the history
…amespace
  • Loading branch information
Montellese authored and opdenkamp committed Sep 19, 2011
1 parent 5ecc7aa commit deab193
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 126 deletions.
6 changes: 3 additions & 3 deletions xbmc/interfaces/json-rpc/JSONServiceDescription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,6 @@ JsonRpcMethodMap CJSONServiceDescription::m_methodMaps[] = {
{ "System.Suspend", CSystemOperations::Suspend },
{ "System.Hibernate", CSystemOperations::Hibernate },
{ "System.Reboot", CSystemOperations::Reboot },
{ "System.GetInfoLabels", CSystemOperations::GetInfoLabels },
{ "System.GetInfoBooleans", CSystemOperations::GetInfoBooleans },

// Input operations
{ "Input.Left", CInputOperations::Left },
Expand All @@ -254,7 +252,9 @@ JsonRpcMethodMap CJSONServiceDescription::m_methodMaps[] = {

// XBMC operations
{ "XBMC.Play", CXBMCOperations::Play },
{ "XBMC.StartSlideshow", CXBMCOperations::StartSlideshow }
{ "XBMC.StartSlideshow", CXBMCOperations::StartSlideshow },
{ "XBMC.GetInfoLabels", CXBMCOperations::GetInfoLabels },
{ "XBMC.GetInfoBooleans", CXBMCOperations::GetInfoBooleans }
};

bool CJSONServiceDescription::prepareDescription(std::string &description, CVariant &descriptionObject, std::string &name)
Expand Down
52 changes: 26 additions & 26 deletions xbmc/interfaces/json-rpc/ServiceDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -2262,32 +2262,6 @@ namespace JSONRPC
"\"params\": [],"
"\"returns\": \"string\""
"}",
"\"System.GetInfoLabels\": {"
"\"type\": \"method\","
"\"description\": \"Retrieve info labels about the system\","
"\"transport\": \"Response\","
"\"permission\": \"ReadData\","
"\"params\": ["
"{ \"name\": \"labels\", \"type\": \"array\", \"required\": true, \"items\": { \"type\": \"string\" }, \"minItems\": 1, \"description\": \"See http://wiki.xbmc.org/index.php?title=InfoLabels for a list of possible info labels\" }"
"],"
"\"returns\": {"
"\"type\": \"object\","
"\"description\": \"List of key-value pairs of the retrieved info labels\""
"}"
"}",
"\"System.GetInfoBooleans\": {"
"\"type\": \"method\","
"\"description\": \"Retrieve info booleans about the system\","
"\"transport\": \"Response\","
"\"permission\": \"ReadData\","
"\"params\": ["
"{ \"name\": \"booleans\", \"type\": \"array\", \"required\": true, \"items\": { \"type\": \"string\" }, \"minItems\": 1 }"
"],"
"\"returns\": {"
"\"type\": \"object\","
"\"description\": \"List of key-value pairs of the retrieved info booleans\""
"}"
"}",
"\"Input.Left\": {"
"\"type\": \"method\","
"\"description\": \"Navigate left in GUI\","
Expand Down Expand Up @@ -2401,6 +2375,32 @@ namespace JSONRPC
"{ \"name\": \"recursive\", \"type\": \"boolean\", \"default\": true }"
"],"
"\"returns\": \"string\""
"}",
"\"XBMC.GetInfoLabels\": {"
"\"type\": \"method\","
"\"description\": \"Retrieve info labels about XBMC and the system\","
"\"transport\": \"Response\","
"\"permission\": \"ReadData\","
"\"params\": ["
"{ \"name\": \"labels\", \"type\": \"array\", \"required\": true, \"items\": { \"type\": \"string\" }, \"minItems\": 1, \"description\": \"See http://wiki.xbmc.org/index.php?title=InfoLabels for a list of possible info labels\" }"
"],"
"\"returns\": {"
"\"type\": \"object\","
"\"description\": \"List of key-value pairs of the retrieved info labels\""
"}"
"}",
"\"XBMC.GetInfoBooleans\": {"
"\"type\": \"method\","
"\"description\": \"Retrieve info booleans about XBMC and the system\","
"\"transport\": \"Response\","
"\"permission\": \"ReadData\","
"\"params\": ["
"{ \"name\": \"booleans\", \"type\": \"array\", \"required\": true, \"items\": { \"type\": \"string\" }, \"minItems\": 1 }"
"],"
"\"returns\": {"
"\"type\": \"object\","
"\"description\": \"List of key-value pairs of the retrieved info booleans\""
"}"
"}"
};

Expand Down
67 changes: 0 additions & 67 deletions xbmc/interfaces/json-rpc/SystemOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,73 +88,6 @@ JSON_STATUS CSystemOperations::Reboot(const CStdString &method, ITransportLayer
return FailedToExecute;
}

JSON_STATUS CSystemOperations::GetInfoLabels(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
std::vector<CStdString> info;

for (unsigned int i = 0; i < parameterObject["labels"].size(); i++)
{
CStdString field = parameterObject["labels"][i].asString();
field = field.ToLower();

info.push_back(parameterObject["labels"][i].asString());
}

if (info.size() > 0)
{
std::vector<CStdString> infoLabels = g_application.getApplicationMessenger().GetInfoLabels(info);
for (unsigned int i = 0; i < info.size(); i++)
{
if (i >= infoLabels.size())
break;
result[info[i].c_str()] = infoLabels[i];
}
}

return OK;
}

JSON_STATUS CSystemOperations::GetInfoBooleans(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
std::vector<CStdString> info;

bool CanControlPower = (client->GetPermissionFlags() & ControlPower) > 0;

for (unsigned int i = 0; i < parameterObject["booleans"].size(); i++)
{
CStdString field = parameterObject["booleans"][i].asString();
field = field.ToLower();

// Need to override power management of whats in infomanager since jsonrpc
// have a security layer aswell.
if (field.Equals("system.canshutdown"))
result[parameterObject["booleans"][i].asString()] = (g_powerManager.CanPowerdown() && CanControlPower);
else if (field.Equals("system.canpowerdown"))
result[parameterObject["booleans"][i].asString()] = (g_powerManager.CanPowerdown() && CanControlPower);
else if (field.Equals("system.cansuspend"))
result[parameterObject["booleans"][i].asString()] = (g_powerManager.CanSuspend() && CanControlPower);
else if (field.Equals("system.canhibernate"))
result[parameterObject["booleans"][i].asString()] = (g_powerManager.CanHibernate() && CanControlPower);
else if (field.Equals("system.canreboot"))
result[parameterObject["booleans"][i].asString()] = (g_powerManager.CanReboot() && CanControlPower);
else
info.push_back(parameterObject["booleans"][i].asString());
}

if (info.size() > 0)
{
std::vector<bool> infoLabels = g_application.getApplicationMessenger().GetInfoBooleans(info);
for (unsigned int i = 0; i < info.size(); i++)
{
if (i >= infoLabels.size())
break;
result[info[i].c_str()] = CVariant(infoLabels[i]);
}
}

return OK;
}

JSON_STATUS CSystemOperations::GetPropertyValue(int permissions, const CStdString &property, CVariant &result)
{
if (property.Equals("canshutdown"))
Expand Down
3 changes: 0 additions & 3 deletions xbmc/interfaces/json-rpc/SystemOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ namespace JSONRPC
static JSON_STATUS Suspend(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSON_STATUS Hibernate(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSON_STATUS Reboot(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);

static JSON_STATUS GetInfoLabels(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSON_STATUS GetInfoBooleans(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
private:
static JSON_STATUS GetPropertyValue(int permissions, const CStdString &property, CVariant &result);
};
Expand Down
69 changes: 68 additions & 1 deletion xbmc/interfaces/json-rpc/XBMCOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "ApplicationMessenger.h"
#include "FileItem.h"
#include "Util.h"
#include "utils/log.h"
#include "powermanagement/PowerManager.h"

using namespace JSONRPC;

Expand Down Expand Up @@ -60,3 +60,70 @@ JSON_STATUS CXBMCOperations::StartSlideshow(const CStdString &method, ITransport

return ACK;
}

JSON_STATUS CXBMCOperations::GetInfoLabels(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
std::vector<CStdString> info;

for (unsigned int i = 0; i < parameterObject["labels"].size(); i++)
{
CStdString field = parameterObject["labels"][i].asString();
field = field.ToLower();

info.push_back(parameterObject["labels"][i].asString());
}

if (info.size() > 0)
{
std::vector<CStdString> infoLabels = g_application.getApplicationMessenger().GetInfoLabels(info);
for (unsigned int i = 0; i < info.size(); i++)
{
if (i >= infoLabels.size())
break;
result[info[i].c_str()] = infoLabels[i];
}
}

return OK;
}

JSON_STATUS CXBMCOperations::GetInfoBooleans(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
std::vector<CStdString> info;

bool CanControlPower = (client->GetPermissionFlags() & ControlPower) > 0;

for (unsigned int i = 0; i < parameterObject["booleans"].size(); i++)
{
CStdString field = parameterObject["booleans"][i].asString();
field = field.ToLower();

// Need to override power management of whats in infomanager since jsonrpc
// have a security layer aswell.
if (field.Equals("system.canshutdown"))
result[parameterObject["booleans"][i].asString()] = (g_powerManager.CanPowerdown() && CanControlPower);
else if (field.Equals("system.canpowerdown"))
result[parameterObject["booleans"][i].asString()] = (g_powerManager.CanPowerdown() && CanControlPower);
else if (field.Equals("system.cansuspend"))
result[parameterObject["booleans"][i].asString()] = (g_powerManager.CanSuspend() && CanControlPower);
else if (field.Equals("system.canhibernate"))
result[parameterObject["booleans"][i].asString()] = (g_powerManager.CanHibernate() && CanControlPower);
else if (field.Equals("system.canreboot"))
result[parameterObject["booleans"][i].asString()] = (g_powerManager.CanReboot() && CanControlPower);
else
info.push_back(parameterObject["booleans"][i].asString());
}

if (info.size() > 0)
{
std::vector<bool> infoLabels = g_application.getApplicationMessenger().GetInfoBooleans(info);
for (unsigned int i = 0; i < info.size(); i++)
{
if (i >= infoLabels.size())
break;
result[info[i].c_str()] = CVariant(infoLabels[i]);
}
}

return OK;
}
3 changes: 3 additions & 0 deletions xbmc/interfaces/json-rpc/XBMCOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ namespace JSONRPC
public:
static JSON_STATUS Play(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSON_STATUS StartSlideshow(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);

static JSON_STATUS GetInfoLabels(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSON_STATUS GetInfoBooleans(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
};
}
52 changes: 26 additions & 26 deletions xbmc/interfaces/json-rpc/methods.json
Original file line number Diff line number Diff line change
Expand Up @@ -1422,32 +1422,6 @@
"params": [],
"returns": "string"
},
"System.GetInfoLabels": {
"type": "method",
"description": "Retrieve info labels about the system",
"transport": "Response",
"permission": "ReadData",
"params": [
{ "name": "labels", "type": "array", "required": true, "items": { "type": "string" }, "minItems": 1, "description": "See http://wiki.xbmc.org/index.php?title=InfoLabels for a list of possible info labels" }
],
"returns": {
"type": "object",
"description": "List of key-value pairs of the retrieved info labels"
}
},
"System.GetInfoBooleans": {
"type": "method",
"description": "Retrieve info booleans about the system",
"transport": "Response",
"permission": "ReadData",
"params": [
{ "name": "booleans", "type": "array", "required": true, "items": { "type": "string" }, "minItems": 1 }
],
"returns": {
"type": "object",
"description": "List of key-value pairs of the retrieved info booleans"
}
},
"Input.Left": {
"type": "method",
"description": "Navigate left in GUI",
Expand Down Expand Up @@ -1561,5 +1535,31 @@
{ "name": "recursive", "type": "boolean", "default": true }
],
"returns": "string"
},
"XBMC.GetInfoLabels": {
"type": "method",
"description": "Retrieve info labels about XBMC and the system",
"transport": "Response",
"permission": "ReadData",
"params": [
{ "name": "labels", "type": "array", "required": true, "items": { "type": "string" }, "minItems": 1, "description": "See http://wiki.xbmc.org/index.php?title=InfoLabels for a list of possible info labels" }
],
"returns": {
"type": "object",
"description": "List of key-value pairs of the retrieved info labels"
}
},
"XBMC.GetInfoBooleans": {
"type": "method",
"description": "Retrieve info booleans about XBMC and the system",
"transport": "Response",
"permission": "ReadData",
"params": [
{ "name": "booleans", "type": "array", "required": true, "items": { "type": "string" }, "minItems": 1 }
],
"returns": {
"type": "object",
"description": "List of key-value pairs of the retrieved info booleans"
}
}
}

0 comments on commit deab193

Please sign in to comment.