Continues migration with DDS, Common
This commit is contained in:
1 parent
9b15cee841
commit
fa48db111e
668 files changed
+111841
-2
No files matched your search
+47
@@ -0,0 +1,47 @@
|
||||
#
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
# Created by Christian Roeskens, NLSE, 2018-03-02
|
||||
|
||||
|
||||
SET(LtsProjectionWorkstation_SRCS
|
||||
|
||||
lts_projection_workstation.h
|
||||
lts_projection_workstation.cpp
|
||||
|
||||
lts_projection_workstation_export.h
|
||||
|
||||
vnc_server_manager.h
|
||||
vnc_server_manager.cpp
|
||||
|
||||
logger.cpp
|
||||
logger.h
|
||||
|
||||
WebSocket/json_keys.h
|
||||
WebSocket/messages.h
|
||||
WebSocket/messages.cpp
|
||||
WebSocket/message_factory.h
|
||||
WebSocket/message_factory.cpp
|
||||
)
|
||||
|
||||
NGL_ADD_LIBRARY(WS LtsProjectionWorkstation SHARED ${LtsProjectionWorkstation_SRCS})
|
||||
|
||||
NGL_TARGET_INCLUDE_DIRECTORIES(LtsProjectionWorkstation
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||
)
|
||||
|
||||
NGL_TARGET_LINK_LIBRARIES(LtsProjectionWorkstation
|
||||
PUBLIC
|
||||
Qt5::Core
|
||||
PRIVATE
|
||||
Qt5::Gui
|
||||
NGLLogger
|
||||
nglsettings
|
||||
LtsWebSocketServer
|
||||
LtsSession
|
||||
LtsSessionData
|
||||
)
|
||||
|
||||
NGL_INSTALL_TARGET(LtsProjectionWorkstation)
|
||||
@@ -0,0 +1,63 @@
|
||||
|
||||
|
||||
|
||||
#include "client_message.h"
|
||||
#include "json_keys.h"
|
||||
#include "message_handler.h"
|
||||
|
||||
namespace LtsProjectionWorkstation
|
||||
{
|
||||
|
||||
|
||||
|
||||
LtsWebSocket::AbstractClientMessage *ClientMessageFactory::createMessage(LtsWebSocket::ReplyHandler *client, const QString &message)
|
||||
{
|
||||
LtsWebSocket::AbstractClientMessage *result = checkAttributes(client, message);
|
||||
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
if (m_type == JsonKeys::LOGIN_REQUEST())
|
||||
result = new LoginRequest(m_messageHandler, client, m_type, m_uuid, m_data);
|
||||
|
||||
if (m_type == JsonKeys::LOGOUT_REQUEST())
|
||||
result = new LoginRequest(m_messageHandler, client, m_type, m_uuid, m_data);
|
||||
|
||||
return checkResult(client, message, result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LoginRequest::process()
|
||||
{
|
||||
if (hasValidData())
|
||||
{
|
||||
int userId = m_data.toObject().value(JsonKeys::USER_ID()).toInt(-1),
|
||||
userPriority = m_data.toObject().value(JsonKeys::USER_PRIORITY()).toInt(-1),
|
||||
exerciseId = m_data.toObject().value(JsonKeys::EXERCISE_ID()).toInt(-1);
|
||||
m_client->addReply(m_messageHandler->handleLoginRequest(userId, userPriority, exerciseId));
|
||||
}
|
||||
}
|
||||
|
||||
bool LoginRequest::hasValidData() const
|
||||
{
|
||||
return m_data.isObject()
|
||||
&& m_data.toObject().value(JsonKeys::USER_ID()).toInt(-1) > -1
|
||||
&& m_data.toObject().value(JsonKeys::USER_PRIORITY()).toInt(-1) > -1
|
||||
&& m_data.toObject().value(JsonKeys::EXERCISE_ID()).toInt(-1) > -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LogoutRequest::process()
|
||||
{
|
||||
m_client->addReply(m_messageHandler->handleLogoutRequest());
|
||||
}
|
||||
|
||||
bool LogoutRequest::hasValidData() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LtsWebSocket/client_message_factory.h>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
|
||||
namespace LtsProjectionWorkstation
|
||||
{
|
||||
class MessageHandler;
|
||||
|
||||
class ClientMessageFactory : public LtsWebSocket::AbstractClientMessageFactory
|
||||
{
|
||||
public:
|
||||
explicit ClientMessageFactory(MessageHandler *messageHandler)
|
||||
: LtsWebSocket::AbstractClientMessageFactory(getLogger("ClientMessageFactory"))
|
||||
, m_messageHandler(messageHandler)
|
||||
{}
|
||||
|
||||
|
||||
LtsWebSocket::AbstractClientMessage *createMessage(LtsWebSocket::ReplyHandler *client, const QString &message) override final;
|
||||
|
||||
private:
|
||||
MessageHandler *m_messageHandler;
|
||||
};
|
||||
|
||||
class ClientMessage : public LtsWebSocket::AbstractClientMessage
|
||||
{
|
||||
public:
|
||||
explicit ClientMessage(MessageHandler *messageHandler, LtsWebSocket::ReplyHandler *client, const QString &type, const QString &uuid, const QJsonValue &data)
|
||||
: AbstractClientMessage(client, type, uuid, data)
|
||||
, m_messageHandler(messageHandler)
|
||||
{}
|
||||
|
||||
protected:
|
||||
MessageHandler *m_messageHandler;
|
||||
|
||||
};
|
||||
|
||||
class LoginRequest : public ClientMessage
|
||||
{
|
||||
public:
|
||||
explicit LoginRequest(MessageHandler *messageHandler, LtsWebSocket::ReplyHandler *client, const QString &type, const QString &uuid, const QJsonValue &data)
|
||||
: ClientMessage(messageHandler, client, type, uuid, data)
|
||||
{}
|
||||
|
||||
void process();
|
||||
bool hasValidData() const;
|
||||
};
|
||||
|
||||
class LogoutRequest : public ClientMessage
|
||||
{
|
||||
public:
|
||||
explicit LogoutRequest(MessageHandler *messageHandler, LtsWebSocket::ReplyHandler *client, const QString &type, const QString &uuid, const QJsonValue &data)
|
||||
: ClientMessage(messageHandler, client, type, uuid, data)
|
||||
{}
|
||||
|
||||
void process();
|
||||
bool hasValidData() const;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace LtsProjectionWorkstation
|
||||
{
|
||||
namespace JsonKeys
|
||||
{
|
||||
|
||||
inline QString ERROR_MESSAGE() { return QStringLiteral("errorMessage"); }
|
||||
|
||||
|
||||
inline QString LOGIN_REQUEST() { return QStringLiteral("loginRequest"); }
|
||||
inline QString LOGOUT_REQUEST() { return QStringLiteral("logoutRequest"); }
|
||||
inline QString DISCONNECT_REQUEST() { return QStringLiteral("disconnectRequest"); }
|
||||
|
||||
|
||||
|
||||
inline QString LOGIN_REPLY() { return QStringLiteral("loginReply"); }
|
||||
inline QString LOGOUT_REPLY() { return QStringLiteral("logoutReply"); }
|
||||
inline QString DEDICAED_DISCONNECT() { return QStringLiteral("dedicatedDisconnect"); }
|
||||
|
||||
|
||||
inline QString USER_ID() { return QStringLiteral("userId"); }
|
||||
inline QString USER_PRIORITY() { return QStringLiteral("userPriority"); }
|
||||
inline QString EXERCISE_ID() { return QStringLiteral("exerciseId"); }
|
||||
inline QString NAME() { return QStringLiteral("name"); }
|
||||
inline QString PORT() { return QStringLiteral("port"); }
|
||||
inline QString WIDTH() { return QStringLiteral("width"); }
|
||||
inline QString HEIGHT() { return QStringLiteral("height"); }
|
||||
inline QString REASON() { return QStringLiteral("reason"); }
|
||||
inline QString SUCCESS() { return QStringLiteral("success"); }
|
||||
inline QString SCREENS() { return QStringLiteral("screens"); }
|
||||
inline QString SETTINGS_DATA() { return QStringLiteral("settingsData"); }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "message_factory.h"
|
||||
#include "messages.h"
|
||||
#include "json_keys.h"
|
||||
|
||||
#include <LtsWebSocket/client_message.h>
|
||||
#include <LtsWebSocket/json_keys.h>
|
||||
|
||||
#include <QUuid>
|
||||
|
||||
namespace LtsProjectionWorkstation
|
||||
{
|
||||
|
||||
LtsWebSocket::AbstractClientMessage *MessageFactory::createMessage(LtsWebSocket::ReplyHandler *client, const QString &message)
|
||||
{
|
||||
|
||||
|
||||
if (m_uuid.isEmpty())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got message without uuid: " << message << "'";
|
||||
WARNING_LOG(m_logger) << "Created UUID for error message!";
|
||||
return new ErrorMessage(QUuid::createUuid().toString(), QStringLiteral("Got message without uuid"));
|
||||
}
|
||||
|
||||
LtsWebSocket::AbstractClientMessage *result = checkAttributes(client, message);
|
||||
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
if (m_type == JsonKeys::DEDICAED_DISCONNECT())
|
||||
result = new STC::DedicatedDisconnect(m_handler, client, m_type, m_uuid, m_data);
|
||||
|
||||
if (m_type == JsonKeys::LOGIN_REPLY())
|
||||
result = new STC::LoginRequestReply(m_handler, client, m_type, m_uuid, m_data);
|
||||
|
||||
if (m_type == JsonKeys::LOGOUT_REPLY())
|
||||
result = new STC::LoginRequestReply(m_handler, client, m_type, m_uuid, m_data);
|
||||
|
||||
if (m_type == JsonKeys::LOGIN_REQUEST())
|
||||
result = new CTS::LoginRequest(m_handler, client, m_type, m_uuid, m_data);
|
||||
|
||||
if (m_type == JsonKeys::LOGOUT_REQUEST())
|
||||
result = new CTS::LogoutRequest(m_handler, client, m_type, m_uuid, m_data);
|
||||
|
||||
if (m_type == JsonKeys::DISCONNECT_REQUEST())
|
||||
result = new CTS::DisconnectRequest(m_handler, client, m_type, m_uuid, m_data);
|
||||
|
||||
if (m_type == LtsWebSocket::JsonKeys::ERROR_())
|
||||
return nullptr;
|
||||
|
||||
return checkResult(client, message, result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <LtsWebSocket/client_message_factory.h>
|
||||
#include <LtsProjectionWorkstation/logger.h>
|
||||
|
||||
#include <LtsProjectionWorkstation/lts_projection_workstation_export.h>
|
||||
|
||||
namespace LtsProjectionWorkstation
|
||||
{
|
||||
|
||||
class AbstractMessageHandler;
|
||||
|
||||
class LTSPROJECTIONWORKSTATION_EXPORT MessageFactory
|
||||
: public LtsWebSocket::AbstractClientMessageFactory
|
||||
{
|
||||
|
||||
public:
|
||||
MessageFactory(AbstractMessageHandler *handler, LOGGER_T &logger)
|
||||
: LtsWebSocket::AbstractClientMessageFactory(logger)
|
||||
, m_handler(handler)
|
||||
{}
|
||||
|
||||
|
||||
LtsWebSocket::AbstractClientMessage *createMessage(LtsWebSocket::ReplyHandler *client, const QString &message) override final;
|
||||
|
||||
private:
|
||||
AbstractMessageHandler *m_handler;
|
||||
};
|
||||
|
||||
}
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
|
||||
|
||||
|
||||
#include "messages.h"
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QDebug>
|
||||
|
||||
namespace LtsProjectionWorkstation
|
||||
{
|
||||
|
||||
|
||||
STC::LoginRequestReply::LoginRequestReply(const QString &uuid, Reason reason, int reasonUserId, const QVector<VncScreen> &screens)
|
||||
: Message(nullptr, nullptr, JsonKeys::LOGIN_REPLY(), uuid, QJsonValue())
|
||||
, m_screens(screens)
|
||||
, m_reasonUserId(reasonUserId)
|
||||
, m_reason(reason)
|
||||
{
|
||||
QJsonObject result;
|
||||
QJsonArray arr;
|
||||
for (const VncScreen &vncScreen : screens)
|
||||
{
|
||||
QJsonObject screen;
|
||||
screen.insert(JsonKeys::NAME(), vncScreen.name);
|
||||
screen.insert(JsonKeys::PORT(), vncScreen.port);
|
||||
screen.insert(JsonKeys::WIDTH(), vncScreen.geometry.width());
|
||||
screen.insert(JsonKeys::HEIGHT(), vncScreen.geometry.height());
|
||||
arr.append(screen);
|
||||
}
|
||||
result.insert(JsonKeys::REASON(), reason);
|
||||
result.insert(JsonKeys::USER_ID(), reasonUserId);
|
||||
result.insert(JsonKeys::SCREENS(), arr);
|
||||
m_replyData = QJsonValue(result);
|
||||
}
|
||||
|
||||
|
||||
void STC::LoginRequestReply::process()
|
||||
{
|
||||
if (!m_handler || !m_client) return;
|
||||
QJsonObject dataObj = m_data.toObject();
|
||||
m_reason = Reason(dataObj.value(JsonKeys::REASON()).toInt());
|
||||
m_reasonUserId = dataObj.value(JsonKeys::USER_ID()).toInt();
|
||||
const auto arr = dataObj.value(JsonKeys::SCREENS()).toArray();
|
||||
for (const QJsonValue &val : arr)
|
||||
{
|
||||
const QJsonObject obj(val.toObject());
|
||||
VncScreen screen;
|
||||
screen.name = obj.value(JsonKeys::NAME()).toString(QStringLiteral("err"));
|
||||
screen.port = obj.value(JsonKeys::PORT()).toInt(-1);
|
||||
screen.geometry = QRect(0, 0,
|
||||
obj.value(JsonKeys::WIDTH()).toInt(-1),
|
||||
obj.value(JsonKeys::HEIGHT()).toInt(-1));
|
||||
m_screens.append(std::move(screen));
|
||||
}
|
||||
m_handler->handleMessage(this);
|
||||
}
|
||||
|
||||
|
||||
bool STC::LoginRequestReply::hasValidData() const
|
||||
{
|
||||
if (!m_handler || !m_client) return false;
|
||||
QJsonObject obj = m_data.toObject();
|
||||
if (obj.value(JsonKeys::REASON()).isUndefined()) return false;
|
||||
if (obj.value(JsonKeys::USER_ID()).isUndefined()) return false;
|
||||
if (obj.value(JsonKeys::SCREENS()).isUndefined()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
STC::DedicatedDisconnect::DedicatedDisconnect(const QString &uuid, int userId)
|
||||
: Message(nullptr, nullptr, JsonKeys::DEDICAED_DISCONNECT(), uuid, QJsonValue())
|
||||
, m_userId(userId)
|
||||
{
|
||||
QJsonObject result;
|
||||
result.insert(JsonKeys::USER_ID(), m_userId);
|
||||
m_replyData = result;
|
||||
}
|
||||
|
||||
|
||||
void STC::DedicatedDisconnect::process()
|
||||
{
|
||||
if (!m_handler || !m_client) return;
|
||||
QJsonObject obj = m_data.toObject();
|
||||
m_userId = obj.value(JsonKeys::USER_ID()).toInt(-1);
|
||||
m_handler->handleMessage(this);
|
||||
}
|
||||
|
||||
|
||||
bool STC::DedicatedDisconnect::hasValidData() const
|
||||
{
|
||||
if (!m_handler || !m_client) return false;
|
||||
QJsonObject obj = m_data.toObject();
|
||||
if (obj.value(JsonKeys::USER_ID()).isUndefined()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
CTS::LoginRequest::LoginRequest(const QString &uuid, int userId, int priority, int exerciseId, const QByteArray &settingsData)
|
||||
: Message(nullptr, nullptr, JsonKeys::LOGIN_REQUEST(), uuid, QJsonValue())
|
||||
, m_settingsData(settingsData), m_userId(userId), m_priority(priority), m_exerciseId(exerciseId)
|
||||
{
|
||||
QJsonObject result;
|
||||
result.insert(JsonKeys::USER_ID(), m_userId);
|
||||
result.insert(JsonKeys::USER_PRIORITY(), m_priority);
|
||||
result.insert(JsonKeys::EXERCISE_ID(), m_exerciseId);
|
||||
result.insert(JsonKeys::SETTINGS_DATA(), QString::fromLatin1(m_settingsData.toBase64()));
|
||||
m_replyData = result;
|
||||
}
|
||||
|
||||
|
||||
void CTS::LoginRequest::process()
|
||||
{
|
||||
if (!m_handler || !m_client) return;
|
||||
QJsonObject obj = m_data.toObject();
|
||||
m_userId = obj.value(JsonKeys::USER_ID()).toInt(-1);
|
||||
m_priority = obj.value(JsonKeys::USER_PRIORITY()).toInt(-1);
|
||||
m_exerciseId = obj.value(JsonKeys::EXERCISE_ID()).toInt(-1);
|
||||
m_settingsData = QByteArray::fromBase64(obj.value(JsonKeys::SETTINGS_DATA()).toString().toLatin1());
|
||||
m_handler->handleMessage(this);
|
||||
}
|
||||
|
||||
|
||||
bool CTS::LoginRequest::hasValidData() const
|
||||
{
|
||||
if (!m_handler || !m_client) return false;
|
||||
QJsonObject obj = m_data.toObject();
|
||||
if (obj.value(JsonKeys::USER_ID()).isUndefined()) return false;
|
||||
if (obj.value(JsonKeys::EXERCISE_ID()).isUndefined()) return false;
|
||||
if (obj.value(JsonKeys::USER_PRIORITY()).isUndefined()) return false;
|
||||
if (obj.value(JsonKeys::SETTINGS_DATA()).isUndefined()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CTS::LogoutRequest::process()
|
||||
{
|
||||
if (!m_handler || !m_client) return;
|
||||
m_handler->handleMessage(this);
|
||||
}
|
||||
|
||||
|
||||
bool CTS::LogoutRequest::hasValidData() const
|
||||
{
|
||||
if (!m_handler || !m_client) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
CTS::DisconnectRequest::DisconnectRequest(const QString &uuid, int userId)
|
||||
: Message(nullptr, nullptr, JsonKeys::DISCONNECT_REQUEST(), uuid, QJsonValue())
|
||||
, m_userId(userId)
|
||||
{
|
||||
qDebug() << " 1 m_userId = " << m_userId;
|
||||
QJsonObject result;
|
||||
result.insert(JsonKeys::USER_ID(), m_userId);
|
||||
m_replyData = result;
|
||||
}
|
||||
|
||||
void CTS::DisconnectRequest::process()
|
||||
{
|
||||
if (!m_handler || !m_client) return;
|
||||
QJsonObject obj = m_data.toObject();
|
||||
m_userId = obj.value(JsonKeys::USER_ID()).toInt(-1);
|
||||
qDebug() << " 2 m_userId = " << m_userId;
|
||||
m_handler->handleMessage(this);
|
||||
}
|
||||
|
||||
bool CTS::DisconnectRequest::hasValidData() const
|
||||
{
|
||||
if (!m_handler || !m_client) return false;
|
||||
QJsonObject obj = m_data.toObject();
|
||||
if (obj.value(JsonKeys::USER_ID()).isUndefined()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ErrorMessage::ErrorMessage(const QString &uuid, const QString &reason)
|
||||
: Message(nullptr, nullptr, JsonKeys::ERROR_MESSAGE(), uuid, QJsonValue())
|
||||
, m_reason(reason)
|
||||
{
|
||||
QJsonObject result;
|
||||
result.insert(JsonKeys::REASON(), m_reason);
|
||||
m_replyData = result;
|
||||
}
|
||||
|
||||
|
||||
void ErrorMessage::process()
|
||||
{
|
||||
if (!m_handler || !m_client) return;
|
||||
QJsonObject obj = m_data.toObject();
|
||||
m_reason = obj.value(JsonKeys::REASON()).toString(QStringLiteral("err"));
|
||||
m_handler->handleMessage(this);
|
||||
}
|
||||
|
||||
|
||||
bool ErrorMessage::hasValidData() const
|
||||
{
|
||||
if (!m_handler || !m_client) return false;
|
||||
QJsonObject obj = m_data.toObject();
|
||||
if (obj.value(JsonKeys::REASON()).isUndefined()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+192
@@ -0,0 +1,192 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "json_keys.h"
|
||||
|
||||
#include <LtsWebSocket/json_keys.h>
|
||||
#include <LtsWebSocket/client_message.h>
|
||||
|
||||
#include <LtsProjectionWorkstation/lts_projection_workstation_export.h>
|
||||
#include <LtsProjectionWorkstation/vnc_server_manager.h>
|
||||
|
||||
#include <QVector>
|
||||
|
||||
namespace LtsWebSocket { class ReplyHandler; }
|
||||
|
||||
namespace LtsProjectionWorkstation
|
||||
{
|
||||
|
||||
class AbstractMessageHandler
|
||||
{
|
||||
public:
|
||||
virtual ~AbstractMessageHandler() = default;
|
||||
virtual void handleMessage(LtsWebSocket::AbstractClientMessage *message) = 0;
|
||||
};
|
||||
|
||||
|
||||
class Reply : public LtsWebSocket::ReplyMessage
|
||||
{
|
||||
public:
|
||||
Reply(const QString &type, const int typeId, const QString &uuid, const QJsonObject &data)
|
||||
: LtsWebSocket::ReplyMessage(type, typeId, uuid)
|
||||
{
|
||||
m_jsonRepresentation.insert(LtsWebSocket::JsonKeys::DATA(), data);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Message : public LtsWebSocket::AbstractClientMessage
|
||||
{
|
||||
public:
|
||||
Message(AbstractMessageHandler *handler, LtsWebSocket::ReplyHandler *client, const QString &type, const QString &uuid, const QJsonValue &data = QJsonValue())
|
||||
: LtsWebSocket::AbstractClientMessage(client, type, 1, uuid, data)
|
||||
, m_handler(handler)
|
||||
{}
|
||||
|
||||
LtsWebSocket::ReplyMessage *toReplyMessage() const
|
||||
{
|
||||
if (!m_handler || !m_client)
|
||||
return new Reply(m_type, m_typeId, m_uuid, m_replyData.toObject());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void addReply(LtsWebSocket::ReplyMessage *reply)
|
||||
{
|
||||
if (m_client)
|
||||
m_client->addReply(reply);
|
||||
}
|
||||
|
||||
protected:
|
||||
AbstractMessageHandler *m_handler;
|
||||
QJsonValue m_replyData;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class LTSPROJECTIONWORKSTATION_EXPORT ErrorMessage : public Message
|
||||
{
|
||||
public:
|
||||
using Message::Message;
|
||||
ErrorMessage(const QString &uuid, const QString &reason);
|
||||
|
||||
|
||||
void process() override final;
|
||||
bool hasValidData() const override final;
|
||||
|
||||
private:
|
||||
QString m_reason;
|
||||
};
|
||||
|
||||
namespace STC
|
||||
{
|
||||
|
||||
class LTSPROJECTIONWORKSTATION_EXPORT LoginRequestReply : public Message
|
||||
{
|
||||
public:
|
||||
enum Reason
|
||||
{
|
||||
LoginSuccessful,
|
||||
OtherUser,
|
||||
};
|
||||
|
||||
using Message::Message;
|
||||
LoginRequestReply(const QString &uuid, Reason reason, int reasonUserId, const QVector<VncScreen> &screens);
|
||||
|
||||
|
||||
void process() override final;
|
||||
bool hasValidData() const override final;
|
||||
|
||||
int reasonUserId() const { return m_reasonUserId; }
|
||||
Reason reason() const { return m_reason; }
|
||||
const QVector<VncScreen> &screens() const { return m_screens; }
|
||||
|
||||
private:
|
||||
QVector<VncScreen> m_screens;
|
||||
int m_reasonUserId = -1;
|
||||
Reason m_reason = LoginSuccessful;
|
||||
};
|
||||
|
||||
class LTSPROJECTIONWORKSTATION_EXPORT DedicatedDisconnect : public Message
|
||||
{
|
||||
public:
|
||||
using Message::Message;
|
||||
DedicatedDisconnect(const QString &uuid, int userId);
|
||||
|
||||
|
||||
void process() override final;
|
||||
bool hasValidData() const override final;
|
||||
|
||||
int userid() const { return m_userId; }
|
||||
|
||||
private:
|
||||
int m_userId = -1;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace CTS
|
||||
{
|
||||
|
||||
class LTSPROJECTIONWORKSTATION_EXPORT LoginRequest : public Message
|
||||
{
|
||||
public:
|
||||
using Message::Message;
|
||||
LoginRequest(const QString &uuid, int userId, int priority, int exerciseId, const QByteArray &settingsData);
|
||||
|
||||
|
||||
void process() override final;
|
||||
bool hasValidData() const override final;
|
||||
|
||||
int userId() const { return m_userId; }
|
||||
int priority() const { return m_priority; }
|
||||
int exerciseId() const { return m_exerciseId; }
|
||||
const QByteArray &settingsData() const { return m_settingsData; }
|
||||
|
||||
private:
|
||||
QByteArray m_settingsData;
|
||||
int m_userId = 0;
|
||||
int m_priority = 0;
|
||||
int m_exerciseId = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class LTSPROJECTIONWORKSTATION_EXPORT LogoutRequest : public Message
|
||||
{
|
||||
public:
|
||||
using Message::Message;
|
||||
explicit LogoutRequest(const QString &uuid)
|
||||
: Message(nullptr, nullptr, JsonKeys::LOGOUT_REQUEST(), uuid, QJsonValue())
|
||||
{}
|
||||
|
||||
|
||||
void process() override final;
|
||||
bool hasValidData() const override final;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class LTSPROJECTIONWORKSTATION_EXPORT DisconnectRequest : public Message
|
||||
{
|
||||
public:
|
||||
using Message::Message;
|
||||
explicit DisconnectRequest(const QString &uuid, int userId);
|
||||
|
||||
|
||||
void process() override final;
|
||||
bool hasValidData() const override final;
|
||||
|
||||
int userId() const { return m_userId; }
|
||||
private:
|
||||
int m_userId{0};
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
|
||||
|
||||
#include "reply_message.h"
|
||||
|
||||
namespace LtsProjectionWorkstation
|
||||
{
|
||||
|
||||
LoginReply::LoginReply(const QJsonObject &data, const QString &uuid)
|
||||
: LtsWebSocket::ReplyMessage(JsonKeys::LOGIN_REPLY(), uuid)
|
||||
{
|
||||
m_jsonRepresentation.insert(LtsWebSocket::JsonKeys::DATA(), data);
|
||||
}
|
||||
|
||||
LogoutReply::LogoutReply(const QJsonObject &data, const QString &uuid)
|
||||
: LtsWebSocket::ReplyMessage(JsonKeys::LOGOUT_REPLY(), uuid)
|
||||
{
|
||||
m_jsonRepresentation.insert(LtsWebSocket::JsonKeys::DATA(), data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
|
||||
|
||||
|
||||
#include "json_keys.h"
|
||||
|
||||
#include <LtsWebSocket/reply_message.h>
|
||||
#include <LtsWebSocket/json_keys.h>
|
||||
|
||||
namespace LtsProjectionWorkstation
|
||||
{
|
||||
|
||||
class LoginReply : public LtsWebSocket::ReplyMessage
|
||||
{
|
||||
public:
|
||||
explicit LoginReply(const QJsonObject &data, const QString &uuid);
|
||||
};
|
||||
|
||||
class LogoutReply : public LtsWebSocket::ReplyMessage
|
||||
{
|
||||
public:
|
||||
explicit LogoutReply(const QJsonObject &data, const QString &uuid);
|
||||
};
|
||||
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
|
||||
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
namespace LtsProjectionWorkstation
|
||||
{
|
||||
|
||||
LOGGER_T getLogger(const char *name)
|
||||
{
|
||||
static const char ns[] = "PWS.";
|
||||
std::string loggerName;
|
||||
const size_t len = strlen(name);
|
||||
loggerName.reserve(sizeof(ns) + len);
|
||||
loggerName.append(ns, sizeof(ns) - 1);
|
||||
loggerName.append(name, len);
|
||||
|
||||
try
|
||||
{
|
||||
return NGL::NGLLoggerBootstrap::getNGLRootLogger().
|
||||
getNGLLogger(loggerName);
|
||||
}
|
||||
catch (const std::exception &ex)
|
||||
{
|
||||
fprintf(stderr, "Error retrieving logger: %s", ex.what());
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
#include "lts_projection_workstation_export.h"
|
||||
|
||||
namespace LtsProjectionWorkstation
|
||||
{
|
||||
using LOGGER_T = NGL::INGLLogger&;
|
||||
|
||||
LTSPROJECTIONWORKSTATION_EXPORT LOGGER_T getLogger(const char *name);
|
||||
inline LOGGER_T getLogger(const QString &loggerName)
|
||||
{
|
||||
return getLogger(loggerName.toUtf8().constData());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_projection_workstation.h"
|
||||
#include "WebSocket/message_factory.h"
|
||||
#include "WebSocket/json_keys.h"
|
||||
|
||||
#include <LtsWebSocket/lts_web_socket_server.h>
|
||||
#include <LtsSession/lts_session_data.h>
|
||||
|
||||
#include <nglsettings/nglsettings_connections.h>
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QUuid>
|
||||
#include <QWebSocket>
|
||||
#include <QTimer>
|
||||
|
||||
namespace LtsProjectionWorkstation
|
||||
{
|
||||
|
||||
static LtsProjectionWorkstation *s_ltsProjectionWorkstation = nullptr;
|
||||
|
||||
LtsProjectionWorkstation *LtsProjectionWorkstation::getInstance()
|
||||
{
|
||||
if (!s_ltsProjectionWorkstation)
|
||||
{
|
||||
s_ltsProjectionWorkstation = new LtsProjectionWorkstation;
|
||||
qAddPostRoutine(&cleanupLtsProjectionWorkstation);
|
||||
}
|
||||
return s_ltsProjectionWorkstation;
|
||||
}
|
||||
|
||||
void LtsProjectionWorkstation::cleanupLtsProjectionWorkstation()
|
||||
{
|
||||
delete s_ltsProjectionWorkstation;
|
||||
s_ltsProjectionWorkstation = nullptr;
|
||||
}
|
||||
|
||||
bool LtsProjectionWorkstation::hasInstance()
|
||||
{
|
||||
return !!s_ltsProjectionWorkstation;
|
||||
}
|
||||
|
||||
LtsProjectionWorkstation::LtsProjectionWorkstation(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_logger(getLogger("LtsProjetionWorkstation"))
|
||||
, m_messageFactory(new MessageFactory(this, m_logger))
|
||||
, m_webSocketServer(new LtsWebSocket::LtsWebSocketServer(m_messageFactory, this))
|
||||
, m_pendingLoginRequest(nullptr)
|
||||
, m_vncManager(new VncServerManager(m_logger, this))
|
||||
{
|
||||
connect(m_webSocketServer, &LtsWebSocket::LtsWebSocketServer::clientDisconnected,
|
||||
this, &LtsProjectionWorkstation::clientDisconnected);
|
||||
connect(m_webSocketServer, &LtsWebSocket::LtsWebSocketServer::clientConnected,
|
||||
this, &LtsProjectionWorkstation::clientConnected);
|
||||
|
||||
int port = NGL::Connections::port(NGL::Connections::eConnection::PWS_WEBSOCKET);
|
||||
|
||||
if (m_webSocketServer->init(QStringLiteral("LtsProjectionWorkstation"), port))
|
||||
{
|
||||
if (m_vncManager->init(qApp->screens()))
|
||||
m_vncManager->startScreens();
|
||||
}
|
||||
}
|
||||
|
||||
LtsProjectionWorkstation::~LtsProjectionWorkstation()
|
||||
{
|
||||
delete m_vncManager;
|
||||
delete m_messageFactory;
|
||||
delete m_webSocketServer;
|
||||
}
|
||||
|
||||
LoginInformation LtsProjectionWorkstation::pendingLoginRequest()
|
||||
{
|
||||
if (!m_pendingLoginRequest)
|
||||
return {};
|
||||
|
||||
LoginInformation result = *m_pendingLoginRequest;
|
||||
|
||||
INFO_LOG(m_logger) << " reset pendingLoginRequest..";
|
||||
|
||||
delete m_pendingLoginRequest;
|
||||
m_pendingLoginRequest = nullptr;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void LtsProjectionWorkstation::handleMessage(LtsWebSocket::AbstractClientMessage *message)
|
||||
{
|
||||
CTS::LoginRequest *login = dynamic_cast<CTS::LoginRequest *>(message);
|
||||
if (login)
|
||||
{
|
||||
INFO_LOG(m_logger) << "Login request received!"
|
||||
<< ", login->userId()=" << login->userId()
|
||||
<< " with login->priority()=" << login->priority()
|
||||
<< " ;;; m_lastLoginRequest.m_userId=" << m_lastLoginRequest.m_userId
|
||||
<< ", m_priority=" << m_lastLoginRequest.m_priority;
|
||||
|
||||
if (login->userId() > 0 && login->priority() > 0 && login->exerciseId() > 0)
|
||||
{
|
||||
|
||||
if ( login->userId() == m_lastLoginRequest.m_userId ||
|
||||
(login->priority() > m_lastLoginRequest.m_priority)
|
||||
)
|
||||
{
|
||||
|
||||
m_webSocketServer->sendToAllClients( (new STC::DedicatedDisconnect(QUuid::createUuid().toString(), login->userId()))->toReplyMessage() );
|
||||
|
||||
|
||||
|
||||
DEBUG_LOG(m_logger) << "Login request received and DedicatedDisconnect distributed, wait some seconds...";
|
||||
int i=0;
|
||||
while(i<20)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Login request received and DedicatedDisconnect distributed, wait some seconds...i=" << i;
|
||||
qApp->processEvents(QEventLoop::AllEvents, 50);
|
||||
QThread::msleep(50);
|
||||
++i;
|
||||
}
|
||||
INFO_LOG(m_logger) << "Login request received and DedicatedDisconnect distributed, wait some seconds... done";
|
||||
|
||||
|
||||
login->addReply((new STC::LoginRequestReply(QUuid::createUuid().toString(),
|
||||
STC::LoginRequestReply::LoginSuccessful,
|
||||
login->userId(),
|
||||
m_vncManager->screens())
|
||||
)->toReplyMessage());
|
||||
|
||||
m_lastLoginRequest.m_userId = login->userId();
|
||||
m_lastLoginRequest.m_priority = login->priority();
|
||||
m_lastLoginRequest.m_exerciseId = login->exerciseId();
|
||||
m_lastLoginRequest.m_settingsData = login->settingsData();
|
||||
|
||||
slotLoginRequestReceived(login->userId(), login->exerciseId());
|
||||
|
||||
INFO_LOG(m_logger) << "Valid login request received -> userId: " << login->userId()
|
||||
<< " priority: " << login->priority()
|
||||
<< " exerciseId: " << login->exerciseId();
|
||||
DEBUG_LOG(m_logger) << "Logging in now!";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
login->addReply((new STC::LoginRequestReply(QUuid::createUuid().toString(),
|
||||
STC::LoginRequestReply::OtherUser,
|
||||
m_lastLoginRequest.m_userId,
|
||||
QVector<VncScreen>())
|
||||
)->toReplyMessage());
|
||||
|
||||
DEBUG_LOG(m_logger) << "Higher prioritized login received -> userId: " << login->userId()
|
||||
<< " priority: " << login->priority()
|
||||
<< " exerciseId: " << login->exerciseId();
|
||||
|
||||
DEBUG_LOG(m_logger) << "Last login data was -> userId: " << m_lastLoginRequest.m_userId
|
||||
<< " priority: " << m_lastLoginRequest.m_priority
|
||||
<< " exerciseId: " << m_lastLoginRequest.m_exerciseId;
|
||||
}
|
||||
}
|
||||
else
|
||||
ERROR_LOG(m_logger) << "invalid login request received -> userId: " << login->userId()
|
||||
<< " priority: " << login->priority()
|
||||
<< " exerciseId: " << login->exerciseId();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
CTS::LogoutRequest *logout = dynamic_cast<CTS::LogoutRequest *>(message);
|
||||
if (logout)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Logging out now!";
|
||||
slotLogoutRequestReceived();
|
||||
return;
|
||||
}
|
||||
|
||||
CTS::DisconnectRequest *discon = dynamic_cast<CTS::DisconnectRequest *>(message);
|
||||
if (discon)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int disconnectingUserId = discon->userId();
|
||||
INFO_LOG(m_logger) << "Disconnecting now! "
|
||||
<< ", disconnectingUserId=" << disconnectingUserId
|
||||
<< ", m_pendingLoginRequest=" << m_pendingLoginRequest;
|
||||
m_lastLoginRequest = LoginInformation();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void LtsProjectionWorkstation::slotLoginRequestReceived(int userId, int exerciseId)
|
||||
{
|
||||
INFO_LOG(m_logger) << "slotLoginRequestReceived.."
|
||||
<< ", userId=" << userId
|
||||
<< ", exerciseId=" << exerciseId;
|
||||
delete m_pendingLoginRequest;
|
||||
m_pendingLoginRequest = new LoginInformation(m_lastLoginRequest);
|
||||
emit signalLoginRequestReceived(userId, exerciseId);
|
||||
}
|
||||
|
||||
void LtsProjectionWorkstation::slotLogoutRequestReceived()
|
||||
{
|
||||
emit signalLogoutRequestReceived();
|
||||
}
|
||||
|
||||
|
||||
void LtsProjectionWorkstation::slotLogoffDone()
|
||||
{
|
||||
if (hasPendingLoginRequest())
|
||||
return;
|
||||
for (LtsWebSocket::ClientConnection *con : qAsConst(m_connections))
|
||||
con->webSocket()->close();
|
||||
}
|
||||
|
||||
|
||||
void LtsProjectionWorkstation::clientDisconnected(LtsWebSocket::ClientConnection *client)
|
||||
{
|
||||
INFO_LOG(m_logger) << LOGFUNCTION << " START"
|
||||
<< ", m_connections.size = " << m_connections.size();
|
||||
|
||||
m_connections.removeOne(client);
|
||||
|
||||
if ( m_connections.size() == 0 && (m_lastLoginRequest.m_userId != 0 || m_lastLoginRequest.m_priority != 0))
|
||||
{
|
||||
INFO_LOG(m_logger) << LOGFUNCTION << " reset m_lastLoginRequest";
|
||||
m_lastLoginRequest = LoginInformation();
|
||||
}
|
||||
INFO_LOG(m_logger) << LOGFUNCTION << " END"
|
||||
<< ", m_connections.size = " << m_connections.size();
|
||||
}
|
||||
|
||||
void LtsProjectionWorkstation::clientConnected(LtsWebSocket::ClientConnection *client)
|
||||
{
|
||||
m_connections.append(client);
|
||||
}
|
||||
|
||||
void LtsProjectionWorkstation::setProjectionOperatorPreset(const QString &operatorName, const QString &operatorPassword)
|
||||
{
|
||||
m_projectionOperatorPreset.first = operatorName;
|
||||
m_projectionOperatorPreset.second = operatorPassword;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "lts_projection_workstation_export.h"
|
||||
#include "vnc_server_manager.h"
|
||||
#include "WebSocket/messages.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <LtsWebSocket/client_connection.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QPair>
|
||||
|
||||
namespace LtsWebSocket { class LtsWebSocketServer; }
|
||||
namespace LtsProjectionWorkstation
|
||||
{
|
||||
|
||||
struct LoginInformation
|
||||
{
|
||||
LoginInformation() = default;
|
||||
LoginInformation(int userId, int priority, int exerciseId, const QByteArray &settingsData)
|
||||
: m_settingsData(settingsData), m_userId(userId), m_priority(priority), m_exerciseId(exerciseId) {}
|
||||
|
||||
QByteArray m_settingsData;
|
||||
int m_userId = 0;
|
||||
int m_priority = 0;
|
||||
int m_exerciseId = 0;
|
||||
};
|
||||
|
||||
class MessageFactory;
|
||||
class LTSPROJECTIONWORKSTATION_EXPORT LtsProjectionWorkstation : public QObject, public AbstractMessageHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static LtsProjectionWorkstation *getInstance();
|
||||
static bool hasInstance();
|
||||
|
||||
const LoginInformation &lastLoginRequest() const { return m_lastLoginRequest; }
|
||||
LoginInformation pendingLoginRequest();
|
||||
bool hasPendingLoginRequest() const { return !!m_pendingLoginRequest; }
|
||||
void setProjectionOperatorPreset(const QString &operatorName, const QString &operatorPassword);
|
||||
const QPair<QString, QString> &projectionOperatorPreset() const { return m_projectionOperatorPreset; }
|
||||
|
||||
|
||||
void handleMessage(LtsWebSocket::AbstractClientMessage *message) override final;
|
||||
|
||||
public slots:
|
||||
void slotLoginRequestReceived(int userId, int exerciseId);
|
||||
void slotLogoutRequestReceived();
|
||||
|
||||
void slotLogoffDone();
|
||||
|
||||
signals:
|
||||
void signalLoginRequestReceived(int userId, int exerciseId);
|
||||
void signalLogoutRequestReceived();
|
||||
|
||||
private slots:
|
||||
void clientDisconnected(LtsWebSocket::ClientConnection* client);
|
||||
void clientConnected(LtsWebSocket::ClientConnection* client);
|
||||
|
||||
private:
|
||||
explicit LtsProjectionWorkstation(QObject *parent = nullptr);
|
||||
~LtsProjectionWorkstation();
|
||||
static void cleanupLtsProjectionWorkstation();
|
||||
|
||||
LOGGER_T m_logger;
|
||||
MessageFactory *m_messageFactory;
|
||||
LtsWebSocket::LtsWebSocketServer *m_webSocketServer;
|
||||
|
||||
|
||||
LoginInformation m_lastLoginRequest;
|
||||
|
||||
LoginInformation *m_pendingLoginRequest;
|
||||
QPair<QString , QString > m_projectionOperatorPreset;
|
||||
|
||||
QVector<LtsWebSocket::ClientConnection*> m_connections;
|
||||
|
||||
VncServerManager *m_vncManager;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#ifndef LTSPROJECTIONWORKSTATION_EXPORT
|
||||
# ifdef BUILD_STATIC_LIBRARIES
|
||||
# define LTSPROJECTIONWORKSTATION_EXPORT
|
||||
# else
|
||||
# if defined(MAKE_LTSPROJECTIONWORKSTATION_LIB)
|
||||
# define LTSPROJECTIONWORKSTATION_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define LTSPROJECTIONWORKSTATION_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
+194
@@ -0,0 +1,194 @@
|
||||
|
||||
|
||||
|
||||
#include "vnc_server_manager.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
#include <QScreen>
|
||||
#include <QDir>
|
||||
|
||||
namespace LtsProjectionWorkstation
|
||||
{
|
||||
|
||||
VncServerManager::VncServerManager(LOGGER_T &logger, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_logger(logger)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
VncServerManager::~VncServerManager()
|
||||
{
|
||||
stopScreens();
|
||||
}
|
||||
|
||||
QList<QScreen *> sortScreen(const QList<QScreen *> &screens)
|
||||
{
|
||||
auto ret(screens);
|
||||
|
||||
auto doSortScreens = [](const QScreen *s1, const QScreen *s2) -> bool
|
||||
{
|
||||
const auto tl1 = s1->geometry().topLeft();
|
||||
const auto tl2 = s2->geometry().topLeft();
|
||||
if (tl1.y() > tl2.y())
|
||||
return true;
|
||||
if (tl1.y() < tl2.y())
|
||||
return false;
|
||||
return tl1.x() < tl2.x();
|
||||
};
|
||||
std::sort(ret.begin(), ret.end(), doSortScreens);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool VncServerManager::init(const QList<QScreen *> &screens)
|
||||
{
|
||||
killScreens();
|
||||
createPwdFile();
|
||||
|
||||
const auto sortedScreens = sortScreen(screens);
|
||||
|
||||
DEBUG_LOG(m_logger) << "Setup VNCScreens with " << screens.size() << " screens";
|
||||
|
||||
int count = 1;
|
||||
|
||||
static constexpr char VNC_START_ARGS[] = "-rfbauth,%1/.vnc/passwd,-clip,%2x%3+%4+%5,-loop100,-forever,-display,:0,-threads,-noxdamage";
|
||||
|
||||
|
||||
for (QScreen *screen : sortedScreens)
|
||||
{
|
||||
VncScreen vncScreen;
|
||||
|
||||
vncScreen.geometry = screen->geometry();
|
||||
vncScreen.name = QStringLiteral("Display%1").arg(count);
|
||||
vncScreen.proc = new QProcess(this);
|
||||
QString startArgs = QString::fromLatin1(VNC_START_ARGS).arg(QDir::home().absolutePath())
|
||||
.arg(screen->geometry().width()).arg(screen->geometry().height())
|
||||
.arg(screen->geometry().x()).arg(screen->geometry().y());
|
||||
|
||||
vncScreen.proc->setProgram(QStringLiteral("x11vnc"));
|
||||
vncScreen.proc->setArguments(startArgs.split(QLatin1Char(',')));
|
||||
|
||||
NOTICE_LOG(m_logger) << "Started VNC for Screen " << count << " with geometry "
|
||||
<< screen->geometry().width() << "," << screen->geometry().height() << "+"
|
||||
<< screen->geometry().x() << "+" << screen->geometry().y();
|
||||
|
||||
m_vncScreens.push_back(vncScreen);
|
||||
count++;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << m_vncScreens.size() << " VNCScreen(s) created - Setup completed.";
|
||||
return true;
|
||||
}
|
||||
|
||||
void VncServerManager::startScreens()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Starting " << m_vncScreens.size() << " VNCScreen(s) ... ";
|
||||
for (const VncScreen &s : qAsConst(m_vncScreens))
|
||||
{
|
||||
connect(s.proc, &QProcess::readyReadStandardOutput,
|
||||
this, &VncServerManager::slotReadStandardOutput, Qt::UniqueConnection);
|
||||
connect(s.proc, &QProcess::errorOccurred,
|
||||
this, &VncServerManager::slotErrorOccured, Qt::UniqueConnection);
|
||||
s.proc->start();
|
||||
}
|
||||
for (const VncScreen &s : qAsConst(m_vncScreens))
|
||||
{
|
||||
if (!s.proc->waitForStarted(2000))
|
||||
ERROR_LOG(m_logger) << "Can not start process '" << s.proc->program() << "': "
|
||||
<< s.proc->errorString();
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "Done";
|
||||
}
|
||||
|
||||
|
||||
void VncServerManager::stopScreens()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Stopping " << m_vncScreens.size() << " VNCScreen(s) ...";
|
||||
|
||||
for (const VncScreen &s : qAsConst(m_vncScreens))
|
||||
{
|
||||
s.proc->disconnect(this);
|
||||
s.proc->terminate();
|
||||
}
|
||||
for (const VncScreen &s : qAsConst(m_vncScreens))
|
||||
{
|
||||
if (!s.proc->waitForFinished(2000))
|
||||
s.proc->kill();
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "Done";
|
||||
}
|
||||
|
||||
|
||||
void VncServerManager::killScreens()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Killing all exisiting x11vnc processes ...";
|
||||
|
||||
SingleShotProcess ssp(QStringLiteral("killall x11vnc"));
|
||||
ssp.execute();
|
||||
DEBUG_LOG(m_logger) << "Done";
|
||||
}
|
||||
|
||||
|
||||
void VncServerManager::createPwdFile()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "(Re)creating x11vnc password-file ...";
|
||||
|
||||
SingleShotProcess ssp(QStringLiteral("x11vnc -storepasswd ctc11de %1/.vnc/passwd")
|
||||
.arg(QDir::home().absolutePath()));
|
||||
ssp.execute();
|
||||
DEBUG_LOG(m_logger) << "Done";
|
||||
}
|
||||
|
||||
|
||||
void VncServerManager::slotReadStandardOutput()
|
||||
{
|
||||
QProcess *p = qobject_cast<QProcess *>(QObject::sender());
|
||||
if (!p)
|
||||
return;
|
||||
|
||||
QString stdOut = QString::fromLocal8Bit(p->readAllStandardOutput());
|
||||
QRegularExpressionMatch match = QRegularExpression(QStringLiteral("PORT=(.*?)\\s")).match(stdOut);
|
||||
if (!match.hasMatch())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Could not retrieve port information from stdout of " << p->program();
|
||||
return;
|
||||
}
|
||||
const quint16 port = match.capturedRef(1).toInt();
|
||||
if (port == 0)
|
||||
return;
|
||||
for (VncScreen &screen : m_vncScreens)
|
||||
{
|
||||
if (screen.proc != p)
|
||||
continue;
|
||||
screen.port = port;
|
||||
disconnect(screen.proc, &QProcess::readyReadStandardOutput, nullptr, nullptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void VncServerManager::slotErrorOccured()
|
||||
{
|
||||
QProcess *p = qobject_cast<QProcess *>(QObject::sender());
|
||||
if (p)
|
||||
ERROR_LOG(m_logger) << p->errorString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
SingleShotProcess::SingleShotProcess(const QString &cmd, bool startImmediatly)
|
||||
: m_cmd(cmd)
|
||||
{
|
||||
if (startImmediatly) execute();
|
||||
}
|
||||
|
||||
bool SingleShotProcess::execute()
|
||||
{
|
||||
m_process.start(m_cmd);
|
||||
return m_process.waitForFinished();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QProcess>
|
||||
#include <QRect>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
class QScreen;
|
||||
|
||||
namespace LtsProjectionWorkstation
|
||||
{
|
||||
|
||||
class SingleShotProcess
|
||||
{
|
||||
public:
|
||||
explicit SingleShotProcess(const QString &cmd, bool startImmediatly = false);
|
||||
|
||||
bool execute();
|
||||
|
||||
private:
|
||||
QProcess m_process;
|
||||
QString m_cmd;
|
||||
};
|
||||
|
||||
|
||||
struct VncScreen
|
||||
{
|
||||
QString name;
|
||||
QProcess *proc = nullptr;
|
||||
QRect geometry;
|
||||
quint16 port = 0;
|
||||
};
|
||||
|
||||
|
||||
class VncServerManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit VncServerManager(LOGGER_T &logger, QObject *parent = nullptr);
|
||||
|
||||
~VncServerManager();
|
||||
|
||||
bool init(const QList<QScreen *> &screens);
|
||||
|
||||
const QVector<VncScreen> &screens() const { return m_vncScreens; }
|
||||
|
||||
|
||||
|
||||
void startScreens();
|
||||
void stopScreens();
|
||||
void killScreens();
|
||||
void createPwdFile();
|
||||
|
||||
private slots:
|
||||
void slotReadStandardOutput();
|
||||
void slotErrorOccured();
|
||||
|
||||
private:
|
||||
QVector<VncScreen> m_vncScreens;
|
||||
LOGGER_T &m_logger;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user