Clang: Move QLocalServer in ConnectionClient

Before the QLocalServer was in the ConnectionServer so more than one
client could connect to the server. But we never used that possibility
which made the hand shaking much more difficult. It is now moved
in the client, so that there is always a QLocalServer.

Change-Id: Ifa357074b0c0809434c49d23b1cee38496f72f43
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Marco Bubke
2016-08-17 15:29:37 +02:00
parent 45c667d52c
commit f70bf3d2d1
44 changed files with 1170 additions and 351 deletions

View File

@@ -27,14 +27,15 @@
#include "clangcodemodelserverproxy.h"
#include "lineprefixer.h"
#include "processcreator.h"
#include <utils/temporarydirectory.h>
#include <QLocalServer>
#include <QLocalSocket>
#include <QProcessEnvironment>
#include <QScopedPointer>
#include <QTemporaryDir>
#include <future>
#include <memory>
QT_BEGIN_NAMESPACE
@@ -53,10 +54,10 @@ class CLANGSUPPORT_EXPORT ConnectionClient : public QObject
Q_OBJECT
public:
ConnectionClient();
ConnectionClient(const QString &connectionName);
virtual ~ConnectionClient();
void startProcessAndConnectToServerAsynchronously();
bool disconnectFromServer();
bool isConnected() const;
void sendEndMessage();
@@ -64,18 +65,17 @@ public:
void resetProcessAliveTimer();
void setProcessAliveTimerInterval(int processTimerInterval);
const QString &processPath() const;
void setProcessPath(const QString &processPath);
void restartProcessAsynchronously();
void restartProcessIfTimerIsNotResettedAndSocketIsEmpty();
void finishProcess();
bool isProcessIsRunning() const;
bool isProcessRunning();
bool waitForEcho();
bool waitForConnected();
QProcess *processForTestOnly() const;
QProcess *processForTestOnly();
signals:
void connectedToLocalSocket();
@@ -90,48 +90,55 @@ protected:
virtual void sendEndCommand() = 0;
virtual void resetCounter() = 0;
virtual QString connectionName() const = 0;
virtual QString outputName() const = 0;
QString connectionName() const;
bool event(QEvent* event);
virtual void newConnectedServer(QIODevice *ioDevice) = 0;
private:
std::unique_ptr<QProcess> startProcess();
void finishProcess(std::unique_ptr<QProcess> &&process);
void connectToLocalSocket();
static bool isProcessRunning(QProcess *process);
void finishProcess(QProcessUniquePointer &&process);
void endProcess(QProcess *process);
void terminateProcess(QProcess *process);
void killProcess(QProcess *process);
void resetProcessIsStarting();
void finishConnection();
void printLocalSocketError(QLocalSocket::LocalSocketError socketError);
void printStandardOutput();
void printStandardError();
void initializeProcess(QProcess *process);
void resetTemporaryDir();
void resetTemporaryDirectory();
void connectLocalSocketConnected();
void connectLocalSocketDisconnected();
void connectProcessFinished(QProcess *process) const;
void connectProcessStarted(QProcess *process) const;
void disconnectProcessFinished(QProcess *process) const;
void disconnectLocalSocketDisconnected();
void connectStandardOutputAndError(QProcess *process) const;
void connectLocalSocketError() const;
void connectAliveTimer();
void connectNewConnection();
void handleNewConnection();
void getProcessFromFuture();
void listenForConnections();
void ensureMessageIsWritten();
QProcessEnvironment processEnvironment() const;
protected:
ProcessCreator m_processCreator;
private:
LinePrefixer m_stdErrPrefixer;
LinePrefixer m_stdOutPrefixer;
mutable std::unique_ptr<QProcess> m_process;
QLocalSocket localSocket;
std::unique_ptr<Utils::TemporaryDirectory> m_temporaryDirectory;
QLocalServer m_localServer;
std::future<QProcessUniquePointer> m_processFuture;
mutable QProcessUniquePointer m_process;
QLocalSocket *m_localSocket = nullptr;
QTimer m_processAliveTimer;
QString m_processPath;
QString m_connectionName;
bool m_isAliveTimerResetted = false;
bool m_processIsStarting = false;
};
} // namespace ClangBackEnd