2021-04-04 21:04:12 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
|
#include <QApplication>
|
2021-04-24 20:23:17 +01:00
|
|
|
|
2021-04-04 21:04:12 +01:00
|
|
|
#include "src/Helpers/Thread.hpp"
|
2021-09-27 23:09:20 +01:00
|
|
|
#include "src/TargetController/TargetControllerConsole.hpp"
|
|
|
|
|
#include "src/Helpers/Paths.hpp"
|
2021-12-31 17:05:31 +00:00
|
|
|
#include "src/ProjectConfig.hpp"
|
2021-09-27 23:09:20 +01:00
|
|
|
|
2021-04-04 21:04:12 +01:00
|
|
|
#include "src/EventManager/EventManager.hpp"
|
|
|
|
|
#include "src/EventManager/EventListener.hpp"
|
2021-09-27 23:09:20 +01:00
|
|
|
|
|
|
|
|
#include "InsightWorker/InsightWorker.hpp"
|
2021-08-22 20:46:52 +01:00
|
|
|
#include "UserInterfaces/InsightWindow/InsightWindow.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
|
|
|
|
|
{
|
2021-10-18 00:33:41 +01:00
|
|
|
Q_OBJECT
|
2021-04-04 21:04:12 +01:00
|
|
|
|
|
|
|
|
public:
|
2021-08-11 00:07:12 +01:00
|
|
|
/**
|
|
|
|
|
* Insight constructor.
|
|
|
|
|
*
|
|
|
|
|
* Note: We use the comma operator in the application() initializer to set the Qt::AA_ShareOpenGLContexts
|
|
|
|
|
* attribute, as this is required by Qt before creating a QCoreApplication instance.
|
|
|
|
|
*
|
|
|
|
|
* @param eventManager
|
|
|
|
|
*/
|
2021-12-31 19:45:15 +00:00
|
|
|
explicit Insight(
|
|
|
|
|
EventManager& eventManager,
|
|
|
|
|
const ProjectConfig& projectConfig,
|
|
|
|
|
const EnvironmentConfig& environmentConfig,
|
|
|
|
|
const InsightConfig& insightConfig
|
|
|
|
|
):
|
2021-08-11 00:07:12 +01:00
|
|
|
eventManager(eventManager),
|
2021-12-31 19:45:15 +00:00
|
|
|
projectConfig(projectConfig),
|
|
|
|
|
environmentConfig(environmentConfig),
|
|
|
|
|
insightConfig(insightConfig),
|
2021-08-11 00:07:12 +01:00
|
|
|
application(
|
|
|
|
|
(
|
2021-09-21 21:24:37 +01:00
|
|
|
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, false),
|
2021-09-27 23:09:20 +01:00
|
|
|
#ifndef BLOOM_DEBUG_BUILD
|
|
|
|
|
QCoreApplication::addLibraryPath(QString::fromStdString(Paths::applicationDirPath() + "/plugins")),
|
|
|
|
|
#endif
|
2021-08-11 00:07:12 +01:00
|
|
|
QApplication(this->qtApplicationArgc, this->qtApplicationArgv.data())
|
|
|
|
|
)
|
|
|
|
|
) {};
|
2021-04-04 21:04:12 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Entry point for Insight.
|
|
|
|
|
*/
|
|
|
|
|
void run();
|
|
|
|
|
|
2021-10-18 00:33:41 +01:00
|
|
|
private:
|
|
|
|
|
std::string qtApplicationName = "Bloom";
|
|
|
|
|
std::array<char*, 1> qtApplicationArgv = {this->qtApplicationName.data()};
|
|
|
|
|
int qtApplicationArgc = 1;
|
|
|
|
|
|
2021-12-31 17:05:31 +00:00
|
|
|
ProjectConfig projectConfig;
|
2021-10-18 00:33:41 +01:00
|
|
|
EnvironmentConfig environmentConfig;
|
|
|
|
|
InsightConfig insightConfig;
|
|
|
|
|
|
|
|
|
|
EventManager& eventManager;
|
|
|
|
|
EventListenerPointer eventListener = std::make_shared<EventListener>("InsightEventListener");
|
|
|
|
|
|
|
|
|
|
QApplication application;
|
|
|
|
|
InsightWorker* insightWorker = new InsightWorker(this->eventManager);
|
2021-12-31 19:45:15 +00:00
|
|
|
InsightWindow* mainWindow = new InsightWindow(
|
|
|
|
|
*(this->insightWorker),
|
|
|
|
|
this->environmentConfig,
|
|
|
|
|
this->insightConfig
|
|
|
|
|
);
|
2021-10-18 00:33:41 +01:00
|
|
|
|
|
|
|
|
TargetControllerConsole targetControllerConsole = TargetControllerConsole(
|
|
|
|
|
this->eventManager,
|
|
|
|
|
*(this->eventListener)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
QThread* workerThread = nullptr;
|
|
|
|
|
|
|
|
|
|
void startup();
|
|
|
|
|
|
2021-04-04 21:04:12 +01:00
|
|
|
/**
|
|
|
|
|
* Shuts down Insight. Called when the user closes the Insight window.
|
|
|
|
|
*/
|
|
|
|
|
void shutdown();
|
|
|
|
|
|
2021-10-18 01:09:53 +01:00
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
* upgrade.
|
|
|
|
|
*/
|
|
|
|
|
void checkBloomVersion();
|
|
|
|
|
|
2021-04-04 21:04:12 +01:00
|
|
|
/**
|
|
|
|
|
* Because Insight occupies the main thread, it must handle any application shutdown requests.
|
|
|
|
|
*
|
|
|
|
|
* @param event
|
|
|
|
|
*/
|
2021-06-22 14:44:00 +01:00
|
|
|
void onShutdownApplicationEvent(const 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
|
|
|
|
|
*/
|
2021-06-22 14:44:00 +01:00
|
|
|
void onTargetControllerThreadStateChangedEvent(const Events::TargetControllerThreadStateChanged& event);
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2021-07-04 00:32:05 +01:00
|
|
|
/**
|
2021-07-04 00:35:01 +01:00
|
|
|
* If something horrible was to happen and the DebugServer dies unexpectedly, Insight will shutdown in
|
|
|
|
|
* response.
|
2021-07-04 00:32:05 +01:00
|
|
|
*
|
|
|
|
|
* @param event
|
|
|
|
|
*/
|
|
|
|
|
void onDebugServerThreadStateChangedEvent(const Events::DebugServerThreadStateChanged& 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();
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|