forked from os-fpga/FOEDAG
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add InteractivePathAnalysis code into FOEDAG
- Loading branch information
Showing
44 changed files
with
2,383 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#include "client.h" | ||
#include "clienttoolswidget.h" | ||
#include "keys.h" | ||
|
||
#include "tcpsocket.h" | ||
#include "requestcreator.h" | ||
#include "ncriticalpathsettings.h" | ||
|
||
#include <QCoreApplication> | ||
#include <QVBoxLayout> | ||
#include <QPushButton> | ||
#include <QJsonParseError> | ||
#include <QJsonDocument> | ||
#include <QJsonObject> | ||
|
||
Client::Client( | ||
#ifndef STANDALONE_APP | ||
FOEDAG::Compiler* compiler | ||
#endif | ||
) | ||
{ | ||
m_socket = std::make_unique<TcpSocket>(); | ||
|
||
/// UI | ||
m_toolsWidget = new ClientToolsWidget( | ||
#ifndef STANDALONE_APP | ||
compiler | ||
#endif | ||
); | ||
|
||
connect(m_toolsWidget, &ClientToolsWidget::getPathListRequested, this, &Client::runGetPathListScenario); | ||
|
||
connect(m_toolsWidget, &ClientToolsWidget::highLightModeChanged, [this](){ | ||
onPathSelected(NCriticalPathSettings::instance().getLastSelectedPathId()); | ||
}); | ||
// | ||
|
||
connect(m_socket.get(), &ISocket::connectedChanged, m_toolsWidget, &ClientToolsWidget::onConnectionStatusChanged); | ||
connect(m_socket.get(), &ISocket::dataRecieved, this, &Client::handleResponse); | ||
/// | ||
|
||
#ifdef ENABLE_AUTOMATIC_REQUEST | ||
m_timer.setInterval(AUTOMATIC_CLIENT_REQUEST_INTERVAL_MS); | ||
QObject::connect(&m_timer, &QTimer::timeout, this, &Client::runGetPathListScenario); | ||
m_timer.start(); | ||
#endif // ENABLE_AUTOMATIC_REQUEST | ||
} | ||
|
||
Client::~Client() | ||
{ | ||
if (!m_toolsWidget->parent()) { | ||
delete m_toolsWidget; | ||
} | ||
} | ||
|
||
bool Client::isConnected() const | ||
{ | ||
return m_socket->isConnected(); | ||
} | ||
|
||
void Client::handleResponse(const QByteArray& bytes) | ||
{ | ||
qDebug() << "from server:" << bytes; | ||
|
||
// Convert the QByteArray to a QJsonDocument | ||
QJsonParseError parseError; | ||
QJsonDocument jsonDoc = QJsonDocument::fromJson(bytes, &parseError); | ||
|
||
if (parseError.error != QJsonParseError::NoError) { | ||
qDebug() << "Error parsing JSON:" << parseError.errorString(); | ||
return; | ||
} | ||
|
||
// Extract the QJsonObject from the QJsonDocument | ||
QJsonObject jsonObject = jsonDoc.object(); | ||
|
||
int cmd = jsonObject[KEY_CMD].toString().toInt(); | ||
bool status = jsonObject[KEY_STATUS].toString().toInt(); | ||
QString data = jsonObject[KEY_DATA].toString(); | ||
|
||
qInfo() << cmd << status << data; | ||
if (status) { | ||
switch(cmd) { | ||
case CMD_GET_PATH_LIST_ID: emit critPathsDataReady(data); break; | ||
} | ||
} else { | ||
qInfo() << "unable to perform cmd on server, error" << data; | ||
} | ||
} | ||
|
||
void Client::sendRequest(const QByteArray& requestBytes) | ||
{ | ||
if (!m_socket->isConnected()) { | ||
m_socket->connect(); | ||
} | ||
qDebug() << "sending:" << requestBytes; | ||
if (!m_socket->write(requestBytes)) { | ||
qCritical() << "unable to send" << requestBytes; | ||
} | ||
} | ||
|
||
void Client::runGetPathListScenario() | ||
{ | ||
QByteArray bytes = RequestCreator::instance().getPathListRequestTelegram(m_toolsWidget->nCriticalPathNum(), | ||
m_toolsWidget->pathType(), | ||
m_toolsWidget->detailesLevel(), | ||
m_toolsWidget->isFlatRouting()); | ||
sendRequest(bytes); | ||
} | ||
|
||
void Client::onPathSelected(const QString& pathId) | ||
{ | ||
NCriticalPathSettings::instance().setLastSelectedPathId(pathId); | ||
QByteArray bytes = RequestCreator::instance().getDrawPathIdTelegram(pathId, m_toolsWidget->highlightMode()); | ||
sendRequest(bytes); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#pragma once | ||
|
||
#include <QWidget> | ||
#include <QObject> | ||
#include <QTimer> | ||
|
||
#include <memory> | ||
|
||
class ClientToolsWidget; | ||
class ISocket; | ||
|
||
#ifndef STANDALONE_APP | ||
#include "../../Compiler/Compiler.h" | ||
#endif | ||
|
||
class Client : public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
Client( | ||
#ifndef STANDALONE_APP | ||
FOEDAG::Compiler* | ||
#endif | ||
); | ||
~Client(); | ||
|
||
ClientToolsWidget* toolsWidget() const { return m_toolsWidget; } | ||
|
||
bool isConnected() const; | ||
|
||
public slots: | ||
void onPathSelected(const QString&); | ||
|
||
signals: | ||
void critPathsDataReady(const QString&); | ||
|
||
private: | ||
ClientToolsWidget* m_toolsWidget = nullptr; | ||
std::unique_ptr<ISocket> m_socket; | ||
#ifdef ENABLE_AUTOMATIC_REQUEST | ||
QTimer m_timer; | ||
#endif // ENABLE_AUTOMATIC_REQUEST | ||
|
||
void sendRequest(const QByteArray&); | ||
void handleResponse(const QByteArray&); | ||
|
||
private slots: | ||
void runGetPathListScenario(); | ||
}; | ||
|
Oops, something went wrong.