mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
* Refactor to fix #1671
* Add GUI/NonGUI mode to info page
* Do not show lock config, if in non-UI mode
* Updae Changelog
* Correct includes
* Ensure key member initialization - RGB Channels
* Ensure key member initialization - WebServer
* Update RGBChannels
* Fix initialization order
* Fix key when inserting new logger in LoggerMap,
Prepare logBuffer-JSON snapshot view in LoggerManager,
Increase buffered loglines to 500
* Fix Memory leak in GrabberWrapper
* Fix Memory leak in BlackBorderProcessor
* Fix Memory leak in BlackBorderProcessor
* use ninja generator under macos
* Fix BGEffectHandler destruction
* Fix Mdns code
* Clear list after applying qDeleteAll
* Fix deletion of CecHandler
* Fix memory leak caused by wrong buffer allocation
* Remove extra pixel consistently
* Change mDNS to Qt SmartPointers
* Correct removal
* Fix usage of _width/_height (they are the output resolution, not the screen resolution)
That avoids unnecessary resizing of the output image with every transferFrame call
* Move main non Thread Objects to Smart Pointers
* Revert "Move main non Thread Objects to Smart Pointers"
This reverts commit 26102ca963.
* Add missing deletes
* Revert MdnsBrowser chnage
* Revert MdnsBrowser change
* Fix memory leaks related standalone grabber
* Address CodeQL finding
* delete pointer OsxFrameGrabber
---------
Co-authored-by: Paulchen-Panther <16664240+Paulchen-Panther@users.noreply.github.com>
124 lines
2.7 KiB
C++
124 lines
2.7 KiB
C++
// system includes
|
|
#include <stdexcept>
|
|
|
|
// qt includes
|
|
#include <QTcpServer>
|
|
#include <QTcpSocket>
|
|
#include <QJsonDocument>
|
|
#include <QByteArray>
|
|
|
|
// project includes
|
|
#include "HyperionConfig.h"
|
|
#include <jsonserver/JsonServer.h>
|
|
#include "JsonClientConnection.h"
|
|
|
|
#include <utils/NetOrigin.h>
|
|
|
|
// Constants
|
|
namespace {
|
|
|
|
const char SERVICE_TYPE[] = "jsonapi";
|
|
|
|
} //End of constants
|
|
|
|
JsonServer::JsonServer(const QJsonDocument& config)
|
|
: QObject()
|
|
, _server(new QTcpServer(this))
|
|
, _openConnections()
|
|
, _log(Logger::getInstance("JSONSERVER"))
|
|
, _netOrigin(NetOrigin::getInstance())
|
|
, _config(config)
|
|
{
|
|
Debug(_log, "Created instance");
|
|
}
|
|
|
|
JsonServer::~JsonServer()
|
|
{
|
|
qDeleteAll(_openConnections);
|
|
_openConnections.clear();
|
|
}
|
|
|
|
void JsonServer::initServer()
|
|
{
|
|
// Set trigger for incoming connections
|
|
connect(_server, &QTcpServer::newConnection, this, &JsonServer::newConnection);
|
|
|
|
// init
|
|
handleSettingsUpdate(settings::JSONSERVER, _config);
|
|
}
|
|
|
|
void JsonServer::start()
|
|
{
|
|
if(!_server->isListening())
|
|
{
|
|
if (!_server->listen(QHostAddress::Any, _port))
|
|
{
|
|
Error(_log,"Could not bind to port '%d', please use an available port", _port);
|
|
}
|
|
else
|
|
{
|
|
Info(_log, "Started on port %d", _port);
|
|
emit publishService(SERVICE_TYPE, _port);
|
|
}
|
|
}
|
|
}
|
|
|
|
void JsonServer::stop()
|
|
{
|
|
if(!_server->isListening())
|
|
return;
|
|
|
|
_server->close();
|
|
Info(_log, "Stopped");
|
|
}
|
|
|
|
void JsonServer::handleSettingsUpdate(settings::type type, const QJsonDocument& config)
|
|
{
|
|
if(type == settings::JSONSERVER)
|
|
{
|
|
QJsonObject obj = config.object();
|
|
if(_port != obj["port"].toInt())
|
|
{
|
|
_port = obj["port"].toInt();
|
|
stop();
|
|
start();
|
|
}
|
|
}
|
|
}
|
|
|
|
uint16_t JsonServer::getPort() const
|
|
{
|
|
return _port;
|
|
}
|
|
|
|
void JsonServer::newConnection()
|
|
{
|
|
while(_server->hasPendingConnections())
|
|
{
|
|
if (QTcpSocket * socket = _server->nextPendingConnection())
|
|
{
|
|
if(_netOrigin->accessAllowed(socket->peerAddress(), socket->localAddress()))
|
|
{
|
|
Debug(_log, "New connection from: %s",QSTRING_CSTR(socket->peerAddress().toString()));
|
|
JsonClientConnection * connection = new JsonClientConnection(socket, _netOrigin->isLocalAddress(socket->peerAddress(), socket->localAddress()));
|
|
_openConnections.insert(connection);
|
|
|
|
// register slot for cleaning up after the connection closed
|
|
connect(connection, &JsonClientConnection::connectionClosed, this, &JsonServer::closedConnection);
|
|
}
|
|
else
|
|
socket->close();
|
|
}
|
|
}
|
|
}
|
|
|
|
void JsonServer::closedConnection()
|
|
{
|
|
JsonClientConnection* connection = qobject_cast<JsonClientConnection*>(sender());
|
|
Debug(_log, "Connection closed for %s", QSTRING_CSTR(connection->getClientAddress().toString()));
|
|
_openConnections.remove(connection);
|
|
|
|
// schedule to delete the connection object
|
|
connection->deleteLater();
|
|
}
|