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:
Marco Bubke
2016-07-04 14:55:58 +02:00
committed by Tim Jenssen
parent e6fa92e58c
commit c5e79f6269
14 changed files with 278 additions and 29 deletions

View File

@@ -48,7 +48,10 @@ SOURCES += $$PWD/clangcodemodelserverinterface.cpp \
$$PWD/updatevisibletranslationunitsmessage.cpp \ $$PWD/updatevisibletranslationunitsmessage.cpp \
$$PWD/highlightingchangedmessage.cpp \ $$PWD/highlightingchangedmessage.cpp \
$$PWD/highlightingmarkcontainer.cpp \ $$PWD/highlightingmarkcontainer.cpp \
$$PWD/messageenvelop.cpp $$PWD/messageenvelop.cpp \
$$PWD/ipcclientinterface.cpp \
$$PWD/ipcserverinterface.cpp \
$$PWD/clangcodemodelconnectionclient.cpp
HEADERS += \ HEADERS += \
$$PWD/clangcodemodelserverinterface.h \ $$PWD/clangcodemodelserverinterface.h \
@@ -92,6 +95,9 @@ HEADERS += \
$$PWD/updatevisibletranslationunitsmessage.h \ $$PWD/updatevisibletranslationunitsmessage.h \
$$PWD/highlightingchangedmessage.h \ $$PWD/highlightingchangedmessage.h \
$$PWD/highlightingmarkcontainer.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 contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols

View File

@@ -25,7 +25,7 @@
#pragma once #pragma once
#include "ipcinterface.h" #include "ipcclientinterface.h"
namespace ClangBackEnd { namespace ClangBackEnd {
@@ -48,7 +48,7 @@ class UpdateVisibleTranslationUnitsMessage;
class RequestHighlightingMessage; class RequestHighlightingMessage;
class HighlightingChangedMessage; class HighlightingChangedMessage;
class CMBIPC_EXPORT ClangCodeModelClientInterface : public IpcInterface class CMBIPC_EXPORT ClangCodeModelClientInterface : public IpcClientInterface
{ {
public: public:
void dispatch(const MessageEnvelop &messageEnvelop) override; void dispatch(const MessageEnvelop &messageEnvelop) override;

View 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

View 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

View File

@@ -25,7 +25,7 @@
#pragma once #pragma once
#include "ipcinterface.h" #include "ipcserverinterface.h"
#include "clangcodemodelclientdispatcher.h" #include "clangcodemodelclientdispatcher.h"
@@ -33,7 +33,7 @@ namespace ClangBackEnd {
class ClangCodeModelClientInterface; class ClangCodeModelClientInterface;
class CMBIPC_EXPORT ClangCodeModelServerInterface : public IpcInterface class CMBIPC_EXPORT ClangCodeModelServerInterface : public IpcServerInterface
{ {
public: public:
void dispatch(const MessageEnvelop &messageEnvelop) override; void dispatch(const MessageEnvelop &messageEnvelop) override;

View File

@@ -57,10 +57,7 @@ QString connectionName()
} }
} }
ConnectionClient::ConnectionClient(ClangCodeModelClientInterface *client) ConnectionClient::ConnectionClient()
: serverProxy_(client, &localSocket),
stdErrPrefixer("clangbackend.stderr: "),
stdOutPrefixer("clangbackend.stdout: ")
{ {
processAliveTimer.setInterval(10000); processAliveTimer.setInterval(10000);
@@ -105,7 +102,7 @@ void ConnectionClient::ensureMessageIsWritten()
void ConnectionClient::sendEndMessage() void ConnectionClient::sendEndMessage()
{ {
serverProxy_.end(); sendEndCommand();
localSocket.flush(); localSocket.flush();
ensureMessageIsWritten(); ensureMessageIsWritten();
} }
@@ -258,7 +255,7 @@ void ConnectionClient::finishProcess(std::unique_ptr<QProcess> &&process)
terminateProcess(process.get()); terminateProcess(process.get());
killProcess(process.get()); killProcess(process.get());
serverProxy_.resetCounter(); resetCounter();
} }
} }
@@ -286,16 +283,17 @@ bool ConnectionClient::waitForConnected()
return isConnected; return isConnected;
} }
ClangCodeModelServerProxy &ConnectionClient::serverProxy()
{
return serverProxy_;
}
QProcess *ConnectionClient::processForTestOnly() const QProcess *ConnectionClient::processForTestOnly() const
{ {
return process_.get(); return process_.get();
} }
QIODevice *ConnectionClient::ioDevice()
{
return &localSocket;
}
bool ConnectionClient::isProcessIsRunning() const bool ConnectionClient::isProcessIsRunning() const
{ {
return process_ && process_->state() == QProcess::Running; return process_ && process_->state() == QProcess::Running;

View File

@@ -49,7 +49,7 @@ class CMBIPC_EXPORT ConnectionClient : public QObject
Q_OBJECT Q_OBJECT
public: public:
ConnectionClient(ClangCodeModelClientInterface *client); ConnectionClient();
~ConnectionClient(); ~ConnectionClient();
void startProcessAndConnectToServerAsynchronously(); void startProcessAndConnectToServerAsynchronously();
@@ -72,14 +72,18 @@ public:
bool waitForEcho(); bool waitForEcho();
bool waitForConnected(); bool waitForConnected();
ClangCodeModelServerProxy &serverProxy();
QProcess *processForTestOnly() const; QProcess *processForTestOnly() const;
signals: signals:
void connectedToLocalSocket(); void connectedToLocalSocket();
void processFinished(); void processFinished();
protected:
QIODevice *ioDevice();
virtual void sendEndCommand() = 0;
virtual void resetCounter() = 0;
private: private:
std::unique_ptr<QProcess> startProcess(); std::unique_ptr<QProcess> startProcess();
void finishProcess(std::unique_ptr<QProcess> &&process); void finishProcess(std::unique_ptr<QProcess> &&process);
@@ -107,14 +111,13 @@ private:
private: private:
mutable std::unique_ptr<QProcess> process_; mutable std::unique_ptr<QProcess> process_;
QLocalSocket localSocket; QLocalSocket localSocket;
ClangCodeModelServerProxy serverProxy_;
QTimer processAliveTimer; QTimer processAliveTimer;
QString processPath_; QString processPath_;
bool isAliveTimerResetted = false; bool isAliveTimerResetted = false;
bool processIsStarting = false; bool processIsStarting = false;
LinePrefixer stdErrPrefixer; LinePrefixer stdErrPrefixer = QByteArrayLiteral("clangbackend.stderr: ");
LinePrefixer stdOutPrefixer; LinePrefixer stdOutPrefixer = QByteArrayLiteral("clangbackend.stdout: ");
}; };
} // namespace ClangBackEnd } // namespace ClangBackEnd

View 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

View 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

View 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

View 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

View File

@@ -216,7 +216,7 @@ void IpcReceiver::projectPartsDoNotExist(const ProjectPartsDoNotExistMessage &me
class IpcSender : public IpcSenderInterface class IpcSender : public IpcSenderInterface
{ {
public: public:
IpcSender(ClangBackEnd::ConnectionClient &connectionClient) IpcSender(ClangBackEnd::ClangCodeModelConnectionClient &connectionClient)
: m_connection(connectionClient) : m_connection(connectionClient)
{} {}
@@ -234,7 +234,7 @@ public:
void updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message) override; void updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message) override;
private: private:
ClangBackEnd::ConnectionClient &m_connection; ClangBackEnd::ClangCodeModelConnectionClient &m_connection;
}; };
void IpcSender::end() void IpcSender::end()

View File

@@ -27,7 +27,7 @@
#include <cpptools/projectpart.h> #include <cpptools/projectpart.h>
#include <clangbackendipc/connectionclient.h> #include <clangbackendipc/clangcodemodelconnectionclient.h>
#include <clangbackendipc/filecontainer.h> #include <clangbackendipc/filecontainer.h>
#include <clangbackendipc/clangcodemodelclientinterface.h> #include <clangbackendipc/clangcodemodelclientinterface.h>
#include <clangbackendipc/projectpartcontainer.h> #include <clangbackendipc/projectpartcontainer.h>
@@ -177,7 +177,7 @@ private:
private: private:
IpcReceiver m_ipcReceiver; IpcReceiver m_ipcReceiver;
ClangBackEnd::ConnectionClient m_connection; ClangBackEnd::ClangCodeModelConnectionClient m_connection;
QScopedPointer<IpcSenderInterface> m_ipcSender; QScopedPointer<IpcSenderInterface> m_ipcSender;
int m_connectedCount = 0; int m_connectedCount = 0;
}; };

View File

@@ -35,7 +35,7 @@
#include <cmbunregisterprojectsforeditormessage.h> #include <cmbunregisterprojectsforeditormessage.h>
#include <cmbunregistertranslationunitsforeditormessage.h> #include <cmbunregistertranslationunitsforeditormessage.h>
#include <highlightingchangedmessage.h> #include <highlightingchangedmessage.h>
#include <connectionclient.h> #include <clangcodemodelconnectionclient.h>
#include <diagnosticschangedmessage.h> #include <diagnosticschangedmessage.h>
#include <projectpartsdonotexistmessage.h> #include <projectpartsdonotexistmessage.h>
#include <readmessageblock.h> #include <readmessageblock.h>
@@ -72,11 +72,11 @@ protected:
static void TearDownTestCase(); static void TearDownTestCase();
static MockClangCodeModelClient mockClangCodeModelClient; static MockClangCodeModelClient mockClangCodeModelClient;
static ClangBackEnd::ConnectionClient client; static ClangBackEnd::ClangCodeModelConnectionClient client;
}; };
MockClangCodeModelClient ClientServerOutsideProcess::mockClangCodeModelClient; MockClangCodeModelClient ClientServerOutsideProcess::mockClangCodeModelClient;
ClangBackEnd::ConnectionClient ClientServerOutsideProcess::client(&ClientServerOutsideProcess::mockClangCodeModelClient); ClangBackEnd::ClangCodeModelConnectionClient ClientServerOutsideProcess::client(&ClientServerOutsideProcess::mockClangCodeModelClient);
TEST_F(ClientServerOutsideProcess, RestartProcessAsynchronously) TEST_F(ClientServerOutsideProcess, RestartProcessAsynchronously)
{ {