Updated Insight component to use the main thread's event listener, as opposed to constructing its own.

This commit is contained in:
Nav
2022-02-09 17:47:05 +00:00
parent 49710e7484
commit 56dc870b8e
3 changed files with 40 additions and 81 deletions

View File

@@ -43,6 +43,7 @@ namespace Bloom
if (this->insightConfig->insightEnabled) { if (this->insightConfig->insightEnabled) {
this->insight = std::make_unique<Insight>( this->insight = std::make_unique<Insight>(
*(this->applicationEventListener),
this->eventManager, this->eventManager,
this->projectConfig.value(), this->projectConfig.value(),
this->environmentConfig.value(), this->environmentConfig.value(),
@@ -128,6 +129,10 @@ namespace Bloom
Thread::setThreadState(ThreadState::SHUTDOWN_INITIATED); Thread::setThreadState(ThreadState::SHUTDOWN_INITIATED);
Logger::info("Shutting down Bloom"); Logger::info("Shutting down Bloom");
if (this->insight != nullptr) {
this->insight->shutdown();
}
this->stopDebugServer(); this->stopDebugServer();
this->stopTargetController(); this->stopTargetController();
this->stopSignalHandler(); this->stopSignalHandler();

View File

@@ -14,6 +14,31 @@ namespace Bloom
{ {
using namespace Bloom::Exceptions; 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() { void Insight::run() {
try { try {
this->startup(); this->startup();
@@ -38,19 +63,6 @@ namespace Bloom
void Insight::startup() { void Insight::startup() {
Logger::info("Starting Insight"); Logger::info("Starting Insight");
this->setThreadState(ThreadState::STARTING); this->setThreadState(ThreadState::STARTING);
this->eventManager.registerListener(this->eventListener);
this->eventListener->registerCallbackForEventType<Events::ShutdownApplication>(
std::bind(&Insight::onShutdownApplicationEvent, this, std::placeholders::_1)
);
this->eventListener->registerCallbackForEventType<Events::TargetControllerThreadStateChanged>(
std::bind(&Insight::onTargetControllerThreadStateChangedEvent, this, std::placeholders::_1)
);
this->eventListener->registerCallbackForEventType<Events::DebugServerThreadStateChanged>(
std::bind(&Insight::onDebugServerThreadStateChangedEvent, this, std::placeholders::_1)
);
auto targetDescriptor = this->targetControllerConsole.getTargetDescriptor(); auto targetDescriptor = this->targetControllerConsole.getTargetDescriptor();
@@ -164,7 +176,6 @@ namespace Bloom
} }
this->application.exit(0); this->application.exit(0);
this->setThreadState(ThreadState::STOPPED); this->setThreadState(ThreadState::STOPPED);
} }
@@ -191,26 +202,4 @@ namespace Bloom
this->insightWorker->queueTask(versionQueryTask); 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();
}
}
} }

View File

@@ -39,32 +39,24 @@ namespace Bloom
* @param eventManager * @param eventManager
*/ */
explicit Insight( explicit Insight(
EventListener& eventListener,
EventManager& eventManager, EventManager& eventManager,
const ProjectConfig& projectConfig, const ProjectConfig& projectConfig,
const EnvironmentConfig& environmentConfig, const EnvironmentConfig& environmentConfig,
const InsightConfig& insightConfig, const InsightConfig& insightConfig,
InsightProjectSettings& insightProjectSettings 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. * Entry point for Insight.
*/ */
void run(); void run();
/**
* Shuts down Insight. Called when the user closes the Insight window or a ShutdownApplication event is fired.
*/
void shutdown();
private: private:
std::string qtApplicationName = "Bloom"; std::string qtApplicationName = "Bloom";
std::array<char*, 1> qtApplicationArgv = {this->qtApplicationName.data()}; std::array<char*, 1> qtApplicationArgv = {this->qtApplicationName.data()};
@@ -77,7 +69,7 @@ namespace Bloom
InsightProjectSettings& insightProjectSettings; InsightProjectSettings& insightProjectSettings;
EventManager& eventManager; EventManager& eventManager;
EventListenerPointer eventListener = std::make_shared<EventListener>("InsightEventListener"); EventListener& eventListener;
QApplication application; QApplication application;
InsightWorker* insightWorker = new InsightWorker(this->eventManager); InsightWorker* insightWorker = new InsightWorker(this->eventManager);
@@ -90,7 +82,7 @@ namespace Bloom
TargetControllerConsole targetControllerConsole = TargetControllerConsole( TargetControllerConsole targetControllerConsole = TargetControllerConsole(
this->eventManager, this->eventManager,
*(this->eventListener) this->eventListener
); );
/** /**
@@ -101,11 +93,6 @@ namespace Bloom
void startup(); 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 * 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 * 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(); 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. * Dispatches any events currently in the queue.
* *
@@ -143,7 +108,7 @@ namespace Bloom
* See Insight::startup() for more. * See Insight::startup() for more.
*/ */
void dispatchEvents() { void dispatchEvents() {
this->eventListener->dispatchCurrentEvents(); this->eventListener.dispatchCurrentEvents();
}; };
}; };
} }