|
|
|
@@ -57,7 +57,8 @@
|
|
|
|
|
using namespace hyperion;
|
|
|
|
|
|
|
|
|
|
// Constants
|
|
|
|
|
namespace {
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
: API(log, localConnection, parent)
|
|
|
|
|
,_noListener(noListener)
|
|
|
|
|
,_peerAddress (std::move(peerAddress))
|
|
|
|
|
,_jsonCB (nullptr)
|
|
|
|
|
: API(log, localConnection, parent), _noListener(noListener), _peerAddress(std::move(peerAddress)), _jsonCB(nullptr)
|
|
|
|
|
{
|
|
|
|
|
Q_INIT_RESOURCE(JSONRPC_schemas);
|
|
|
|
|
|
|
|
|
@@ -188,10 +186,12 @@ void JsonAPI::handleMessage(const QString &messageString, const QString &httpAut
|
|
|
|
|
if (!httpAuthHeader.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
int bearTokenLenght{0};
|
|
|
|
|
if (httpAuthHeader.startsWith(BEARER_TOKEN_TAG, Qt::CaseInsensitive)) {
|
|
|
|
|
if (httpAuthHeader.startsWith(BEARER_TOKEN_TAG, Qt::CaseInsensitive))
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -253,7 +253,8 @@ void JsonAPI::handleInstanceCommand(const JsonApiCommand& cmd, const QJsonObject
|
|
|
|
|
if (instanceElement.isDouble())
|
|
|
|
|
{
|
|
|
|
|
instances.append(instanceElement);
|
|
|
|
|
} else if (instanceElement.isArray())
|
|
|
|
|
}
|
|
|
|
|
else if (instanceElement.isArray())
|
|
|
|
|
{
|
|
|
|
|
instances = instanceElement.toArray();
|
|
|
|
|
}
|
|
|
|
@@ -271,7 +272,8 @@ void JsonAPI::handleInstanceCommand(const JsonApiCommand& cmd, const QJsonObject
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (const auto &instance : std::as_const(instances)) {
|
|
|
|
|
for (const auto &instance : std::as_const(instances))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
quint8 instanceIdx = static_cast<quint8>(instance.toInt());
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.command) {
|
|
|
|
|
switch (cmd.command)
|
|
|
|
|
{
|
|
|
|
|
case Command::Authorize:
|
|
|
|
|
handleAuthorizeCommand(message, cmd);
|
|
|
|
|
break;
|
|
|
|
@@ -386,6 +389,9 @@ void JsonAPI::handleCommand(const JsonApiCommand& cmd, const QJsonObject &messag
|
|
|
|
|
case Command::ClearAll:
|
|
|
|
|
handleClearallCommand(message, cmd);
|
|
|
|
|
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
|
|
|
|
|
case Command::Transform:
|
|
|
|
|
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);
|
|
|
|
|
break;
|
|
|
|
|
// END
|
|
|
|
|
case Command::GetCurrentImage:
|
|
|
|
|
handleGetCurrentImageCommand(message, cmd);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonAPI::handleGetCurrentImageCommand(const QJsonObject &message, const JsonApiCommand& cmd)
|
|
|
|
|
void JsonAPI::handleGetImageSnapshotCommand(const QJsonObject &message, const JsonApiCommand &cmd)
|
|
|
|
|
{
|
|
|
|
|
QString replyMsg;
|
|
|
|
|
|
|
|
|
|
Debug(_log, "Get image command received");
|
|
|
|
|
QString savePath = message["path"].toString();
|
|
|
|
|
|
|
|
|
|
Debug(_log,"Save path: %s", QSTRING_CSTR(savePath));
|
|
|
|
|
|
|
|
|
|
int priority = _hyperion->getCurrentPriority();
|
|
|
|
|
const PriorityMuxer::InputInfo priorityInfo = _hyperion->getPriorityInfo(priority);
|
|
|
|
|
QString filetype = message["filetype"].toString();
|
|
|
|
|
const QStringList fileTypes{"BMP", "JPG", "PNG"};
|
|
|
|
|
if (filetype.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
sendErrorReply("Missing filetype. Available filetypes: " + fileTypes.join(", "), cmd);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
QImage jpgImage(reinterpret_cast<const uchar*>(image.memptr()), image.width(), image.height(), qsizetype(3) * image.width(), QImage::Format_RGB888);
|
|
|
|
|
QImage snapshot(reinterpret_cast<const uchar *>(image.memptr()), image.width(), image.height(), qsizetype(3) * image.width(), QImage::Format_RGB888);
|
|
|
|
|
QByteArray byteArray;
|
|
|
|
|
QBuffer buffer(&byteArray);
|
|
|
|
|
|
|
|
|
|
QBuffer buffer{&byteArray};
|
|
|
|
|
buffer.open(QIODevice::WriteOnly);
|
|
|
|
|
jpgImage.save(&buffer, "JPG");
|
|
|
|
|
QString base64Image = QString::fromLatin1(byteArray.toBase64().data());
|
|
|
|
|
if (!savePath.isEmpty())
|
|
|
|
|
if (!snapshot.save(&buffer, filetype.toUtf8().constData()))
|
|
|
|
|
{
|
|
|
|
|
if (!jpgImage.save(savePath, "JPG"))
|
|
|
|
|
{
|
|
|
|
|
replyMsg = "Failed to save image to: " + savePath;
|
|
|
|
|
replyMsg = QString("Failed to create snapshot of the current image in %1 format").arg(filetype);
|
|
|
|
|
sendErrorReply(replyMsg, cmd);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
QByteArray base64Image = byteArray.toBase64();
|
|
|
|
|
|
|
|
|
|
QJsonObject info;
|
|
|
|
|
info["path"] = savePath;
|
|
|
|
|
info["format"] = "JPG";
|
|
|
|
|
info["format"] = filetype;
|
|
|
|
|
info["width"] = image.width();
|
|
|
|
|
info["height"] = image.height();
|
|
|
|
|
info["size"] = image.width() * image.height() * 3;
|
|
|
|
|
info["data"] = base64Image;
|
|
|
|
|
info["data"] = QString::fromLatin1(base64Image.data());
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
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()));
|
|
|
|
|
// Transform each entry in jsonColor to uint8_t and append to 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);
|
|
|
|
|
sendSuccessReply(cmd);
|
|
|
|
@@ -474,9 +518,12 @@ void JsonAPI::handleImageCommand(const QJsonObject &message, const JsonApiComman
|
|
|
|
|
idata.data = QByteArray::fromBase64(QByteArray(message["imagedata"].toString().toUtf8()));
|
|
|
|
|
QString replyMsg;
|
|
|
|
|
|
|
|
|
|
if (API::setImage(idata, COMP_IMAGE, replyMsg)) {
|
|
|
|
|
if (API::setImage(idata, COMP_IMAGE, replyMsg))
|
|
|
|
|
{
|
|
|
|
|
sendSuccessReply(cmd);
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sendErrorReply(replyMsg, cmd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -495,9 +542,12 @@ void JsonAPI::handleEffectCommand(const QJsonObject &message, const JsonApiComma
|
|
|
|
|
dat.data = message["imageData"].toString("").toUtf8();
|
|
|
|
|
dat.args = message["effect"].toObject()["args"].toObject();
|
|
|
|
|
|
|
|
|
|
if (API::setEffect(dat)) {
|
|
|
|
|
if (API::setEffect(dat))
|
|
|
|
|
{
|
|
|
|
|
sendSuccessReply(cmd);
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sendErrorReply("Effect '" + dat.effectName + "' not found", cmd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -525,7 +575,8 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject &message, const JsonApiC
|
|
|
|
|
QJsonObject info{};
|
|
|
|
|
QStringList errorDetails;
|
|
|
|
|
|
|
|
|
|
switch (cmd.getSubCommand()) {
|
|
|
|
|
switch (cmd.getSubCommand())
|
|
|
|
|
{
|
|
|
|
|
case SubCommand::Empty:
|
|
|
|
|
case SubCommand::GetInfo:
|
|
|
|
|
info["priorities"] = JsonInfo::getPrioritiestInfo(_hyperion);
|
|
|
|
@@ -569,7 +620,8 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject &message, const JsonApiC
|
|
|
|
|
{
|
|
|
|
|
const QJsonObject ¶ms = message["data"].toObject();
|
|
|
|
|
const QJsonArray &subscriptions = params["subscriptions"].toArray();
|
|
|
|
|
if (subscriptions.isEmpty()) {
|
|
|
|
|
if (subscriptions.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
sendErrorReply("Invalid params", {"No subscriptions provided"}, cmd);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@@ -633,14 +685,16 @@ void JsonAPI::handleAdjustmentCommand(const QJsonObject &message, const JsonApiC
|
|
|
|
|
const QJsonObject &adjustment = message["adjustment"].toObject();
|
|
|
|
|
|
|
|
|
|
const QList<QString> adjustmentIds = _hyperion->getAdjustmentIds();
|
|
|
|
|
if (adjustmentIds.isEmpty()) {
|
|
|
|
|
if (adjustmentIds.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
sendErrorReply("No adjustment data available", cmd);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString adjustmentId = adjustment["id"].toString(adjustmentIds.first());
|
|
|
|
|
ColorAdjustment *colorAdjustment = _hyperion->getAdjustment(adjustmentId);
|
|
|
|
|
if (colorAdjustment == nullptr) {
|
|
|
|
|
if (colorAdjustment == nullptr)
|
|
|
|
|
{
|
|
|
|
|
Warning(_log, "Incorrect adjustment identifier: %s", adjustmentId.toStdString().c_str());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@@ -664,9 +718,11 @@ void JsonAPI::applyColorAdjustments(const QJsonObject &adjustment, ColorAdjustme
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
if (values.size() >= 3) {
|
|
|
|
|
if (values.size() >= 3)
|
|
|
|
|
{
|
|
|
|
|
rgbAdjustment.setAdjustment(static_cast<uint8_t>(values[0U].toInt()),
|
|
|
|
|
static_cast<uint8_t>(values[1U].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)
|
|
|
|
|
{
|
|
|
|
|
if (adjustment.contains(transformName)) {
|
|
|
|
|
if (adjustment.contains(transformName))
|
|
|
|
|
{
|
|
|
|
|
rgbTransform.setGamma(channel == 'r' ? adjustment[transformName].toDouble() : rgbTransform.getGammaR(),
|
|
|
|
|
channel == 'g' ? adjustment[transformName].toDouble() : rgbTransform.getGammaG(),
|
|
|
|
|
channel == 'b' ? adjustment[transformName].toDouble() : rgbTransform.getGammaB());
|
|
|
|
@@ -700,7 +757,8 @@ void JsonAPI::applyGammaTransform(const QString &transformName, const QJsonObjec
|
|
|
|
|
template <typename T>
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -708,7 +766,8 @@ void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &ad
|
|
|
|
|
template <typename T>
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -716,7 +775,8 @@ void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &ad
|
|
|
|
|
template <typename T>
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -724,7 +784,8 @@ void JsonAPI::applyTransform(const QString &transformName, const QJsonObject &ad
|
|
|
|
|
template <typename 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()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -749,7 +810,8 @@ void JsonAPI::handleSourceSelectCommand(const QJsonObject &message, const JsonAp
|
|
|
|
|
|
|
|
|
|
void JsonAPI::handleConfigCommand(const QJsonObject &message, const JsonApiCommand &cmd)
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.subCommand) {
|
|
|
|
|
switch (cmd.subCommand)
|
|
|
|
|
{
|
|
|
|
|
case SubCommand::GetSchema:
|
|
|
|
|
handleSchemaGetCommand(message, cmd);
|
|
|
|
|
break;
|
|
|
|
@@ -831,7 +893,8 @@ void JsonAPI::handleConfigSetCommand(const QJsonObject &message, const JsonApiCo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMapIterator<quint8, QJsonObject> i(instancesNewConfigs);
|
|
|
|
|
while (i.hasNext()) {
|
|
|
|
|
while (i.hasNext())
|
|
|
|
|
{
|
|
|
|
|
i.next();
|
|
|
|
|
|
|
|
|
|
quint8 idx = i.key();
|
|
|
|
@@ -864,8 +927,10 @@ void JsonAPI::handleConfigGetCommand(const QJsonObject &message, const JsonApiCo
|
|
|
|
|
if (!globalConfig.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
const QJsonArray globalTypes = globalConfig["types"].toArray();
|
|
|
|
|
for (const auto &type : globalTypes) {
|
|
|
|
|
if (type.isString()) {
|
|
|
|
|
for (const auto &type : globalTypes)
|
|
|
|
|
{
|
|
|
|
|
if (type.isString())
|
|
|
|
|
{
|
|
|
|
|
globalFilterTypes.append(type.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -879,8 +944,10 @@ void JsonAPI::handleConfigGetCommand(const QJsonObject &message, const JsonApiCo
|
|
|
|
|
{
|
|
|
|
|
QList<quint8> configuredInstanceIds = _instanceManager->getInstanceIds();
|
|
|
|
|
const QJsonArray instanceIds = instances["ids"].toArray();
|
|
|
|
|
for (const auto &idx : instanceIds) {
|
|
|
|
|
if (idx.isDouble()) {
|
|
|
|
|
for (const auto &idx : instanceIds)
|
|
|
|
|
{
|
|
|
|
|
if (idx.isDouble())
|
|
|
|
|
{
|
|
|
|
|
quint8 instanceId = static_cast<quint8>(idx.toInt());
|
|
|
|
|
if (configuredInstanceIds.contains(instanceId))
|
|
|
|
|
{
|
|
|
|
@@ -894,8 +961,10 @@ void JsonAPI::handleConfigGetCommand(const QJsonObject &message, const JsonApiCo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QJsonArray instanceTypes = instances["types"].toArray();
|
|
|
|
|
for (const auto &type : instanceTypes) {
|
|
|
|
|
if (type.isString()) {
|
|
|
|
|
for (const auto &type : instanceTypes)
|
|
|
|
|
{
|
|
|
|
|
if (type.isString())
|
|
|
|
|
{
|
|
|
|
|
instanceFilterTypes.append(type.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -1026,16 +1095,20 @@ void JsonAPI::handleComponentStateCommand(const QJsonObject &message, const Json
|
|
|
|
|
bool compState = componentState["state"].toBool(true);
|
|
|
|
|
QString replyMsg;
|
|
|
|
|
|
|
|
|
|
if (API::setComponentState(comp, compState, replyMsg)) {
|
|
|
|
|
if (API::setComponentState(comp, compState, replyMsg))
|
|
|
|
|
{
|
|
|
|
|
sendSuccessReply(cmd);
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sendErrorReply(replyMsg, cmd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JsonAPI::handleLedColorsCommand(const QJsonObject & /*message*/, const JsonApiCommand &cmd)
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.subCommand) {
|
|
|
|
|
switch (cmd.subCommand)
|
|
|
|
|
{
|
|
|
|
|
case SubCommand::LedStreamStart:
|
|
|
|
|
_jsonCB->subscribe(Subscription::LedColorsUpdate);
|
|
|
|
|
// push once
|
|
|
|
@@ -1065,7 +1138,8 @@ void JsonAPI::handleLedColorsCommand(const QJsonObject& /*message*/, const JsonA
|
|
|
|
|
|
|
|
|
|
void JsonAPI::handleLoggingCommand(const QJsonObject & /*message*/, const JsonApiCommand &cmd)
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.subCommand) {
|
|
|
|
|
switch (cmd.subCommand)
|
|
|
|
|
{
|
|
|
|
|
case SubCommand::Start:
|
|
|
|
|
_jsonCB->subscribe("logmsg-update");
|
|
|
|
|
sendSuccessReply(cmd);
|
|
|
|
@@ -1094,7 +1168,8 @@ void JsonAPI::handleVideoModeCommand(const QJsonObject &message, const JsonApiCo
|
|
|
|
|
|
|
|
|
|
void JsonAPI::handleAuthorizeCommand(const QJsonObject &message, const JsonApiCommand &cmd)
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.subCommand) {
|
|
|
|
|
switch (cmd.subCommand)
|
|
|
|
|
{
|
|
|
|
|
case SubCommand::TokenRequired:
|
|
|
|
|
handleTokenRequired(cmd);
|
|
|
|
|
break;
|
|
|
|
@@ -1169,9 +1244,12 @@ void JsonAPI::handleNewPassword(const QJsonObject &message, const JsonApiCommand
|
|
|
|
|
{
|
|
|
|
|
const QString password = message["password"].toString().trimmed();
|
|
|
|
|
const QString newPassword = message["newPassword"].toString().trimmed();
|
|
|
|
|
if (API::updateHyperionPassword(password, newPassword)) {
|
|
|
|
|
if (API::updateHyperionPassword(password, newPassword))
|
|
|
|
|
{
|
|
|
|
|
sendSuccessReply(cmd);
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
AuthManager::AuthDefinition def;
|
|
|
|
|
const QString createTokenResult = API::createToken(comment, def);
|
|
|
|
|
if (createTokenResult.isEmpty()) {
|
|
|
|
|
if (createTokenResult.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
QJsonObject newTok;
|
|
|
|
|
newTok["comment"] = def.comment;
|
|
|
|
|
newTok["id"] = def.id;
|
|
|
|
|
newTok["token"] = def.token;
|
|
|
|
|
|
|
|
|
|
sendSuccessDataReply(newTok, cmd);
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
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 &comment = message["comment"].toString().trimmed();
|
|
|
|
|
const QString renameTokenResult = API::renameToken(identifier, comment);
|
|
|
|
|
if (renameTokenResult.isEmpty()) {
|
|
|
|
|
if (renameTokenResult.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
sendSuccessReply(cmd);
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
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 deleteTokenResult = API::deleteToken(identifier);
|
|
|
|
|
if (deleteTokenResult.isEmpty()) {
|
|
|
|
|
if (deleteTokenResult.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
sendSuccessReply(cmd);
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
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 &comment = message["comment"].toString().trimmed();
|
|
|
|
|
const bool &acc = message["accept"].toBool(true);
|
|
|
|
|
if (acc) {
|
|
|
|
|
if (acc)
|
|
|
|
|
{
|
|
|
|
|
API::setNewTokenRequest(comment, identifier, cmd.tan);
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
API::cancelNewTokenRequest(comment, identifier);
|
|
|
|
|
// client should wait for answer
|
|
|
|
|
}
|
|
|
|
@@ -1232,7 +1322,8 @@ void JsonAPI::handleRequestToken(const QJsonObject &message, const JsonApiComman
|
|
|
|
|
void JsonAPI::handleGetPendingTokenRequests(const JsonApiCommand &cmd)
|
|
|
|
|
{
|
|
|
|
|
QVector<AuthManager::AuthDefinition> vec;
|
|
|
|
|
if (API::getPendingTokenRequests(vec)) {
|
|
|
|
|
if (API::getPendingTokenRequests(vec))
|
|
|
|
|
{
|
|
|
|
|
QJsonArray pendingTokeRequests;
|
|
|
|
|
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 bool &accept = message["accept"].toBool(false);
|
|
|
|
|
if (API::handlePendingTokenRequest(identifier, accept)) {
|
|
|
|
|
if (API::handlePendingTokenRequest(identifier, accept))
|
|
|
|
|
{
|
|
|
|
|
sendSuccessReply(cmd);
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
if (token.size() > APP_TOKEN_LENGTH)
|
|
|
|
|
{
|
|
|
|
|
if (API::isUserTokenAuthorized(token)) {
|
|
|
|
|
if (API::isUserTokenAuthorized(token))
|
|
|
|
|
{
|
|
|
|
|
sendSuccessReply(cmd);
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sendNoAuthorization(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1296,9 +1393,12 @@ void JsonAPI::handleLogin(const QJsonObject &message, const JsonApiCommand& cmd)
|
|
|
|
|
|
|
|
|
|
if (token.size() == APP_TOKEN_LENGTH)
|
|
|
|
|
{
|
|
|
|
|
if (API::isTokenAuthorized(token)) {
|
|
|
|
|
if (API::isTokenAuthorized(token))
|
|
|
|
|
{
|
|
|
|
|
sendSuccessReply(cmd);
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sendNoAuthorization(cmd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -1345,9 +1445,12 @@ void JsonAPI::handleTokenResponse(bool success, const QString &token, const QStr
|
|
|
|
|
result["comment"] = comment;
|
|
|
|
|
result["id"] = identifier;
|
|
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
sendSuccessDataReply(result, cmd, tan);
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
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 QString &name = message["name"].toString();
|
|
|
|
|
|
|
|
|
|
switch (cmd.subCommand) {
|
|
|
|
|
switch (cmd.subCommand)
|
|
|
|
|
{
|
|
|
|
|
case SubCommand::SwitchTo:
|
|
|
|
|
if (handleInstanceSwitch(inst))
|
|
|
|
|
{
|
|
|
|
@@ -1375,9 +1479,7 @@ void JsonAPI::handleInstanceCommand(const QJsonObject &message, const JsonApiCom
|
|
|
|
|
case SubCommand::StartInstance:
|
|
|
|
|
// Only send update once
|
|
|
|
|
weakConnect(this, &API::onStartInstanceResponse, [this, cmd]()
|
|
|
|
|
{
|
|
|
|
|
sendSuccessReply(cmd);
|
|
|
|
|
});
|
|
|
|
|
{ sendSuccessReply(cmd); });
|
|
|
|
|
|
|
|
|
|
if (!API::startInstance(inst, cmd.tan))
|
|
|
|
|
{
|
|
|
|
@@ -1404,20 +1506,27 @@ void JsonAPI::handleInstanceCommand(const QJsonObject &message, const JsonApiCom
|
|
|
|
|
case SubCommand::CreateInstance:
|
|
|
|
|
case SubCommand::SaveName:
|
|
|
|
|
// create and save name requires name
|
|
|
|
|
if (name.isEmpty()) {
|
|
|
|
|
if (name.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
sendErrorReply("Name string required for this command", cmd);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cmd.subCommand == SubCommand::CreateInstance) {
|
|
|
|
|
if (cmd.subCommand == SubCommand::CreateInstance)
|
|
|
|
|
{
|
|
|
|
|
replyMsg = API::createInstance(name);
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
replyMsg = API::setInstanceName(inst, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (replyMsg.isEmpty()) {
|
|
|
|
|
if (replyMsg.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
sendSuccessReply(cmd);
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sendErrorReply(replyMsg, cmd);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
@@ -1431,7 +1540,8 @@ void JsonAPI::handleLedDeviceCommand(const QJsonObject &message, const JsonApiCo
|
|
|
|
|
const QString &devType = message["ledDeviceType"].toString().trimmed();
|
|
|
|
|
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);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@@ -1439,7 +1549,8 @@ void JsonAPI::handleLedDeviceCommand(const QJsonObject &message, const JsonApiCo
|
|
|
|
|
QJsonObject config{{"type", devType}};
|
|
|
|
|
LedDevice *ledDevice = LedDeviceFactory::construct(config);
|
|
|
|
|
|
|
|
|
|
switch (cmd.subCommand) {
|
|
|
|
|
switch (cmd.subCommand)
|
|
|
|
|
{
|
|
|
|
|
case SubCommand::Discover:
|
|
|
|
|
handleLedDeviceDiscover(*ledDevice, message, cmd);
|
|
|
|
|
break;
|
|
|
|
@@ -1489,16 +1600,19 @@ void JsonAPI::handleLedDeviceAddAuthorization(LedDevice& ledDevice, const QJsonO
|
|
|
|
|
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 QStringList sourceTypes{"screen", "video", "audio"};
|
|
|
|
|
|
|
|
|
|
if (!sourceTypes.contains(sourceType)) {
|
|
|
|
|
if (!sourceTypes.contains(sourceType))
|
|
|
|
|
{
|
|
|
|
|
sendErrorReply(QString("Unknown input source type: %1").arg(sourceType), cmd);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cmd.subCommand == SubCommand::Discover) {
|
|
|
|
|
if (cmd.subCommand == SubCommand::Discover)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
const QJsonObject ¶ms = message["params"].toObject();
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.subCommand) {
|
|
|
|
|
switch (cmd.subCommand)
|
|
|
|
|
{
|
|
|
|
|
case SubCommand::Suspend:
|
|
|
|
|
emit signalEvent(Event::Suspend);
|
|
|
|
|
break;
|
|
|
|
@@ -1720,7 +1835,8 @@ QString JsonAPI::findCommand (const QString& jsonString)
|
|
|
|
|
static QRegularExpression regex("\"command\"\\s*:\\s*\"([^\"]+)\"");
|
|
|
|
|
QRegularExpressionMatch match = regex.match(jsonString);
|
|
|
|
|
|
|
|
|
|
if (match.hasMatch()) {
|
|
|
|
|
if (match.hasMatch())
|
|
|
|
|
{
|
|
|
|
|
commandValue = match.captured(1);
|
|
|
|
|
}
|
|
|
|
|
return commandValue;
|
|
|
|
@@ -1732,7 +1848,8 @@ int JsonAPI::findTan (const QString& jsonString)
|
|
|
|
|
static QRegularExpression regex("\"tan\"\\s*:\\s*(\\d+)");
|
|
|
|
|
QRegularExpressionMatch match = regex.match(jsonString);
|
|
|
|
|
|
|
|
|
|
if (match.hasMatch()) {
|
|
|
|
|
if (match.hasMatch())
|
|
|
|
|
{
|
|
|
|
|
QString valueStr = match.captured(1);
|
|
|
|
|
tanValue = valueStr.toInt();
|
|
|
|
|
}
|
|
|
|
|