Introduced the TargetControllerConsole class to provide access to common functionality within the TargetController.
This commit is contained in:
@@ -46,7 +46,7 @@ void Insight::startup() {
|
||||
std::bind(&Insight::onTargetControllerStateChangedEvent, this, std::placeholders::_1)
|
||||
);
|
||||
|
||||
auto targetDescriptor = this->getTargetDescriptor();
|
||||
auto targetDescriptor = this->targetControllerConsole.getTargetDescriptor();
|
||||
|
||||
std::string qtAppName = "Bloom";
|
||||
char* appArguments[] = {qtAppName.data()};
|
||||
@@ -91,24 +91,6 @@ void Insight::startup() {
|
||||
connect(&(this->mainWindow), &InsightWindow::setTargetPinState, worker, &InsightWorker::requestPinStateUpdate);
|
||||
}
|
||||
|
||||
Targets::TargetDescriptor Insight::getTargetDescriptor() {
|
||||
auto extractEvent = std::make_shared<Events::ExtractTargetDescriptor>();
|
||||
this->eventManager.triggerEvent(extractEvent);
|
||||
auto responseEvent = this->eventListener->waitForEvent<
|
||||
Events::TargetDescriptorExtracted,
|
||||
Events::TargetControllerErrorOccurred
|
||||
>(std::chrono::milliseconds(5000), extractEvent->id);
|
||||
|
||||
if (!responseEvent.has_value()
|
||||
|| !std::holds_alternative<EventPointer<Events::TargetDescriptorExtracted>>(responseEvent.value())
|
||||
) {
|
||||
throw Exception("Unexpected response from TargetController");
|
||||
}
|
||||
|
||||
auto descriptorExtracted = std::get<EventPointer<Events::TargetDescriptorExtracted>>(responseEvent.value());
|
||||
return descriptorExtracted->targetDescriptor;
|
||||
}
|
||||
|
||||
void Insight::shutdown() {
|
||||
if (this->getState() == ThreadState::STOPPED) {
|
||||
return;
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
#include <QtCore>
|
||||
#include <QApplication>
|
||||
|
||||
#include "UserInterfaces/InsightWindow/InsightWindow.hpp"
|
||||
|
||||
#include "src/Helpers/Thread.hpp"
|
||||
#include "src/ApplicationConfig.hpp"
|
||||
#include "src/EventManager/EventManager.hpp"
|
||||
#include "src/EventManager/EventListener.hpp"
|
||||
#include "src/Targets/TargetDescriptor.hpp"
|
||||
#include "src/TargetController/TargetControllerConsole.hpp"
|
||||
|
||||
namespace Bloom
|
||||
{
|
||||
@@ -34,6 +34,11 @@ namespace Bloom
|
||||
QApplication* application = nullptr;
|
||||
InsightWindow mainWindow;
|
||||
|
||||
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.
|
||||
@@ -42,8 +47,6 @@ namespace Bloom
|
||||
|
||||
void startup();
|
||||
|
||||
Targets::TargetDescriptor getTargetDescriptor();
|
||||
|
||||
public:
|
||||
Insight(EventManager& eventManager): eventManager(eventManager) {};
|
||||
|
||||
|
||||
@@ -43,10 +43,7 @@ void InsightWorker::startup() {
|
||||
}
|
||||
|
||||
void InsightWorker::requestPinStates(int variantId) {
|
||||
auto requestEvent = std::make_shared<Events::RetrieveTargetPinStates>();
|
||||
requestEvent->variantId = variantId;
|
||||
|
||||
this->eventManager.triggerEvent(requestEvent);
|
||||
this->targetControllerConsole.requestPinStates(variantId);
|
||||
}
|
||||
|
||||
void InsightWorker::requestPinStateUpdate(
|
||||
@@ -54,12 +51,7 @@ void InsightWorker::requestPinStateUpdate(
|
||||
Bloom::Targets::TargetPinDescriptor pinDescriptor,
|
||||
Bloom::Targets::TargetPinState pinState
|
||||
) {
|
||||
auto updateEvent = std::make_shared<Events::SetTargetPinState>();
|
||||
updateEvent->variantId = variantId;
|
||||
updateEvent->pinDescriptor = pinDescriptor;
|
||||
updateEvent->pinState = pinState;
|
||||
|
||||
this->eventManager.triggerEvent(updateEvent);
|
||||
this->targetControllerConsole.setPinState(variantId, pinDescriptor, pinState);
|
||||
}
|
||||
|
||||
void InsightWorker::onTargetStoppedEvent(EventPointer<TargetExecutionStopped> event) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "src/ApplicationConfig.hpp"
|
||||
#include "src/EventManager/EventManager.hpp"
|
||||
#include "src/EventManager/EventListener.hpp"
|
||||
#include "src/TargetController/TargetControllerConsole.hpp"
|
||||
|
||||
namespace Bloom
|
||||
{
|
||||
@@ -25,6 +26,11 @@ namespace Bloom
|
||||
EventManager& eventManager;
|
||||
EventListenerPointer eventListener = std::make_shared<EventListener>("InsightWorkerEventListener");
|
||||
|
||||
TargetControllerConsole targetControllerConsole = TargetControllerConsole(
|
||||
this->eventManager,
|
||||
*(this->eventListener)
|
||||
);
|
||||
|
||||
QTimer* eventDispatchTimer = nullptr;
|
||||
|
||||
void onTargetStoppedEvent(EventPointer<TargetExecutionStopped> event);
|
||||
|
||||
Reference in New Issue
Block a user