11 #include <QMessageBox> 18 #include <QInputDialog> 22 _server(
"plotJuggler", QWebSocketServer::NonSecureMode)
37 _port = QInputDialog::getInt(
nullptr, tr(
""),
38 tr(
"On whish port should the server listen to:"), 6666, 1111, 65535, 1, &ok);
41 qDebug() <<
"Websocket listening on port" <<
_port;
42 connect(&
_server, &QWebSocketServer::newConnection,
47 qDebug() <<
"Couldn't open websocket on port " <<
_port;
52 qDebug() <<
"Server already running on port " <<
_port;
53 QMessageBox::information(
nullptr,
"Info",QString(
"Server already running on port: %1").
arg(
_port));
69 qDebug() <<
"DataStreamServer: onNewConnection";
70 QWebSocket *pSocket =
_server.nextPendingConnection();
80 std::lock_guard<std::mutex> lock(
mutex() );
83 QStringList lst = message.split(
':');
84 if (lst.size() == 3) {
85 QString key = lst.at(0);
86 double time = lst.at(1).toDouble();
87 double value = lst.at(2).toDouble();
91 const std::string name_str = key.toStdString();
92 auto plotIt = numeric_plots.find(name_str);
94 if (plotIt == numeric_plots.end())
99 plotIt->second.pushBack( {time, value} );
106 qDebug() <<
"DataStreamServer: socketDisconnected";
107 QWebSocket *pClient = qobject_cast<QWebSocket *>(sender());
113 pClient->deleteLater();
std::unordered_map< std::string, PlotData > numeric
PlotDataMapRef & dataMap()
virtual void shutdown() override
void socketDisconnected()
void processMessage(QString message)
virtual ~DataStreamServer()
QList< QWebSocket * > _clients
std::unordered_map< std::string, PlotData >::iterator addNumeric(const std::string &name)
virtual bool start(QStringList *) override