forked from qt-creator/qt-creator
Clang: Decouple ConnectionClient and ClangCodeModel*
We want to reuse the connection client in other plugins. This is the first step, the next step is refactoring the IPC mechanismn and move it up to the IpcServer- and IpcClientInterface. Change-Id: I6eb6db1e9bc18232c8df350a6303afd2edc68da8 Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
@@ -48,7 +48,10 @@ SOURCES += $$PWD/clangcodemodelserverinterface.cpp \
|
||||
$$PWD/updatevisibletranslationunitsmessage.cpp \
|
||||
$$PWD/highlightingchangedmessage.cpp \
|
||||
$$PWD/highlightingmarkcontainer.cpp \
|
||||
$$PWD/messageenvelop.cpp
|
||||
$$PWD/messageenvelop.cpp \
|
||||
$$PWD/ipcclientinterface.cpp \
|
||||
$$PWD/ipcserverinterface.cpp \
|
||||
$$PWD/clangcodemodelconnectionclient.cpp
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/clangcodemodelserverinterface.h \
|
||||
@@ -92,6 +95,9 @@ HEADERS += \
|
||||
$$PWD/updatevisibletranslationunitsmessage.h \
|
||||
$$PWD/highlightingchangedmessage.h \
|
||||
$$PWD/highlightingmarkcontainer.h \
|
||||
$$PWD/messageenvelop.h
|
||||
$$PWD/messageenvelop.h \
|
||||
$$PWD/ipcclientinterface.h \
|
||||
$$PWD/ipcserverinterface.h \
|
||||
$$PWD/clangcodemodelconnectionclient.h
|
||||
|
||||
contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ipcinterface.h"
|
||||
#include "ipcclientinterface.h"
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
@@ -48,7 +48,7 @@ class UpdateVisibleTranslationUnitsMessage;
|
||||
class RequestHighlightingMessage;
|
||||
class HighlightingChangedMessage;
|
||||
|
||||
class CMBIPC_EXPORT ClangCodeModelClientInterface : public IpcInterface
|
||||
class CMBIPC_EXPORT ClangCodeModelClientInterface : public IpcClientInterface
|
||||
{
|
||||
public:
|
||||
void dispatch(const MessageEnvelop &messageEnvelop) override;
|
||||
|
||||
53
src/libs/clangbackendipc/clangcodemodelconnectionclient.cpp
Normal file
53
src/libs/clangbackendipc/clangcodemodelconnectionclient.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** 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
|
||||
** 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.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "clangcodemodelconnectionclient.h"
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
|
||||
ClangCodeModelConnectionClient::ClangCodeModelConnectionClient(
|
||||
ClangCodeModelClientInterface *client)
|
||||
: serverProxy_(client, ioDevice())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ClangCodeModelServerProxy &ClangCodeModelConnectionClient::serverProxy()
|
||||
{
|
||||
return serverProxy_;
|
||||
}
|
||||
|
||||
void ClangCodeModelConnectionClient::sendEndCommand()
|
||||
{
|
||||
serverProxy_.end();
|
||||
}
|
||||
|
||||
void ClangCodeModelConnectionClient::resetCounter()
|
||||
{
|
||||
serverProxy_.resetCounter();
|
||||
}
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
47
src/libs/clangbackendipc/clangcodemodelconnectionclient.h
Normal file
47
src/libs/clangbackendipc/clangcodemodelconnectionclient.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** 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
|
||||
** 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.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "connectionclient.h"
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
class CMBIPC_EXPORT ClangCodeModelConnectionClient : public ConnectionClient
|
||||
{
|
||||
public:
|
||||
ClangCodeModelConnectionClient(ClangCodeModelClientInterface *client);
|
||||
|
||||
ClangCodeModelServerProxy &serverProxy();
|
||||
|
||||
protected:
|
||||
void sendEndCommand() override;
|
||||
void resetCounter() override;
|
||||
|
||||
private:
|
||||
ClangCodeModelServerProxy serverProxy_;
|
||||
};
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ipcinterface.h"
|
||||
#include "ipcserverinterface.h"
|
||||
|
||||
#include "clangcodemodelclientdispatcher.h"
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace ClangBackEnd {
|
||||
|
||||
class ClangCodeModelClientInterface;
|
||||
|
||||
class CMBIPC_EXPORT ClangCodeModelServerInterface : public IpcInterface
|
||||
class CMBIPC_EXPORT ClangCodeModelServerInterface : public IpcServerInterface
|
||||
{
|
||||
public:
|
||||
void dispatch(const MessageEnvelop &messageEnvelop) override;
|
||||
|
||||
@@ -57,10 +57,7 @@ QString connectionName()
|
||||
}
|
||||
}
|
||||
|
||||
ConnectionClient::ConnectionClient(ClangCodeModelClientInterface *client)
|
||||
: serverProxy_(client, &localSocket),
|
||||
stdErrPrefixer("clangbackend.stderr: "),
|
||||
stdOutPrefixer("clangbackend.stdout: ")
|
||||
ConnectionClient::ConnectionClient()
|
||||
{
|
||||
processAliveTimer.setInterval(10000);
|
||||
|
||||
@@ -105,7 +102,7 @@ void ConnectionClient::ensureMessageIsWritten()
|
||||
|
||||
void ConnectionClient::sendEndMessage()
|
||||
{
|
||||
serverProxy_.end();
|
||||
sendEndCommand();
|
||||
localSocket.flush();
|
||||
ensureMessageIsWritten();
|
||||
}
|
||||
@@ -258,7 +255,7 @@ void ConnectionClient::finishProcess(std::unique_ptr<QProcess> &&process)
|
||||
terminateProcess(process.get());
|
||||
killProcess(process.get());
|
||||
|
||||
serverProxy_.resetCounter();
|
||||
resetCounter();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,16 +283,17 @@ bool ConnectionClient::waitForConnected()
|
||||
return isConnected;
|
||||
}
|
||||
|
||||
ClangCodeModelServerProxy &ConnectionClient::serverProxy()
|
||||
{
|
||||
return serverProxy_;
|
||||
}
|
||||
|
||||
QProcess *ConnectionClient::processForTestOnly() const
|
||||
{
|
||||
return process_.get();
|
||||
}
|
||||
|
||||
QIODevice *ConnectionClient::ioDevice()
|
||||
{
|
||||
return &localSocket;
|
||||
}
|
||||
|
||||
bool ConnectionClient::isProcessIsRunning() const
|
||||
{
|
||||
return process_ && process_->state() == QProcess::Running;
|
||||
|
||||
@@ -49,7 +49,7 @@ class CMBIPC_EXPORT ConnectionClient : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ConnectionClient(ClangCodeModelClientInterface *client);
|
||||
ConnectionClient();
|
||||
~ConnectionClient();
|
||||
|
||||
void startProcessAndConnectToServerAsynchronously();
|
||||
@@ -72,14 +72,18 @@ public:
|
||||
bool waitForEcho();
|
||||
bool waitForConnected();
|
||||
|
||||
ClangCodeModelServerProxy &serverProxy();
|
||||
|
||||
QProcess *processForTestOnly() const;
|
||||
|
||||
signals:
|
||||
void connectedToLocalSocket();
|
||||
void processFinished();
|
||||
|
||||
protected:
|
||||
QIODevice *ioDevice();
|
||||
|
||||
virtual void sendEndCommand() = 0;
|
||||
virtual void resetCounter() = 0;
|
||||
|
||||
private:
|
||||
std::unique_ptr<QProcess> startProcess();
|
||||
void finishProcess(std::unique_ptr<QProcess> &&process);
|
||||
@@ -107,14 +111,13 @@ private:
|
||||
private:
|
||||
mutable std::unique_ptr<QProcess> process_;
|
||||
QLocalSocket localSocket;
|
||||
ClangCodeModelServerProxy serverProxy_;
|
||||
QTimer processAliveTimer;
|
||||
QString processPath_;
|
||||
bool isAliveTimerResetted = false;
|
||||
bool processIsStarting = false;
|
||||
|
||||
LinePrefixer stdErrPrefixer;
|
||||
LinePrefixer stdOutPrefixer;
|
||||
LinePrefixer stdErrPrefixer = QByteArrayLiteral("clangbackend.stderr: ");
|
||||
LinePrefixer stdOutPrefixer = QByteArrayLiteral("clangbackend.stdout: ");
|
||||
};
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
35
src/libs/clangbackendipc/ipcclientinterface.cpp
Normal file
35
src/libs/clangbackendipc/ipcclientinterface.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** 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
|
||||
** 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.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "ipcclientinterface.h"
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
IpcClientInterface::IpcClientInterface()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
38
src/libs/clangbackendipc/ipcclientinterface.h
Normal file
38
src/libs/clangbackendipc/ipcclientinterface.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** 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
|
||||
** 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.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ipcinterface.h"
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
class CMBIPC_EXPORT IpcClientInterface : public IpcInterface
|
||||
{
|
||||
public:
|
||||
IpcClientInterface();
|
||||
};
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
31
src/libs/clangbackendipc/ipcserverinterface.cpp
Normal file
31
src/libs/clangbackendipc/ipcserverinterface.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** 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
|
||||
** 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.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "ipcserverinterface.h"
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
38
src/libs/clangbackendipc/ipcserverinterface.h
Normal file
38
src/libs/clangbackendipc/ipcserverinterface.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** 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
|
||||
** 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.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ipcinterface.h"
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
class CMBIPC_EXPORT IpcServerInterface : public IpcInterface
|
||||
{
|
||||
public:
|
||||
|
||||
};
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
@@ -216,7 +216,7 @@ void IpcReceiver::projectPartsDoNotExist(const ProjectPartsDoNotExistMessage &me
|
||||
class IpcSender : public IpcSenderInterface
|
||||
{
|
||||
public:
|
||||
IpcSender(ClangBackEnd::ConnectionClient &connectionClient)
|
||||
IpcSender(ClangBackEnd::ClangCodeModelConnectionClient &connectionClient)
|
||||
: m_connection(connectionClient)
|
||||
{}
|
||||
|
||||
@@ -234,7 +234,7 @@ public:
|
||||
void updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message) override;
|
||||
|
||||
private:
|
||||
ClangBackEnd::ConnectionClient &m_connection;
|
||||
ClangBackEnd::ClangCodeModelConnectionClient &m_connection;
|
||||
};
|
||||
|
||||
void IpcSender::end()
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include <cpptools/projectpart.h>
|
||||
|
||||
#include <clangbackendipc/connectionclient.h>
|
||||
#include <clangbackendipc/clangcodemodelconnectionclient.h>
|
||||
#include <clangbackendipc/filecontainer.h>
|
||||
#include <clangbackendipc/clangcodemodelclientinterface.h>
|
||||
#include <clangbackendipc/projectpartcontainer.h>
|
||||
@@ -177,7 +177,7 @@ private:
|
||||
|
||||
private:
|
||||
IpcReceiver m_ipcReceiver;
|
||||
ClangBackEnd::ConnectionClient m_connection;
|
||||
ClangBackEnd::ClangCodeModelConnectionClient m_connection;
|
||||
QScopedPointer<IpcSenderInterface> m_ipcSender;
|
||||
int m_connectedCount = 0;
|
||||
};
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include <cmbunregisterprojectsforeditormessage.h>
|
||||
#include <cmbunregistertranslationunitsforeditormessage.h>
|
||||
#include <highlightingchangedmessage.h>
|
||||
#include <connectionclient.h>
|
||||
#include <clangcodemodelconnectionclient.h>
|
||||
#include <diagnosticschangedmessage.h>
|
||||
#include <projectpartsdonotexistmessage.h>
|
||||
#include <readmessageblock.h>
|
||||
@@ -72,11 +72,11 @@ protected:
|
||||
static void TearDownTestCase();
|
||||
|
||||
static MockClangCodeModelClient mockClangCodeModelClient;
|
||||
static ClangBackEnd::ConnectionClient client;
|
||||
static ClangBackEnd::ClangCodeModelConnectionClient client;
|
||||
};
|
||||
|
||||
MockClangCodeModelClient ClientServerOutsideProcess::mockClangCodeModelClient;
|
||||
ClangBackEnd::ConnectionClient ClientServerOutsideProcess::client(&ClientServerOutsideProcess::mockClangCodeModelClient);
|
||||
ClangBackEnd::ClangCodeModelConnectionClient ClientServerOutsideProcess::client(&ClientServerOutsideProcess::mockClangCodeModelClient);
|
||||
|
||||
TEST_F(ClientServerOutsideProcess, RestartProcessAsynchronously)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user