Files
BloomPatched/src/Insight/Insight.hpp

107 lines
3.6 KiB
C++
Raw Normal View History

2021-04-04 21:04:12 +01:00
#pragma once
#include <QtCore>
#include <QApplication>
#include "UserInterfaces/InsightWindow/InsightWindow.hpp"
2021-04-04 21:04:12 +01:00
#include "src/Helpers/Thread.hpp"
#include "src/ApplicationConfig.hpp"
#include "src/EventManager/EventManager.hpp"
#include "src/EventManager/EventListener.hpp"
#include "src/TargetController/TargetControllerConsole.hpp"
2021-04-04 21:04:12 +01:00
namespace Bloom
{
/**
* The Insight component provides a GUI for insight into the target's GPIO state.
* Insight relies heavily on the Qt framework - it's practically a small Qt application. Each supported target
* package variant implements a custom Qt widget that presents the user with the current state of the target's GPIO
* pins, as well as the ability to manipulate the pin states of output pins by clicking on them.
*
* The Insight component occupies the Bloom's main thread. See Application::run() for more.
*/
class Insight: public QObject, public Thread
{
Q_OBJECT
private:
std::string qtApplicationName = "Bloom";
std::array<char*, 1> qtApplicationArgv = {this->qtApplicationName.data()};
int qtApplicationArgc = 1;
2021-04-04 21:04:12 +01:00
ApplicationConfig applicationConfig;
EnvironmentConfig environmentConfig;
InsightConfig insightConfig;
2021-04-04 21:04:12 +01:00
EventManager& eventManager;
EventListenerPointer eventListener = std::make_shared<EventListener>("InsightEventListener");
QApplication* application = nullptr;
InsightWindow mainWindow;
TargetControllerConsole targetControllerConsole = TargetControllerConsole(
this->eventManager,
*(this->eventListener)
);
2021-04-04 21:04:12 +01:00
/**
* Insight consists of two threads - the main thread where the main Qt event loop runs (for the GUI), and
* a single worker thread to handle any blocking/time-expensive operations.
*/
2021-06-21 00:14:31 +01:00
QThread* workerThread = nullptr;
2021-04-04 21:04:12 +01:00
void startup();
public:
2021-06-21 00:14:31 +01:00
explicit Insight(EventManager& eventManager): eventManager(eventManager) {};
2021-04-04 21:04:12 +01:00
void setApplicationConfig(const ApplicationConfig& applicationConfig) {
this->applicationConfig = applicationConfig;
}
void setEnvironmentConfig(const EnvironmentConfig& environmentConfig) {
this->environmentConfig = environmentConfig;
}
void setInsightConfig(const InsightConfig& insightConfig) {
this->insightConfig = insightConfig;
}
2021-04-04 21:04:12 +01:00
/**
* Entry point for Insight.
*/
void run();
/**
* Shuts down Insight. Called when the user closes the Insight window.
*/
void shutdown();
/**
* Because Insight occupies the main thread, it must handle any application shutdown requests.
*
* @param event
*/
void onShutdownApplicationEvent(Events::EventPointer<Events::ShutdownApplication> event);
2021-04-04 21:04:12 +01:00
/**
* If the something horrible was to happen and the TC dies unexpectedly, Insight will shutdown in response.
*
* @param event
*/
void onTargetControllerThreadStateChangedEvent(
Events::EventPointer<Events::TargetControllerThreadStateChanged> event
);
2021-04-04 21:04:12 +01:00
/**
* Dispatches any events currently in the queue.
*
* Because Insight is effectively a Qt application, we cannot use our own event loop. We must use Qt's event
* loop. We do this by utilizing a QTimer instance to call this method on an interval.
* See Insight::startup() for more.
*/
void dispatchEvents() {
this->eventListener->dispatchCurrentEvents();
};
};
}