TargetController suspension
This commit is contained in:
@@ -15,7 +15,7 @@ void EventListener::clearAllCallbacks() {
|
||||
void EventListener::registerEvent(GenericEventPointer event) {
|
||||
auto eventName = event->getName();
|
||||
Logger::debug("Event \"" + eventName + "\" (" + std::to_string(event->id)
|
||||
+ ") registered for listener " + std::to_string(this->id));
|
||||
+ ") registered for listener " + this->name);
|
||||
auto queueLock = this->eventQueueByEventType.acquireLock();
|
||||
auto& eventQueueByType = this->eventQueueByEventType.getReference();
|
||||
|
||||
@@ -57,7 +57,7 @@ std::vector<GenericEventPointer> EventListener::getEvents() {
|
||||
|
||||
void EventListener::dispatchEvent(GenericEventPointer event) {
|
||||
auto eventName = event->getName();
|
||||
Logger::debug("Dispatching event " + eventName + ".");
|
||||
Logger::debug("Dispatching event " + eventName + " (" + std::to_string(event->id) + ").");
|
||||
// Dispatch the event to all registered handlers
|
||||
auto mappingLock = this->eventTypeToCallbacksMapping.acquireLock();
|
||||
auto& callbacks = this->eventTypeToCallbacksMapping.getReference().find(eventName)->second;
|
||||
|
||||
@@ -141,6 +141,40 @@ namespace Bloom
|
||||
this->registeredEventTypes.getReference().insert(EventType::name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all registered callbacks for a specific event type.
|
||||
*
|
||||
* @tparam EventType
|
||||
*/
|
||||
template<class EventType>
|
||||
void deregisterCallbacksForEventType() {
|
||||
static_assert(
|
||||
std::is_base_of<Events::Event, EventType>::value,
|
||||
"EventType is not a derivation of Event"
|
||||
);
|
||||
|
||||
{
|
||||
auto mappingLock = this->eventTypeToCallbacksMapping.acquireLock();
|
||||
auto& mapping = this->eventTypeToCallbacksMapping.getReference();
|
||||
|
||||
if (mapping.contains(EventType::name)) {
|
||||
mapping.at(EventType::name).clear();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto registeredEventTypesLock = this->registeredEventTypes.acquireLock();
|
||||
this->registeredEventTypes.getReference().erase(EventType::name);
|
||||
}
|
||||
|
||||
auto queueLock = this->eventQueueByEventType.acquireLock();
|
||||
auto& eventQueueByType = this->eventQueueByEventType.getReference();
|
||||
|
||||
if (eventQueueByType.contains(EventType::name)) {
|
||||
eventQueueByType.erase(EventType::name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for an event (of type EventTypeA, EventTypeB or EventTypeC) to be dispatched to the listener.
|
||||
* Then returns the event object. If timeout is reached, an std::nullopt object will be returned.
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "DebugSessionStarted.hpp"
|
||||
#include "DebugSessionFinished.hpp"
|
||||
#include "TargetControllerThreadStateChanged.hpp"
|
||||
#include "ReportTargetControllerState.hpp"
|
||||
#include "TargetControllerStateReported.hpp"
|
||||
#include "ShutdownTargetController.hpp"
|
||||
#include "TargetControllerErrorOccurred.hpp"
|
||||
#include "ShutdownApplication.hpp"
|
||||
@@ -33,7 +35,7 @@
|
||||
#include "ProgramCounterSetOnTarget.hpp"
|
||||
#include "ExtractTargetDescriptor.hpp"
|
||||
#include "TargetDescriptorExtracted.hpp"
|
||||
#include "InsightStateChanged.hpp"
|
||||
#include "InsightThreadStateChanged.hpp"
|
||||
#include "RetrieveTargetPinStates.hpp"
|
||||
#include "TargetPinStatesRetrieved.hpp"
|
||||
#include "SetTargetPinState.hpp"
|
||||
|
||||
@@ -7,19 +7,17 @@
|
||||
|
||||
namespace Bloom::Events
|
||||
{
|
||||
class InsightStateChanged: public Event
|
||||
class InsightThreadStateChanged: public Event
|
||||
{
|
||||
private:
|
||||
ThreadState state;
|
||||
public:
|
||||
InsightStateChanged(ThreadState state): state(state) {
|
||||
InsightThreadStateChanged(ThreadState state): state(state) {};
|
||||
|
||||
};
|
||||
|
||||
static inline const std::string name = "InsightStateChanged";
|
||||
static inline const std::string name = "InsightThreadStateChanged";
|
||||
|
||||
std::string getName() const override {
|
||||
return InsightStateChanged::name;
|
||||
return InsightThreadStateChanged::name;
|
||||
}
|
||||
|
||||
ThreadState getState() const {
|
||||
20
src/EventManager/Events/ReportTargetControllerState.hpp
Normal file
20
src/EventManager/Events/ReportTargetControllerState.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Event.hpp"
|
||||
|
||||
namespace Bloom::Events
|
||||
{
|
||||
class ReportTargetControllerState: public Event
|
||||
{
|
||||
public:
|
||||
ReportTargetControllerState() {};
|
||||
|
||||
static inline const std::string name = "ReportTargetControllerState";
|
||||
|
||||
std::string getName() const override {
|
||||
return ReportTargetControllerState::name;
|
||||
}
|
||||
};
|
||||
}
|
||||
23
src/EventManager/Events/TargetControllerStateReported.hpp
Normal file
23
src/EventManager/Events/TargetControllerStateReported.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Event.hpp"
|
||||
#include "src/TargetController/TargetControllerState.hpp"
|
||||
|
||||
namespace Bloom::Events
|
||||
{
|
||||
class TargetControllerStateReported: public Event
|
||||
{
|
||||
public:
|
||||
TargetControllerState state;
|
||||
|
||||
TargetControllerStateReported(TargetControllerState state): state(state) {};
|
||||
|
||||
static inline const std::string name = "TargetControllerStateReported";
|
||||
|
||||
std::string getName() const override {
|
||||
return TargetControllerStateReported::name;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user