forked from qt-creator/qt-creator
NimSuggestServer: Connect to done() signal instead of finished()
Get rid of crashed() signal, since the handler of this signal was doing the same as the handler for finished() signal. Change-Id: I7cb2d53bbf0bdcea58c2101efe97a82505333740 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -32,8 +32,7 @@ NimSuggest::NimSuggest(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
connect(&m_server, &NimSuggestServer::started, this, &NimSuggest::onServerStarted);
|
||||
connect(&m_server, &NimSuggestServer::crashed, this, &NimSuggest::onServerCrashed);
|
||||
connect(&m_server, &NimSuggestServer::finished, this, &NimSuggest::onServerFinished);
|
||||
connect(&m_server, &NimSuggestServer::done, this, &NimSuggest::onServerDone);
|
||||
|
||||
connect(&m_client, &NimSuggestClient::disconnected, this, &NimSuggest::onClientDisconnected);
|
||||
connect(&m_client, &NimSuggestClient::connected, this, &NimSuggest::onClientConnected);
|
||||
@@ -134,14 +133,13 @@ void NimSuggest::disconnectClient()
|
||||
|
||||
void NimSuggest::stopServer()
|
||||
{
|
||||
m_server.kill();
|
||||
m_server.stop();
|
||||
}
|
||||
|
||||
void NimSuggest::startServer()
|
||||
{
|
||||
if (!m_projectFile.isEmpty() && !m_executablePath.isEmpty()) {
|
||||
if (!m_projectFile.isEmpty() && !m_executablePath.isEmpty())
|
||||
m_server.start(m_executablePath, m_projectFile);
|
||||
}
|
||||
}
|
||||
|
||||
void NimSuggest::onServerStarted()
|
||||
@@ -150,18 +148,13 @@ void NimSuggest::onServerStarted()
|
||||
connectClient();
|
||||
}
|
||||
|
||||
void NimSuggest::onServerCrashed()
|
||||
void NimSuggest::onServerDone()
|
||||
{
|
||||
setServerReady(false);
|
||||
disconnectClient();
|
||||
restart();
|
||||
}
|
||||
|
||||
void NimSuggest::onServerFinished()
|
||||
{
|
||||
onServerCrashed();
|
||||
}
|
||||
|
||||
void NimSuggest::onClientConnected()
|
||||
{
|
||||
setClientReady(true);
|
||||
|
@@ -75,8 +75,7 @@ private:
|
||||
void startServer();
|
||||
|
||||
void onServerStarted();
|
||||
void onServerCrashed();
|
||||
void onServerFinished();
|
||||
void onServerDone();
|
||||
|
||||
void onClientConnected();
|
||||
void onClientDisconnected();
|
||||
|
@@ -32,17 +32,11 @@ namespace Suggest {
|
||||
|
||||
NimSuggestServer::NimSuggestServer(QObject *parent) : QObject(parent)
|
||||
{
|
||||
connect(&m_process, &QtcProcess::finished, this, &NimSuggestServer::onFinished);
|
||||
connect(&m_process, &QtcProcess::started, this, &NimSuggestServer::onStarted);
|
||||
connect(&m_process, &QtcProcess::done, this, &NimSuggestServer::onDone);
|
||||
connect(&m_process, &QtcProcess::readyReadStandardOutput, this,
|
||||
&NimSuggestServer::onStandardOutputAvailable);
|
||||
}
|
||||
|
||||
NimSuggestServer::~NimSuggestServer()
|
||||
{
|
||||
kill();
|
||||
}
|
||||
|
||||
QString NimSuggestServer::executablePath() const
|
||||
{
|
||||
return m_executablePath;
|
||||
@@ -61,7 +55,7 @@ bool NimSuggestServer::start(const QString &executablePath,
|
||||
return false;
|
||||
}
|
||||
|
||||
m_port = 0;
|
||||
stop();
|
||||
m_executablePath = executablePath;
|
||||
m_projectFilePath = projectFilePath;
|
||||
m_process.setCommand({FilePath::fromString(executablePath), {"--epc", m_projectFilePath}});
|
||||
@@ -69,11 +63,9 @@ bool NimSuggestServer::start(const QString &executablePath,
|
||||
return true;
|
||||
}
|
||||
|
||||
void NimSuggestServer::kill()
|
||||
void NimSuggestServer::stop()
|
||||
{
|
||||
disconnect(&m_process, &QtcProcess::finished, this, &NimSuggestServer::onFinished);
|
||||
m_process.kill();
|
||||
m_process.waitForFinished();
|
||||
m_process.close();
|
||||
clearState();
|
||||
}
|
||||
|
||||
@@ -87,15 +79,10 @@ QString NimSuggestServer::projectFilePath() const
|
||||
return m_projectFilePath;
|
||||
}
|
||||
|
||||
void NimSuggestServer::onStarted()
|
||||
{
|
||||
m_started = true;
|
||||
}
|
||||
|
||||
void NimSuggestServer::onStandardOutputAvailable()
|
||||
{
|
||||
if (m_started && !m_portAvailable) {
|
||||
auto output = QString::fromUtf8(m_process.readAllStandardOutput());
|
||||
if (!m_portAvailable) {
|
||||
const QString output = QString::fromUtf8(m_process.readAllStandardOutput());
|
||||
m_port = static_cast<uint16_t>(output.toUInt());
|
||||
m_portAvailable = true;
|
||||
emit started();
|
||||
@@ -104,19 +91,14 @@ void NimSuggestServer::onStandardOutputAvailable()
|
||||
}
|
||||
}
|
||||
|
||||
void NimSuggestServer::onFinished()
|
||||
void NimSuggestServer::onDone()
|
||||
{
|
||||
clearState();
|
||||
|
||||
if (m_process.exitStatus() == QProcess::CrashExit)
|
||||
emit crashed();
|
||||
else
|
||||
emit finished();
|
||||
emit done();
|
||||
}
|
||||
|
||||
void NimSuggestServer::clearState()
|
||||
{
|
||||
m_started = false;
|
||||
m_portAvailable = false;
|
||||
m_port = 0;
|
||||
}
|
||||
|
@@ -40,10 +40,9 @@ class NimSuggestServer : public QObject
|
||||
|
||||
public:
|
||||
NimSuggestServer(QObject *parent = nullptr);
|
||||
~NimSuggestServer();
|
||||
|
||||
bool start(const QString &executablePath, const QString &projectFilePath);
|
||||
void kill();
|
||||
void stop();
|
||||
|
||||
quint16 port() const;
|
||||
QString executablePath() const;
|
||||
@@ -51,16 +50,13 @@ public:
|
||||
|
||||
signals:
|
||||
void started();
|
||||
void finished();
|
||||
void crashed();
|
||||
void done();
|
||||
|
||||
private:
|
||||
void onStarted();
|
||||
void onStandardOutputAvailable();
|
||||
void onFinished();
|
||||
void onDone();
|
||||
void clearState();
|
||||
|
||||
bool m_started = false;
|
||||
bool m_portAvailable = false;
|
||||
Utils::QtcProcess m_process;
|
||||
quint16 m_port = 0;
|
||||
|
Reference in New Issue
Block a user