From 56dc870b8e193523fca416ba034e76a680b57375 Mon Sep 17 00:00:00 2001 From: Nav Date: Wed, 9 Feb 2022 17:47:05 +0000 Subject: [PATCH] Updated Insight component to use the main thread's event listener, as opposed to constructing its own. --- src/Application.cpp | 5 ++++ src/Insight/Insight.cpp | 61 +++++++++++++++++------------------------ src/Insight/Insight.hpp | 55 +++++++------------------------------ 3 files changed, 40 insertions(+), 81 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index 1f9305cf..3435aa9e 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -43,6 +43,7 @@ namespace Bloom if (this->insightConfig->insightEnabled) { this->insight = std::make_unique( + *(this->applicationEventListener), this->eventManager, this->projectConfig.value(), this->environmentConfig.value(), @@ -128,6 +129,10 @@ namespace Bloom Thread::setThreadState(ThreadState::SHUTDOWN_INITIATED); Logger::info("Shutting down Bloom"); + if (this->insight != nullptr) { + this->insight->shutdown(); + } + this->stopDebugServer(); this->stopTargetController(); this->stopSignalHandler(); diff --git a/src/Insight/Insight.cpp b/src/Insight/Insight.cpp index bf300a3f..e5e1ed18 100644 --- a/src/Insight/Insight.cpp +++ b/src/Insight/Insight.cpp @@ -14,6 +14,31 @@ namespace Bloom { using namespace Bloom::Exceptions; + Insight::Insight( + EventListener& eventListener, + EventManager& eventManager, + const ProjectConfig& projectConfig, + const EnvironmentConfig& environmentConfig, + const InsightConfig& insightConfig, + InsightProjectSettings& insightProjectSettings + ) + : eventListener(eventListener) + , eventManager(eventManager) + , projectConfig(projectConfig) + , environmentConfig(environmentConfig) + , insightConfig(insightConfig) + , insightProjectSettings(insightProjectSettings) + , application( + ( + QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, false), +#ifndef BLOOM_DEBUG_BUILD + QCoreApplication::addLibraryPath(QString::fromStdString(Paths::applicationDirPath() + "/plugins")), +#endif + QApplication(this->qtApplicationArgc, this->qtApplicationArgv.data()) + ) + ) + {} + void Insight::run() { try { this->startup(); @@ -38,19 +63,6 @@ namespace Bloom void Insight::startup() { Logger::info("Starting Insight"); this->setThreadState(ThreadState::STARTING); - this->eventManager.registerListener(this->eventListener); - - this->eventListener->registerCallbackForEventType( - std::bind(&Insight::onShutdownApplicationEvent, this, std::placeholders::_1) - ); - - this->eventListener->registerCallbackForEventType( - std::bind(&Insight::onTargetControllerThreadStateChangedEvent, this, std::placeholders::_1) - ); - - this->eventListener->registerCallbackForEventType( - std::bind(&Insight::onDebugServerThreadStateChangedEvent, this, std::placeholders::_1) - ); auto targetDescriptor = this->targetControllerConsole.getTargetDescriptor(); @@ -164,7 +176,6 @@ namespace Bloom } this->application.exit(0); - this->setThreadState(ThreadState::STOPPED); } @@ -191,26 +202,4 @@ namespace Bloom this->insightWorker->queueTask(versionQueryTask); } - - void Insight::onShutdownApplicationEvent(const Events::ShutdownApplication&) { - /* - * Once Insight shuts down, control of the main thread will be returned to Application::run(), which - * will pickup the ShutdownApplication event and proceed with the shutdown. - */ - this->shutdown(); - } - - void Insight::onTargetControllerThreadStateChangedEvent(const Events::TargetControllerThreadStateChanged& event) { - if (event.getState() == ThreadState::STOPPED) { - // Something horrible has happened with the TargetController - Insight is useless without the TargetController - this->shutdown(); - } - } - - void Insight::onDebugServerThreadStateChangedEvent(const Events::DebugServerThreadStateChanged& event) { - if (event.getState() == ThreadState::STOPPED) { - // Something horrible has happened with the DebugServer - this->shutdown(); - } - } } diff --git a/src/Insight/Insight.hpp b/src/Insight/Insight.hpp index 2fd67b8a..705808f5 100644 --- a/src/Insight/Insight.hpp +++ b/src/Insight/Insight.hpp @@ -39,32 +39,24 @@ namespace Bloom * @param eventManager */ explicit Insight( + EventListener& eventListener, EventManager& eventManager, const ProjectConfig& projectConfig, const EnvironmentConfig& environmentConfig, const InsightConfig& insightConfig, InsightProjectSettings& insightProjectSettings - ): - eventManager(eventManager), - projectConfig(projectConfig), - environmentConfig(environmentConfig), - insightConfig(insightConfig), - insightProjectSettings(insightProjectSettings), - application( - ( - QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, false), -#ifndef BLOOM_DEBUG_BUILD - QCoreApplication::addLibraryPath(QString::fromStdString(Paths::applicationDirPath() + "/plugins")), -#endif - QApplication(this->qtApplicationArgc, this->qtApplicationArgv.data()) - ) - ) {}; + ); /** * Entry point for Insight. */ void run(); + /** + * Shuts down Insight. Called when the user closes the Insight window or a ShutdownApplication event is fired. + */ + void shutdown(); + private: std::string qtApplicationName = "Bloom"; std::array qtApplicationArgv = {this->qtApplicationName.data()}; @@ -77,7 +69,7 @@ namespace Bloom InsightProjectSettings& insightProjectSettings; EventManager& eventManager; - EventListenerPointer eventListener = std::make_shared("InsightEventListener"); + EventListener& eventListener; QApplication application; InsightWorker* insightWorker = new InsightWorker(this->eventManager); @@ -90,7 +82,7 @@ namespace Bloom TargetControllerConsole targetControllerConsole = TargetControllerConsole( this->eventManager, - *(this->eventListener) + this->eventListener ); /** @@ -101,11 +93,6 @@ namespace Bloom void startup(); - /** - * Shuts down Insight. Called when the user closes the Insight window. - */ - void shutdown(); - /** * Queries the Bloom server for the latest version number. If the current version number doesn't match the * latest version number returned by the server, we'll display a warning in the logs to instruct the user to @@ -113,28 +100,6 @@ namespace Bloom */ void checkBloomVersion(); - /** - * Because Insight occupies the main thread, it must handle any application shutdown requests. - * - * @param event - */ - void onShutdownApplicationEvent(const Events::ShutdownApplication& event); - - /** - * If the something horrible was to happen and the TC dies unexpectedly, Insight will shutdown in response. - * - * @param event - */ - void onTargetControllerThreadStateChangedEvent(const Events::TargetControllerThreadStateChanged& event); - - /** - * If something horrible was to happen and the DebugServer dies unexpectedly, Insight will shutdown in - * response. - * - * @param event - */ - void onDebugServerThreadStateChangedEvent(const Events::DebugServerThreadStateChanged& event); - /** * Dispatches any events currently in the queue. * @@ -143,7 +108,7 @@ namespace Bloom * See Insight::startup() for more. */ void dispatchEvents() { - this->eventListener->dispatchCurrentEvents(); + this->eventListener.dispatchCurrentEvents(); }; }; }