diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index 464923e3..64211d73 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -16,6 +16,7 @@ #include "component/view/DialogView.h" #include "component/view/GraphViewStyle.h" #include "component/controller/NetworkFactory.h" +#include "component/controller/IDECommunicationController.h" #include "component/view/MainView.h" #include "component/view/ViewFactory.h" #include "data/StorageCache.h" @@ -55,6 +56,7 @@ void Application::createInstance( { s_instance->m_ideCommunicationController = networkFactory->createIDECommunicationController(s_instance->m_storageCache.get()); + s_instance->m_ideCommunicationController->startListening(); } s_instance->startMessagingAndScheduling(); diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 42c1d9d8..34346998 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -271,6 +271,7 @@ add_files( utility/messaging/type/MessageInterruptTasks.h utility/messaging/type/MessageLoadProject.h utility/messaging/type/MessageMoveIDECursor.h + utility/messaging/type/MessagePluginPortChange.h utility/messaging/type/MessageProjectEdit.h utility/messaging/type/MessageProjectNew.h utility/messaging/type/MessageRedo.h diff --git a/src/lib/component/controller/IDECommunicationController.cpp b/src/lib/component/controller/IDECommunicationController.cpp index d7f9b61f..039fc5d0 100644 --- a/src/lib/component/controller/IDECommunicationController.cpp +++ b/src/lib/component/controller/IDECommunicationController.cpp @@ -152,3 +152,9 @@ void IDECommunicationController::handleMessage(MessageMoveIDECursor* message) sendMessage(networkMessage); } + +void IDECommunicationController::handleMessage(MessagePluginPortChange* message) +{ + stopListening(); + startListening(); +} diff --git a/src/lib/component/controller/IDECommunicationController.h b/src/lib/component/controller/IDECommunicationController.h index 55d48fde..102da9c4 100644 --- a/src/lib/component/controller/IDECommunicationController.h +++ b/src/lib/component/controller/IDECommunicationController.h @@ -4,17 +4,18 @@ #include #include "component/controller/Controller.h" - #include "component/controller/helper/NetworkProtocolHelper.h" #include "utility/messaging/MessageListener.h" #include "utility/messaging/type/MessageMoveIDECursor.h" +#include "utility/messaging/type/MessagePluginPortChange.h" class StorageAccess; class IDECommunicationController : public Controller , public MessageListener + , public MessageListener { public: IDECommunicationController(StorageAccess* storageAccess); @@ -22,18 +23,21 @@ public: virtual void clear(); + virtual void startListening() = 0; + virtual void stopListening() = 0; + virtual bool isListening() const = 0; + void handleIncomingMessage(const std::string& message); bool getEnabled() const; void setEnabled(const bool enabled); - virtual bool isListening() const = 0; - private: void handleSetActiveTokenMessage(const NetworkProtocolHelper::SetActiveTokenMessage& message); void handleCreateProjectMessage(const NetworkProtocolHelper::CreateProjectMessage& message); virtual void handleMessage(MessageMoveIDECursor* message); + virtual void handleMessage(MessagePluginPortChange* message); virtual void sendMessage(const std::string& message) const = 0; StorageAccess* m_storageAccess; diff --git a/src/lib/utility/messaging/type/MessagePluginPortChange.h b/src/lib/utility/messaging/type/MessagePluginPortChange.h new file mode 100644 index 00000000..d6997b60 --- /dev/null +++ b/src/lib/utility/messaging/type/MessagePluginPortChange.h @@ -0,0 +1,20 @@ +#ifndef MESSAGE_PLUGIN_PORT_CHANGE_H +#define MESSAGE_PLUGIN_PORT_CHANGE_H + +#include "utility/messaging/Message.h" + +class MessagePluginPortChange + : public Message +{ +public: + MessagePluginPortChange() + { + } + + static const std::string getStaticType() + { + return "MessagePluginPortChange"; + } +}; + +#endif // MESSAGE_PLUGIN_PORT_CHANGE_H diff --git a/src/lib_gui/qt/network/QtIDECommunicationController.cpp b/src/lib_gui/qt/network/QtIDECommunicationController.cpp index 574a939e..b8a09905 100644 --- a/src/lib_gui/qt/network/QtIDECommunicationController.cpp +++ b/src/lib_gui/qt/network/QtIDECommunicationController.cpp @@ -6,17 +6,35 @@ QtIDECommunicationController::QtIDECommunicationController(QObject* parent, Stor : IDECommunicationController(storageAccess) , m_tcpWrapper(parent) { - ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); - m_tcpWrapper.setReadCallback(std::bind(&QtIDECommunicationController::handleIncomingMessage, this, std::placeholders::_1)); - m_tcpWrapper.setServerPort(appSettings->getCoatiPort()); - m_tcpWrapper.setClientPort(appSettings->getPluginPort()); - m_tcpWrapper.startListening(); } QtIDECommunicationController::~QtIDECommunicationController() {} +void QtIDECommunicationController::startListening() +{ + m_onQtThread( + [=]() + { + ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); + m_tcpWrapper.setServerPort(appSettings->getCoatiPort()); + m_tcpWrapper.setClientPort(appSettings->getPluginPort()); + m_tcpWrapper.startListening(); + } + ); +} + +void QtIDECommunicationController::stopListening() +{ + m_onQtThread( + [=]() + { + m_tcpWrapper.stopListening(); + } + ); +} + bool QtIDECommunicationController::isListening() const { return m_tcpWrapper.isListening(); @@ -25,4 +43,4 @@ bool QtIDECommunicationController::isListening() const void QtIDECommunicationController::sendMessage(const std::string& message) const { m_tcpWrapper.sendMessage(message); -} \ No newline at end of file +} diff --git a/src/lib_gui/qt/network/QtIDECommunicationController.h b/src/lib_gui/qt/network/QtIDECommunicationController.h index 9cbcc8ab..f36a6f7a 100644 --- a/src/lib_gui/qt/network/QtIDECommunicationController.h +++ b/src/lib_gui/qt/network/QtIDECommunicationController.h @@ -6,6 +6,7 @@ #include "QtTcpWrapper.h" #include "component/controller/IDECommunicationController.h" +#include "qt/utility/QtThreadedFunctor.h" #include "settings/ApplicationSettings.h" class StorageAccess; @@ -17,12 +18,17 @@ public: QtIDECommunicationController(QObject* parent, StorageAccess* storageAccess); ~QtIDECommunicationController(); + virtual void startListening(); + virtual void stopListening(); + virtual bool isListening() const; private: virtual void sendMessage(const std::string& message) const; QtTcpWrapper m_tcpWrapper; + + QtThreadedLambdaFunctor m_onQtThread; }; -#endif // QT_IDE_COMMUNICATION_CONTROLLER \ No newline at end of file +#endif // QT_IDE_COMMUNICATION_CONTROLLER diff --git a/src/lib_gui/qt/network/QtTcpWrapper.cpp b/src/lib_gui/qt/network/QtTcpWrapper.cpp index c5b6329f..a08be9e9 100644 --- a/src/lib_gui/qt/network/QtTcpWrapper.cpp +++ b/src/lib_gui/qt/network/QtTcpWrapper.cpp @@ -8,22 +8,29 @@ QtTcpWrapper::QtTcpWrapper(QObject* parent, const std::string& ip, const quint16 , m_clientPort(clientPort) , m_ip(ip) { + m_tcpServer = new QTcpServer(this); + + connect(m_tcpServer, SIGNAL(newConnection()), this, SLOT(acceptConnection())); } void QtTcpWrapper::startListening() { QHostAddress address(m_ip.c_str()); - m_tcpServer = new QTcpServer(this); - - connect(m_tcpServer, SIGNAL(newConnection()), this, SLOT(acceptConnection())); - if (!m_tcpServer->listen(QHostAddress::LocalHost, m_serverPort)) { LOG_ERROR_STREAM(<< "TCP server failed to start with error: \"" + m_tcpServer->errorString().toStdString() + "\". Unable to listen for IDE plugin messages."); } } +void QtTcpWrapper::stopListening() +{ + if (isListening()) + { + m_tcpServer->close(); + } +} + QtTcpWrapper::~QtTcpWrapper() { if (m_tcpServer != NULL) diff --git a/src/lib_gui/qt/network/QtTcpWrapper.h b/src/lib_gui/qt/network/QtTcpWrapper.h index 5c128475..b01d6ab7 100644 --- a/src/lib_gui/qt/network/QtTcpWrapper.h +++ b/src/lib_gui/qt/network/QtTcpWrapper.h @@ -17,6 +17,7 @@ public: ~QtTcpWrapper(); void startListening(); + void stopListening(); void sendMessage(const std::string& message) const; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp index 53851d22..f0550c28 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp @@ -21,6 +21,7 @@ #include "utility/logging/logging.h" #include "utility/messaging/type/MessageDispatchWhenLicenseValid.h" #include "utility/messaging/type/MessageLoadProject.h" +#include "utility/messaging/type/MessagePluginPortChange.h" #include "utility/messaging/type/MessageRefresh.h" #include "utility/messaging/type/MessageScrollSpeedChange.h" #include "utility/messaging/type/MessageStatus.h" @@ -42,6 +43,8 @@ QtProjectWizzard::QtProjectWizzard(QWidget* parent) m_appSettings.setHeaderSearchPaths(appSettings->getHeaderSearchPaths()); m_appSettings.setFrameworkSearchPaths(appSettings->getFrameworkSearchPaths()); m_appSettings.setScrollSpeed(appSettings->getScrollSpeed()); + m_appSettings.setCoatiPort(appSettings->getCoatiPort()); + m_appSettings.setPluginPort(appSettings->getPluginPort()); m_parserManager = std::make_shared(); @@ -616,7 +619,7 @@ void QtProjectWizzard::createProject() { settingsChanged = !(application->getCurrentProject()->settingsEqualExceptNameAndLocation(*(m_settings.get()))); } - + bool appSettingsChanged = !(m_appSettings == *ApplicationSettings::getInstance().get()); if (settingsChanged || appSettingsChanged) @@ -641,6 +644,12 @@ void QtProjectWizzard::savePreferences() MessageScrollSpeedChange(ApplicationSettings::getInstance()->getScrollSpeed()).dispatch(); } + if (m_appSettings.getCoatiPort() != ApplicationSettings::getInstance()->getCoatiPort() || + m_appSettings.getPluginPort() != ApplicationSettings::getInstance()->getPluginPort()) + { + MessagePluginPortChange().dispatch(); + } + if (appSettingsChanged) { Project* currentProject = Application::getInstance()->getCurrentProject().get(); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp index 6dbe3fbb..0e8d94ec 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp @@ -115,6 +115,7 @@ void QtProjectWizzardContentPreferences::populateForm(QGridLayout* layout, int& layout->setRowMinimumHeight(row++, 20); + // indexing layout->addWidget(createFormTitle("INDEXING"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignLeft); row++; @@ -151,6 +152,36 @@ void QtProjectWizzardContentPreferences::populateForm(QGridLayout* layout, int& layout->setRowMinimumHeight(row++, 20); + + // Plugins + layout->addWidget(createFormTitle("PLUGIN"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignLeft); + row++; + + // Coati port + m_coatiPort = new QLineEdit(); + m_coatiPort->setObjectName("name"); + m_coatiPort->setAttribute(Qt::WA_MacShowFocusRect, 0); + + layout->addWidget(createFormLabel("Coati Port"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); + layout->addWidget(m_coatiPort, row, QtProjectWizzardWindow::BACK_COL); + + addHelpButton("Port number that Coati uses to listen for incoming messages from plugins.", layout, row); + row++; + + // Coati port + m_pluginPort = new QLineEdit(); + m_pluginPort->setObjectName("name"); + m_pluginPort->setAttribute(Qt::WA_MacShowFocusRect, 0); + + layout->addWidget(createFormLabel("Plugin Port"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); + layout->addWidget(m_pluginPort, row, QtProjectWizzardWindow::BACK_COL); + + addHelpButton("Port number that Coati sends outgoing messages to.", layout, row); + row++; + + layout->setRowMinimumHeight(row++, 20); + + // Java layout->addWidget(createFormTitle("JAVA"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignLeft); row++; @@ -192,6 +223,7 @@ void QtProjectWizzardContentPreferences::populateForm(QGridLayout* layout, int& layout->setRowMinimumHeight(row++, 20); + // C/C++ layout->addWidget(createFormTitle("C/C++"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignLeft); row++; @@ -220,6 +252,9 @@ void QtProjectWizzardContentPreferences::load() m_scrollSpeed->setText(QString::number(appSettings->getScrollSpeed(), 'f', 1)); m_loggingEnabled->setChecked(appSettings->getLoggingEnabled()); + m_coatiPort->setText(QString::number(appSettings->getCoatiPort())); + m_pluginPort->setText(QString::number(appSettings->getPluginPort())); + m_threads->setCurrentIndex(appSettings->getIndexerThreadCount() - 1); m_fatalErrors->setChecked(appSettings->getShowExternalNonFatalErrors()); @@ -242,13 +277,16 @@ void QtProjectWizzardContentPreferences::save() m_oldColorSchemeIndex = -1; float scrollSpeed = m_scrollSpeed->text().toFloat(); - if (scrollSpeed) - { - appSettings->setScrollSpeed(scrollSpeed); - } + if (scrollSpeed) appSettings->setScrollSpeed(scrollSpeed); appSettings->setLoggingEnabled(m_loggingEnabled->isChecked()); + int coatiPort = m_coatiPort->text().toInt(); + if (coatiPort) appSettings->setCoatiPort(coatiPort); + + int pluginPort = m_pluginPort->text().toInt(); + if (pluginPort) appSettings->setPluginPort(pluginPort); + appSettings->setIndexerThreadCount(m_threads->currentIndex() + 1); appSettings->setShowExternalNonFatalErrors(m_fatalErrors->isChecked()); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h index de572a48..b8fc62b0 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h @@ -44,6 +44,9 @@ private: QLineEdit* m_scrollSpeed; QCheckBox* m_loggingEnabled; + QLineEdit* m_coatiPort; + QLineEdit* m_pluginPort; + QComboBox* m_threads; QCheckBox* m_fatalErrors;