2016-02-16 14:59:31 +01:00
|
|
|
// STL includes
|
2016-02-16 15:56:20 +01:00
|
|
|
#include <stdexcept>
|
2016-02-16 14:59:31 +01:00
|
|
|
|
2019-02-03 14:36:57 +01:00
|
|
|
// project includes
|
2016-02-15 18:25:18 +01:00
|
|
|
#include <hyperion/MessageForwarder.h>
|
|
|
|
|
2019-02-03 14:36:57 +01:00
|
|
|
// hyperion includes
|
2018-12-27 23:11:32 +01:00
|
|
|
#include <hyperion/Hyperion.h>
|
2016-02-15 18:25:18 +01:00
|
|
|
|
2019-02-03 14:36:57 +01:00
|
|
|
// utils includes
|
|
|
|
#include <utils/Logger.h>
|
|
|
|
|
|
|
|
// qt includes
|
|
|
|
#include <QTcpServer>
|
|
|
|
#include <QTcpSocket>
|
|
|
|
|
|
|
|
#include <flatbufserver/FlatBufferConnection.h>
|
|
|
|
|
|
|
|
MessageForwarder::MessageForwarder(Hyperion *hyperion)
|
2018-12-27 23:11:32 +01:00
|
|
|
: QObject()
|
|
|
|
, _hyperion(hyperion)
|
|
|
|
, _log(Logger::getInstance("NETFORWARDER"))
|
2019-02-03 14:36:57 +01:00
|
|
|
, _muxer(_hyperion->getMuxerInstance())
|
|
|
|
, _forwarder_enabled(true)
|
|
|
|
, _priority(140)
|
2016-02-15 18:25:18 +01:00
|
|
|
{
|
2018-12-27 23:11:32 +01:00
|
|
|
// get settings updates
|
|
|
|
connect(_hyperion, &Hyperion::settingsChanged, this, &MessageForwarder::handleSettingsUpdate);
|
2019-02-03 14:36:57 +01:00
|
|
|
|
|
|
|
// component changes
|
2020-02-26 18:54:56 +01:00
|
|
|
connect(_hyperion, &Hyperion::compStateChangeRequest, this, &MessageForwarder::handleCompStateChangeRequest);
|
2019-02-03 14:36:57 +01:00
|
|
|
|
|
|
|
// connect with Muxer visible priority changes
|
|
|
|
connect(_muxer, &PriorityMuxer::visiblePriorityChanged, this, &MessageForwarder::handlePriorityChanges);
|
|
|
|
|
|
|
|
// init
|
|
|
|
handleSettingsUpdate(settings::NETFORWARD, _hyperion->getSetting(settings::NETFORWARD));
|
2016-02-15 18:25:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageForwarder::~MessageForwarder()
|
|
|
|
{
|
2019-02-03 14:36:57 +01:00
|
|
|
while (!_forwardClients.isEmpty())
|
|
|
|
delete _forwardClients.takeFirst();
|
2016-02-15 18:25:18 +01:00
|
|
|
}
|
|
|
|
|
2020-08-08 13:09:15 +02:00
|
|
|
void MessageForwarder::handleSettingsUpdate(settings::type type, const QJsonDocument &config)
|
2018-12-27 23:11:32 +01:00
|
|
|
{
|
|
|
|
if(type == settings::NETFORWARD)
|
|
|
|
{
|
|
|
|
// clear the current targets
|
|
|
|
_jsonSlaves.clear();
|
2019-08-24 21:12:53 +02:00
|
|
|
_flatSlaves.clear();
|
2019-02-03 14:36:57 +01:00
|
|
|
while (!_forwardClients.isEmpty())
|
|
|
|
delete _forwardClients.takeFirst();
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
// build new one
|
|
|
|
const QJsonObject &obj = config.object();
|
|
|
|
if ( !obj["json"].isNull() )
|
|
|
|
{
|
|
|
|
const QJsonArray & addr = obj["json"].toArray();
|
|
|
|
for (const auto& entry : addr)
|
|
|
|
{
|
|
|
|
addJsonSlave(entry.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-24 21:12:53 +02:00
|
|
|
if ( !obj["flat"].isNull() )
|
2018-12-27 23:11:32 +01:00
|
|
|
{
|
2019-08-24 21:12:53 +02:00
|
|
|
const QJsonArray & addr = obj["flat"].toArray();
|
2018-12-27 23:11:32 +01:00
|
|
|
for (const auto& entry : addr)
|
|
|
|
{
|
2019-08-24 21:12:53 +02:00
|
|
|
addFlatbufferSlave(entry.toString());
|
2018-12-27 23:11:32 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-03 14:36:57 +01:00
|
|
|
|
|
|
|
if (!_jsonSlaves.isEmpty() && obj["enable"].toBool() && _forwarder_enabled)
|
|
|
|
{
|
|
|
|
InfoIf(obj["enable"].toBool(true), _log, "Forward now to json targets '%s'", QSTRING_CSTR(_jsonSlaves.join(", ")));
|
|
|
|
connect(_hyperion, &Hyperion::forwardJsonMessage, this, &MessageForwarder::forwardJsonMessage, Qt::UniqueConnection);
|
|
|
|
} else if (_jsonSlaves.isEmpty() || ! obj["enable"].toBool() || !_forwarder_enabled)
|
|
|
|
disconnect(_hyperion, &Hyperion::forwardJsonMessage, 0, 0);
|
|
|
|
|
2019-08-24 21:12:53 +02:00
|
|
|
if (!_flatSlaves.isEmpty() && obj["enable"].toBool() && _forwarder_enabled)
|
2019-02-03 14:36:57 +01:00
|
|
|
{
|
2019-08-24 21:12:53 +02:00
|
|
|
InfoIf(obj["enable"].toBool(true), _log, "Forward now to flatbuffer targets '%s'", QSTRING_CSTR(_flatSlaves.join(", ")));
|
|
|
|
}
|
|
|
|
else if ( _flatSlaves.isEmpty() || ! obj["enable"].toBool() || !_forwarder_enabled)
|
2019-07-02 19:06:36 +02:00
|
|
|
{
|
|
|
|
disconnect(_hyperion, &Hyperion::forwardSystemProtoMessage, 0, 0);
|
|
|
|
disconnect(_hyperion, &Hyperion::forwardV4lProtoMessage, 0, 0);
|
|
|
|
}
|
2019-02-03 14:36:57 +01:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
// update comp state
|
2020-02-26 18:54:56 +01:00
|
|
|
_hyperion->setNewComponentState(hyperion::COMP_FORWARDER, obj["enable"].toBool(true));
|
2018-12-27 23:11:32 +01:00
|
|
|
}
|
|
|
|
}
|
2016-02-15 18:25:18 +01:00
|
|
|
|
2020-08-08 13:09:15 +02:00
|
|
|
void MessageForwarder::handleCompStateChangeRequest(hyperion::Components component, bool enable)
|
2019-02-03 14:36:57 +01:00
|
|
|
{
|
|
|
|
if (component == hyperion::COMP_FORWARDER && _forwarder_enabled != enable)
|
|
|
|
{
|
|
|
|
_forwarder_enabled = enable;
|
|
|
|
handleSettingsUpdate(settings::NETFORWARD, _hyperion->getSetting(settings::NETFORWARD));
|
2019-02-05 19:55:48 +01:00
|
|
|
Info(_log, "Forwarder change state to %s", (_forwarder_enabled ? "enabled" : "disabled"));
|
2020-02-26 18:54:56 +01:00
|
|
|
_hyperion->setNewComponentState(component, _forwarder_enabled);
|
2019-02-03 14:36:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-08 13:09:15 +02:00
|
|
|
void MessageForwarder::handlePriorityChanges(quint8 priority)
|
2019-02-03 14:36:57 +01:00
|
|
|
{
|
|
|
|
const QJsonObject obj = _hyperion->getSetting(settings::NETFORWARD).object();
|
|
|
|
if (priority != 0 && _forwarder_enabled && obj["enable"].toBool())
|
|
|
|
{
|
add Hue EntertainmentAPI + Forwarder & other Fixes (#592)
* whitespaces + typo fixes
* JS / LGTM fixes
* SSDP Handler crash fix
* MessageForwarder handlePriorityChanges Slave fixes
* use aboutToQuit Signal
* complete rewriten Hue Entertainment API structure
combined Philips Hue and Entertainment API
with new MbedTLS based SSL UDP Provider
* add required cross-compile submodules
* logical rebuild fn: initLeds, setLights + new logs
-more detailed checks and error handling inside iniLeds and setLights
- logical script procedure before ProviderUdpSSL init
- first steps for multiple ProviderUdpSSL usage
- better fallback support to old RestAPI, if entertainment api is not supported
- just 4 u LordGrey: new log fn for cosmetic config outputs ;)
* add OSX CompileHowTo - undo from CrossCompileHowTo
* whitespace fixes
* lightID toString fix
* fix unsigned int E-API + debug output
* bugfixes, reworked black signal detection, wizard:
- change device config field light-ids from int to string -> real unsigned int fix
- add signal detection brightness minimum threshold value
0.0 for 0% brightness - 1.0 for 100% brightness to count for blacklight signal detection
reason: input may not 100% black, like mine - i have a deep dark gray input signal
-> my threshold value is set to 0.005 for 0.5% minimum brightness = 1 (from max 255) to count as black
- wizard optimations, with fallback without entertainment support (beta state)
- whitespace fixes
* cleanup + minor fixes
* change fixed Hue UPD SSL config to _devConfig paras
* Hotfix SSL Connection, new light models, wizard:
- Fix UPD SSL Connection failed Problems
- add new supported gamut C light models: LCG002, LCA001, LCA002, LCA003
- wizard: extend fallback support to classic mode + hints
* whitespace, typo fix
* uncheck useEntertainmentAPI, if noAPISupport detected + hint
* coredump fix -> add _blackLightsTimer nullptr init
* code cleanup / remove old debugs + whitespacefixes
* add gamut C LCP001, LCP002
* SSL UDP config made more flexible + remove qDebug
-> switch to hyerion.ng _log
-> replace logCommand with verbose
-> code cleanups etc...
* extended mbedtls debugging infos
* add adjustable ssl timeout settings
* error handling
* streamdebugger bugfixes
* UPDSSL psk / psk_identity bugfixes! + hue wizard fn typo fix +
- verbose option available without dependencies
- whitespace fixes
* Philips Hue Assistant now recognizes non-original bridges better...
+ Added note if no clientkey is set when using the entertainment API
+ User creation (+ clientkey) for non-original bridges can now also be used
+ Minor changes and bug fixes
* CMAKE mbedTLS detection
* minor bug fixes + code cleanups
* FindMbedTLS.cmake remove Path-Hints + wizard.js: ajax timeout handling
Test - content_grabber.js: run relevant code only, if V4L2_AVAIL is true:
conf_grabber don't displays other devices, if V4L2 is not available
* compile mbedtls via cmake as static lib
* remove libmbedtls-dev from compileHowto / scripts
* Fix Windows build
* Fix windows build (part 2)
* removed unnecessary osx x11 include directory path
* QTimer Shutdown bugfix
* cmake win32 fix + minor bugfixes
* cmake debug msg used mbedtls libs
* Bugfix: noSignalDetection wasn't switchedOn again
if no signal was previously detected
* Some code fixes based on alerts from lgtm.com
Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com>
2020-05-22 19:40:50 +02:00
|
|
|
//_flatSlaves.clear();
|
|
|
|
//while (!_forwardClients.isEmpty())
|
|
|
|
// delete _forwardClients.takeFirst();
|
2019-02-03 14:36:57 +01:00
|
|
|
|
2019-07-02 19:06:36 +02:00
|
|
|
hyperion::Components activeCompId = _hyperion->getPriorityInfo(priority).componentId;
|
|
|
|
if (activeCompId == hyperion::COMP_GRABBER || activeCompId == hyperion::COMP_V4L)
|
2019-02-03 14:36:57 +01:00
|
|
|
{
|
2020-03-01 15:37:06 +01:00
|
|
|
if ( !obj["flat"].isNull() )
|
2019-02-03 14:36:57 +01:00
|
|
|
{
|
2020-03-01 15:37:06 +01:00
|
|
|
const QJsonArray & addr = obj["flat"].toArray();
|
2019-02-03 14:36:57 +01:00
|
|
|
for (const auto& entry : addr)
|
|
|
|
{
|
2019-08-24 21:12:53 +02:00
|
|
|
addFlatbufferSlave(entry.toString());
|
2019-02-03 14:36:57 +01:00
|
|
|
}
|
|
|
|
}
|
2019-07-02 19:06:36 +02:00
|
|
|
|
|
|
|
switch(activeCompId)
|
|
|
|
{
|
|
|
|
case hyperion::COMP_GRABBER:
|
|
|
|
{
|
|
|
|
disconnect(_hyperion, &Hyperion::forwardV4lProtoMessage, 0, 0);
|
2019-08-24 21:12:53 +02:00
|
|
|
connect(_hyperion, &Hyperion::forwardSystemProtoMessage, this, &MessageForwarder::forwardFlatbufferMessage, Qt::UniqueConnection);
|
2019-07-02 19:06:36 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case hyperion::COMP_V4L:
|
|
|
|
{
|
|
|
|
disconnect(_hyperion, &Hyperion::forwardSystemProtoMessage, 0, 0);
|
2019-08-24 21:12:53 +02:00
|
|
|
connect(_hyperion, &Hyperion::forwardV4lProtoMessage, this, &MessageForwarder::forwardFlatbufferMessage, Qt::UniqueConnection);
|
2019-07-02 19:06:36 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
disconnect(_hyperion, &Hyperion::forwardSystemProtoMessage, 0, 0);
|
|
|
|
disconnect(_hyperion, &Hyperion::forwardV4lProtoMessage, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
2019-02-03 14:36:57 +01:00
|
|
|
}
|
|
|
|
else
|
2019-07-02 19:06:36 +02:00
|
|
|
{
|
|
|
|
disconnect(_hyperion, &Hyperion::forwardSystemProtoMessage, 0, 0);
|
|
|
|
disconnect(_hyperion, &Hyperion::forwardV4lProtoMessage, 0, 0);
|
|
|
|
}
|
2019-02-03 14:36:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-08 23:12:43 +02:00
|
|
|
void MessageForwarder::addJsonSlave(const QString& slave)
|
2016-02-15 18:25:18 +01:00
|
|
|
{
|
2017-03-04 22:17:42 +01:00
|
|
|
QStringList parts = slave.split(":");
|
2016-02-15 20:53:03 +01:00
|
|
|
if (parts.size() != 2)
|
2018-12-27 23:11:32 +01:00
|
|
|
{
|
|
|
|
Error(_log, "Unable to parse address (%s)",QSTRING_CSTR(slave));
|
|
|
|
return;
|
|
|
|
}
|
2016-02-15 20:53:03 +01:00
|
|
|
|
|
|
|
bool ok;
|
2018-12-27 23:11:32 +01:00
|
|
|
parts[1].toUShort(&ok);
|
2016-02-15 20:53:03 +01:00
|
|
|
if (!ok)
|
2018-12-27 23:11:32 +01:00
|
|
|
{
|
|
|
|
Error(_log, "Unable to parse port number (%s)",QSTRING_CSTR(parts[1]));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// verify loop with jsonserver
|
2019-02-03 14:36:57 +01:00
|
|
|
const QJsonObject &obj = _hyperion->getSetting(settings::JSONSERVER).object();
|
2018-12-27 23:11:32 +01:00
|
|
|
if(QHostAddress(parts[0]) == QHostAddress::LocalHost && parts[1].toInt() == obj["port"].toInt())
|
|
|
|
{
|
|
|
|
Error(_log, "Loop between JsonServer and Forwarder! (%s)",QSTRING_CSTR(slave));
|
|
|
|
return;
|
|
|
|
}
|
2016-02-15 20:53:03 +01:00
|
|
|
|
add Hue EntertainmentAPI + Forwarder & other Fixes (#592)
* whitespaces + typo fixes
* JS / LGTM fixes
* SSDP Handler crash fix
* MessageForwarder handlePriorityChanges Slave fixes
* use aboutToQuit Signal
* complete rewriten Hue Entertainment API structure
combined Philips Hue and Entertainment API
with new MbedTLS based SSL UDP Provider
* add required cross-compile submodules
* logical rebuild fn: initLeds, setLights + new logs
-more detailed checks and error handling inside iniLeds and setLights
- logical script procedure before ProviderUdpSSL init
- first steps for multiple ProviderUdpSSL usage
- better fallback support to old RestAPI, if entertainment api is not supported
- just 4 u LordGrey: new log fn for cosmetic config outputs ;)
* add OSX CompileHowTo - undo from CrossCompileHowTo
* whitespace fixes
* lightID toString fix
* fix unsigned int E-API + debug output
* bugfixes, reworked black signal detection, wizard:
- change device config field light-ids from int to string -> real unsigned int fix
- add signal detection brightness minimum threshold value
0.0 for 0% brightness - 1.0 for 100% brightness to count for blacklight signal detection
reason: input may not 100% black, like mine - i have a deep dark gray input signal
-> my threshold value is set to 0.005 for 0.5% minimum brightness = 1 (from max 255) to count as black
- wizard optimations, with fallback without entertainment support (beta state)
- whitespace fixes
* cleanup + minor fixes
* change fixed Hue UPD SSL config to _devConfig paras
* Hotfix SSL Connection, new light models, wizard:
- Fix UPD SSL Connection failed Problems
- add new supported gamut C light models: LCG002, LCA001, LCA002, LCA003
- wizard: extend fallback support to classic mode + hints
* whitespace, typo fix
* uncheck useEntertainmentAPI, if noAPISupport detected + hint
* coredump fix -> add _blackLightsTimer nullptr init
* code cleanup / remove old debugs + whitespacefixes
* add gamut C LCP001, LCP002
* SSL UDP config made more flexible + remove qDebug
-> switch to hyerion.ng _log
-> replace logCommand with verbose
-> code cleanups etc...
* extended mbedtls debugging infos
* add adjustable ssl timeout settings
* error handling
* streamdebugger bugfixes
* UPDSSL psk / psk_identity bugfixes! + hue wizard fn typo fix +
- verbose option available without dependencies
- whitespace fixes
* Philips Hue Assistant now recognizes non-original bridges better...
+ Added note if no clientkey is set when using the entertainment API
+ User creation (+ clientkey) for non-original bridges can now also be used
+ Minor changes and bug fixes
* CMAKE mbedTLS detection
* minor bug fixes + code cleanups
* FindMbedTLS.cmake remove Path-Hints + wizard.js: ajax timeout handling
Test - content_grabber.js: run relevant code only, if V4L2_AVAIL is true:
conf_grabber don't displays other devices, if V4L2 is not available
* compile mbedtls via cmake as static lib
* remove libmbedtls-dev from compileHowto / scripts
* Fix Windows build
* Fix windows build (part 2)
* removed unnecessary osx x11 include directory path
* QTimer Shutdown bugfix
* cmake win32 fix + minor bugfixes
* cmake debug msg used mbedtls libs
* Bugfix: noSignalDetection wasn't switchedOn again
if no signal was previously detected
* Some code fixes based on alerts from lgtm.com
Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com>
2020-05-22 19:40:50 +02:00
|
|
|
if (_forwarder_enabled && !_jsonSlaves.contains(slave))
|
2019-02-03 14:36:57 +01:00
|
|
|
_jsonSlaves << slave;
|
2016-02-15 18:25:18 +01:00
|
|
|
}
|
|
|
|
|
2020-08-08 23:12:43 +02:00
|
|
|
void MessageForwarder::addFlatbufferSlave(const QString& slave)
|
2016-02-15 18:25:18 +01:00
|
|
|
{
|
2018-12-27 23:11:32 +01:00
|
|
|
QStringList parts = slave.split(":");
|
|
|
|
if (parts.size() != 2)
|
|
|
|
{
|
|
|
|
Error(_log, "Unable to parse address (%s)",QSTRING_CSTR(slave));
|
|
|
|
return;
|
|
|
|
}
|
2016-02-15 18:25:18 +01:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
bool ok;
|
|
|
|
parts[1].toUShort(&ok);
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
Error(_log, "Unable to parse port number (%s)",QSTRING_CSTR(parts[1]));
|
|
|
|
return;
|
|
|
|
}
|
2016-02-15 20:53:03 +01:00
|
|
|
|
2020-03-01 15:37:06 +01:00
|
|
|
// verify loop with flatbufserver
|
2019-02-03 14:36:57 +01:00
|
|
|
const QJsonObject &obj = _hyperion->getSetting(settings::FLATBUFSERVER).object();
|
2018-12-27 23:11:32 +01:00
|
|
|
if(QHostAddress(parts[0]) == QHostAddress::LocalHost && parts[1].toInt() == obj["port"].toInt())
|
|
|
|
{
|
2019-08-24 21:12:53 +02:00
|
|
|
Error(_log, "Loop between Flatbuffer Server and Forwarder! (%s)",QSTRING_CSTR(slave));
|
2018-12-27 23:11:32 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-02-03 14:36:57 +01:00
|
|
|
|
add Hue EntertainmentAPI + Forwarder & other Fixes (#592)
* whitespaces + typo fixes
* JS / LGTM fixes
* SSDP Handler crash fix
* MessageForwarder handlePriorityChanges Slave fixes
* use aboutToQuit Signal
* complete rewriten Hue Entertainment API structure
combined Philips Hue and Entertainment API
with new MbedTLS based SSL UDP Provider
* add required cross-compile submodules
* logical rebuild fn: initLeds, setLights + new logs
-more detailed checks and error handling inside iniLeds and setLights
- logical script procedure before ProviderUdpSSL init
- first steps for multiple ProviderUdpSSL usage
- better fallback support to old RestAPI, if entertainment api is not supported
- just 4 u LordGrey: new log fn for cosmetic config outputs ;)
* add OSX CompileHowTo - undo from CrossCompileHowTo
* whitespace fixes
* lightID toString fix
* fix unsigned int E-API + debug output
* bugfixes, reworked black signal detection, wizard:
- change device config field light-ids from int to string -> real unsigned int fix
- add signal detection brightness minimum threshold value
0.0 for 0% brightness - 1.0 for 100% brightness to count for blacklight signal detection
reason: input may not 100% black, like mine - i have a deep dark gray input signal
-> my threshold value is set to 0.005 for 0.5% minimum brightness = 1 (from max 255) to count as black
- wizard optimations, with fallback without entertainment support (beta state)
- whitespace fixes
* cleanup + minor fixes
* change fixed Hue UPD SSL config to _devConfig paras
* Hotfix SSL Connection, new light models, wizard:
- Fix UPD SSL Connection failed Problems
- add new supported gamut C light models: LCG002, LCA001, LCA002, LCA003
- wizard: extend fallback support to classic mode + hints
* whitespace, typo fix
* uncheck useEntertainmentAPI, if noAPISupport detected + hint
* coredump fix -> add _blackLightsTimer nullptr init
* code cleanup / remove old debugs + whitespacefixes
* add gamut C LCP001, LCP002
* SSL UDP config made more flexible + remove qDebug
-> switch to hyerion.ng _log
-> replace logCommand with verbose
-> code cleanups etc...
* extended mbedtls debugging infos
* add adjustable ssl timeout settings
* error handling
* streamdebugger bugfixes
* UPDSSL psk / psk_identity bugfixes! + hue wizard fn typo fix +
- verbose option available without dependencies
- whitespace fixes
* Philips Hue Assistant now recognizes non-original bridges better...
+ Added note if no clientkey is set when using the entertainment API
+ User creation (+ clientkey) for non-original bridges can now also be used
+ Minor changes and bug fixes
* CMAKE mbedTLS detection
* minor bug fixes + code cleanups
* FindMbedTLS.cmake remove Path-Hints + wizard.js: ajax timeout handling
Test - content_grabber.js: run relevant code only, if V4L2_AVAIL is true:
conf_grabber don't displays other devices, if V4L2 is not available
* compile mbedtls via cmake as static lib
* remove libmbedtls-dev from compileHowto / scripts
* Fix Windows build
* Fix windows build (part 2)
* removed unnecessary osx x11 include directory path
* QTimer Shutdown bugfix
* cmake win32 fix + minor bugfixes
* cmake debug msg used mbedtls libs
* Bugfix: noSignalDetection wasn't switchedOn again
if no signal was previously detected
* Some code fixes based on alerts from lgtm.com
Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com>
2020-05-22 19:40:50 +02:00
|
|
|
if (_forwarder_enabled && !_flatSlaves.contains(slave))
|
2019-02-03 14:36:57 +01:00
|
|
|
{
|
2019-08-24 21:12:53 +02:00
|
|
|
_flatSlaves << slave;
|
2019-02-05 19:55:48 +01:00
|
|
|
FlatBufferConnection* flatbuf = new FlatBufferConnection("Forwarder", slave.toLocal8Bit().constData(), _priority, false);
|
2019-02-03 14:36:57 +01:00
|
|
|
_forwardClients << flatbuf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessageForwarder::forwardJsonMessage(const QJsonObject &message)
|
|
|
|
{
|
|
|
|
if (_forwarder_enabled)
|
|
|
|
{
|
|
|
|
QTcpSocket client;
|
|
|
|
for (int i=0; i<_jsonSlaves.size(); i++)
|
|
|
|
{
|
|
|
|
QStringList parts = _jsonSlaves.at(i).split(":");
|
|
|
|
client.connectToHost(QHostAddress(parts[0]), parts[1].toUShort());
|
|
|
|
if ( client.waitForConnected(500) )
|
|
|
|
{
|
|
|
|
sendJsonMessage(message,&client);
|
|
|
|
client.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-15 20:53:03 +01:00
|
|
|
}
|
2016-02-19 13:31:08 +01:00
|
|
|
|
2019-08-24 21:12:53 +02:00
|
|
|
void MessageForwarder::forwardFlatbufferMessage(const QString& name, const Image<ColorRgb> &image)
|
2016-02-19 13:31:08 +01:00
|
|
|
{
|
2019-02-03 14:36:57 +01:00
|
|
|
if (_forwarder_enabled)
|
|
|
|
{
|
|
|
|
for (int i=0; i < _forwardClients.size(); i++)
|
|
|
|
_forwardClients.at(i)->setImage(image);
|
|
|
|
}
|
2016-02-19 13:31:08 +01:00
|
|
|
}
|
2016-09-07 20:10:37 +02:00
|
|
|
|
2019-02-03 14:36:57 +01:00
|
|
|
void MessageForwarder::sendJsonMessage(const QJsonObject &message, QTcpSocket *socket)
|
2016-09-07 20:10:37 +02:00
|
|
|
{
|
2019-02-03 14:36:57 +01:00
|
|
|
// 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 reply = QJsonDocument::fromJson(serializedReply ,&error);
|
|
|
|
|
|
|
|
if (error.error != QJsonParseError::NoError)
|
|
|
|
{
|
|
|
|
Error(_log, "Error while parsing reply: invalid json");
|
|
|
|
return;
|
|
|
|
}
|
2016-09-07 20:10:37 +02:00
|
|
|
}
|