diff options
author | Marco Bubke <marco.bubke@theqtcompany.com> | 2015-05-21 15:45:11 +0200 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2015-05-21 13:48:25 +0000 |
commit | 2c2619051f600de40db9b884116a56387e9c6f9d (patch) | |
tree | 6ec22faf15a048b57c08611b62341ca44d29bc23 | |
parent | 35919e4bcc5b570f73597dec6f83ac87d3b55cf6 (diff) | |
download | qt-creator-2c2619051f600de40db9b884116a56387e9c6f9d.tar.gz |
Add process id to connection name
Change-Id: Ia0bc74e55eec390fc660e0cad6d06a76658e6bbc
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
7 files changed, 45 insertions, 19 deletions
diff --git a/src/libs/codemodelbackendipc/source/connectionclient.cpp b/src/libs/codemodelbackendipc/source/connectionclient.cpp index 2960d29e17..be1dce22bb 100644 --- a/src/libs/codemodelbackendipc/source/connectionclient.cpp +++ b/src/libs/codemodelbackendipc/source/connectionclient.cpp @@ -1,4 +1,4 @@ -/**************************************************************************** +/**************************************************************************** ** ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal @@ -40,6 +40,18 @@ namespace CodeModelBackEnd { +namespace { +QString currentProcessId() +{ + return QString::number(QCoreApplication::applicationPid()); +} + +QString connectionName() +{ + return QStringLiteral("CodeModelBackEnd-") + currentProcessId(); +} +} + ConnectionClient::ConnectionClient(IpcClientInterface *client) : serverProxy_(client, &localSocket), isInConnectedMode(false) @@ -55,7 +67,7 @@ ConnectionClient::~ConnectionClient() } bool ConnectionClient::connectToServer() -{localSocket.connectToServer(QStringLiteral("CodeModelBackEnd")); +{localSocket.connectToServer(connectionName()); isInConnectedMode = true; bool isConnected = localSocket.waitForConnected(); if (!isConnected) { @@ -103,7 +115,7 @@ void ConnectionClient::startProcess() if (!isProcessIsRunning()) { process()->setProcessChannelMode(QProcess::ForwardedErrorChannel); process()->setReadChannel(QProcess::StandardOutput); - process()->start(processPath()); + process()->start(processPath(), {connectionName()}); process()->waitForStarted(); processAliveTimer.start(); } @@ -122,7 +134,7 @@ void ConnectionClient::restartProcess() bool ConnectionClient::retryToConnectToServer() { for (int counter = 0; counter < 1000; counter++) { - localSocket.connectToServer(QStringLiteral("CodeModelBackEnd")); + localSocket.connectToServer(connectionName()); bool isConnected = localSocket.waitForConnected(20); if (isConnected) diff --git a/src/libs/codemodelbackendipc/source/connectionclient.h b/src/libs/codemodelbackendipc/source/connectionclient.h index 5c7c54e5f0..e1128fc69a 100644 --- a/src/libs/codemodelbackendipc/source/connectionclient.h +++ b/src/libs/codemodelbackendipc/source/connectionclient.h @@ -1,4 +1,4 @@ -/**************************************************************************** +/**************************************************************************** ** ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal @@ -85,7 +85,6 @@ private: void endProcess(); void terminateProcess(); void killProcess(); - QProcess *process() const; private: diff --git a/src/libs/codemodelbackendipc/source/connectionserver.cpp b/src/libs/codemodelbackendipc/source/connectionserver.cpp index ff2b888e08..6a3a872759 100644 --- a/src/libs/codemodelbackendipc/source/connectionserver.cpp +++ b/src/libs/codemodelbackendipc/source/connectionserver.cpp @@ -1,4 +1,4 @@ -/**************************************************************************** +/**************************************************************************** ** ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal @@ -40,9 +40,13 @@ namespace CodeModelBackEnd { -ConnectionServer::ConnectionServer() +QString ConnectionServer::connectionName; + +ConnectionServer::ConnectionServer(const QString &connectionName) : aliveTimerId(startTimer(5000)) { + this->connectionName = connectionName; + connect(&localServer, &QLocalServer::newConnection, this, &ConnectionServer::handleNewConnection); std::atexit(&ConnectionServer::removeServer); #if defined(Q_OS_LINUX) @@ -58,8 +62,8 @@ ConnectionServer::~ConnectionServer() void ConnectionServer::start() { - QLocalServer::removeServer(QStringLiteral("CodeModelBackEnd")); - localServer.listen(QStringLiteral("CodeModelBackEnd")); + QLocalServer::removeServer(connectionName); + localServer.listen(connectionName); } void ConnectionServer::setIpcServer(IpcServerInterface *ipcServer) @@ -127,7 +131,7 @@ QLocalSocket *ConnectionServer::nextPendingConnection() void ConnectionServer::removeServer() { - QLocalServer::removeServer(QStringLiteral("CodeModelBackEnd")); + QLocalServer::removeServer(connectionName); } void ConnectionServer::delayedExitApplicationIfNoSockedIsConnected() diff --git a/src/libs/codemodelbackendipc/source/connectionserver.h b/src/libs/codemodelbackendipc/source/connectionserver.h index 43b2034aa6..471129e1cd 100644 --- a/src/libs/codemodelbackendipc/source/connectionserver.h +++ b/src/libs/codemodelbackendipc/source/connectionserver.h @@ -1,4 +1,4 @@ -/**************************************************************************** +/**************************************************************************** ** ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal @@ -44,7 +44,7 @@ class CMBIPC_EXPORT ConnectionServer : public QObject { Q_OBJECT public: - ConnectionServer(); + ConnectionServer(const QString &connectionName); ~ConnectionServer(); void start(); @@ -74,6 +74,7 @@ private: std::vector<QLocalSocket*> localSockets; IpcServerInterface *ipcServer; QLocalServer localServer; + static QString connectionName; int aliveTimerId; }; diff --git a/src/tools/codemodelbackend/codemodelbackendmain.cpp b/src/tools/codemodelbackend/codemodelbackendmain.cpp index f600039841..398ebaaaf5 100644 --- a/src/tools/codemodelbackend/codemodelbackendmain.cpp +++ b/src/tools/codemodelbackend/codemodelbackendmain.cpp @@ -1,4 +1,4 @@ -/**************************************************************************** +/**************************************************************************** ** ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal @@ -38,15 +38,20 @@ int main(int argc, char *argv[]) { QCoreApplication::setOrganizationName(QStringLiteral("QtProject")); QCoreApplication::setOrganizationDomain(QStringLiteral("qt-project.org")); - QCoreApplication::setApplicationName(QStringLiteral("EchoCodeModelBackend")); + QCoreApplication::setApplicationName(QStringLiteral("CodeModelBackend")); QCoreApplication::setApplicationVersion(QStringLiteral("1.0.0")); QCoreApplication application(argc, argv); + if (application.arguments().count() != 2) { + qWarning() << "wrong argument count"; + return 1; + } + CodeModelBackEnd::Commands::registerCommands(); CodeModelBackEnd::ClangIpcServer clangIpcServer; - CodeModelBackEnd::ConnectionServer connectionServer; + CodeModelBackEnd::ConnectionServer connectionServer(application.arguments()[1]); connectionServer.start(); connectionServer.setIpcServer(&clangIpcServer); diff --git a/src/tools/codemodelbackend/ipcsource/translationunit.h b/src/tools/codemodelbackend/ipcsource/translationunit.h index 8d4347ac3c..cb939446ce 100644 --- a/src/tools/codemodelbackend/ipcsource/translationunit.h +++ b/src/tools/codemodelbackend/ipcsource/translationunit.h @@ -61,7 +61,7 @@ public: TranslationUnit(const Utf8String &filePath, const UnsavedFiles &unsavedFiles, const ProjectPart &projectPart, - FileExistsCheck fileExitsCheck = CheckIfFileExists); + FileExistsCheck fileExistsCheck = CheckIfFileExists); ~TranslationUnit(); TranslationUnit(const TranslationUnit &cxTranslationUnit); diff --git a/tests/unit/codemodelbackend/echoserver/echoserverprocessmain.cpp b/tests/unit/codemodelbackend/echoserver/echoserverprocessmain.cpp index 0f9b020555..7590ea0bf6 100644 --- a/tests/unit/codemodelbackend/echoserver/echoserverprocessmain.cpp +++ b/tests/unit/codemodelbackend/echoserver/echoserverprocessmain.cpp @@ -1,4 +1,4 @@ -/**************************************************************************** +/**************************************************************************** ** ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal @@ -43,10 +43,15 @@ int main(int argc, char *argv[]) QCoreApplication application(argc, argv); + if (application.arguments().count() != 2) { + qWarning() << "wrong argument count"; + return 1; + } + CodeModelBackEnd::Commands::registerCommands(); CodeModelBackEnd::EchoIpcServer echoIpcServer; - CodeModelBackEnd::ConnectionServer connectionServer; + CodeModelBackEnd::ConnectionServer connectionServer(application.arguments()[1]); connectionServer.start(); connectionServer.setIpcServer(&echoIpcServer); |