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