Refactored insight startup code to accommodate on-demand activation.
Also created new event for activation request
This commit is contained in:
@@ -57,33 +57,19 @@ namespace Bloom
|
|||||||
this->startup();
|
this->startup();
|
||||||
|
|
||||||
#ifndef EXCLUDE_INSIGHT
|
#ifndef EXCLUDE_INSIGHT
|
||||||
if (this->insightConfig->insightEnabled) {
|
this->insightActivationPending = this->insightConfig->insightEnabled;
|
||||||
this->insight = std::make_unique<Insight>(
|
|
||||||
*(this->applicationEventListener),
|
|
||||||
this->projectConfig.value(),
|
|
||||||
this->environmentConfig.value(),
|
|
||||||
this->insightConfig.value(),
|
|
||||||
this->projectSettings.value().insightSettings
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Before letting Insight occupy the main thread, process any pending events that accumulated
|
|
||||||
* during startup.
|
|
||||||
*/
|
|
||||||
this->applicationEventListener->dispatchCurrentEvents();
|
|
||||||
|
|
||||||
if (Thread::getThreadState() == ThreadState::READY) {
|
|
||||||
this->insight->run();
|
|
||||||
Logger::debug("Insight closed");
|
|
||||||
}
|
|
||||||
|
|
||||||
this->shutdown();
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Main event loop
|
// Main event loop
|
||||||
while (Thread::getThreadState() == ThreadState::READY) {
|
while (Thread::getThreadState() == ThreadState::READY) {
|
||||||
|
#ifndef EXCLUDE_INSIGHT
|
||||||
|
if (this->insightActivationPending) {
|
||||||
|
this->insightActivationPending = false;
|
||||||
|
this->startInsight();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
this->applicationEventListener->waitAndDispatch();
|
this->applicationEventListener->waitAndDispatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,6 +145,11 @@ namespace Bloom
|
|||||||
std::bind(&Application::onDebugSessionFinished, this, std::placeholders::_1)
|
std::bind(&Application::onDebugSessionFinished, this, std::placeholders::_1)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#ifndef EXCLUDE_INSIGHT
|
||||||
|
applicationEventListener->registerCallbackForEventType<Events::InsightActivationRequested>(
|
||||||
|
std::bind(&Application::onInsightActivationRequest, this, std::placeholders::_1)
|
||||||
|
);
|
||||||
|
#endif
|
||||||
this->startTargetController();
|
this->startTargetController();
|
||||||
this->startDebugServer();
|
this->startDebugServer();
|
||||||
|
|
||||||
@@ -507,6 +498,41 @@ namespace Bloom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef EXCLUDE_INSIGHT
|
||||||
|
void Application::startInsight() {
|
||||||
|
assert(!this->insight);
|
||||||
|
|
||||||
|
this->insight = std::make_unique<Insight>(
|
||||||
|
*(this->applicationEventListener),
|
||||||
|
this->projectConfig.value(),
|
||||||
|
this->environmentConfig.value(),
|
||||||
|
this->insightConfig.value(),
|
||||||
|
this->projectSettings.value().insightSettings
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Before letting Insight occupy the main thread, process any pending events that accumulated
|
||||||
|
* during startup.
|
||||||
|
*/
|
||||||
|
this->applicationEventListener->dispatchCurrentEvents();
|
||||||
|
|
||||||
|
if (Thread::getThreadState() == ThreadState::READY) {
|
||||||
|
this->insight->run();
|
||||||
|
Logger::debug("Insight closed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::onInsightActivationRequest(const Events::InsightActivationRequested&) {
|
||||||
|
if (this->insight) {
|
||||||
|
// Insight has already been started
|
||||||
|
this->insight->showMainWindow();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->insightActivationPending = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void Application::onShutdownApplicationRequest(const Events::ShutdownApplication&) {
|
void Application::onShutdownApplicationRequest(const Events::ShutdownApplication&) {
|
||||||
Logger::debug("ShutdownApplication event received.");
|
Logger::debug("ShutdownApplication event received.");
|
||||||
this->shutdown();
|
this->shutdown();
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ namespace Bloom
|
|||||||
|
|
||||||
#ifndef EXCLUDE_INSIGHT
|
#ifndef EXCLUDE_INSIGHT
|
||||||
/**
|
/**
|
||||||
* Insight is, effectively, a small Qt application that serves a GUI to the user. It occupies the main thread,
|
* Insight is a small Qt application that serves a GUI to the user. It occupies the main thread, as well as a
|
||||||
* as well as a single worker thread, and possibly other threads created by Qt.
|
* single worker thread, and possibly other threads created by Qt.
|
||||||
*
|
*
|
||||||
* Insight is optional - users can disable it via their project configuration.
|
* Insight is optional - users can disable it via their project configuration.
|
||||||
*
|
*
|
||||||
@@ -100,6 +100,13 @@ namespace Bloom
|
|||||||
* as we want to manage the lifetime of the object here.
|
* as we want to manage the lifetime of the object here.
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<Insight> insight = nullptr;
|
std::unique_ptr<Insight> insight = nullptr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activation of the Insight GUI can be requested by triggering an InsightActivationRequested event.
|
||||||
|
*
|
||||||
|
* This flag will be set upon that event being triggered. The Insight GUI will be started shortly after.
|
||||||
|
*/
|
||||||
|
bool insightActivationPending = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -231,6 +238,20 @@ namespace Bloom
|
|||||||
*/
|
*/
|
||||||
void stopDebugServer();
|
void stopDebugServer();
|
||||||
|
|
||||||
|
#ifndef EXCLUDE_INSIGHT
|
||||||
|
/**
|
||||||
|
* Starts the Insight GUI.
|
||||||
|
*
|
||||||
|
* This function should never be called more than once.
|
||||||
|
*/
|
||||||
|
void startInsight();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles requests to start the Insight GUI.
|
||||||
|
*/
|
||||||
|
void onInsightActivationRequest(const Events::InsightActivationRequested&);
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggers a shutdown of Bloom and all of its components.
|
* Triggers a shutdown of Bloom and all of its components.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ namespace Bloom::Events
|
|||||||
TARGET_RESET,
|
TARGET_RESET,
|
||||||
PROGRAMMING_MODE_ENABLED,
|
PROGRAMMING_MODE_ENABLED,
|
||||||
PROGRAMMING_MODE_DISABLED,
|
PROGRAMMING_MODE_DISABLED,
|
||||||
|
INSIGHT_ACTIVATION_REQUESTED,
|
||||||
};
|
};
|
||||||
|
|
||||||
class Event
|
class Event
|
||||||
|
|||||||
@@ -20,6 +20,10 @@
|
|||||||
#include "ProgrammingModeEnabled.hpp"
|
#include "ProgrammingModeEnabled.hpp"
|
||||||
#include "ProgrammingModeDisabled.hpp"
|
#include "ProgrammingModeDisabled.hpp"
|
||||||
|
|
||||||
|
#ifndef EXCLUDE_INSIGHT
|
||||||
|
#include "InsightActivationRequested.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Bloom::Events
|
namespace Bloom::Events
|
||||||
{
|
{
|
||||||
template <class EventType>
|
template <class EventType>
|
||||||
|
|||||||
26
src/EventManager/Events/InsightActivationRequested.hpp
Normal file
26
src/EventManager/Events/InsightActivationRequested.hpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "Event.hpp"
|
||||||
|
|
||||||
|
namespace Bloom::Events
|
||||||
|
{
|
||||||
|
class InsightActivationRequested: public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static constexpr EventType type = EventType::INSIGHT_ACTIVATION_REQUESTED;
|
||||||
|
static const inline std::string name = "InsightActivationRequested";
|
||||||
|
|
||||||
|
InsightActivationRequested() = default;
|
||||||
|
|
||||||
|
[[nodiscard]] EventType getType() const override {
|
||||||
|
return InsightActivationRequested::type;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] std::string getName() const override {
|
||||||
|
return InsightActivationRequested::name;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -66,6 +66,11 @@ namespace Bloom
|
|||||||
this->shutdown();
|
this->shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Insight::showMainWindow() {
|
||||||
|
this->mainWindow->show();
|
||||||
|
this->mainWindow->activateWindow();
|
||||||
|
}
|
||||||
|
|
||||||
void Insight::startup() {
|
void Insight::startup() {
|
||||||
Logger::info("Starting Insight");
|
Logger::info("Starting Insight");
|
||||||
this->setThreadState(ThreadState::STARTING);
|
this->setThreadState(ThreadState::STARTING);
|
||||||
@@ -102,7 +107,7 @@ namespace Bloom
|
|||||||
std::bind(&Insight::onProgrammingModeDisabledEvent, this, std::placeholders::_1)
|
std::bind(&Insight::onProgrammingModeDisabledEvent, this, std::placeholders::_1)
|
||||||
);
|
);
|
||||||
|
|
||||||
QApplication::setQuitOnLastWindowClosed(true);
|
QApplication::setQuitOnLastWindowClosed(false);
|
||||||
QApplication::setStyle(new BloomProxyStyle());
|
QApplication::setStyle(new BloomProxyStyle());
|
||||||
|
|
||||||
auto globalStylesheet = QFile(
|
auto globalStylesheet = QFile(
|
||||||
|
|||||||
@@ -61,6 +61,11 @@ namespace Bloom
|
|||||||
*/
|
*/
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens main window and obtains focus.
|
||||||
|
*/
|
||||||
|
void showMainWindow();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shuts down Insight. Called when the user closes the Insight window or a ShutdownApplication event is fired.
|
* Shuts down Insight. Called when the user closes the Insight window or a ShutdownApplication event is fired.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -318,6 +318,10 @@ namespace Bloom
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InsightWindow::showEvent(QShowEvent* event) {
|
void InsightWindow::showEvent(QShowEvent* event) {
|
||||||
|
if (!this->activated) {
|
||||||
|
this->activate();
|
||||||
|
}
|
||||||
|
|
||||||
this->adjustPanels();
|
this->adjustPanels();
|
||||||
this->adjustMinimumSize();
|
this->adjustMinimumSize();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user