fix houskeeping of ruleengine
This commit is contained in:
parent
006d8ab99d
commit
2d53d3dc83
@ -647,16 +647,14 @@ void GuhCore::deviceManagerLoaded()
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: this removes all timedescriptors
|
||||
|
||||
// foreach (const DeviceId &deviceId, m_ruleEngine->devicesInRules()) {
|
||||
// if (!m_deviceManager->findConfiguredDevice(deviceId)) {
|
||||
// qCDebug(dcApplication()) << "Cleaning stale rule entries for device id" << deviceId;
|
||||
// foreach (const RuleId &ruleId, m_ruleEngine->findRules(deviceId)) {
|
||||
// m_ruleEngine->removeDeviceFromRule(ruleId, deviceId);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
foreach (const DeviceId &deviceId, m_ruleEngine->devicesInRules()) {
|
||||
if (!m_deviceManager->findConfiguredDevice(deviceId)) {
|
||||
qCDebug(dcApplication()) << "Cleaning stale rule entries for device id" << deviceId;
|
||||
foreach (const RuleId &ruleId, m_ruleEngine->findRules(deviceId)) {
|
||||
m_ruleEngine->removeDeviceFromRule(ruleId, deviceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qCDebug(dcApplication()) << "Housekeeping done in" << startTime.msecsTo(QDateTime::currentDateTime()) << "ms.";
|
||||
}
|
||||
|
||||
@ -900,12 +900,12 @@ QList<DeviceId> RuleEngine::devicesInRules() const
|
||||
QList<DeviceId> tmp;
|
||||
foreach (const Rule &rule, m_rules) {
|
||||
foreach (const EventDescriptor &descriptor, rule.eventDescriptors()) {
|
||||
if (!tmp.contains(descriptor.deviceId())) {
|
||||
if (!tmp.contains(descriptor.deviceId()) && !descriptor.deviceId().isNull()) {
|
||||
tmp.append(descriptor.deviceId());
|
||||
}
|
||||
}
|
||||
foreach (const DeviceId &deviceId, rule.stateEvaluator().containedDevices()) {
|
||||
if (!tmp.contains(deviceId)) {
|
||||
if (!tmp.contains(deviceId) && !deviceId.isNull()) {
|
||||
tmp.append(deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,10 +57,15 @@ TcpServer::TcpServer(const ServerConfiguration &configuration, const QSslConfigu
|
||||
/*! Destructor of this \l{TcpServer}. */
|
||||
TcpServer::~TcpServer()
|
||||
{
|
||||
qCDebug(dcApplication) << "Shutting down \"TCP Server\"" << QString("%1://%2:%3").arg((configuration().sslEnabled ? "guhs" : "guh")).arg(configuration().address.toString()).arg(configuration().port);
|
||||
qCDebug(dcApplication) << "Shutting down \"TCP Server\"" << serverUrl().toString();
|
||||
stopServer();
|
||||
}
|
||||
|
||||
QUrl TcpServer::serverUrl() const
|
||||
{
|
||||
return QUrl(QString("%1://%2:%3").arg((configuration().sslEnabled ? "guhs" : "guh")).arg(configuration().address.toString()).arg(configuration().port));
|
||||
}
|
||||
|
||||
/*! Sending \a data to a list of \a clients.*/
|
||||
void TcpServer::sendData(const QList<QUuid> &clients, const QByteArray &data)
|
||||
{
|
||||
@ -160,7 +165,7 @@ bool TcpServer::startServer()
|
||||
qCWarning(dcTcpServer()) << "Could not register avahi service for" << configuration();
|
||||
}
|
||||
|
||||
qCDebug(dcConnection) << "Started Tcp server on" << m_server->serverAddress().toString() << m_server->serverPort();
|
||||
qCDebug(dcConnection) << "Started Tcp server" << serverUrl().toString();
|
||||
connect(m_server, SIGNAL(clientConnected(QSslSocket *)), SLOT(onClientConnected(QSslSocket *)));
|
||||
connect(m_server, SIGNAL(clientDisconnected(QSslSocket *)), SLOT(onClientDisconnected(QSslSocket *)));
|
||||
connect(m_server, &SslServer::dataAvailable, this, &TcpServer::onDataAvailable);
|
||||
|
||||
@ -75,6 +75,8 @@ public:
|
||||
explicit TcpServer(const ServerConfiguration &configuration, const QSslConfiguration &sslConfiguration, QObject *parent = 0);
|
||||
~TcpServer();
|
||||
|
||||
QUrl serverUrl() const;
|
||||
|
||||
void sendData(const QUuid &clientId, const QByteArray &data) override;
|
||||
void sendData(const QList<QUuid> &clients, const QByteArray &data) override;
|
||||
|
||||
|
||||
@ -115,11 +115,16 @@ WebServer::WebServer(const WebServerConfiguration &configuration, const QSslConf
|
||||
/*! Destructor of this \l{WebServer}. */
|
||||
WebServer::~WebServer()
|
||||
{
|
||||
qCDebug(dcApplication) << "Shutting down \"Webserver\"" << QString("%1://%2:%3").arg((m_configuration.sslEnabled ? "https" : "http")).arg(m_configuration.address.toString()).arg(m_configuration.port);
|
||||
qCDebug(dcApplication) << "Shutting down \"Webserver\"" << serverUrl().toString();
|
||||
|
||||
this->close();
|
||||
}
|
||||
|
||||
QUrl WebServer::serverUrl() const
|
||||
{
|
||||
return QUrl(QString("%1://%2:%3").arg((m_configuration.sslEnabled ? "https" : "http")).arg(m_configuration.address.toString()).arg(m_configuration.port));
|
||||
}
|
||||
|
||||
/*! Send the given \a reply map to the corresponding client.
|
||||
*
|
||||
* \sa HttpReply
|
||||
@ -503,16 +508,12 @@ void WebServer::reconfigureServer(const WebServerConfiguration &config)
|
||||
bool WebServer::startServer()
|
||||
{
|
||||
if (!listen(m_configuration.address, m_configuration.port)) {
|
||||
qCWarning(dcWebServer()) << "Webserver could not listen on" << m_configuration.address.toString() << m_configuration.port << errorString();
|
||||
qCWarning(dcWebServer()) << "Webserver could not listen on" << serverUrl().toString() << errorString();
|
||||
m_enabled = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_configuration.sslEnabled) {
|
||||
qCDebug(dcWebServer()) << "Started webserver on" << QString("https://%1:%2").arg(m_configuration.address.toString()).arg(m_configuration.port);
|
||||
} else {
|
||||
qCDebug(dcWebServer()) << "Started webserver on" << QString("http://%1:%2").arg(m_configuration.address.toString()).arg(m_configuration.port);
|
||||
}
|
||||
qCDebug(dcConnection()) << "Started web server on" << serverUrl().toString();
|
||||
|
||||
// Note: reversed order
|
||||
QHash<QString, QString> txt;
|
||||
|
||||
@ -77,6 +77,8 @@ public:
|
||||
explicit WebServer(const WebServerConfiguration &configuration, const QSslConfiguration &sslConfiguration, QObject *parent = 0);
|
||||
~WebServer();
|
||||
|
||||
QUrl serverUrl() const;
|
||||
|
||||
void sendHttpReply(HttpReply *reply);
|
||||
|
||||
private:
|
||||
|
||||
@ -73,10 +73,15 @@ WebSocketServer::WebSocketServer(const ServerConfiguration &configuration, const
|
||||
/*! Destructor of this \l{WebSocketServer}. */
|
||||
WebSocketServer::~WebSocketServer()
|
||||
{
|
||||
qCDebug(dcApplication) << "Shutting down \"Websocket server\"" << QString("%1://%2:%3").arg((configuration().sslEnabled ? "wss" : "ws")).arg(configuration().address.toString()).arg(configuration().port);
|
||||
qCDebug(dcApplication) << "Shutting down \"Websocket server\"" << serverUrl().toString();
|
||||
stopServer();
|
||||
}
|
||||
|
||||
QUrl WebSocketServer::serverUrl() const
|
||||
{
|
||||
return QUrl(QString("%1://%2:%3").arg((configuration().sslEnabled ? "wss" : "ws")).arg(configuration().address.toString()).arg(configuration().port));
|
||||
}
|
||||
|
||||
/*! Send the given \a data map to the client with the given \a clientId.
|
||||
*
|
||||
* \sa TransportInterface::sendData()
|
||||
@ -206,15 +211,11 @@ bool WebSocketServer::startServer()
|
||||
connect (m_server, &QWebSocketServer::acceptError, this, &WebSocketServer::onServerError);
|
||||
|
||||
if (!m_server->listen(configuration().address, configuration().port)) {
|
||||
qCWarning(dcConnection) << "Websocket server" << m_server->serverName() << QString("could not listen on %1:%2").arg(m_server->serverAddress().toString()).arg(configuration().port);
|
||||
qCWarning(dcConnection) << "Websocket server" << m_server->serverName() << "could not listen on" << serverUrl().toString();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_server->secureMode() == QWebSocketServer::NonSecureMode) {
|
||||
qCDebug(dcConnection) << "Started websocket server" << m_server->serverName() << QString("on ws://%1:%2").arg(m_server->serverAddress().toString()).arg(configuration().port);
|
||||
} else {
|
||||
qCDebug(dcConnection) << "Started websocket server" << m_server->serverName() << QString("on wss://%1:%2").arg(m_server->serverAddress().toString()).arg(configuration().port);
|
||||
}
|
||||
qCDebug(dcConnection()) << "Started websocket server" << m_server->serverName() << "on" << serverUrl().toString();
|
||||
|
||||
// Note: reversed order
|
||||
QHash<QString, QString> txt;
|
||||
@ -224,8 +225,8 @@ bool WebSocketServer::startServer()
|
||||
txt.insert("uuid", GuhCore::instance()->configuration()->serverUuid().toString());
|
||||
txt.insert("name", GuhCore::instance()->configuration()->serverName());
|
||||
txt.insert("sslEnabled", configuration().sslEnabled ? "true" : "false");
|
||||
if (m_avahiService->registerService(QString("guhIO-ws-%1").arg(configuration().id), configuration().port, "_ws._tcp", txt)) {
|
||||
qCWarning(dcTcpServer()) << "Could not register avahi service for" << configuration();
|
||||
if (!m_avahiService->registerService(QString("guhIO-ws-%1").arg(configuration().id), configuration().port, "_ws._tcp", txt)) {
|
||||
qCWarning(dcWebServer()) << "Could not register avahi service for" << configuration();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@ -45,6 +45,8 @@ public:
|
||||
explicit WebSocketServer(const ServerConfiguration &configuration, const QSslConfiguration &sslConfiguration, QObject *parent = 0);
|
||||
~WebSocketServer();
|
||||
|
||||
QUrl serverUrl() const;
|
||||
|
||||
void sendData(const QUuid &clientId, const QByteArray &data) override;
|
||||
void sendData(const QList<QUuid> &clients, const QByteArray &data) override;
|
||||
|
||||
|
||||
@ -106,8 +106,10 @@ QtAvahiService::QtAvahiServiceState QtAvahiService::state() const
|
||||
bool QtAvahiService::registerService(const QString &name, const quint16 &port, const QString &serviceType, const QHash<QString, QString> &txtRecords)
|
||||
{
|
||||
// Check if the client is running
|
||||
if (!d_ptr->client->client || AVAHI_CLIENT_S_RUNNING != avahi_client_get_state(d_ptr->client->client))
|
||||
if (!d_ptr->client->client || AVAHI_CLIENT_S_RUNNING != avahi_client_get_state(d_ptr->client->client)) {
|
||||
qCWarning(dcAvahi()) << "Could not register service" << name << port << serviceType << ". The client is not available.";
|
||||
return false;
|
||||
}
|
||||
|
||||
d_ptr->name = name;
|
||||
d_ptr->port = port;
|
||||
|
||||
Reference in New Issue
Block a user