diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-03-11 15:25:11 +0100 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-03-11 15:25:11 +0100 |
| commit | 094b8aa2bbb8b90dff9da199873cbc6b36549eb6 (patch) | |
| tree | f7dea55e25ca4f9a0461c88a9c91953bb77336fc /mock-server/main.cpp | |
| parent | 920a1adeadef58eb04f2bf83af8fb8bc6c01a986 (diff) | |
| download | QtXpl2-094b8aa2bbb8b90dff9da199873cbc6b36549eb6.tar.gz QtXpl2-094b8aa2bbb8b90dff9da199873cbc6b36549eb6.zip | |
Refactor: three XPL2 ports, EchoServer class, dark debug console, qmllint clean
- Xpl2Client: replace single port with commandPort/imagingPort/statusPort (9110/9111/9112)
- Mock server: extract EchoServer class from lambda-based listenOn()
- Demo: dark debug console matching BobinkQtOpcUa style, 2-column connection layout
- Fix qmlls module resolution via IMPORT_PATH in qt_add_qml_module()
- Add pragma ComponentBehavior: Bound, fix all qmllint warnings
Diffstat (limited to 'mock-server/main.cpp')
| -rw-r--r-- | mock-server/main.cpp | 55 |
1 files changed, 5 insertions, 50 deletions
diff --git a/mock-server/main.cpp b/mock-server/main.cpp index 4818d6f..0694e4d 100644 --- a/mock-server/main.cpp +++ b/mock-server/main.cpp @@ -2,63 +2,18 @@ * @file main.cpp * @brief Mock XPL2 server — echoes back on three ports. */ -#include <QCoreApplication> -#include <QTcpServer> -#include <QTcpSocket> - -static QTcpServer * -listenOn (quint16 port, const char *name, QObject *parent) -{ - auto *server = new QTcpServer (parent); - - QObject::connect ( - server, &QTcpServer::newConnection, server, - [=] () - { - while (auto *sock = server->nextPendingConnection ()) - { - qInfo ("[%s:%d] client connected", name, port); - - QObject::connect (sock, &QTcpSocket::readyRead, sock, - [=] () - { - QByteArray data = sock->readAll (); - qInfo ("[%s:%d] echo %lld bytes", name, - port, data.size ()); - sock->write (data); - }); +#include "EchoServer.h" - QObject::connect (sock, &QTcpSocket::disconnected, sock, - [=] () - { - qInfo ("[%s:%d] client disconnected", name, - port); - sock->deleteLater (); - }); - } - }); - - if (!server->listen (QHostAddress::Any, port)) - { - qCritical ("Failed to listen on %s port %d: %s", name, port, - qPrintable (server->errorString ())); - } - else - { - qInfo ("Listening on %s port %d", name, port); - } - - return server; -} +#include <QCoreApplication> int main (int argc, char *argv[]) { QCoreApplication app (argc, argv); - listenOn (9110, "Command", &app); - listenOn (9111, "Imaging", &app); - listenOn (9112, "Status", &app); + new EchoServer (9110, "Command", &app); + new EchoServer (9111, "Imaging", &app); + new EchoServer (9112, "Status", &app); return app.exec (); } |
