mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Separate handleInstanceCommand out
This commit is contained in:
parent
12ace5e418
commit
c4b88a2e0e
@ -97,6 +97,7 @@ signals:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
void handleCommand(const JsonApiCommand& cmd, const QJsonObject &message);
|
void handleCommand(const JsonApiCommand& cmd, const QJsonObject &message);
|
||||||
|
void handleInstanceCommand(const JsonApiCommand& cmd, const QJsonObject &message);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// @brief Handle the switches of Hyperion instances
|
/// @brief Handle the switches of Hyperion instances
|
||||||
|
@ -235,16 +235,15 @@ void JsonAPI::handleMessage(const QString &messageString, const QString &httpAut
|
|||||||
handleCommand(cmd, message);
|
handleCommand(cmd, message);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
handleInstanceCommand(cmd, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void JsonAPI::handleInstanceCommand(const JsonApiCommand& cmd, const QJsonObject &message)
|
||||||
{
|
{
|
||||||
const QJsonValue instanceElement = message.value("instance");
|
const QJsonValue instanceElement = message.value("instance");
|
||||||
|
|
||||||
QList<quint8> runningInstanceIdxs = _instanceManager->getRunningInstanceIdx();
|
|
||||||
|
|
||||||
QList<quint8> intanceIdxList;
|
|
||||||
QStringList errorDetails;
|
|
||||||
|
|
||||||
QJsonArray instances;
|
QJsonArray instances;
|
||||||
|
|
||||||
if (instanceElement.isDouble())
|
if (instanceElement.isDouble())
|
||||||
{
|
{
|
||||||
instances.append(instanceElement);
|
instances.append(instanceElement);
|
||||||
@ -253,11 +252,15 @@ void JsonAPI::handleMessage(const QString &messageString, const QString &httpAut
|
|||||||
instances = instanceElement.toArray();
|
instances = instanceElement.toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<quint8> runningInstanceIdxs = _instanceManager->getRunningInstanceIdx();
|
||||||
|
|
||||||
|
QList<quint8> instanceIdxList;
|
||||||
|
QStringList errorDetails;
|
||||||
if (instances.contains("all"))
|
if (instances.contains("all"))
|
||||||
{
|
{
|
||||||
for (const auto& instanceIdx : runningInstanceIdxs)
|
for (const auto& instanceIdx : runningInstanceIdxs)
|
||||||
{
|
{
|
||||||
intanceIdxList.append(instanceIdx);
|
instanceIdxList.append(instanceIdx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -267,7 +270,7 @@ void JsonAPI::handleMessage(const QString &messageString, const QString &httpAut
|
|||||||
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))
|
||||||
{
|
{
|
||||||
intanceIdxList.append(instanceIdx);
|
instanceIdxList.append(instanceIdx);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -276,15 +279,14 @@ void JsonAPI::handleMessage(const QString &messageString, const QString &httpAut
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (intanceIdxList.isEmpty() || !errorDetails.isEmpty() )
|
if (instanceIdxList.isEmpty() || !errorDetails.isEmpty() )
|
||||||
{
|
{
|
||||||
cmd.isInstanceCmd = InstanceCmd::No;
|
|
||||||
sendErrorReply("Invalid instance(s) given", errorDetails, cmd);
|
sendErrorReply("Invalid instance(s) given", errorDetails, cmd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint8 currentInstanceIdx = getCurrentInstanceIndex();
|
quint8 currentInstanceIdx = getCurrentInstanceIndex();
|
||||||
if (intanceIdxList.size() > 1)
|
if (instanceIdxList.size() > 1)
|
||||||
{
|
{
|
||||||
if (cmd.isInstanceCmd != InstanceCmd::Multi)
|
if (cmd.isInstanceCmd != InstanceCmd::Multi)
|
||||||
{
|
{
|
||||||
@ -293,7 +295,7 @@ void JsonAPI::handleMessage(const QString &messageString, const QString &httpAut
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &instanceIdx : intanceIdxList)
|
for (const auto &instanceIdx : instanceIdxList)
|
||||||
{
|
{
|
||||||
if (setHyperionInstance(instanceIdx))
|
if (setHyperionInstance(instanceIdx))
|
||||||
{
|
{
|
||||||
@ -304,8 +306,6 @@ void JsonAPI::handleMessage(const QString &messageString, const QString &httpAut
|
|||||||
setHyperionInstance(currentInstanceIdx);
|
setHyperionInstance(currentInstanceIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void JsonAPI::handleCommand(const JsonApiCommand& cmd, const QJsonObject &message)
|
void JsonAPI::handleCommand(const JsonApiCommand& cmd, const QJsonObject &message)
|
||||||
{
|
{
|
||||||
switch (cmd.command) {
|
switch (cmd.command) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user