mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Hyperion "Light", Build improvements and minor fixes (#1400)
* Allow build, if no grabbers are enabled * Align available functions to right Qt version * Update to next development version * Align available functions to right Qt version * fix workflows (apt/nightly) * Disable QNetworkConfigurationManager deprecation warnings * Initial go on Smart Pointers * Add Deallocation * Correct QT_WARNING_DISABLE_DEPRECATED (available since 5.9) * Cluster Build Variables * Hyperion Light * Address build warnings * Hyperion Light - UI * Update Protobuf to latest master * Removed compiler warnings * Added restart ability to systray * Correct Protobuf * Ignore 'no-return' warning on protobuf build * hyperion-remote: Fix auto discovery of hyperion server * Fix Qt version override * Update changelog * Remove Grabber Components, if no Grabber exists * Standalone Grabber - Fix fps default * Remote Control - Have Source Selction accrosswhole screen * Enable Blackborder detection only, if relevant input sources available * Enable Blackborder detection only, if relevant input sources available * Remote UI - rearrange containers * - QT5/6 path for arm64 added - Remove ZLib Dependency - Fix macOS bundle info details - Cleanup Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com> Co-authored-by: Paulchen Panther <Paulchen-Panter@protonmail.com>
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/hyperion)
|
||||
SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/hyperion)
|
||||
|
||||
if(ENABLE_FLATBUF_SERVER)
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../../libsrc/flatbufserver
|
||||
)
|
||||
endif()
|
||||
|
||||
FILE ( GLOB Hyperion_SOURCES "${CURRENT_HEADER_DIR}/*.h" "${CURRENT_SOURCE_DIR}/*.h" "${CURRENT_SOURCE_DIR}/*.cpp" )
|
||||
|
||||
@@ -19,18 +21,24 @@ add_library(hyperion
|
||||
target_link_libraries(hyperion
|
||||
blackborder
|
||||
hyperion-utils
|
||||
flatbufserver
|
||||
flatbuffers
|
||||
leddevice
|
||||
effectengine
|
||||
database
|
||||
${QT_LIBRARIES}
|
||||
)
|
||||
|
||||
if(ENABLE_BOBLIGHT)
|
||||
if(ENABLE_BOBLIGHT_SERVER)
|
||||
target_link_libraries(hyperion boblightserver)
|
||||
endif()
|
||||
|
||||
if(ENABLE_FLATBUF_SERVER)
|
||||
target_link_libraries(hyperion flatbufserver)
|
||||
endif()
|
||||
|
||||
if(ENABLE_FORWARDER)
|
||||
target_link_libraries(hyperion forwarder)
|
||||
endif()
|
||||
|
||||
if (ENABLE_AVAHI)
|
||||
target_link_libraries(hyperion bonjour)
|
||||
endif ()
|
||||
|
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <hyperion/Hyperion.h>
|
||||
|
||||
#include <hyperion/GrabberWrapper.h>
|
||||
|
||||
using namespace hyperion;
|
||||
|
||||
ComponentRegister::ComponentRegister(Hyperion* hyperion)
|
||||
@@ -11,12 +13,45 @@ ComponentRegister::ComponentRegister(Hyperion* hyperion)
|
||||
{
|
||||
// init all comps to false
|
||||
QVector<hyperion::Components> vect;
|
||||
vect << COMP_ALL << COMP_SMOOTHING << COMP_BLACKBORDER << COMP_FORWARDER << COMP_GRABBER << COMP_V4L << COMP_LEDDEVICE;
|
||||
vect << COMP_ALL << COMP_SMOOTHING << COMP_LEDDEVICE;
|
||||
|
||||
#if defined(ENABLE_BOBLIGHT)
|
||||
bool areScreenGrabberAvailable = !GrabberWrapper::availableGrabbers(GrabberTypeFilter::VIDEO).isEmpty();
|
||||
bool areVideoGrabberAvailable = !GrabberWrapper::availableGrabbers(GrabberTypeFilter::VIDEO).isEmpty();
|
||||
bool flatBufServerAvailable { false };
|
||||
bool protoBufServerAvailable{ false };
|
||||
|
||||
#if defined(ENABLE_FLATBUF_SERVER)
|
||||
flatBufServerAvailable = true;
|
||||
#endif
|
||||
|
||||
#if defined(ENABLE_PROTOBUF_SERVER)
|
||||
protoBufServerAvailable = true;
|
||||
#endif
|
||||
|
||||
if (areScreenGrabberAvailable)
|
||||
{
|
||||
vect << COMP_GRABBER;
|
||||
}
|
||||
|
||||
if (areVideoGrabberAvailable)
|
||||
{
|
||||
vect << COMP_V4L;
|
||||
}
|
||||
|
||||
if (areScreenGrabberAvailable || areVideoGrabberAvailable || flatBufServerAvailable || protoBufServerAvailable)
|
||||
{
|
||||
vect << COMP_BLACKBORDER;
|
||||
}
|
||||
|
||||
|
||||
#if defined(ENABLE_BOBLIGHT_SERVER)
|
||||
vect << COMP_BOBLIGHTSERVER;
|
||||
#endif
|
||||
|
||||
#if defined(ENABLE_FORWARDER)
|
||||
vect << COMP_FORWARDER;
|
||||
#endif
|
||||
|
||||
for(auto e : vect)
|
||||
{
|
||||
_componentStates.emplace(e, (e == COMP_ALL));
|
||||
@@ -36,12 +71,16 @@ int ComponentRegister::isComponentEnabled(hyperion::Components comp) const
|
||||
|
||||
void ComponentRegister::setNewComponentState(hyperion::Components comp, bool activated)
|
||||
{
|
||||
if(_componentStates[comp] != activated)
|
||||
|
||||
if (_componentStates.count(comp) > 0)
|
||||
{
|
||||
Debug( _log, "%s: %s", componentToString(comp), (activated? "enabled" : "disabled"));
|
||||
_componentStates[comp] = activated;
|
||||
// emit component has changed state
|
||||
emit updatedComponentState(comp, activated);
|
||||
if (_componentStates[comp] != activated)
|
||||
{
|
||||
Debug(_log, "%s: %s", componentToString(comp), (activated ? "enabled" : "disabled"));
|
||||
_componentStates[comp] = activated;
|
||||
// emit component has changed state
|
||||
emit updatedComponentState(comp, activated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -83,58 +83,70 @@ bool GrabberWrapper::isActive() const
|
||||
return _timer->isActive();
|
||||
}
|
||||
|
||||
QStringList GrabberWrapper::getActive(int inst) const
|
||||
QStringList GrabberWrapper::getActive(int inst, GrabberTypeFilter type) const
|
||||
{
|
||||
QStringList result = QStringList();
|
||||
|
||||
if(GRABBER_V4L_CLIENTS.contains(inst))
|
||||
result << GRABBER_V4L_CLIENTS.value(inst);
|
||||
if (type == GrabberTypeFilter::SCREEN || type == GrabberTypeFilter::ALL)
|
||||
{
|
||||
if (GRABBER_SYS_CLIENTS.contains(inst))
|
||||
result << GRABBER_SYS_CLIENTS.value(inst);
|
||||
}
|
||||
|
||||
if(GRABBER_SYS_CLIENTS.contains(inst))
|
||||
result << GRABBER_SYS_CLIENTS.value(inst);
|
||||
if (type == GrabberTypeFilter::VIDEO || type == GrabberTypeFilter::ALL)
|
||||
{
|
||||
if (GRABBER_V4L_CLIENTS.contains(inst))
|
||||
result << GRABBER_V4L_CLIENTS.value(inst);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QStringList GrabberWrapper::availableGrabbers()
|
||||
QStringList GrabberWrapper::availableGrabbers(GrabberTypeFilter type)
|
||||
{
|
||||
QStringList grabbers;
|
||||
|
||||
#ifdef ENABLE_DISPMANX
|
||||
grabbers << "dispmanx";
|
||||
#endif
|
||||
if (type == GrabberTypeFilter::SCREEN || type == GrabberTypeFilter::ALL)
|
||||
{
|
||||
#ifdef ENABLE_DISPMANX
|
||||
grabbers << "dispmanx";
|
||||
#endif
|
||||
|
||||
#if defined(ENABLE_V4L2) || defined(ENABLE_MF)
|
||||
grabbers << "v4l2";
|
||||
#endif
|
||||
#ifdef ENABLE_FB
|
||||
grabbers << "framebuffer";
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_FB
|
||||
grabbers << "framebuffer";
|
||||
#endif
|
||||
#ifdef ENABLE_AMLOGIC
|
||||
grabbers << "amlogic";
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_AMLOGIC
|
||||
grabbers << "amlogic";
|
||||
#endif
|
||||
#ifdef ENABLE_OSX
|
||||
grabbers << "osx";
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_OSX
|
||||
grabbers << "osx";
|
||||
#endif
|
||||
#ifdef ENABLE_X11
|
||||
grabbers << "x11";
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_X11
|
||||
grabbers << "x11";
|
||||
#endif
|
||||
#ifdef ENABLE_XCB
|
||||
grabbers << "xcb";
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_XCB
|
||||
grabbers << "xcb";
|
||||
#endif
|
||||
#ifdef ENABLE_QT
|
||||
grabbers << "qt";
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_QT
|
||||
grabbers << "qt";
|
||||
#endif
|
||||
#ifdef ENABLE_DX
|
||||
grabbers << "dx";
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ENABLE_DX
|
||||
grabbers << "dx";
|
||||
#endif
|
||||
if (type == GrabberTypeFilter::VIDEO || type == GrabberTypeFilter::ALL)
|
||||
{
|
||||
#if defined(ENABLE_V4L2) || defined(ENABLE_MF)
|
||||
grabbers << "v4l2";
|
||||
#endif
|
||||
}
|
||||
|
||||
return grabbers;
|
||||
}
|
||||
|
@@ -9,7 +9,11 @@
|
||||
|
||||
// hyperion include
|
||||
#include <hyperion/Hyperion.h>
|
||||
#include <hyperion/MessageForwarder.h>
|
||||
|
||||
#if defined(ENABLE_FORWARDER)
|
||||
#include <forwarder/MessageForwarder.h>
|
||||
#endif
|
||||
|
||||
#include <hyperion/ImageProcessor.h>
|
||||
#include <hyperion/ColorAdjustment.h>
|
||||
|
||||
@@ -37,7 +41,7 @@
|
||||
#include <hyperion/CaptureCont.h>
|
||||
|
||||
// Boblight
|
||||
#if defined(ENABLE_BOBLIGHT)
|
||||
#if defined(ENABLE_BOBLIGHT_SERVER)
|
||||
#include <boblightserver/BoblightServer.h>
|
||||
#endif
|
||||
|
||||
@@ -53,14 +57,16 @@ Hyperion::Hyperion(quint8 instance, bool readonlyMode)
|
||||
, _ledDeviceWrapper(nullptr)
|
||||
, _deviceSmooth(nullptr)
|
||||
, _effectEngine(nullptr)
|
||||
#if defined(ENABLE_FORWARDER)
|
||||
, _messageForwarder(nullptr)
|
||||
#endif
|
||||
, _log(Logger::getInstance("HYPERION"))
|
||||
, _hwLedCount()
|
||||
, _ledGridSize(hyperion::getLedLayoutGridSize(getSetting(settings::LEDS).array()))
|
||||
, _BGEffectHandler(nullptr)
|
||||
, _captureCont(nullptr)
|
||||
, _ledBuffer(_ledString.leds().size(), ColorRgb::BLACK)
|
||||
#if defined(ENABLE_BOBLIGHT)
|
||||
#if defined(ENABLE_BOBLIGHT_SERVER)
|
||||
, _boblightServer(nullptr)
|
||||
#endif
|
||||
, _readOnlyMode(readonlyMode)
|
||||
@@ -127,11 +133,13 @@ void Hyperion::start()
|
||||
//Start in pause mode, a new priority will activate smoothing (either start-effect or grabber)
|
||||
_deviceSmooth->setPause(true);
|
||||
|
||||
#if defined(ENABLE_FORWARDER)
|
||||
// create the message forwarder only on main instance
|
||||
if (_instIndex == 0)
|
||||
{
|
||||
_messageForwarder = new MessageForwarder(this);
|
||||
}
|
||||
#endif
|
||||
|
||||
// create the effect engine; needs to be initialized after smoothing!
|
||||
_effectEngine = new EffectEngine(this);
|
||||
@@ -155,7 +163,7 @@ void Hyperion::start()
|
||||
// if there is no startup / background effect and no sending capture interface we probably want to push once BLACK (as PrioMuxer won't emit a priority change)
|
||||
update();
|
||||
|
||||
#if defined(ENABLE_BOBLIGHT)
|
||||
#if defined(ENABLE_BOBLIGHT_SERVER)
|
||||
// boblight, can't live in global scope as it depends on layout
|
||||
_boblightServer = new BoblightServer(this, getSetting(settings::BOBLSERVER));
|
||||
connect(this, &Hyperion::settingsChanged, _boblightServer, &BoblightServer::handleSettingsUpdate);
|
||||
@@ -177,13 +185,18 @@ void Hyperion::freeObjects()
|
||||
clear(-1,true);
|
||||
|
||||
// delete components on exit of hyperion core
|
||||
#if defined(ENABLE_BOBLIGHT)
|
||||
#if defined(ENABLE_BOBLIGHT_SERVER)
|
||||
delete _boblightServer;
|
||||
#endif
|
||||
|
||||
delete _captureCont;
|
||||
delete _effectEngine;
|
||||
delete _raw2ledAdjustment;
|
||||
|
||||
#if defined(ENABLE_FORWARDER)
|
||||
delete _messageForwarder;
|
||||
#endif
|
||||
|
||||
delete _settingsManager;
|
||||
delete _ledDeviceWrapper;
|
||||
}
|
||||
|
@@ -1,324 +0,0 @@
|
||||
// STL includes
|
||||
#include <stdexcept>
|
||||
|
||||
// project includes
|
||||
#include <hyperion/MessageForwarder.h>
|
||||
|
||||
// hyperion includes
|
||||
#include <hyperion/Hyperion.h>
|
||||
|
||||
// utils includes
|
||||
#include <utils/Logger.h>
|
||||
#include <utils/NetUtils.h>
|
||||
|
||||
// qt includes
|
||||
#include <QTcpServer>
|
||||
#include <QTcpSocket>
|
||||
#include <QHostInfo>
|
||||
#include <QNetworkInterface>
|
||||
|
||||
#include <flatbufserver/FlatBufferConnection.h>
|
||||
|
||||
MessageForwarder::MessageForwarder(Hyperion* hyperion)
|
||||
: _hyperion(hyperion)
|
||||
, _log(Logger::getInstance("NETFORWARDER"))
|
||||
, _muxer(_hyperion->getMuxerInstance())
|
||||
, _forwarder_enabled(true)
|
||||
, _priority(140)
|
||||
{
|
||||
// get settings updates
|
||||
connect(_hyperion, &Hyperion::settingsChanged, this, &MessageForwarder::handleSettingsUpdate);
|
||||
|
||||
// component changes
|
||||
connect(_hyperion, &Hyperion::compStateChangeRequest, this, &MessageForwarder::handleCompStateChangeRequest);
|
||||
|
||||
// connect with Muxer visible priority changes
|
||||
connect(_muxer, &PriorityMuxer::visiblePriorityChanged, this, &MessageForwarder::handlePriorityChanges);
|
||||
|
||||
// init
|
||||
handleSettingsUpdate(settings::NETFORWARD, _hyperion->getSetting(settings::NETFORWARD));
|
||||
}
|
||||
|
||||
MessageForwarder::~MessageForwarder()
|
||||
{
|
||||
while (!_forwardClients.isEmpty())
|
||||
{
|
||||
delete _forwardClients.takeFirst();
|
||||
}
|
||||
}
|
||||
|
||||
void MessageForwarder::handleSettingsUpdate(settings::type type, const QJsonDocument& config)
|
||||
{
|
||||
if (type == settings::NETFORWARD)
|
||||
{
|
||||
// clear the current targets
|
||||
_jsonTargets.clear();
|
||||
_flatbufferTargets.clear();
|
||||
while (!_forwardClients.isEmpty())
|
||||
{
|
||||
delete _forwardClients.takeFirst();
|
||||
}
|
||||
|
||||
// build new one
|
||||
const QJsonObject& obj = config.object();
|
||||
if (!obj["json"].isNull())
|
||||
{
|
||||
const QJsonArray& addr = obj["json"].toArray();
|
||||
for (const auto& entry : addr)
|
||||
{
|
||||
addJsonTarget(entry.toObject());
|
||||
}
|
||||
}
|
||||
|
||||
if (!obj["flat"].isNull())
|
||||
{
|
||||
const QJsonArray& addr = obj["flat"].toArray();
|
||||
for (const auto& entry : addr)
|
||||
{
|
||||
addFlatbufferTarget(entry.toObject());
|
||||
}
|
||||
}
|
||||
|
||||
bool isForwarderEnabledinSettings = obj["enable"].toBool(false);
|
||||
|
||||
if (!_jsonTargets.isEmpty() && isForwarderEnabledinSettings && _forwarder_enabled)
|
||||
{
|
||||
for (const auto& targetHost : qAsConst(_jsonTargets))
|
||||
{
|
||||
InfoIf(isForwarderEnabledinSettings, _log, "Forwarding now to JSON-target host: %s port: %u", QSTRING_CSTR(targetHost.host.toString()), targetHost.port);
|
||||
}
|
||||
|
||||
connect(_hyperion, &Hyperion::forwardJsonMessage, this, &MessageForwarder::forwardJsonMessage, Qt::UniqueConnection);
|
||||
}
|
||||
else if (_jsonTargets.isEmpty() || !isForwarderEnabledinSettings || !_forwarder_enabled)
|
||||
{
|
||||
disconnect(_hyperion, &Hyperion::forwardJsonMessage, nullptr, nullptr);
|
||||
}
|
||||
|
||||
if (!_flatbufferTargets.isEmpty() && isForwarderEnabledinSettings && _forwarder_enabled)
|
||||
{
|
||||
for (const auto& targetHost : qAsConst(_flatbufferTargets))
|
||||
{
|
||||
InfoIf(isForwarderEnabledinSettings, _log, "Forwarding now to Flatbuffer-target host: %s port: %u", QSTRING_CSTR(targetHost.host.toString()), targetHost.port);
|
||||
}
|
||||
}
|
||||
else if (_flatbufferTargets.isEmpty() || !isForwarderEnabledinSettings || !_forwarder_enabled)
|
||||
{
|
||||
disconnect(_hyperion, &Hyperion::forwardSystemProtoMessage, nullptr, nullptr);
|
||||
disconnect(_hyperion, &Hyperion::forwardV4lProtoMessage, nullptr, nullptr);
|
||||
}
|
||||
|
||||
// update comp state
|
||||
_hyperion->setNewComponentState(hyperion::COMP_FORWARDER, isForwarderEnabledinSettings);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageForwarder::handleCompStateChangeRequest(hyperion::Components component, bool enable)
|
||||
{
|
||||
if (component == hyperion::COMP_FORWARDER && _forwarder_enabled != enable)
|
||||
{
|
||||
_forwarder_enabled = enable;
|
||||
handleSettingsUpdate(settings::NETFORWARD, _hyperion->getSetting(settings::NETFORWARD));
|
||||
Info(_log, "Forwarder change state to %s", (_forwarder_enabled ? "enabled" : "disabled"));
|
||||
_hyperion->setNewComponentState(component, _forwarder_enabled);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageForwarder::handlePriorityChanges(quint8 priority)
|
||||
{
|
||||
const QJsonObject obj = _hyperion->getSetting(settings::NETFORWARD).object();
|
||||
if (priority != 0 && _forwarder_enabled && obj["enable"].toBool())
|
||||
{
|
||||
hyperion::Components activeCompId = _hyperion->getPriorityInfo(priority).componentId;
|
||||
if (activeCompId == hyperion::COMP_GRABBER || activeCompId == hyperion::COMP_V4L)
|
||||
{
|
||||
if (!obj["flat"].isNull())
|
||||
{
|
||||
const QJsonArray& addr = obj["flat"].toArray();
|
||||
for (const auto& entry : addr)
|
||||
{
|
||||
addFlatbufferTarget(entry.toObject());
|
||||
}
|
||||
}
|
||||
|
||||
switch (activeCompId)
|
||||
{
|
||||
case hyperion::COMP_GRABBER:
|
||||
{
|
||||
disconnect(_hyperion, &Hyperion::forwardV4lProtoMessage, nullptr, nullptr);
|
||||
connect(_hyperion, &Hyperion::forwardSystemProtoMessage, this, &MessageForwarder::forwardFlatbufferMessage, Qt::UniqueConnection);
|
||||
}
|
||||
break;
|
||||
case hyperion::COMP_V4L:
|
||||
{
|
||||
disconnect(_hyperion, &Hyperion::forwardSystemProtoMessage, nullptr, nullptr);
|
||||
connect(_hyperion, &Hyperion::forwardV4lProtoMessage, this, &MessageForwarder::forwardFlatbufferMessage, Qt::UniqueConnection);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
disconnect(_hyperion, &Hyperion::forwardSystemProtoMessage, nullptr, nullptr);
|
||||
disconnect(_hyperion, &Hyperion::forwardV4lProtoMessage, nullptr, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
disconnect(_hyperion, &Hyperion::forwardSystemProtoMessage, nullptr, nullptr);
|
||||
disconnect(_hyperion, &Hyperion::forwardV4lProtoMessage, nullptr, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessageForwarder::addJsonTarget(const QJsonObject& targetConfig)
|
||||
{
|
||||
TargetHost targetHost;
|
||||
|
||||
QString config_host = targetConfig["host"].toString();
|
||||
if (NetUtils::resolveHostAddress(_log, config_host, targetHost.host))
|
||||
{
|
||||
int config_port = targetConfig["port"].toInt();
|
||||
if (NetUtils::isValidPort(_log, config_port, config_host))
|
||||
{
|
||||
targetHost.port = static_cast<quint16>(config_port);
|
||||
|
||||
// verify loop with JSON-server
|
||||
const QJsonObject& obj = _hyperion->getSetting(settings::JSONSERVER).object();
|
||||
if ((QNetworkInterface::allAddresses().indexOf(targetHost.host) != -1) && targetHost.port == static_cast<quint16>(obj["port"].toInt()))
|
||||
{
|
||||
Error(_log, "Loop between JSON-Server and Forwarder! Configuration for host: %s, port: %d is ignored.", QSTRING_CSTR(config_host), config_port);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_forwarder_enabled)
|
||||
{
|
||||
if (_jsonTargets.indexOf(targetHost) == -1)
|
||||
{
|
||||
Info(_log, "JSON-Forwarder settings: Adding target host: %s port: %u", QSTRING_CSTR(targetHost.host.toString()), targetHost.port);
|
||||
_jsonTargets << targetHost;
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning(_log, "JSON Forwarder settings: Duplicate target host configuration! Configuration for host: %s, port: %d is ignored.", QSTRING_CSTR(targetHost.host.toString()), targetHost.port);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessageForwarder::addFlatbufferTarget(const QJsonObject& targetConfig)
|
||||
{
|
||||
TargetHost targetHost;
|
||||
|
||||
QString config_host = targetConfig["host"].toString();
|
||||
if (NetUtils::resolveHostAddress(_log, config_host, targetHost.host))
|
||||
{
|
||||
int config_port = targetConfig["port"].toInt();
|
||||
if (NetUtils::isValidPort(_log, config_port, config_host))
|
||||
{
|
||||
targetHost.port = static_cast<quint16>(config_port);
|
||||
|
||||
// verify loop with Flatbuffer-server
|
||||
const QJsonObject& obj = _hyperion->getSetting(settings::FLATBUFSERVER).object();
|
||||
if ((QNetworkInterface::allAddresses().indexOf(targetHost.host) != -1) && targetHost.port == static_cast<quint16>(obj["port"].toInt()))
|
||||
{
|
||||
Error(_log, "Loop between Flatbuffer-Server and Forwarder! Configuration for host: %s, port: %d is ignored.", QSTRING_CSTR(config_host), config_port);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_forwarder_enabled)
|
||||
{
|
||||
if (_flatbufferTargets.indexOf(targetHost) == -1)
|
||||
{
|
||||
Info(_log, "Flatbuffer-Forwarder settings: Adding target host: %s port: %u", QSTRING_CSTR(targetHost.host.toString()), targetHost.port);
|
||||
_flatbufferTargets << targetHost;
|
||||
|
||||
FlatBufferConnection* flatbuf = new FlatBufferConnection("Forwarder", targetHost.host.toString(), _priority, false, targetHost.port);
|
||||
_forwardClients << flatbuf;
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning(_log, "Flatbuffer Forwarder settings: Duplicate target host configuration! Configuration for host: %s, port: %d is ignored.", QSTRING_CSTR(targetHost.host.toString()), targetHost.port);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessageForwarder::forwardJsonMessage(const QJsonObject& message)
|
||||
{
|
||||
if (_forwarder_enabled)
|
||||
{
|
||||
QTcpSocket client;
|
||||
for (const auto& targetHost : qAsConst(_jsonTargets))
|
||||
{
|
||||
client.connectToHost(targetHost.host, targetHost.port);
|
||||
if (client.waitForConnected(500))
|
||||
{
|
||||
sendJsonMessage(message, &client);
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessageForwarder::forwardFlatbufferMessage(const QString& /*name*/, const Image<ColorRgb>& image)
|
||||
{
|
||||
if (_forwarder_enabled)
|
||||
{
|
||||
for (int i = 0; i < _forwardClients.size(); i++)
|
||||
{
|
||||
_forwardClients.at(i)->setImage(image);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessageForwarder::sendJsonMessage(const QJsonObject& message, QTcpSocket* socket)
|
||||
{
|
||||
// for hyperion classic compatibility
|
||||
QJsonObject jsonMessage = message;
|
||||
if (jsonMessage.contains("tan") && jsonMessage["tan"].isNull())
|
||||
{
|
||||
jsonMessage["tan"] = 100;
|
||||
}
|
||||
|
||||
// serialize message
|
||||
QJsonDocument writer(jsonMessage);
|
||||
QByteArray serializedMessage = writer.toJson(QJsonDocument::Compact) + "\n";
|
||||
|
||||
// write message
|
||||
socket->write(serializedMessage);
|
||||
if (!socket->waitForBytesWritten())
|
||||
{
|
||||
Debug(_log, "Error while writing data to host");
|
||||
return;
|
||||
}
|
||||
|
||||
// read reply data
|
||||
QByteArray serializedReply;
|
||||
while (!serializedReply.contains('\n'))
|
||||
{
|
||||
// receive reply
|
||||
if (!socket->waitForReadyRead())
|
||||
{
|
||||
Debug(_log, "Error while writing data from host");
|
||||
return;
|
||||
}
|
||||
|
||||
serializedReply += socket->readAll();
|
||||
}
|
||||
|
||||
// parse reply data
|
||||
QJsonParseError error;
|
||||
QJsonDocument::fromJson(serializedReply, &error);
|
||||
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
{
|
||||
Error(_log, "Error while parsing reply: invalid json");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user