2015-10-01 12:45:06 +02:00
|
|
|
/****************************************************************************
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:58:39 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
#include "clangcodemodelserverproxy.h"
|
2015-06-18 18:08:48 +02:00
|
|
|
#include "lineprefixer.h"
|
2016-08-17 15:29:37 +02:00
|
|
|
#include "processcreator.h"
|
2015-06-16 12:38:04 +02:00
|
|
|
|
2016-08-17 15:29:37 +02:00
|
|
|
#include <QLocalServer>
|
2015-06-01 18:51:55 +02:00
|
|
|
#include <QLocalSocket>
|
2016-10-21 10:22:38 +02:00
|
|
|
#include <QScopedPointer>
|
|
|
|
|
#include <QTemporaryDir>
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-08-17 15:29:37 +02:00
|
|
|
#include <future>
|
2015-06-01 18:51:55 +02:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QProcess;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
class Utf8String;
|
|
|
|
|
class Utf8StringVector;
|
|
|
|
|
|
2015-06-16 11:56:00 +02:00
|
|
|
namespace ClangBackEnd {
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
class FileContainer;
|
|
|
|
|
|
2017-10-06 09:55:02 +03:00
|
|
|
class CLANGSUPPORT_EXPORT ConnectionClient : public QObject
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2016-08-17 15:29:37 +02:00
|
|
|
ConnectionClient(const QString &connectionName);
|
|
|
|
|
virtual ~ConnectionClient();
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-07-11 13:44:02 +02:00
|
|
|
void startProcessAndConnectToServerAsynchronously();
|
2017-11-27 16:13:25 +01:00
|
|
|
void disconnectFromServer();
|
2015-06-01 18:51:55 +02:00
|
|
|
bool isConnected() const;
|
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
void sendEndMessage();
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
void resetProcessAliveTimer();
|
|
|
|
|
void setProcessAliveTimerInterval(int processTimerInterval);
|
|
|
|
|
|
|
|
|
|
void setProcessPath(const QString &processPath);
|
|
|
|
|
|
2016-07-11 13:44:02 +02:00
|
|
|
void restartProcessAsynchronously();
|
2015-06-01 18:51:55 +02:00
|
|
|
void restartProcessIfTimerIsNotResettedAndSocketIsEmpty();
|
|
|
|
|
void finishProcess();
|
2016-08-17 15:29:37 +02:00
|
|
|
bool isProcessRunning();
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
bool waitForEcho();
|
2016-07-11 13:44:02 +02:00
|
|
|
bool waitForConnected();
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-08-17 15:29:37 +02:00
|
|
|
QProcess *processForTestOnly();
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
signals:
|
2016-07-11 13:44:02 +02:00
|
|
|
void connectedToLocalSocket();
|
2016-10-07 12:11:01 +02:00
|
|
|
void disconnectedFromLocalSocket();
|
2016-07-11 13:44:02 +02:00
|
|
|
void processFinished();
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-07-04 14:55:58 +02:00
|
|
|
protected:
|
|
|
|
|
QIODevice *ioDevice();
|
2016-08-04 15:26:53 +02:00
|
|
|
const QTemporaryDir &temporaryDirectory() const;
|
|
|
|
|
LinePrefixer &stdErrPrefixer();
|
|
|
|
|
LinePrefixer &stdOutPrefixer();
|
2016-07-04 14:55:58 +02:00
|
|
|
|
|
|
|
|
virtual void sendEndCommand() = 0;
|
|
|
|
|
virtual void resetCounter() = 0;
|
2016-08-04 15:26:53 +02:00
|
|
|
virtual QString outputName() const = 0;
|
2016-07-04 14:55:58 +02:00
|
|
|
|
2016-08-17 15:29:37 +02:00
|
|
|
QString connectionName() const;
|
|
|
|
|
bool event(QEvent* event);
|
|
|
|
|
|
|
|
|
|
virtual void newConnectedServer(QIODevice *ioDevice) = 0;
|
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
private:
|
2016-08-17 15:29:37 +02:00
|
|
|
static bool isProcessRunning(QProcess *process);
|
|
|
|
|
void finishProcess(QProcessUniquePointer &&process);
|
2016-07-11 13:44:02 +02:00
|
|
|
void endProcess(QProcess *process);
|
|
|
|
|
void terminateProcess(QProcess *process);
|
|
|
|
|
void killProcess(QProcess *process);
|
2016-08-17 15:29:37 +02:00
|
|
|
void finishConnection();
|
2015-06-01 18:51:55 +02:00
|
|
|
void printLocalSocketError(QLocalSocket::LocalSocketError socketError);
|
|
|
|
|
void printStandardOutput();
|
|
|
|
|
void printStandardError();
|
2016-08-17 15:29:37 +02:00
|
|
|
void initializeProcess(QProcess *process);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-08-17 15:29:37 +02:00
|
|
|
void resetTemporaryDirectory();
|
2016-10-21 10:22:38 +02:00
|
|
|
|
2016-10-07 12:11:01 +02:00
|
|
|
void connectLocalSocketDisconnected();
|
2016-08-17 15:29:37 +02:00
|
|
|
void disconnectLocalSocketDisconnected();
|
2016-07-11 13:44:02 +02:00
|
|
|
void connectStandardOutputAndError(QProcess *process) const;
|
|
|
|
|
void connectLocalSocketError() const;
|
|
|
|
|
void connectAliveTimer();
|
2016-08-17 15:29:37 +02:00
|
|
|
void connectNewConnection();
|
|
|
|
|
void handleNewConnection();
|
|
|
|
|
void getProcessFromFuture();
|
|
|
|
|
void listenForConnections();
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
void ensureMessageIsWritten();
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-08-17 15:29:37 +02:00
|
|
|
protected:
|
|
|
|
|
ProcessCreator m_processCreator;
|
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
private:
|
2017-06-12 20:03:34 +02:00
|
|
|
LinePrefixer m_stdErrPrefixer;
|
|
|
|
|
LinePrefixer m_stdOutPrefixer;
|
2016-08-17 15:29:37 +02:00
|
|
|
QLocalServer m_localServer;
|
|
|
|
|
std::future<QProcessUniquePointer> m_processFuture;
|
|
|
|
|
mutable QProcessUniquePointer m_process;
|
|
|
|
|
QLocalSocket *m_localSocket = nullptr;
|
2017-06-12 20:03:34 +02:00
|
|
|
QTimer m_processAliveTimer;
|
2016-08-17 15:29:37 +02:00
|
|
|
QString m_connectionName;
|
2017-06-12 20:03:34 +02:00
|
|
|
bool m_isAliveTimerResetted = false;
|
|
|
|
|
bool m_processIsStarting = false;
|
2015-06-01 18:51:55 +02:00
|
|
|
};
|
|
|
|
|
|
2015-06-16 11:56:00 +02:00
|
|
|
} // namespace ClangBackEnd
|