mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
add command for getting schema via json api (#179)
* - update coding style - add command for getting schema via json api - json api: merge config commands into one single "config" command with subcommands * make setconfig work
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include <QCryptographicHash>
|
||||
#include <QHostInfo>
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
|
||||
// hyperion util includes
|
||||
#include <hyperion/ImageProcessorFactory.h>
|
||||
@@ -266,10 +267,8 @@ void JsonClientConnection::handleMessage(const std::string &messageString)
|
||||
handleAdjustmentCommand(message);
|
||||
else if (command == "sourceselect")
|
||||
handleSourceSelectCommand(message);
|
||||
else if (command == "configget")
|
||||
handleConfigGetCommand(message);
|
||||
else if (command == "configset")
|
||||
handleConfigSetCommand(message);
|
||||
else if (command == "config")
|
||||
handleConfigCommand(message);
|
||||
else if (command == "componentstate")
|
||||
handleComponentStateCommand(message);
|
||||
else
|
||||
@@ -833,7 +832,28 @@ void JsonClientConnection::handleSourceSelectCommand(const Json::Value & message
|
||||
}
|
||||
}
|
||||
|
||||
void JsonClientConnection::handleConfigGetCommand(const Json::Value &)
|
||||
void JsonClientConnection::handleConfigCommand(const Json::Value & message)
|
||||
{
|
||||
std::string subcommand = message.get("subcommand","").asString();
|
||||
if (subcommand == "getschema")
|
||||
{
|
||||
handleSchemaGetCommand(message);
|
||||
}
|
||||
else if (subcommand == "getconfig")
|
||||
{
|
||||
handleConfigGetCommand(message);
|
||||
}
|
||||
else if (subcommand == "setconfig")
|
||||
{
|
||||
handleConfigSetCommand(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendErrorReply("unknown or missing subcommand");
|
||||
}
|
||||
}
|
||||
|
||||
void JsonClientConnection::handleConfigGetCommand(const Json::Value & message)
|
||||
{
|
||||
// create result
|
||||
Json::Value result;
|
||||
@@ -845,6 +865,30 @@ void JsonClientConnection::handleConfigGetCommand(const Json::Value &)
|
||||
sendMessage(result);
|
||||
}
|
||||
|
||||
void JsonClientConnection::handleSchemaGetCommand(const Json::Value & message)
|
||||
{
|
||||
// create result
|
||||
Json::Value result;
|
||||
result["success"] = true;
|
||||
Json::Value & schemaJson = result["result"];
|
||||
|
||||
// make sure the resources are loaded (they may be left out after static linking)
|
||||
Q_INIT_RESOURCE(resource);
|
||||
|
||||
// read the json schema from the resource
|
||||
QResource schemaData(":/hyperion-schema");
|
||||
assert(schemaData.isValid());
|
||||
|
||||
Json::Reader jsonReader;
|
||||
if (!jsonReader.parse(reinterpret_cast<const char *>(schemaData.data()), reinterpret_cast<const char *>(schemaData.data()) + schemaData.size(), schemaJson, false))
|
||||
{
|
||||
throw std::runtime_error("ERROR: Json schema wrong: " + jsonReader.getFormattedErrorMessages()) ;
|
||||
}
|
||||
|
||||
// send the result
|
||||
sendMessage(result);
|
||||
}
|
||||
|
||||
void JsonClientConnection::handleConfigSetCommand(const Json::Value &message)
|
||||
{
|
||||
struct nested
|
||||
@@ -871,10 +915,10 @@ void JsonClientConnection::handleConfigSetCommand(const Json::Value &message)
|
||||
|
||||
if(message.size() > 0)
|
||||
{
|
||||
if (message.isObject() && message.isMember("configset"))
|
||||
if (message.isObject() && message.isMember("config"))
|
||||
{
|
||||
std::string errors;
|
||||
if (!checkJson(message["configset"], ":/hyperion-schema", errors, true))
|
||||
if (!checkJson(message["config"], ":/hyperion-schema", errors, true))
|
||||
{
|
||||
sendErrorReply("Error while validating json: " + errors);
|
||||
return;
|
||||
@@ -882,7 +926,7 @@ void JsonClientConnection::handleConfigSetCommand(const Json::Value &message)
|
||||
|
||||
bool createKey = message.isMember("create");
|
||||
Json::Value hyperionConfig = _hyperion->getJsonConfig();
|
||||
nested::configSetCommand(message["configset"], hyperionConfig, createKey);
|
||||
nested::configSetCommand(message["config"], hyperionConfig, createKey);
|
||||
|
||||
JsonFactory::writeJson(_hyperion->getConfigFileName(), hyperionConfig);
|
||||
|
||||
|
@@ -139,6 +139,18 @@ private:
|
||||
///
|
||||
void handleSourceSelectCommand(const Json::Value & message);
|
||||
|
||||
/// Handle an incoming JSON GetConfig message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleConfigCommand(const Json::Value & message);
|
||||
|
||||
/// Handle an incoming JSON GetConfig message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleSchemaGetCommand(const Json::Value & message);
|
||||
|
||||
/// Handle an incoming JSON GetConfig message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
|
@@ -12,8 +12,7 @@
|
||||
<file alias="schema-adjustment">schema/schema-adjustment.json</file>
|
||||
<file alias="schema-effect">schema/schema-effect.json</file>
|
||||
<file alias="schema-sourceselect">schema/schema-sourceselect.json</file>
|
||||
<file alias="schema-configget">schema/schema-configget.json</file>
|
||||
<file alias="schema-configset">schema/schema-configset.json</file>
|
||||
<file alias="schema-config">schema/schema-config.json</file>
|
||||
<file alias="schema-componentstate">schema/schema-componentstate.json</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
23
libsrc/jsonserver/schema/schema-config.json
Normal file
23
libsrc/jsonserver/schema/schema-config.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"properties":{
|
||||
"command": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["config"]
|
||||
},
|
||||
"subcommand": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["getconfig","setconfig","getschema"]
|
||||
},
|
||||
"config": {
|
||||
"type" : "object"
|
||||
},
|
||||
"create": {
|
||||
"type" : "boolean"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"properties":{
|
||||
"command": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["configget"]
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"type" : "object",
|
||||
"required" : true,
|
||||
"properties" : {
|
||||
"command": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["configset"]
|
||||
},
|
||||
"configset": {
|
||||
"type" : "object",
|
||||
"required" : true
|
||||
},
|
||||
"create": {
|
||||
"type" : "boolean",
|
||||
"required" : false
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
@@ -5,7 +5,7 @@
|
||||
"command": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["color", "image", "effect", "serverinfo", "clear", "clearall", "transform", "correction", "temperature", "adjustment", "sourceselect", "configget", "configset", "componentstate"]
|
||||
"enum" : ["color", "image", "effect", "serverinfo", "clear", "clearall", "transform", "correction", "temperature", "adjustment", "sourceselect", "config", "componentstate"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user