mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Updated behaviour of the API to handle instance data requests such as getImageSnapshot and getLedSnapshot.
This commit is contained in:
parent
e7c46f4c9e
commit
a30e67fc11
@ -285,10 +285,24 @@ private:
|
|||||||
///
|
///
|
||||||
void handleSystemCommand(const QJsonObject &message, const JsonApiCommand& cmd);
|
void handleSystemCommand(const QJsonObject &message, const JsonApiCommand& cmd);
|
||||||
|
|
||||||
/// @brief Handle an incoming JSON message for actions related to the current image
|
/// Handle an incoming data request message
|
||||||
|
///
|
||||||
/// @param message the incoming message
|
/// @param message the incoming message
|
||||||
///
|
///
|
||||||
void handleGetCurrentImageCommand(const QJsonObject &message, const JsonApiCommand& cmd);
|
void handleInstanceDataCommand(const QJsonObject &message, const JsonApiCommand& cmd);
|
||||||
|
|
||||||
|
/// Handle an incoming JSON message to request the current image
|
||||||
|
///
|
||||||
|
/// @param message the incoming message
|
||||||
|
///
|
||||||
|
void handleGetImageSnapshotCommand(const QJsonObject &message, const JsonApiCommand& cmd);
|
||||||
|
|
||||||
|
/// Handle an incoming JSON message to request the current led colors
|
||||||
|
///
|
||||||
|
/// @param message the incoming message
|
||||||
|
///
|
||||||
|
void handleGetLedSnapshotCommand(const QJsonObject &message, const JsonApiCommand& cmd);
|
||||||
|
|
||||||
|
|
||||||
void applyColorAdjustments(const QJsonObject &adjustment, ColorAdjustment *colorAdjustment);
|
void applyColorAdjustments(const QJsonObject &adjustment, ColorAdjustment *colorAdjustment);
|
||||||
void applyColorAdjustment(const QString &colorName, const QJsonObject &adjustment, RgbChannelAdjustment &rgbAdjustment);
|
void applyColorAdjustment(const QString &colorName, const QJsonObject &adjustment, RgbChannelAdjustment &rgbAdjustment);
|
||||||
@ -408,4 +422,7 @@ private:
|
|||||||
|
|
||||||
// The JsonCallbacks instance which handles data subscription/notifications
|
// The JsonCallbacks instance which handles data subscription/notifications
|
||||||
QSharedPointer<JsonCallbacks> _jsonCB;
|
QSharedPointer<JsonCallbacks> _jsonCB;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -23,6 +23,7 @@ public:
|
|||||||
Image,
|
Image,
|
||||||
InputSource,
|
InputSource,
|
||||||
Instance,
|
Instance,
|
||||||
|
InstanceData,
|
||||||
LedColors,
|
LedColors,
|
||||||
LedDevice,
|
LedDevice,
|
||||||
Logging,
|
Logging,
|
||||||
@ -34,8 +35,7 @@ public:
|
|||||||
System,
|
System,
|
||||||
Temperature,
|
Temperature,
|
||||||
Transform,
|
Transform,
|
||||||
VideoMode,
|
VideoMode
|
||||||
GetCurrentImage
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static QString toString(Type type) {
|
static QString toString(Type type) {
|
||||||
@ -54,6 +54,7 @@ public:
|
|||||||
case Image: return "image";
|
case Image: return "image";
|
||||||
case InputSource: return "inputsource";
|
case InputSource: return "inputsource";
|
||||||
case Instance: return "instance";
|
case Instance: return "instance";
|
||||||
|
case InstanceData: return "instance-data";
|
||||||
case LedColors: return "ledcolors";
|
case LedColors: return "ledcolors";
|
||||||
case LedDevice: return "leddevice";
|
case LedDevice: return "leddevice";
|
||||||
case Logging: return "logging";
|
case Logging: return "logging";
|
||||||
@ -66,7 +67,6 @@ public:
|
|||||||
case Transform: return "transform";
|
case Transform: return "transform";
|
||||||
case VideoMode: return "videomode";
|
case VideoMode: return "videomode";
|
||||||
case Service: return "service";
|
case Service: return "service";
|
||||||
case GetCurrentImage: return "getcurrentimage";
|
|
||||||
default: return "unknown";
|
default: return "unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,7 +87,9 @@ public:
|
|||||||
Discover,
|
Discover,
|
||||||
GetConfig,
|
GetConfig,
|
||||||
GetConfigOld,
|
GetConfigOld,
|
||||||
|
GetImageSnapshot,
|
||||||
GetInfo,
|
GetInfo,
|
||||||
|
GetLedSnapshot,
|
||||||
GetPendingTokenRequests,
|
GetPendingTokenRequests,
|
||||||
GetProperties,
|
GetProperties,
|
||||||
GetSchema,
|
GetSchema,
|
||||||
@ -138,7 +140,9 @@ public:
|
|||||||
case Discover: return "discover";
|
case Discover: return "discover";
|
||||||
case GetConfig: return "getconfig";
|
case GetConfig: return "getconfig";
|
||||||
case GetConfigOld: return "getconfig-old";
|
case GetConfigOld: return "getconfig-old";
|
||||||
|
case GetImageSnapshot: return "getImageSnapshot";
|
||||||
case GetInfo: return "getInfo";
|
case GetInfo: return "getInfo";
|
||||||
|
case GetLedSnapshot: return "getLedSnapshot";
|
||||||
case GetPendingTokenRequests: return "getPendingTokenRequests";
|
case GetPendingTokenRequests: return "getPendingTokenRequests";
|
||||||
case GetProperties: return "getProperties";
|
case GetProperties: return "getProperties";
|
||||||
case GetSchema: return "getschema";
|
case GetSchema: return "getschema";
|
||||||
@ -296,6 +300,9 @@ public:
|
|||||||
{ {"instance", "startInstance"}, { Command::Instance, SubCommand::StartInstance, Authorization::Yes, InstanceCmd::No, NoListenerCmd::Yes} },
|
{ {"instance", "startInstance"}, { Command::Instance, SubCommand::StartInstance, Authorization::Yes, InstanceCmd::No, NoListenerCmd::Yes} },
|
||||||
{ {"instance", "stopInstance"}, { Command::Instance, SubCommand::StopInstance, Authorization::Yes, InstanceCmd::No, NoListenerCmd::Yes} },
|
{ {"instance", "stopInstance"}, { Command::Instance, SubCommand::StopInstance, Authorization::Yes, InstanceCmd::No, NoListenerCmd::Yes} },
|
||||||
{ {"instance", "switchTo"}, { Command::Instance, SubCommand::SwitchTo, Authorization::Yes, InstanceCmd::No, NoListenerCmd::Yes} },
|
{ {"instance", "switchTo"}, { Command::Instance, SubCommand::SwitchTo, Authorization::Yes, InstanceCmd::No, NoListenerCmd::Yes} },
|
||||||
|
{ {"instance-data", ""}, { Command::InstanceData, SubCommand::Empty, Authorization::Yes, InstanceCmd::Yes, NoListenerCmd::Yes} },
|
||||||
|
{ {"instance-data", "getImageSnapshot"}, { Command::InstanceData, SubCommand::GetImageSnapshot, Authorization::Yes, InstanceCmd::Yes, NoListenerCmd::Yes} },
|
||||||
|
{ {"instance-data", "getLedSnapshot"}, { Command::InstanceData, SubCommand::GetLedSnapshot, Authorization::Yes, InstanceCmd::Yes, NoListenerCmd::Yes } },
|
||||||
{ {"ledcolors", "imagestream-start"}, { Command::LedColors, SubCommand::ImageStreamStart, Authorization::Yes, InstanceCmd::Yes, NoListenerCmd::Yes} },
|
{ {"ledcolors", "imagestream-start"}, { Command::LedColors, SubCommand::ImageStreamStart, Authorization::Yes, InstanceCmd::Yes, NoListenerCmd::Yes} },
|
||||||
{ {"ledcolors", "imagestream-stop"}, { Command::LedColors, SubCommand::ImageStreamStop, Authorization::Yes, InstanceCmd::Yes, NoListenerCmd::Yes} },
|
{ {"ledcolors", "imagestream-stop"}, { Command::LedColors, SubCommand::ImageStreamStop, Authorization::Yes, InstanceCmd::Yes, NoListenerCmd::Yes} },
|
||||||
{ {"ledcolors", "ledstream-start"}, { Command::LedColors, SubCommand::LedStreamStart, Authorization::Yes, InstanceCmd::Yes, NoListenerCmd::Yes} },
|
{ {"ledcolors", "ledstream-start"}, { Command::LedColors, SubCommand::LedStreamStart, Authorization::Yes, InstanceCmd::Yes, NoListenerCmd::Yes} },
|
||||||
@ -324,8 +331,7 @@ public:
|
|||||||
{ {"system", "toggleIdle"}, { Command::System, SubCommand::ToggleIdle, Authorization::Yes, InstanceCmd::No, NoListenerCmd::Yes} },
|
{ {"system", "toggleIdle"}, { Command::System, SubCommand::ToggleIdle, Authorization::Yes, InstanceCmd::No, NoListenerCmd::Yes} },
|
||||||
{ {"temperature", ""}, { Command::Temperature, SubCommand::Empty, Authorization::Yes, InstanceCmd::Yes, NoListenerCmd::Yes} },
|
{ {"temperature", ""}, { Command::Temperature, SubCommand::Empty, Authorization::Yes, InstanceCmd::Yes, NoListenerCmd::Yes} },
|
||||||
{ {"transform", ""}, { Command::Transform, SubCommand::Empty, Authorization::Yes, InstanceCmd::Yes, NoListenerCmd::Yes} },
|
{ {"transform", ""}, { Command::Transform, SubCommand::Empty, Authorization::Yes, InstanceCmd::Yes, NoListenerCmd::Yes} },
|
||||||
{ {"videomode", ""}, { Command::VideoMode, SubCommand::Empty, Authorization::Yes, InstanceCmd::No, NoListenerCmd::Yes} },
|
{ {"videomode", ""}, { Command::VideoMode, SubCommand::Empty, Authorization::Yes, InstanceCmd::No, NoListenerCmd::Yes} }
|
||||||
{ {"getcurrentimage", ""}, { Command::GetCurrentImage, SubCommand::Empty, Authorization::Yes, InstanceCmd::No, NoListenerCmd::Yes} }
|
|
||||||
};
|
};
|
||||||
return commandLookup;
|
return commandLookup;
|
||||||
}
|
}
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
{
|
|
||||||
"type":"object",
|
|
||||||
"required":true,
|
|
||||||
"properties":{
|
|
||||||
"command": {
|
|
||||||
"type" : "string",
|
|
||||||
"required" : true,
|
|
||||||
"enum" : ["getcurrentimage"]
|
|
||||||
},
|
|
||||||
"tan" : {
|
|
||||||
"type" : "integer"
|
|
||||||
},
|
|
||||||
"path": {
|
|
||||||
"type": "string",
|
|
||||||
"required": false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"additionalProperties": false
|
|
||||||
}
|
|
29
libsrc/api/JSONRPC_schema/schema-instancedata.json
Normal file
29
libsrc/api/JSONRPC_schema/schema-instancedata.json
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"type":"object",
|
||||||
|
"required":true,
|
||||||
|
"properties":{
|
||||||
|
"command": {
|
||||||
|
"type" : "string",
|
||||||
|
"required" : true,
|
||||||
|
"enum" : ["instance-data"]
|
||||||
|
},
|
||||||
|
"subcommand" : {
|
||||||
|
"type" : "string",
|
||||||
|
"required" : true,
|
||||||
|
"enum" : ["getImageSnapshot","getLedSnapshot"]
|
||||||
|
},
|
||||||
|
"instance" : {
|
||||||
|
"type": "integer",
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 255
|
||||||
|
},
|
||||||
|
"filetype" : {
|
||||||
|
"type" : "string",
|
||||||
|
"enum" : ["BMP","JPG","PNG"]
|
||||||
|
},
|
||||||
|
"tan" : {
|
||||||
|
"type" : "integer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
@ -5,7 +5,7 @@
|
|||||||
"command": {
|
"command": {
|
||||||
"type" : "string",
|
"type" : "string",
|
||||||
"required" : true,
|
"required" : true,
|
||||||
"enum": [ "color", "image", "effect", "create-effect", "delete-effect", "serverinfo", "clear", "clearall", "adjustment", "sourceselect", "config", "componentstate", "ledcolors", "logging", "processing", "sysinfo", "videomode", "authorize", "instance", "leddevice", "inputsource", "service", "system", "transform", "correction", "temperature", "getcurrentimage" ]
|
"enum": [ "color", "image", "effect", "create-effect", "delete-effect", "serverinfo", "clear", "clearall", "adjustment", "sourceselect", "config", "componentstate", "ledcolors", "logging", "processing", "sysinfo", "videomode", "authorize", "instance", "instance-data", "leddevice", "inputsource", "service", "system", "transform", "correction", "temperature" ]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
<file alias="schema-color">JSONRPC_schema/schema-color.json</file>
|
<file alias="schema-color">JSONRPC_schema/schema-color.json</file>
|
||||||
<file alias="schema-image">JSONRPC_schema/schema-image.json</file>
|
<file alias="schema-image">JSONRPC_schema/schema-image.json</file>
|
||||||
<file alias="schema-serverinfo">JSONRPC_schema/schema-serverinfo.json</file>
|
<file alias="schema-serverinfo">JSONRPC_schema/schema-serverinfo.json</file>
|
||||||
<file alias="schema-getcurrentimage">JSONRPC_schema/schema-getcurrentimage.json</file>
|
|
||||||
<file alias="schema-sysinfo">JSONRPC_schema/schema-sysinfo.json</file>
|
<file alias="schema-sysinfo">JSONRPC_schema/schema-sysinfo.json</file>
|
||||||
<file alias="schema-clear">JSONRPC_schema/schema-clear.json</file>
|
<file alias="schema-clear">JSONRPC_schema/schema-clear.json</file>
|
||||||
<file alias="schema-clearall">JSONRPC_schema/schema-clearall.json</file>
|
<file alias="schema-clearall">JSONRPC_schema/schema-clearall.json</file>
|
||||||
@ -21,6 +20,7 @@
|
|||||||
<file alias="schema-videomode">JSONRPC_schema/schema-videomode.json</file>
|
<file alias="schema-videomode">JSONRPC_schema/schema-videomode.json</file>
|
||||||
<file alias="schema-authorize">JSONRPC_schema/schema-authorize.json</file>
|
<file alias="schema-authorize">JSONRPC_schema/schema-authorize.json</file>
|
||||||
<file alias="schema-instance">JSONRPC_schema/schema-instance.json</file>
|
<file alias="schema-instance">JSONRPC_schema/schema-instance.json</file>
|
||||||
|
<file alias="schema-instance-data">JSONRPC_schema/schema-instancedata.json</file>
|
||||||
<file alias="schema-leddevice">JSONRPC_schema/schema-leddevice.json</file>
|
<file alias="schema-leddevice">JSONRPC_schema/schema-leddevice.json</file>
|
||||||
<file alias="schema-inputsource">JSONRPC_schema/schema-inputsource.json</file>
|
<file alias="schema-inputsource">JSONRPC_schema/schema-inputsource.json</file>
|
||||||
<file alias="schema-service">JSONRPC_schema/schema-service.json</file>
|
<file alias="schema-service">JSONRPC_schema/schema-service.json</file>
|
||||||
|
@ -57,7 +57,8 @@
|
|||||||
using namespace hyperion;
|
using namespace hyperion;
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
namespace {
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
constexpr std::chrono::milliseconds NEW_TOKEN_REQUEST_TIMEOUT{180000};
|
constexpr std::chrono::milliseconds NEW_TOKEN_REQUEST_TIMEOUT{180000};
|
||||||
|
|
||||||
@ -75,10 +76,7 @@ const bool verbose = false;
|
|||||||
}
|
}
|
||||||
|
|
||||||
JsonAPI::JsonAPI(QString peerAddress, Logger *log, bool localConnection, QObject *parent, bool noListener)
|
JsonAPI::JsonAPI(QString peerAddress, Logger *log, bool localConnection, QObject *parent, bool noListener)
|
||||||
: API(log, localConnection, parent)
|
: API(log, localConnection, parent), _noListener(noListener), _peerAddress(std::move(peerAddress)), _jsonCB(nullptr)
|
||||||
,_noListener(noListener)
|
|
||||||
,_peerAddress (std::move(peerAddress))
|
|
||||||
,_jsonCB (nullptr)
|
|
||||||
{
|
{
|
||||||
Q_INIT_RESOURCE(JSONRPC_schemas);
|
Q_INIT_RESOURCE(JSONRPC_schemas);
|
||||||
|
|
||||||
@ -188,10 +186,12 @@ void JsonAPI::handleMessage(const QString &messageString, const QString &httpAut
|
|||||||
if (!httpAuthHeader.isEmpty())
|
if (!httpAuthHeader.isEmpty())
|
||||||
{
|
{
|
||||||
int bearTokenLenght{0};
|
int bearTokenLenght{0};
|
||||||
if (httpAuthHeader.startsWith(BEARER_TOKEN_TAG, Qt::CaseInsensitive)) {
|
if (httpAuthHeader.startsWith(BEARER_TOKEN_TAG, Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
bearTokenLenght = BEARER_TOKEN_TAG_LENGTH;
|
bearTokenLenght = BEARER_TOKEN_TAG_LENGTH;
|
||||||
}
|
}
|
||||||
else if (httpAuthHeader.startsWith(TOKEN_TAG, Qt::CaseInsensitive)) {
|
else if (httpAuthHeader.startsWith(TOKEN_TAG, Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
bearTokenLenght = TOKEN_TAG_LENGTH;
|
bearTokenLenght = TOKEN_TAG_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +253,8 @@ void JsonAPI::handleInstanceCommand(const JsonApiCommand& cmd, const QJsonObject
|
|||||||
if (instanceElement.isDouble())
|
if (instanceElement.isDouble())
|
||||||
{
|
{
|
||||||
instances.append(instanceElement);
|
instances.append(instanceElement);
|
||||||
} else if (instanceElement.isArray())
|
}
|
||||||
|
else if (instanceElement.isArray())
|
||||||
{
|
{
|
||||||
instances = instanceElement.toArray();
|
instances = instanceElement.toArray();
|
||||||
}
|
}
|
||||||
@ -271,7 +272,8 @@ void JsonAPI::handleInstanceCommand(const JsonApiCommand& cmd, const QJsonObject
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (const auto &instance : std::as_const(instances)) {
|
for (const auto &instance : std::as_const(instances))
|
||||||
|
{
|
||||||
|
|
||||||
quint8 instanceIdx = static_cast<quint8>(instance.toInt());
|
quint8 instanceIdx = static_cast<quint8>(instance.toInt());
|
||||||
if (instance.isDouble() && runningInstanceIdxs.contains(instanceIdx))
|
if (instance.isDouble() && runningInstanceIdxs.contains(instanceIdx))
|
||||||
@ -314,7 +316,8 @@ void JsonAPI::handleInstanceCommand(const JsonApiCommand& cmd, const QJsonObject
|
|||||||
|
|
||||||
void JsonAPI::handleCommand(const JsonApiCommand &cmd, const QJsonObject &message)
|
void JsonAPI::handleCommand(const JsonApiCommand &cmd, const QJsonObject &message)
|
||||||
{
|
{
|
||||||
switch (cmd.command) {
|
switch (cmd.command)
|
||||||
|
{
|
||||||
case Command::Authorize:
|
case Command::Authorize:
|
||||||
handleAuthorizeCommand(message, cmd);
|
handleAuthorizeCommand(message, cmd);
|
||||||
break;
|
break;
|
||||||
@ -386,6 +389,9 @@ void JsonAPI::handleCommand(const JsonApiCommand& cmd, const QJsonObject &messag
|
|||||||
case Command::ClearAll:
|
case Command::ClearAll:
|
||||||
handleClearallCommand(message, cmd);
|
handleClearallCommand(message, cmd);
|
||||||
break;
|
break;
|
||||||
|
case Command::InstanceData:
|
||||||
|
handleInstanceDataCommand(message, cmd);
|
||||||
|
break;
|
||||||
// BEGIN | The following commands are deprecated but used to ensure backward compatibility with Hyperion Classic remote control
|
// BEGIN | The following commands are deprecated but used to ensure backward compatibility with Hyperion Classic remote control
|
||||||
case Command::Transform:
|
case Command::Transform:
|
||||||
case Command::Correction:
|
case Command::Correction:
|
||||||
@ -393,53 +399,90 @@ void JsonAPI::handleCommand(const JsonApiCommand& cmd, const QJsonObject &messag
|
|||||||
sendErrorReply("The command is deprecated, please use the Hyperion Web Interface to configure", cmd);
|
sendErrorReply("The command is deprecated, please use the Hyperion Web Interface to configure", cmd);
|
||||||
break;
|
break;
|
||||||
// END
|
// END
|
||||||
case Command::GetCurrentImage:
|
|
||||||
handleGetCurrentImageCommand(message, cmd);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonAPI::handleGetCurrentImageCommand(const QJsonObject &message, const JsonApiCommand& cmd)
|
void JsonAPI::handleGetImageSnapshotCommand(const QJsonObject &message, const JsonApiCommand &cmd)
|
||||||
{
|
{
|
||||||
QString replyMsg;
|
QString replyMsg;
|
||||||
|
QString filetype = message["filetype"].toString();
|
||||||
Debug(_log, "Get image command received");
|
const QStringList fileTypes{"BMP", "JPG", "PNG"};
|
||||||
QString savePath = message["path"].toString();
|
if (filetype.isEmpty())
|
||||||
|
{
|
||||||
Debug(_log,"Save path: %s", QSTRING_CSTR(savePath));
|
sendErrorReply("Missing filetype. Available filetypes: " + fileTypes.join(", "), cmd);
|
||||||
|
return;
|
||||||
int priority = _hyperion->getCurrentPriority();
|
}
|
||||||
const PriorityMuxer::InputInfo priorityInfo = _hyperion->getPriorityInfo(priority);
|
else if (!fileTypes.contains(filetype, Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
|
sendErrorReply("Invalid filetype. Available filetypes: " + fileTypes.join(", "), cmd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const PriorityMuxer::InputInfo priorityInfo = _hyperion->getPriorityInfo(_hyperion->getCurrentPriority());
|
||||||
Image<ColorRgb> image = priorityInfo.image;
|
Image<ColorRgb> image = priorityInfo.image;
|
||||||
|
QImage snapshot(reinterpret_cast<const uchar *>(image.memptr()), image.width(), image.height(), qsizetype(3) * image.width(), QImage::Format_RGB888);
|
||||||
QImage jpgImage(reinterpret_cast<const uchar*>(image.memptr()), image.width(), image.height(), qsizetype(3) * image.width(), QImage::Format_RGB888);
|
|
||||||
QByteArray byteArray;
|
QByteArray byteArray;
|
||||||
QBuffer buffer(&byteArray);
|
|
||||||
|
QBuffer buffer{&byteArray};
|
||||||
buffer.open(QIODevice::WriteOnly);
|
buffer.open(QIODevice::WriteOnly);
|
||||||
jpgImage.save(&buffer, "JPG");
|
if (!snapshot.save(&buffer, filetype.toUtf8().constData()))
|
||||||
QString base64Image = QString::fromLatin1(byteArray.toBase64().data());
|
|
||||||
if (!savePath.isEmpty())
|
|
||||||
{
|
{
|
||||||
if (!jpgImage.save(savePath, "JPG"))
|
replyMsg = QString("Failed to create snapshot of the current image in %1 format").arg(filetype);
|
||||||
{
|
|
||||||
replyMsg = "Failed to save image to: " + savePath;
|
|
||||||
sendErrorReply(replyMsg, cmd);
|
sendErrorReply(replyMsg, cmd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
QByteArray base64Image = byteArray.toBase64();
|
||||||
|
|
||||||
QJsonObject info;
|
QJsonObject info;
|
||||||
info["path"] = savePath;
|
info["format"] = filetype;
|
||||||
info["format"] = "JPG";
|
|
||||||
info["width"] = image.width();
|
info["width"] = image.width();
|
||||||
info["height"] = image.height();
|
info["height"] = image.height();
|
||||||
info["size"] = image.width() * image.height() * 3;
|
info["data"] = QString::fromLatin1(base64Image.data());
|
||||||
info["data"] = base64Image;
|
|
||||||
sendSuccessDataReply(info, cmd);
|
sendSuccessDataReply(info, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JsonAPI::handleGetLedSnapshotCommand(const QJsonObject &message, const JsonApiCommand &cmd)
|
||||||
|
{
|
||||||
|
QString replyMsg;
|
||||||
|
const PriorityMuxer::InputInfo priorityInfo = _hyperion->getPriorityInfo(_hyperion->getCurrentPriority());
|
||||||
|
const std::vector<ColorRgb> ledColors = _hyperion->getImageProcessor()->process(priorityInfo.image);
|
||||||
|
if (ledColors.empty())
|
||||||
|
{
|
||||||
|
replyMsg = "No led colors available";
|
||||||
|
sendErrorReply(replyMsg, cmd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QJsonArray ledColorsArray;
|
||||||
|
for (const auto &color : ledColors)
|
||||||
|
{
|
||||||
|
QJsonArray rgbArray;
|
||||||
|
rgbArray.append(color.red);
|
||||||
|
rgbArray.append(color.green);
|
||||||
|
rgbArray.append(color.blue);
|
||||||
|
ledColorsArray.append(rgbArray);
|
||||||
|
}
|
||||||
|
QJsonObject info;
|
||||||
|
info["leds"] = ledColorsArray;
|
||||||
|
sendSuccessDataReply(info, cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void JsonAPI::handleInstanceDataCommand(const QJsonObject &message, const JsonApiCommand &cmd)
|
||||||
|
{
|
||||||
|
|
||||||
|
switch (cmd.subCommand)
|
||||||
|
{
|
||||||
|
case SubCommand::GetImageSnapshot:
|
||||||
|
handleGetImageSnapshotCommand(message, cmd);
|
||||||
|
break;
|
||||||
|
case SubCommand::GetLedSnapshot:
|
||||||
|
handleGetLedSnapshotCommand(message, cmd);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sendErrorReply("Unknown subcommand", cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void JsonAPI::handleColorCommand(const QJsonObject &message, const JsonApiCommand &cmd)
|
void JsonAPI::handleColorCommand(const QJsonObject &message, const JsonApiCommand &cmd)
|
||||||
{
|
{
|
||||||
emit forwardJsonMessage(message);
|
emit forwardJsonMessage(message);
|
||||||
@ -452,7 +495,8 @@ void JsonAPI::handleColorCommand(const QJsonObject &message, const JsonApiComman
|
|||||||
colors.reserve(static_cast<std::vector<uint8_t>::size_type>(jsonColor.size()));
|
colors.reserve(static_cast<std::vector<uint8_t>::size_type>(jsonColor.size()));
|
||||||
// Transform each entry in jsonColor to uint8_t and append to colors
|
// Transform each entry in jsonColor to uint8_t and append to colors
|
||||||
std::transform(jsonColor.begin(), jsonColor.end(), std::back_inserter(colors),
|
std::transform(jsonColor.begin(), jsonColor.end(), std::back_inserter(colors),
|
||||||
[](const QJsonValue &value) { return static_cast<uint8_t>(value.toInt()); });
|
[](const QJsonValue &value)
|
||||||
|
{ return static_cast<uint8_t>(value.toInt()); });
|
||||||
|
|
||||||
API::setColor(priority, colors, duration, origin);
|
API::setColor(priority, colors, duration, origin);
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
@ -474,9 +518,12 @@ void JsonAPI::handleImageCommand(const QJsonObject &message, const JsonApiComman
|
|||||||
idata.data = QByteArray::fromBase64(QByteArray(message["imagedata"].toString().toUtf8()));
|
idata.data = QByteArray::fromBase64(QByteArray(message["imagedata"].toString().toUtf8()));
|
||||||
QString replyMsg;
|
QString replyMsg;
|
||||||
|
|
||||||
if (API::setImage(idata, COMP_IMAGE, replyMsg)) {
|
if (API::setImage(idata, COMP_IMAGE, replyMsg))
|
||||||
|
{
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
sendErrorReply(replyMsg, cmd);
|
sendErrorReply(replyMsg, cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -495,9 +542,12 @@ void JsonAPI::handleEffectCommand(const QJsonObject &message, const JsonApiComma
|
|||||||
dat.data = message["imageData"].toString("").toUtf8();
|
dat.data = message["imageData"].toString("").toUtf8();
|
||||||
dat.args = message["effect"].toObject()["args"].toObject();
|
dat.args = message["effect"].toObject()["args"].toObject();
|
||||||
|
|
||||||
if (API::setEffect(dat)) {
|
if (API::setEffect(dat))
|
||||||
|
{
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
sendErrorReply("Effect '" + dat.effectName + "' not found", cmd);
|
sendErrorReply("Effect '" + dat.effectName + "' not found", cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -525,7 +575,8 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject &message, const JsonApiC
|
|||||||
QJsonObject info{};
|
QJsonObject info{};
|
||||||
QStringList errorDetails;
|
QStringList errorDetails;
|
||||||
|
|
||||||
switch (cmd.getSubCommand()) {
|
switch (cmd.getSubCommand())
|
||||||
|
{
|
||||||
case SubCommand::Empty:
|
case SubCommand::Empty:
|
||||||
case SubCommand::GetInfo:
|
case SubCommand::GetInfo:
|
||||||
info["priorities"] = JsonInfo::getPrioritiestInfo(_hyperion);
|
info["priorities"] = JsonInfo::getPrioritiestInfo(_hyperion);
|
||||||
@ -569,7 +620,8 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject &message, const JsonApiC
|
|||||||
{
|
{
|
||||||
const QJsonObject ¶ms = message["data"].toObject();
|
const QJsonObject ¶ms = message["data"].toObject();
|
||||||
const QJsonArray &subscriptions = params["subscriptions"].toArray();
|
const QJsonArray &subscriptions = params["subscriptions"].toArray();
|
||||||
if (subscriptions.isEmpty()) {
|
if (subscriptions.isEmpty())
|
||||||
|
{
|
||||||
sendErrorReply("Invalid params", {"No subscriptions provided"}, cmd);
|
sendErrorReply("Invalid params", {"No subscriptions provided"}, cmd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -633,14 +685,16 @@ void JsonAPI::handleAdjustmentCommand(const QJsonObject &message, const JsonApiC
|
|||||||
const QJsonObject &adjustment = message["adjustment"].toObject();
|
const QJsonObject &adjustment = message["adjustment"].toObject();
|
||||||
|
|
||||||
const QList<QString> adjustmentIds = _hyperion->getAdjustmentIds();
|
const QList<QString> adjustmentIds = _hyperion->getAdjustmentIds();
|
||||||
if (adjustmentIds.isEmpty()) {
|
if (adjustmentIds.isEmpty())
|
||||||
|
{
|
||||||
sendErrorReply("No adjustment data available", cmd);
|
sendErrorReply("No adjustment data available", cmd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString adjustmentId = adjustment["id"].toString(adjustmentIds.first());
|
const QString adjustmentId = adjustment["id"].toString(adjustmentIds.first());
|
||||||
ColorAdjustment *colorAdjustment = _hyperion->getAdjustment(adjustmentId);
|
ColorAdjustment *colorAdjustment = _hyperion->getAdjustment(adjustmentId);
|
||||||
if (colorAdjustment == nullptr) {
|
if (colorAdjustment == nullptr)
|
||||||
|
{
|
||||||
Warning(_log, "Incorrect adjustment identifier: %s", adjustmentId.toStdString().c_str());
|
Warning(_log, "Incorrect adjustment identifier: %s", adjustmentId.toStdString().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -664,9 +718,11 @@ void JsonAPI::applyColorAdjustments(const QJsonObject &adjustment, ColorAdjustme
|
|||||||
|
|
||||||
void JsonAPI::applyColorAdjustment(const QString &colorName, const QJsonObject &adjustment, RgbChannelAdjustment &rgbAdjustment)
|
void JsonAPI::applyColorAdjustment(const QString &colorName, const QJsonObject &adjustment, RgbChannelAdjustment &rgbAdjustment)
|
||||||
{
|
{
|
||||||
if (adjustment.contains(colorName)) {
|
if (adjustment.contains(colorName))
|
||||||
|
{
|
||||||
const QJsonArray &values = adjustment[colorName].toArray();
|
const QJsonArray &values = adjustment[colorName].toArray();
|
||||||
if (values.size() >= 3) {
|
if (values.size() >= 3)
|
||||||
|
{
|
||||||
rgbAdjustment.setAdjustment(static_cast<uint8_t>(values[0U].toInt()),
|
rgbAdjustment.setAdjustment(static_cast<uint8_t>(values[0U].toInt()),
|
||||||
static_cast<uint8_t>(values[1U].toInt()),
|
static_cast<uint8_t>(values[1U].toInt()),
|
||||||
static_cast<uint8_t>(values[2U].toInt()));
|
static_cast<uint8_t>(values[2U].toInt()));
|
||||||
@ -690,7 +746,8 @@ void JsonAPI::applyTransforms(const QJsonObject &adjustment, ColorAdjustment *co
|
|||||||
|
|
||||||
void JsonAPI::applyGammaTransform(const QString &transformName, const QJsonObject &adjustment, RgbTransform &rgbTransform, char channel)
|
void JsonAPI::applyGammaTransform(const QString &transformName, const QJsonObject &adjustment, RgbTransform &rgbTransform, char channel)
|
||||||
{
|
{
|
||||||
if (adjustment.contains(transformName)) {
|
if (adjustment.contains(transformName))
|
||||||
|
{
|
||||||
rgbTransform.setGamma(channel == 'r' ? adjustment[transformName].toDouble() : rgbTransform.getGammaR(),
|
rgbTransform.setGamma(channel == 'r' ? adjustment[transformName].toDouble() : rgbTransform.getGammaR(),
|
||||||
channel == 'g' ? adjustment[transformName].toDouble() : rgbTransform.getGammaG(),
|
channel == 'g' ? adjustment[transformName].toDouble() : rgbTransform.getGammaG(),
|
||||||
channel == 'b' ? adjustment[transformName].toDouble() : rgbTransform.getGammaB());
|
channel == 'b' ? adjustment[transformName].toDouble() : rgbTransform.getGammaB());
|
||||||
@ -700,7 +757,8 @@ void JsonAPI::applyGammaTransform(const QString &transformName, const QJsonObjec
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(bool))
|
void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(bool))
|
||||||
{
|
{
|
||||||
if (adjustment.contains(transformName)) {
|
if (adjustment.contains(transformName))
|
||||||
|
{
|
||||||
(transform.*setFunction)(adjustment[transformName].toBool());
|
(transform.*setFunction)(adjustment[transformName].toBool());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -708,7 +766,8 @@ void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &ad
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(double))
|
void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(double))
|
||||||
{
|
{
|
||||||
if (adjustment.contains(transformName)) {
|
if (adjustment.contains(transformName))
|
||||||
|
{
|
||||||
(transform.*setFunction)(adjustment[transformName].toDouble());
|
(transform.*setFunction)(adjustment[transformName].toDouble());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -716,7 +775,8 @@ void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &ad
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(int))
|
void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(int))
|
||||||
{
|
{
|
||||||
if (adjustment.contains(transformName)) {
|
if (adjustment.contains(transformName))
|
||||||
|
{
|
||||||
(transform.*setFunction)(adjustment[transformName].toInt());
|
(transform.*setFunction)(adjustment[transformName].toInt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -724,7 +784,8 @@ void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &ad
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(uint8_t))
|
void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(uint8_t))
|
||||||
{
|
{
|
||||||
if (adjustment.contains(transformName)) {
|
if (adjustment.contains(transformName))
|
||||||
|
{
|
||||||
(transform.*setFunction)(static_cast<uint8_t>(adjustment[transformName].toInt()));
|
(transform.*setFunction)(static_cast<uint8_t>(adjustment[transformName].toInt()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -749,7 +810,8 @@ void JsonAPI::handleSourceSelectCommand(const QJsonObject &message, const JsonAp
|
|||||||
|
|
||||||
void JsonAPI::handleConfigCommand(const QJsonObject &message, const JsonApiCommand &cmd)
|
void JsonAPI::handleConfigCommand(const QJsonObject &message, const JsonApiCommand &cmd)
|
||||||
{
|
{
|
||||||
switch (cmd.subCommand) {
|
switch (cmd.subCommand)
|
||||||
|
{
|
||||||
case SubCommand::GetSchema:
|
case SubCommand::GetSchema:
|
||||||
handleSchemaGetCommand(message, cmd);
|
handleSchemaGetCommand(message, cmd);
|
||||||
break;
|
break;
|
||||||
@ -831,7 +893,8 @@ void JsonAPI::handleConfigSetCommand(const QJsonObject &message, const JsonApiCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
QMapIterator<quint8, QJsonObject> i(instancesNewConfigs);
|
QMapIterator<quint8, QJsonObject> i(instancesNewConfigs);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext())
|
||||||
|
{
|
||||||
i.next();
|
i.next();
|
||||||
|
|
||||||
quint8 idx = i.key();
|
quint8 idx = i.key();
|
||||||
@ -864,8 +927,10 @@ void JsonAPI::handleConfigGetCommand(const QJsonObject &message, const JsonApiCo
|
|||||||
if (!globalConfig.isEmpty())
|
if (!globalConfig.isEmpty())
|
||||||
{
|
{
|
||||||
const QJsonArray globalTypes = globalConfig["types"].toArray();
|
const QJsonArray globalTypes = globalConfig["types"].toArray();
|
||||||
for (const auto &type : globalTypes) {
|
for (const auto &type : globalTypes)
|
||||||
if (type.isString()) {
|
{
|
||||||
|
if (type.isString())
|
||||||
|
{
|
||||||
globalFilterTypes.append(type.toString());
|
globalFilterTypes.append(type.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -879,8 +944,10 @@ void JsonAPI::handleConfigGetCommand(const QJsonObject &message, const JsonApiCo
|
|||||||
{
|
{
|
||||||
QList<quint8> configuredInstanceIds = _instanceManager->getInstanceIds();
|
QList<quint8> configuredInstanceIds = _instanceManager->getInstanceIds();
|
||||||
const QJsonArray instanceIds = instances["ids"].toArray();
|
const QJsonArray instanceIds = instances["ids"].toArray();
|
||||||
for (const auto &idx : instanceIds) {
|
for (const auto &idx : instanceIds)
|
||||||
if (idx.isDouble()) {
|
{
|
||||||
|
if (idx.isDouble())
|
||||||
|
{
|
||||||
quint8 instanceId = static_cast<quint8>(idx.toInt());
|
quint8 instanceId = static_cast<quint8>(idx.toInt());
|
||||||
if (configuredInstanceIds.contains(instanceId))
|
if (configuredInstanceIds.contains(instanceId))
|
||||||
{
|
{
|
||||||
@ -894,8 +961,10 @@ void JsonAPI::handleConfigGetCommand(const QJsonObject &message, const JsonApiCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QJsonArray instanceTypes = instances["types"].toArray();
|
const QJsonArray instanceTypes = instances["types"].toArray();
|
||||||
for (const auto &type : instanceTypes) {
|
for (const auto &type : instanceTypes)
|
||||||
if (type.isString()) {
|
{
|
||||||
|
if (type.isString())
|
||||||
|
{
|
||||||
instanceFilterTypes.append(type.toString());
|
instanceFilterTypes.append(type.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1026,16 +1095,20 @@ void JsonAPI::handleComponentStateCommand(const QJsonObject &message, const Json
|
|||||||
bool compState = componentState["state"].toBool(true);
|
bool compState = componentState["state"].toBool(true);
|
||||||
QString replyMsg;
|
QString replyMsg;
|
||||||
|
|
||||||
if (API::setComponentState(comp, compState, replyMsg)) {
|
if (API::setComponentState(comp, compState, replyMsg))
|
||||||
|
{
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
sendErrorReply(replyMsg, cmd);
|
sendErrorReply(replyMsg, cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonAPI::handleLedColorsCommand(const QJsonObject & /*message*/, const JsonApiCommand &cmd)
|
void JsonAPI::handleLedColorsCommand(const QJsonObject & /*message*/, const JsonApiCommand &cmd)
|
||||||
{
|
{
|
||||||
switch (cmd.subCommand) {
|
switch (cmd.subCommand)
|
||||||
|
{
|
||||||
case SubCommand::LedStreamStart:
|
case SubCommand::LedStreamStart:
|
||||||
_jsonCB->subscribe(Subscription::LedColorsUpdate);
|
_jsonCB->subscribe(Subscription::LedColorsUpdate);
|
||||||
// push once
|
// push once
|
||||||
@ -1065,7 +1138,8 @@ void JsonAPI::handleLedColorsCommand(const QJsonObject& /*message*/, const JsonA
|
|||||||
|
|
||||||
void JsonAPI::handleLoggingCommand(const QJsonObject & /*message*/, const JsonApiCommand &cmd)
|
void JsonAPI::handleLoggingCommand(const QJsonObject & /*message*/, const JsonApiCommand &cmd)
|
||||||
{
|
{
|
||||||
switch (cmd.subCommand) {
|
switch (cmd.subCommand)
|
||||||
|
{
|
||||||
case SubCommand::Start:
|
case SubCommand::Start:
|
||||||
_jsonCB->subscribe("logmsg-update");
|
_jsonCB->subscribe("logmsg-update");
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
@ -1094,7 +1168,8 @@ void JsonAPI::handleVideoModeCommand(const QJsonObject &message, const JsonApiCo
|
|||||||
|
|
||||||
void JsonAPI::handleAuthorizeCommand(const QJsonObject &message, const JsonApiCommand &cmd)
|
void JsonAPI::handleAuthorizeCommand(const QJsonObject &message, const JsonApiCommand &cmd)
|
||||||
{
|
{
|
||||||
switch (cmd.subCommand) {
|
switch (cmd.subCommand)
|
||||||
|
{
|
||||||
case SubCommand::TokenRequired:
|
case SubCommand::TokenRequired:
|
||||||
handleTokenRequired(cmd);
|
handleTokenRequired(cmd);
|
||||||
break;
|
break;
|
||||||
@ -1169,9 +1244,12 @@ void JsonAPI::handleNewPassword(const QJsonObject &message, const JsonApiCommand
|
|||||||
{
|
{
|
||||||
const QString password = message["password"].toString().trimmed();
|
const QString password = message["password"].toString().trimmed();
|
||||||
const QString newPassword = message["newPassword"].toString().trimmed();
|
const QString newPassword = message["newPassword"].toString().trimmed();
|
||||||
if (API::updateHyperionPassword(password, newPassword)) {
|
if (API::updateHyperionPassword(password, newPassword))
|
||||||
|
{
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
sendErrorReply("Failed to update user password", cmd);
|
sendErrorReply("Failed to update user password", cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1181,14 +1259,17 @@ void JsonAPI::handleCreateToken(const QJsonObject &message, const JsonApiCommand
|
|||||||
const QString &comment = message["comment"].toString().trimmed();
|
const QString &comment = message["comment"].toString().trimmed();
|
||||||
AuthManager::AuthDefinition def;
|
AuthManager::AuthDefinition def;
|
||||||
const QString createTokenResult = API::createToken(comment, def);
|
const QString createTokenResult = API::createToken(comment, def);
|
||||||
if (createTokenResult.isEmpty()) {
|
if (createTokenResult.isEmpty())
|
||||||
|
{
|
||||||
QJsonObject newTok;
|
QJsonObject newTok;
|
||||||
newTok["comment"] = def.comment;
|
newTok["comment"] = def.comment;
|
||||||
newTok["id"] = def.id;
|
newTok["id"] = def.id;
|
||||||
newTok["token"] = def.token;
|
newTok["token"] = def.token;
|
||||||
|
|
||||||
sendSuccessDataReply(newTok, cmd);
|
sendSuccessDataReply(newTok, cmd);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
sendErrorReply("Token creation failed", {createTokenResult}, cmd);
|
sendErrorReply("Token creation failed", {createTokenResult}, cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1198,9 +1279,12 @@ void JsonAPI::handleRenameToken(const QJsonObject &message, const JsonApiCommand
|
|||||||
const QString &identifier = message["id"].toString().trimmed();
|
const QString &identifier = message["id"].toString().trimmed();
|
||||||
const QString &comment = message["comment"].toString().trimmed();
|
const QString &comment = message["comment"].toString().trimmed();
|
||||||
const QString renameTokenResult = API::renameToken(identifier, comment);
|
const QString renameTokenResult = API::renameToken(identifier, comment);
|
||||||
if (renameTokenResult.isEmpty()) {
|
if (renameTokenResult.isEmpty())
|
||||||
|
{
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
sendErrorReply("Token rename failed", {renameTokenResult}, cmd);
|
sendErrorReply("Token rename failed", {renameTokenResult}, cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1209,9 +1293,12 @@ void JsonAPI::handleDeleteToken(const QJsonObject &message, const JsonApiCommand
|
|||||||
{
|
{
|
||||||
const QString &identifier = message["id"].toString().trimmed();
|
const QString &identifier = message["id"].toString().trimmed();
|
||||||
const QString deleteTokenResult = API::deleteToken(identifier);
|
const QString deleteTokenResult = API::deleteToken(identifier);
|
||||||
if (deleteTokenResult.isEmpty()) {
|
if (deleteTokenResult.isEmpty())
|
||||||
|
{
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
sendErrorReply("Token deletion failed", {deleteTokenResult}, cmd);
|
sendErrorReply("Token deletion failed", {deleteTokenResult}, cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1221,9 +1308,12 @@ void JsonAPI::handleRequestToken(const QJsonObject &message, const JsonApiComman
|
|||||||
const QString &identifier = message["id"].toString().trimmed();
|
const QString &identifier = message["id"].toString().trimmed();
|
||||||
const QString &comment = message["comment"].toString().trimmed();
|
const QString &comment = message["comment"].toString().trimmed();
|
||||||
const bool &acc = message["accept"].toBool(true);
|
const bool &acc = message["accept"].toBool(true);
|
||||||
if (acc) {
|
if (acc)
|
||||||
|
{
|
||||||
API::setNewTokenRequest(comment, identifier, cmd.tan);
|
API::setNewTokenRequest(comment, identifier, cmd.tan);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
API::cancelNewTokenRequest(comment, identifier);
|
API::cancelNewTokenRequest(comment, identifier);
|
||||||
// client should wait for answer
|
// client should wait for answer
|
||||||
}
|
}
|
||||||
@ -1232,7 +1322,8 @@ void JsonAPI::handleRequestToken(const QJsonObject &message, const JsonApiComman
|
|||||||
void JsonAPI::handleGetPendingTokenRequests(const JsonApiCommand &cmd)
|
void JsonAPI::handleGetPendingTokenRequests(const JsonApiCommand &cmd)
|
||||||
{
|
{
|
||||||
QVector<AuthManager::AuthDefinition> vec;
|
QVector<AuthManager::AuthDefinition> vec;
|
||||||
if (API::getPendingTokenRequests(vec)) {
|
if (API::getPendingTokenRequests(vec))
|
||||||
|
{
|
||||||
QJsonArray pendingTokeRequests;
|
QJsonArray pendingTokeRequests;
|
||||||
for (const auto &entry : std::as_const(vec))
|
for (const auto &entry : std::as_const(vec))
|
||||||
{
|
{
|
||||||
@ -1251,9 +1342,12 @@ void JsonAPI::handleAnswerRequest(const QJsonObject &message, const JsonApiComma
|
|||||||
{
|
{
|
||||||
const QString &identifier = message["id"].toString().trimmed();
|
const QString &identifier = message["id"].toString().trimmed();
|
||||||
const bool &accept = message["accept"].toBool(false);
|
const bool &accept = message["accept"].toBool(false);
|
||||||
if (API::handlePendingTokenRequest(identifier, accept)) {
|
if (API::handlePendingTokenRequest(identifier, accept))
|
||||||
|
{
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
sendErrorReply("Unable to handle token acceptance or denial", cmd);
|
sendErrorReply("Unable to handle token acceptance or denial", cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1285,9 +1379,12 @@ void JsonAPI::handleLogin(const QJsonObject &message, const JsonApiCommand& cmd)
|
|||||||
// userToken is longer than app token
|
// userToken is longer than app token
|
||||||
if (token.size() > APP_TOKEN_LENGTH)
|
if (token.size() > APP_TOKEN_LENGTH)
|
||||||
{
|
{
|
||||||
if (API::isUserTokenAuthorized(token)) {
|
if (API::isUserTokenAuthorized(token))
|
||||||
|
{
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
sendNoAuthorization(cmd);
|
sendNoAuthorization(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1296,9 +1393,12 @@ void JsonAPI::handleLogin(const QJsonObject &message, const JsonApiCommand& cmd)
|
|||||||
|
|
||||||
if (token.size() == APP_TOKEN_LENGTH)
|
if (token.size() == APP_TOKEN_LENGTH)
|
||||||
{
|
{
|
||||||
if (API::isTokenAuthorized(token)) {
|
if (API::isTokenAuthorized(token))
|
||||||
|
{
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
sendNoAuthorization(cmd);
|
sendNoAuthorization(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1345,9 +1445,12 @@ void JsonAPI::handleTokenResponse(bool success, const QString &token, const QStr
|
|||||||
result["comment"] = comment;
|
result["comment"] = comment;
|
||||||
result["id"] = identifier;
|
result["id"] = identifier;
|
||||||
|
|
||||||
if (success) {
|
if (success)
|
||||||
|
{
|
||||||
sendSuccessDataReply(result, cmd, tan);
|
sendSuccessDataReply(result, cmd, tan);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
sendErrorReply("Token request timeout or denied", {}, cmd, tan);
|
sendErrorReply("Token request timeout or denied", {}, cmd, tan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1359,7 +1462,8 @@ void JsonAPI::handleInstanceCommand(const QJsonObject &message, const JsonApiCom
|
|||||||
const quint8 inst = static_cast<quint8>(message["instance"].toInt());
|
const quint8 inst = static_cast<quint8>(message["instance"].toInt());
|
||||||
const QString &name = message["name"].toString();
|
const QString &name = message["name"].toString();
|
||||||
|
|
||||||
switch (cmd.subCommand) {
|
switch (cmd.subCommand)
|
||||||
|
{
|
||||||
case SubCommand::SwitchTo:
|
case SubCommand::SwitchTo:
|
||||||
if (handleInstanceSwitch(inst))
|
if (handleInstanceSwitch(inst))
|
||||||
{
|
{
|
||||||
@ -1375,9 +1479,7 @@ void JsonAPI::handleInstanceCommand(const QJsonObject &message, const JsonApiCom
|
|||||||
case SubCommand::StartInstance:
|
case SubCommand::StartInstance:
|
||||||
// Only send update once
|
// Only send update once
|
||||||
weakConnect(this, &API::onStartInstanceResponse, [this, cmd]()
|
weakConnect(this, &API::onStartInstanceResponse, [this, cmd]()
|
||||||
{
|
{ sendSuccessReply(cmd); });
|
||||||
sendSuccessReply(cmd);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!API::startInstance(inst, cmd.tan))
|
if (!API::startInstance(inst, cmd.tan))
|
||||||
{
|
{
|
||||||
@ -1404,20 +1506,27 @@ void JsonAPI::handleInstanceCommand(const QJsonObject &message, const JsonApiCom
|
|||||||
case SubCommand::CreateInstance:
|
case SubCommand::CreateInstance:
|
||||||
case SubCommand::SaveName:
|
case SubCommand::SaveName:
|
||||||
// create and save name requires name
|
// create and save name requires name
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty())
|
||||||
|
{
|
||||||
sendErrorReply("Name string required for this command", cmd);
|
sendErrorReply("Name string required for this command", cmd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd.subCommand == SubCommand::CreateInstance) {
|
if (cmd.subCommand == SubCommand::CreateInstance)
|
||||||
|
{
|
||||||
replyMsg = API::createInstance(name);
|
replyMsg = API::createInstance(name);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
replyMsg = API::setInstanceName(inst, name);
|
replyMsg = API::setInstanceName(inst, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (replyMsg.isEmpty()) {
|
if (replyMsg.isEmpty())
|
||||||
|
{
|
||||||
sendSuccessReply(cmd);
|
sendSuccessReply(cmd);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
sendErrorReply(replyMsg, cmd);
|
sendErrorReply(replyMsg, cmd);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1431,7 +1540,8 @@ void JsonAPI::handleLedDeviceCommand(const QJsonObject &message, const JsonApiCo
|
|||||||
const QString &devType = message["ledDeviceType"].toString().trimmed();
|
const QString &devType = message["ledDeviceType"].toString().trimmed();
|
||||||
const LedDeviceRegistry &ledDevices = LedDeviceWrapper::getDeviceMap();
|
const LedDeviceRegistry &ledDevices = LedDeviceWrapper::getDeviceMap();
|
||||||
|
|
||||||
if (ledDevices.count(devType) == 0) {
|
if (ledDevices.count(devType) == 0)
|
||||||
|
{
|
||||||
sendErrorReply(QString("Unknown LED-Device type: %1").arg(devType), cmd);
|
sendErrorReply(QString("Unknown LED-Device type: %1").arg(devType), cmd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1439,7 +1549,8 @@ void JsonAPI::handleLedDeviceCommand(const QJsonObject &message, const JsonApiCo
|
|||||||
QJsonObject config{{"type", devType}};
|
QJsonObject config{{"type", devType}};
|
||||||
LedDevice *ledDevice = LedDeviceFactory::construct(config);
|
LedDevice *ledDevice = LedDeviceFactory::construct(config);
|
||||||
|
|
||||||
switch (cmd.subCommand) {
|
switch (cmd.subCommand)
|
||||||
|
{
|
||||||
case SubCommand::Discover:
|
case SubCommand::Discover:
|
||||||
handleLedDeviceDiscover(*ledDevice, message, cmd);
|
handleLedDeviceDiscover(*ledDevice, message, cmd);
|
||||||
break;
|
break;
|
||||||
@ -1489,16 +1600,19 @@ void JsonAPI::handleLedDeviceAddAuthorization(LedDevice& ledDevice, const QJsonO
|
|||||||
sendSuccessDataReply(response, cmd);
|
sendSuccessDataReply(response, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonAPI::handleInputSourceCommand(const QJsonObject& message, const JsonApiCommand& cmd) {
|
void JsonAPI::handleInputSourceCommand(const QJsonObject &message, const JsonApiCommand &cmd)
|
||||||
|
{
|
||||||
const QString &sourceType = message["sourceType"].toString().trimmed();
|
const QString &sourceType = message["sourceType"].toString().trimmed();
|
||||||
const QStringList sourceTypes{"screen", "video", "audio"};
|
const QStringList sourceTypes{"screen", "video", "audio"};
|
||||||
|
|
||||||
if (!sourceTypes.contains(sourceType)) {
|
if (!sourceTypes.contains(sourceType))
|
||||||
|
{
|
||||||
sendErrorReply(QString("Unknown input source type: %1").arg(sourceType), cmd);
|
sendErrorReply(QString("Unknown input source type: %1").arg(sourceType), cmd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd.subCommand == SubCommand::Discover) {
|
if (cmd.subCommand == SubCommand::Discover)
|
||||||
|
{
|
||||||
|
|
||||||
const QJsonObject ¶ms = message["params"].toObject();
|
const QJsonObject ¶ms = message["params"].toObject();
|
||||||
QJsonObject inputSourcesDiscovered = JsonInfo().discoverSources(sourceType, params);
|
QJsonObject inputSourcesDiscovered = JsonInfo().discoverSources(sourceType, params);
|
||||||
@ -1549,7 +1663,8 @@ void JsonAPI::handleServiceCommand(const QJsonObject &message, const JsonApiComm
|
|||||||
|
|
||||||
void JsonAPI::handleSystemCommand(const QJsonObject & /*message*/, const JsonApiCommand &cmd)
|
void JsonAPI::handleSystemCommand(const QJsonObject & /*message*/, const JsonApiCommand &cmd)
|
||||||
{
|
{
|
||||||
switch (cmd.subCommand) {
|
switch (cmd.subCommand)
|
||||||
|
{
|
||||||
case SubCommand::Suspend:
|
case SubCommand::Suspend:
|
||||||
emit signalEvent(Event::Suspend);
|
emit signalEvent(Event::Suspend);
|
||||||
break;
|
break;
|
||||||
@ -1720,7 +1835,8 @@ QString JsonAPI::findCommand (const QString& jsonString)
|
|||||||
static QRegularExpression regex("\"command\"\\s*:\\s*\"([^\"]+)\"");
|
static QRegularExpression regex("\"command\"\\s*:\\s*\"([^\"]+)\"");
|
||||||
QRegularExpressionMatch match = regex.match(jsonString);
|
QRegularExpressionMatch match = regex.match(jsonString);
|
||||||
|
|
||||||
if (match.hasMatch()) {
|
if (match.hasMatch())
|
||||||
|
{
|
||||||
commandValue = match.captured(1);
|
commandValue = match.captured(1);
|
||||||
}
|
}
|
||||||
return commandValue;
|
return commandValue;
|
||||||
@ -1732,7 +1848,8 @@ int JsonAPI::findTan (const QString& jsonString)
|
|||||||
static QRegularExpression regex("\"tan\"\\s*:\\s*(\\d+)");
|
static QRegularExpression regex("\"tan\"\\s*:\\s*(\\d+)");
|
||||||
QRegularExpressionMatch match = regex.match(jsonString);
|
QRegularExpressionMatch match = regex.match(jsonString);
|
||||||
|
|
||||||
if (match.hasMatch()) {
|
if (match.hasMatch())
|
||||||
|
{
|
||||||
QString valueStr = match.captured(1);
|
QString valueStr = match.captured(1);
|
||||||
tanValue = valueStr.toInt();
|
tanValue = valueStr.toInt();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user