Moved away from shared pointers in event handlers - didn't make sense to expose the event management implementation to handlers.

Also some other bits of tidying.
This commit is contained in:
Nav
2021-06-22 03:06:20 +01:00
parent 139e880646
commit a7df862d36
19 changed files with 193 additions and 212 deletions

View File

@@ -323,20 +323,20 @@ void Application::stopDebugServer() {
} }
} }
void Application::onTargetControllerThreadStateChanged(EventPointer<Events::TargetControllerThreadStateChanged> event) { void Application::onTargetControllerThreadStateChanged(EventRef<Events::TargetControllerThreadStateChanged> event) {
if (event->getState() == ThreadState::STOPPED || event->getState() == ThreadState::SHUTDOWN_INITIATED) { if (event.getState() == ThreadState::STOPPED || event.getState() == ThreadState::SHUTDOWN_INITIATED) {
// TargetController has unexpectedly shutdown - it must have encountered a fatal error. // TargetController has unexpectedly shutdown - it must have encountered a fatal error.
this->shutdown(); this->shutdown();
} }
} }
void Application::onShutdownApplicationRequest(EventPointer<Events::ShutdownApplication>) { void Application::onShutdownApplicationRequest(EventRef<Events::ShutdownApplication>) {
Logger::debug("ShutdownApplication event received."); Logger::debug("ShutdownApplication event received.");
this->shutdown(); this->shutdown();
} }
void Application::onDebugServerThreadStateChanged(EventPointer<Events::DebugServerThreadStateChanged> event) { void Application::onDebugServerThreadStateChanged(EventRef<Events::DebugServerThreadStateChanged> event) {
if (event->getState() == ThreadState::STOPPED || event->getState() == ThreadState::SHUTDOWN_INITIATED) { if (event.getState() == ThreadState::STOPPED || event.getState() == ThreadState::SHUTDOWN_INITIATED) {
// DebugServer has unexpectedly shutdown - it must have encountered a fatal error. // DebugServer has unexpectedly shutdown - it must have encountered a fatal error.
this->shutdown(); this->shutdown();
} }

View File

@@ -233,7 +233,7 @@ namespace Bloom
* *
* @param event * @param event
*/ */
void onTargetControllerThreadStateChanged(Events::EventPointer<Events::TargetControllerThreadStateChanged> event); void onTargetControllerThreadStateChanged(Events::EventRef<Events::TargetControllerThreadStateChanged> event);
/** /**
* Same goes for the DebugServer - it should never shutdown unless a shutdown request was issued. If it does, * Same goes for the DebugServer - it should never shutdown unless a shutdown request was issued. If it does,
@@ -241,12 +241,12 @@ namespace Bloom
* *
* @param event * @param event
*/ */
void onDebugServerThreadStateChanged(Events::EventPointer<Events::DebugServerThreadStateChanged> event); void onDebugServerThreadStateChanged(Events::EventRef<Events::DebugServerThreadStateChanged> event);
/** /**
* Triggers a shutdown of Bloom and all of its components. * Triggers a shutdown of Bloom and all of its components.
*/ */
void onShutdownApplicationRequest(Events::EventPointer<Events::ShutdownApplication>); void onShutdownApplicationRequest(Events::EventRef<Events::ShutdownApplication>);
/** /**
* Checks if the current effective user running Bloom has root privileges. * Checks if the current effective user running Bloom has root privileges.

View File

@@ -55,6 +55,6 @@ void DebugServer::shutdown() {
this->eventManager.deregisterListener(this->eventListener->getId()); this->eventManager.deregisterListener(this->eventListener->getId());
} }
void DebugServer::onShutdownDebugServerEvent(EventPointer<Events::ShutdownDebugServer> event) { void DebugServer::onShutdownDebugServerEvent(EventRef<Events::ShutdownDebugServer> event) {
this->shutdown(); this->shutdown();
} }

View File

@@ -59,7 +59,7 @@ namespace Bloom::DebugServers
* *
* @param event * @param event
*/ */
void onShutdownDebugServerEvent(Events::EventPointer<Events::ShutdownDebugServer> event); void onShutdownDebugServerEvent(Events::EventRef<Events::ShutdownDebugServer> event);
protected: protected:
/** /**

View File

@@ -201,8 +201,8 @@ void GdbRspDebugServer::waitForConnection() {
} }
} }
void GdbRspDebugServer::onTargetControllerStateReported(Events::EventPointer<Events::TargetControllerStateReported> event) { void GdbRspDebugServer::onTargetControllerStateReported(Events::EventRef<Events::TargetControllerStateReported> event) {
if (event->state == TargetControllerState::SUSPENDED && this->clientConnection.has_value()) { if (event.state == TargetControllerState::SUSPENDED && this->clientConnection.has_value()) {
Logger::warning("Terminating debug session - TargetController suspended unexpectedly"); Logger::warning("Terminating debug session - TargetController suspended unexpectedly");
this->closeClientConnection(); this->closeClientConnection();
} }
@@ -232,7 +232,7 @@ void GdbRspDebugServer::handleGdbPacket(CommandPacket& packet) {
} }
} }
void GdbRspDebugServer::onTargetExecutionStopped(EventPointer<Events::TargetExecutionStopped>) { void GdbRspDebugServer::onTargetExecutionStopped(EventRef<Events::TargetExecutionStopped>) {
if (this->clientConnection.has_value() && this->clientConnection->waitingForBreak) { if (this->clientConnection.has_value() && this->clientConnection->waitingForBreak) {
this->clientConnection->writePacket(TargetStopped(Signal::TRAP)); this->clientConnection->writePacket(TargetStopped(Signal::TRAP));
this->clientConnection->waitingForBreak = false; this->clientConnection->waitingForBreak = false;
@@ -243,7 +243,8 @@ void GdbRspDebugServer::handleGdbPacket(CommandPackets::SupportedFeaturesQuery&
Logger::debug("Handling QuerySupport packet"); Logger::debug("Handling QuerySupport packet");
if (!packet.isFeatureSupported(Feature::HARDWARE_BREAKPOINTS) if (!packet.isFeatureSupported(Feature::HARDWARE_BREAKPOINTS)
&& !packet.isFeatureSupported(Feature::SOFTWARE_BREAKPOINTS)) { && !packet.isFeatureSupported(Feature::SOFTWARE_BREAKPOINTS)
) {
// All GDB clients are expected to support breakpoints! // All GDB clients are expected to support breakpoints!
throw ClientNotSupported("GDB client does not support HW or SW breakpoints"); throw ClientNotSupported("GDB client does not support HW or SW breakpoints");
} }

View File

@@ -163,19 +163,19 @@ namespace Bloom::DebugServers::Gdb
} }
public: public:
GdbRspDebugServer(EventManager& eventManager): DebugServer(eventManager) {}; explicit GdbRspDebugServer(EventManager& eventManager): DebugServer(eventManager) {};
std::string getName() const override { std::string getName() const override {
return "GDB Remote Serial Protocol DebugServer"; return "GDB Remote Serial Protocol DebugServer";
}; };
void onTargetControllerStateReported(Events::EventPointer<Events::TargetControllerStateReported> event); void onTargetControllerStateReported(Events::EventRef<Events::TargetControllerStateReported> event);
/** /**
* If the GDB client is currently waiting for the target execution to stop, this event handler will issue * If the GDB client is currently waiting for the target execution to stop, this event handler will issue
* a "stop reply" packet to the client once the target execution stops. * a "stop reply" packet to the client once the target execution stops.
*/ */
void onTargetExecutionStopped(Events::EventPointer<Events::TargetExecutionStopped>); void onTargetExecutionStopped(Events::EventRef<Events::TargetExecutionStopped>);
/** /**
* Handles any other GDB command packet that has not been promoted to a more specific type. * Handles any other GDB command packet that has not been promoted to a more specific type.

View File

@@ -18,7 +18,7 @@ void AtmelIce::init() {
if (!usbHidInterface.isInitialised()) { if (!usbHidInterface.isInitialised()) {
usbHidInterface.detachKernelDriver(); usbHidInterface.detachKernelDriver();
UsbDevice::setConfiguration(0); this->setConfiguration(0);
usbHidInterface.init(); usbHidInterface.init();
} }

View File

@@ -12,23 +12,14 @@ void EventListener::clearAllCallbacks() {
this->eventTypeToCallbacksMapping.getReference().clear(); this->eventTypeToCallbacksMapping.getReference().clear();
} }
void EventListener::registerEvent(GenericEventPointer event) { void EventListener::registerEvent(SharedGenericEventPointer event) {
auto eventName = event->getName(); auto eventType = event->getName();
Logger::debug("Event \"" + eventName + "\" (" + std::to_string(event->id) Logger::debug("Event \"" + eventType + "\" (" + std::to_string(event->id)
+ ") registered for listener " + this->name); + ") registered for listener " + this->name);
auto queueLock = this->eventQueueByEventType.acquireLock(); auto queueLock = this->eventQueueByEventType.acquireLock();
auto& eventQueueByType = this->eventQueueByEventType.getReference(); auto& eventQueueByType = this->eventQueueByEventType.getReference();
if (!eventQueueByType.contains(eventName)) { eventQueueByType[eventType].push(std::move(event));
eventQueueByType.insert(
std::pair<std::string, std::queue<GenericEventPointer>>(
eventName,
std::queue<GenericEventPointer>()
)
);
}
eventQueueByType[eventName].push(event);
this->eventQueueByEventTypeCV.notify_all(); this->eventQueueByEventTypeCV.notify_all();
if (this->interruptEventNotifier != nullptr && this->interruptEventNotifier->isInitialised()) { if (this->interruptEventNotifier != nullptr && this->interruptEventNotifier->isInitialised()) {
@@ -36,26 +27,26 @@ void EventListener::registerEvent(GenericEventPointer event) {
} }
} }
std::vector<GenericEventPointer> EventListener::getEvents() { std::vector<SharedGenericEventPointer> EventListener::getEvents() {
auto queueLock = this->eventQueueByEventType.acquireLock(); auto queueLock = this->eventQueueByEventType.acquireLock();
auto& eventQueueByType = this->eventQueueByEventType.getReference(); auto& eventQueueByType = this->eventQueueByEventType.getReference();
std::vector<GenericEventPointer> output; std::vector<SharedGenericEventPointer> output;
for (auto& eventQueue: eventQueueByType) { for (auto& eventQueue: eventQueueByType) {
if (eventQueue.second.size() > 0) { if (!eventQueue.second.empty()) {
output.push_back(eventQueue.second.front()); output.push_back(std::move(eventQueue.second.front()));
eventQueue.second.pop(); eventQueue.second.pop();
} }
} }
std::sort(output.begin(), output.end(), [](GenericEventPointer a, GenericEventPointer b) { std::sort(output.begin(), output.end(), [](const SharedGenericEventPointer& a, const SharedGenericEventPointer& b) {
return a->id < b->id; return a->id < b->id;
}); });
return output; return output;
} }
void EventListener::dispatchEvent(GenericEventPointer event) { void EventListener::dispatchEvent(const SharedGenericEventPointer& event) {
auto eventName = event->getName(); auto eventName = event->getName();
Logger::debug("Dispatching event " + eventName + " (" + std::to_string(event->id) + ")."); Logger::debug("Dispatching event " + eventName + " (" + std::to_string(event->id) + ").");
// Dispatch the event to all registered handlers // Dispatch the event to all registered handlers
@@ -64,7 +55,7 @@ void EventListener::dispatchEvent(GenericEventPointer event) {
mappingLock.unlock(); mappingLock.unlock();
for (auto& callback : callbacks) { for (auto& callback : callbacks) {
callback(event); callback(*(event.get()));
} }
} }
@@ -80,12 +71,12 @@ void EventListener::waitAndDispatch(int msTimeout) {
auto queueLock = this->eventQueueByEventType.acquireLock(); auto queueLock = this->eventQueueByEventType.acquireLock();
auto& eventQueueByType = this->eventQueueByEventType.getReference(); auto& eventQueueByType = this->eventQueueByEventType.getReference();
auto registeredEventTypes = this->getRegisteredEventTypeNames(); auto registeredEventTypes = this->getRegisteredEventTypeNames();
std::optional<GenericEventPointer> event; std::optional<SharedGenericEventPointer> event;
auto eventsFound = [&registeredEventTypes, &event, &eventQueueByType]() -> bool { auto eventsFound = [&registeredEventTypes, &event, &eventQueueByType]() -> bool {
for (auto& eventQueue: eventQueueByType) { for (auto& eventQueue: eventQueueByType) {
if (registeredEventTypes.find(eventQueue.first) != registeredEventTypes.end() if (registeredEventTypes.find(eventQueue.first) != registeredEventTypes.end()
&& eventQueue.second.size() > 0 && !eventQueue.second.empty()
) { ) {
return true; return true;
} }

View File

@@ -5,6 +5,7 @@
#include <functional> #include <functional>
#include <queue> #include <queue>
#include <memory> #include <memory>
#include <utility>
#include <variant> #include <variant>
#include <optional> #include <optional>
#include <mutex> #include <mutex>
@@ -50,7 +51,7 @@ namespace Bloom
std::string name; std::string name;
static inline std::atomic<std::size_t> lastId = 0; static inline std::atomic<std::size_t> lastId = 0;
std::size_t id = ++(this->lastId); std::size_t id = ++(EventListener::lastId);
/** /**
* Holds all events registered to this listener. * Holds all events registered to this listener.
@@ -58,26 +59,26 @@ namespace Bloom
* Events are grouped by event type name, and removed from their queue just *before* the dispatching to * Events are grouped by event type name, and removed from their queue just *before* the dispatching to
* registered handlers begins. * registered handlers begins.
*/ */
SyncSafe<std::map<std::string, std::queue<Events::GenericEventPointer>>> eventQueueByEventType; SyncSafe<std::map<std::string, std::queue<Events::SharedGenericEventPointer>>> eventQueueByEventType;
std::condition_variable eventQueueByEventTypeCV; std::condition_variable eventQueueByEventTypeCV;
/** /**
* A mapping of event type names to a vector of callback functions. Events will be dispatched to these * A mapping of event type names to a vector of callback functions. Events will be dispatched to these
* callback functions, during a call to EventListener::dispatchEvent(). * callback functions, during a call to EventListener::dispatchEvent().
* *
* Each callback will be passed an std::shared_ptr<const EventType> of the event (we wrap all registered * Each callback will be passed a reference to the event (we wrap all registered callbacks in a lambda, where
* callbacks in a lambda, where we perform a downcast before invoking the callback. * we perform a downcast before invoking the callback. See EventListener::registerCallbackForEventType()
* See EventListener::registerCallbackForEventType() for more) * for more)
*/ */
SyncSafe<std::map<std::string, std::vector<std::function<void(Events::GenericEventPointer)>>>> eventTypeToCallbacksMapping; SyncSafe<std::map<std::string, std::vector<std::function<void(Events::GenericEventRef)>>>> eventTypeToCallbacksMapping;
SyncSafe<std::set<std::string>> registeredEventTypes; SyncSafe<std::set<std::string>> registeredEventTypes;
std::shared_ptr<EventNotifier> interruptEventNotifier = nullptr; std::shared_ptr<EventNotifier> interruptEventNotifier = nullptr;
std::vector<Events::GenericEventPointer> getEvents(); std::vector<Events::SharedGenericEventPointer> getEvents();
public: public:
explicit EventListener(const std::string& name): name(name) {}; explicit EventListener(std::string name): name(std::move(name)) {};
std::size_t getId() const { std::size_t getId() const {
return this->id; return this->id;
@@ -95,10 +96,10 @@ namespace Bloom
* *
* @param event * @param event
*/ */
void registerEvent(Events::GenericEventPointer event); void registerEvent(Events::SharedGenericEventPointer event);
void setInterruptEventNotifier(std::shared_ptr<EventNotifier> interruptEventNotifier) { void setInterruptEventNotifier(std::shared_ptr<EventNotifier> interruptEventNotifier) {
this->interruptEventNotifier = interruptEventNotifier; this->interruptEventNotifier = std::move(interruptEventNotifier);
} }
/** /**
@@ -109,33 +110,18 @@ namespace Bloom
* @param callback * @param callback
*/ */
template<class EventType> template<class EventType>
void registerCallbackForEventType(std::function<void(std::shared_ptr<const EventType>)> callback) { void registerCallbackForEventType(std::function<void(Events::EventRef<EventType>)> callback) {
// We encapsulate the callback in a lambda to handle the downcasting. // We encapsulate the callback in a lambda to handle the downcasting.
std::function<void(Events::GenericEventPointer)> parentCallback = std::function<void(Events::GenericEventRef)> parentCallback =
[callback] (Events::GenericEventPointer event) { [callback] (Events::GenericEventRef event) {
// Downcast the event to the expected type // Downcast the event to the expected type
callback(std::dynamic_pointer_cast<const EventType>(event)); callback(dynamic_cast<Events::EventRef<EventType>>(event));
} }
; ;
auto mappingLock = this->eventTypeToCallbacksMapping.acquireLock(); auto mappingLock = this->eventTypeToCallbacksMapping.acquireLock();
auto& mapping = this->eventTypeToCallbacksMapping.getReference(); auto& mapping = this->eventTypeToCallbacksMapping.getReference();
if (mapping.find(EventType::name) == mapping.end()) {
/*
* Multiple callbacks can be registered for a single event type.
*
* We have no callbacks for this event type registered in this listener, so setup
* the type name to callback vector mapping.
*/
mapping.insert(
std::pair<std::string, std::vector<std::function<void(Events::GenericEventPointer)>>>(
EventType::name,
std::vector<std::function<void(Events::GenericEventPointer)>>()
)
);
}
mapping[EventType::name].push_back(parentCallback); mapping[EventType::name].push_back(parentCallback);
auto registeredEventTypesLock = this->registeredEventTypes.acquireLock(); auto registeredEventTypesLock = this->registeredEventTypes.acquireLock();
this->registeredEventTypes.getReference().insert(EventType::name); this->registeredEventTypes.getReference().insert(EventType::name);
@@ -201,20 +187,20 @@ namespace Bloom
std::optional<int> correlationId = std::nullopt std::optional<int> correlationId = std::nullopt
) { ) {
// Different return types, depending on how many event type arguments are passed in. // Different return types, depending on how many event type arguments are passed in.
using MonoType = std::optional<Events::EventPointer<EventTypeA>>; using MonoType = std::optional<Events::SharedEventPointer<EventTypeA>>;
using BiVariantType = std::optional< using BiVariantType = std::optional<
std::variant< std::variant<
std::monostate, std::monostate,
Events::EventPointer<EventTypeA>, Events::SharedEventPointer<EventTypeA>,
Events::EventPointer<EventTypeB> Events::SharedEventPointer<EventTypeB>
> >
>; >;
using TriVariantType = std::optional< using TriVariantType = std::optional<
std::variant< std::variant<
std::monostate, std::monostate,
Events::EventPointer<EventTypeA>, Events::SharedEventPointer<EventTypeA>,
Events::EventPointer<EventTypeB>, Events::SharedEventPointer<EventTypeB>,
Events::EventPointer<EventTypeC> Events::SharedEventPointer<EventTypeC>
> >
>; >;
using ReturnType = typename std::conditional< using ReturnType = typename std::conditional<
@@ -262,14 +248,14 @@ namespace Bloom
} }
} }
Events::GenericEventPointer foundEvent = nullptr; Events::SharedGenericEventPointer foundEvent = nullptr;
auto eventsFound = [&eventTypeNames, &eventQueueByType, &correlationId, &foundEvent]() -> bool { auto eventsFound = [&eventTypeNames, &eventQueueByType, &correlationId, &foundEvent]() -> bool {
for (const auto& eventTypeName : eventTypeNames) { for (const auto& eventTypeName : eventTypeNames) {
if (eventQueueByType.find(eventTypeName) != eventQueueByType.end() if (eventQueueByType.find(eventTypeName) != eventQueueByType.end()
&& eventQueueByType.find(eventTypeName)->second.size() > 0 && !eventQueueByType.find(eventTypeName)->second.empty()
) { ) {
auto& queue = eventQueueByType.find(eventTypeName)->second; auto& queue = eventQueueByType.find(eventTypeName)->second;
while (queue.size() > 0) { while (!queue.empty()) {
auto event = queue.front(); auto event = queue.front();
if (!correlationId.has_value() if (!correlationId.has_value()
@@ -347,7 +333,7 @@ namespace Bloom
*/ */
void waitAndDispatch(int msTimeout = 0); void waitAndDispatch(int msTimeout = 0);
void dispatchEvent(Events::GenericEventPointer event); void dispatchEvent(const Events::SharedGenericEventPointer& event);
void dispatchCurrentEvents(); void dispatchCurrentEvents();

View File

@@ -53,7 +53,7 @@ namespace Bloom
* *
* @param event * @param event
*/ */
void triggerEvent(Events::GenericEventPointer event); void triggerEvent(Events::SharedGenericEventPointer event);
}; };
} }

View File

@@ -14,21 +14,17 @@ namespace Bloom::Events
class Event class Event
{ {
private: private:
QDateTime createdTimestamp = DateTime::currentDateTime();
static inline std::atomic<int> lastEventId = 0; static inline std::atomic<int> lastEventId = 0;
public: public:
int id = ++(this->lastEventId); int id = ++(Event::lastEventId);
QDateTime createdTimestamp = DateTime::currentDateTime();
std::optional<int> correlationId; std::optional<int> correlationId;
static inline const std::string name = "GenericEvent"; static inline const std::string name = "GenericEvent";
virtual std::string getName() const { [[nodiscard]] virtual std::string getName() const {
return Event::name; return Event::name;
} }
long getCreatedEpochTimestamp() const {
return this->createdTimestamp.toMSecsSinceEpoch();
}
}; };
} }

View File

@@ -44,7 +44,11 @@
namespace Bloom::Events namespace Bloom::Events
{ {
template <class EventType> template <class EventType>
using EventPointer = std::shared_ptr<const EventType>; using SharedEventPointer = std::shared_ptr<const EventType>;
using GenericEventPointer = EventPointer<Event>; template <class EventType>
using EventRef = const EventType&;
using SharedGenericEventPointer = SharedEventPointer<Event>;
using GenericEventRef = EventRef<Event>;
} }

View File

@@ -119,7 +119,7 @@ void Insight::shutdown() {
this->setThreadState(ThreadState::STOPPED); this->setThreadState(ThreadState::STOPPED);
} }
void Insight::onShutdownApplicationEvent(EventPointer<ShutdownApplication>) { void Insight::onShutdownApplicationEvent(EventRef<ShutdownApplication>) {
/* /*
* Once Insight shuts down, control of the main thread will be returned to Application::run(), which * Once Insight shuts down, control of the main thread will be returned to Application::run(), which
* will pickup the ShutdownApplication event and proceed with the shutdown. * will pickup the ShutdownApplication event and proceed with the shutdown.
@@ -127,8 +127,8 @@ void Insight::onShutdownApplicationEvent(EventPointer<ShutdownApplication>) {
this->shutdown(); this->shutdown();
} }
void Insight::onTargetControllerThreadStateChangedEvent(EventPointer<TargetControllerThreadStateChanged> event) { void Insight::onTargetControllerThreadStateChangedEvent(EventRef<TargetControllerThreadStateChanged> event) {
if (event->getState() == ThreadState::STOPPED) { if (event.getState() == ThreadState::STOPPED) {
// Something horrible has happened with the TargetController - Insight is useless without the TargetController // Something horrible has happened with the TargetController - Insight is useless without the TargetController
this->shutdown(); this->shutdown();
} }

View File

@@ -81,7 +81,7 @@ namespace Bloom
* *
* @param event * @param event
*/ */
void onShutdownApplicationEvent(Events::EventPointer<Events::ShutdownApplication> event); void onShutdownApplicationEvent(Events::EventRef<Events::ShutdownApplication> event);
/** /**
* If the something horrible was to happen and the TC dies unexpectedly, Insight will shutdown in response. * If the something horrible was to happen and the TC dies unexpectedly, Insight will shutdown in response.
@@ -89,7 +89,7 @@ namespace Bloom
* @param event * @param event
*/ */
void onTargetControllerThreadStateChangedEvent( void onTargetControllerThreadStateChangedEvent(
Events::EventPointer<Events::TargetControllerThreadStateChanged> event Events::EventRef<Events::TargetControllerThreadStateChanged> event
); );
/** /**

View File

@@ -60,7 +60,7 @@ void InsightWorker::requestPinStateUpdate(
this->targetControllerConsole.setPinState(variantId, pinDescriptor, pinState); this->targetControllerConsole.setPinState(variantId, pinDescriptor, pinState);
} }
void InsightWorker::onTargetStoppedEvent(EventPointer<TargetExecutionStopped> event) { void InsightWorker::onTargetStoppedEvent(EventRef<TargetExecutionStopped> event) {
/* /*
* When we report a target halt to Insight, Insight will immediately seek more data from the target (such as GPIO * When we report a target halt to Insight, Insight will immediately seek more data from the target (such as GPIO
* pin states). This can be problematic for cases where the target had halted due to a conditional breakpoint. * pin states). This can be problematic for cases where the target had halted due to a conditional breakpoint.
@@ -88,30 +88,30 @@ void InsightWorker::onTargetStoppedEvent(EventPointer<TargetExecutionStopped> ev
if (!resumedEvent.has_value()) { if (!resumedEvent.has_value()) {
emit this->targetStateUpdated(TargetState::STOPPED); emit this->targetStateUpdated(TargetState::STOPPED);
emit this->targetProgramCounterUpdated(event->programCounter); emit this->targetProgramCounterUpdated(event.programCounter);
} }
} }
void InsightWorker::onTargetResumedEvent(EventPointer<TargetExecutionResumed> event) { void InsightWorker::onTargetResumedEvent(EventRef<TargetExecutionResumed> event) {
emit this->targetStateUpdated(TargetState::RUNNING); emit this->targetStateUpdated(TargetState::RUNNING);
} }
void InsightWorker::onTargetPinStatesRetrievedEvent(EventPointer<TargetPinStatesRetrieved> event) { void InsightWorker::onTargetPinStatesRetrievedEvent(EventRef<TargetPinStatesRetrieved> event) {
emit this->targetPinStatesUpdated(event->variantId, event->pinSatesByNumber); emit this->targetPinStatesUpdated(event.variantId, event.pinSatesByNumber);
} }
void InsightWorker::onTargetIoPortsUpdatedEvent(EventPointer<TargetIoPortsUpdated> event) { void InsightWorker::onTargetIoPortsUpdatedEvent(EventRef<TargetIoPortsUpdated> event) {
emit this->targetIoPortsUpdated(); emit this->targetIoPortsUpdated();
} }
void InsightWorker::onTargetControllerStateReported(EventPointer<TargetControllerStateReported> event) { void InsightWorker::onTargetControllerStateReported(EventRef<TargetControllerStateReported> event) {
if (this->lastTargetControllerState == TargetControllerState::ACTIVE if (this->lastTargetControllerState == TargetControllerState::ACTIVE
&& event->state == TargetControllerState::SUSPENDED && event.state == TargetControllerState::SUSPENDED
) { ) {
emit this->targetControllerSuspended(); emit this->targetControllerSuspended();
} else if (this->lastTargetControllerState == TargetControllerState::SUSPENDED } else if (this->lastTargetControllerState == TargetControllerState::SUSPENDED
&& event->state == TargetControllerState::ACTIVE && event.state == TargetControllerState::ACTIVE
) { ) {
try { try {
emit this->targetControllerResumed(this->targetControllerConsole.getTargetDescriptor()); emit this->targetControllerResumed(this->targetControllerConsole.getTargetDescriptor());
@@ -120,5 +120,5 @@ void InsightWorker::onTargetControllerStateReported(EventPointer<TargetControlle
Logger::error("Insight resume failed - " + exception.getMessage()); Logger::error("Insight resume failed - " + exception.getMessage());
} }
} }
this->lastTargetControllerState = event->state; this->lastTargetControllerState = event.state;
} }

View File

@@ -33,11 +33,11 @@ namespace Bloom
QTimer* eventDispatchTimer = nullptr; QTimer* eventDispatchTimer = nullptr;
void onTargetStoppedEvent(Events::EventPointer<Events::TargetExecutionStopped> event); void onTargetStoppedEvent(Events::EventRef<Events::TargetExecutionStopped> event);
void onTargetResumedEvent(Events::EventPointer<Events::TargetExecutionResumed> event); void onTargetResumedEvent(Events::EventRef<Events::TargetExecutionResumed> event);
void onTargetPinStatesRetrievedEvent(Events::EventPointer<Events::TargetPinStatesRetrieved> event); void onTargetPinStatesRetrievedEvent(Events::EventRef<Events::TargetPinStatesRetrieved> event);
void onTargetIoPortsUpdatedEvent(Events::EventPointer<Events::TargetIoPortsUpdated> event); void onTargetIoPortsUpdatedEvent(Events::EventRef<Events::TargetIoPortsUpdated> event);
void onTargetControllerStateReported(Events::EventPointer<Events::TargetControllerStateReported> event); void onTargetControllerStateReported(Events::EventRef<Events::TargetControllerStateReported> event);
public: public:
explicit InsightWorker(EventManager& eventManager): eventManager(eventManager) {}; explicit InsightWorker(EventManager& eventManager): eventManager(eventManager) {};
@@ -62,6 +62,5 @@ namespace Bloom
void targetIoPortsUpdated(); void targetIoPortsUpdated();
void targetControllerSuspended(); void targetControllerSuspended();
void targetControllerResumed(const Bloom::Targets::TargetDescriptor& targetDescriptor); void targetControllerResumed(const Bloom::Targets::TargetDescriptor& targetDescriptor);
}; };
} }

View File

@@ -68,7 +68,7 @@ void TargetController::startup() {
this->eventManager.registerListener(this->eventListener); this->eventManager.registerListener(this->eventListener);
// Install Bloom's udev rules if not already installed // Install Bloom's udev rules if not already installed
this->checkUdevRules(); TargetController::checkUdevRules();
// Register event handlers // Register event handlers
this->eventListener->registerCallbackForEventType<Events::ReportTargetControllerState>( this->eventListener->registerCallbackForEventType<Events::ReportTargetControllerState>(
@@ -303,7 +303,7 @@ void TargetController::acquireHardware() {
break; break;
} }
this->target.reset(promotedTarget.release()); this->target = std::move(promotedTarget);
this->target->postPromotionConfigure(); this->target->postPromotionConfigure();
} }
@@ -360,17 +360,17 @@ void TargetController::emitErrorEvent(int correlationId) {
this->eventManager.triggerEvent(errorEvent); this->eventManager.triggerEvent(errorEvent);
} }
void TargetController::onShutdownTargetControllerEvent(EventPointer<Events::ShutdownTargetController>) { void TargetController::onShutdownTargetControllerEvent(EventRef<Events::ShutdownTargetController>) {
this->shutdown(); this->shutdown();
} }
void TargetController::onStateReportRequest(EventPointer<Events::ReportTargetControllerState> event) { void TargetController::onStateReportRequest(EventRef<Events::ReportTargetControllerState> event) {
auto stateEvent = std::make_shared<TargetControllerStateReported>(this->state); auto stateEvent = std::make_shared<TargetControllerStateReported>(this->state);
stateEvent->correlationId = event->id; stateEvent->correlationId = event.id;
this->eventManager.triggerEvent(stateEvent); this->eventManager.triggerEvent(stateEvent);
} }
void TargetController::onDebugSessionStartedEvent(EventPointer<Events::DebugSessionStarted>) { void TargetController::onDebugSessionStartedEvent(EventRef<Events::DebugSessionStarted>) {
if (this->state == TargetControllerState::SUSPENDED) { if (this->state == TargetControllerState::SUSPENDED) {
Logger::debug("Waking TargetController"); Logger::debug("Waking TargetController");
@@ -385,7 +385,7 @@ void TargetController::onDebugSessionStartedEvent(EventPointer<Events::DebugSess
} }
} }
void TargetController::onDebugSessionFinishedEvent(EventPointer<DebugSessionFinished>) { void TargetController::onDebugSessionFinishedEvent(EventRef<DebugSessionFinished>) {
if (this->target->getState() != TargetState::RUNNING) { if (this->target->getState() != TargetState::RUNNING) {
this->target->run(); this->target->run();
this->fireTargetEvents(); this->fireTargetEvents();
@@ -396,7 +396,7 @@ void TargetController::onDebugSessionFinishedEvent(EventPointer<DebugSessionFini
} }
} }
void TargetController::onExtractTargetDescriptor(EventPointer<Events::ExtractTargetDescriptor> event) { void TargetController::onExtractTargetDescriptor(EventRef<Events::ExtractTargetDescriptor> event) {
if (!this->cachedTargetDescriptor.has_value()) { if (!this->cachedTargetDescriptor.has_value()) {
this->cachedTargetDescriptor = this->target->getDescriptor(); this->cachedTargetDescriptor = this->target->getDescriptor();
} }
@@ -404,11 +404,11 @@ void TargetController::onExtractTargetDescriptor(EventPointer<Events::ExtractTar
auto targetDescriptorExtracted = std::make_shared<TargetDescriptorExtracted>(); auto targetDescriptorExtracted = std::make_shared<TargetDescriptorExtracted>();
targetDescriptorExtracted->targetDescriptor = this->cachedTargetDescriptor.value(); targetDescriptorExtracted->targetDescriptor = this->cachedTargetDescriptor.value();
targetDescriptorExtracted->correlationId = event->id; targetDescriptorExtracted->correlationId = event.id;
this->eventManager.triggerEvent(targetDescriptorExtracted); this->eventManager.triggerEvent(targetDescriptorExtracted);
} }
void TargetController::onStopTargetExecutionEvent(EventPointer<Events::StopTargetExecution> event) { void TargetController::onStopTargetExecutionEvent(EventRef<Events::StopTargetExecution> event) {
if (this->target->getState() != TargetState::STOPPED) { if (this->target->getState() != TargetState::STOPPED) {
this->target->stop(); this->target->stop();
this->lastTargetState = TargetState::STOPPED; this->lastTargetState = TargetState::STOPPED;
@@ -419,39 +419,39 @@ void TargetController::onStopTargetExecutionEvent(EventPointer<Events::StopTarge
TargetBreakCause::UNKNOWN TargetBreakCause::UNKNOWN
); );
executionStoppedEvent->correlationId = event->id; executionStoppedEvent->correlationId = event.id;
this->eventManager.triggerEvent(executionStoppedEvent); this->eventManager.triggerEvent(executionStoppedEvent);
} }
void TargetController::onStepTargetExecutionEvent(EventPointer<Events::StepTargetExecution> event) { void TargetController::onStepTargetExecutionEvent(EventRef<Events::StepTargetExecution> event) {
try { try {
if (this->target->getState() != TargetState::STOPPED) { if (this->target->getState() != TargetState::STOPPED) {
// We can't step the target if it's already running. // We can't step the target if it's already running.
throw Exception("Target is already running"); throw Exception("Target is already running");
} }
if (event->fromProgramCounter.has_value()) { if (event.fromProgramCounter.has_value()) {
this->target->setProgramCounter(event->fromProgramCounter.value()); this->target->setProgramCounter(event.fromProgramCounter.value());
} }
this->target->step(); this->target->step();
this->lastTargetState = TargetState::RUNNING; this->lastTargetState = TargetState::RUNNING;
auto executionResumedEvent = std::make_shared<TargetExecutionResumed>(); auto executionResumedEvent = std::make_shared<TargetExecutionResumed>();
executionResumedEvent->correlationId = event->id; executionResumedEvent->correlationId = event.id;
this->eventManager.triggerEvent(executionResumedEvent); this->eventManager.triggerEvent(executionResumedEvent);
} catch (const Exception& exception) { } catch (const Exception& exception) {
Logger::error("Failed to step execution on target - " + exception.getMessage()); Logger::error("Failed to step execution on target - " + exception.getMessage());
this->emitErrorEvent(event->id); this->emitErrorEvent(event.id);
} }
} }
void TargetController::onResumeTargetExecutionEvent(EventPointer<Events::ResumeTargetExecution> event) { void TargetController::onResumeTargetExecutionEvent(EventRef<Events::ResumeTargetExecution> event) {
try { try {
if (this->target->getState() != TargetState::RUNNING) { if (this->target->getState() != TargetState::RUNNING) {
if (event->fromProgramCounter.has_value()) { if (event.fromProgramCounter.has_value()) {
this->target->setProgramCounter(event->fromProgramCounter.value()); this->target->setProgramCounter(event.fromProgramCounter.value());
} }
this->target->run(); this->target->run();
@@ -459,72 +459,72 @@ void TargetController::onResumeTargetExecutionEvent(EventPointer<Events::ResumeT
} }
auto executionResumedEvent = std::make_shared<Events::TargetExecutionResumed>(); auto executionResumedEvent = std::make_shared<Events::TargetExecutionResumed>();
executionResumedEvent->correlationId = event->id; executionResumedEvent->correlationId = event.id;
this->eventManager.triggerEvent(executionResumedEvent); this->eventManager.triggerEvent(executionResumedEvent);
} catch (const Exception& exception) { } catch (const Exception& exception) {
Logger::error("Failed to resume execution on target - " + exception.getMessage()); Logger::error("Failed to resume execution on target - " + exception.getMessage());
this->emitErrorEvent(event->id); this->emitErrorEvent(event.id);
} }
} }
void TargetController::onReadRegistersEvent(EventPointer<Events::RetrieveRegistersFromTarget> event) { void TargetController::onReadRegistersEvent(EventRef<Events::RetrieveRegistersFromTarget> event) {
try { try {
auto registers = this->target->readRegisters(event->descriptors); auto registers = this->target->readRegisters(event.descriptors);
if (registers.size() > 0) { if (registers.size() > 0) {
auto registersRetrievedEvent = std::make_shared<Events::RegistersRetrievedFromTarget>(); auto registersRetrievedEvent = std::make_shared<Events::RegistersRetrievedFromTarget>();
registersRetrievedEvent->correlationId = event->id; registersRetrievedEvent->correlationId = event.id;
registersRetrievedEvent->registers = registers; registersRetrievedEvent->registers = registers;
this->eventManager.triggerEvent(registersRetrievedEvent); this->eventManager.triggerEvent(registersRetrievedEvent);
} }
} catch (const Exception& exception) { } catch (const Exception& exception) {
Logger::error("Failed to read general registers from target - " + exception.getMessage()); Logger::error("Failed to read general registers from target - " + exception.getMessage());
this->emitErrorEvent(event->id); this->emitErrorEvent(event.id);
} }
} }
void TargetController::onWriteRegistersEvent(EventPointer<Events::WriteRegistersToTarget> event) { void TargetController::onWriteRegistersEvent(EventRef<Events::WriteRegistersToTarget> event) {
try { try {
this->target->writeRegisters(event->registers); this->target->writeRegisters(event.registers);
auto registersWrittenEvent = std::make_shared<Events::RegistersWrittenToTarget>(); auto registersWrittenEvent = std::make_shared<Events::RegistersWrittenToTarget>();
registersWrittenEvent->correlationId = event->id; registersWrittenEvent->correlationId = event.id;
this->eventManager.triggerEvent(registersWrittenEvent); this->eventManager.triggerEvent(registersWrittenEvent);
} catch (const Exception& exception) { } catch (const Exception& exception) {
Logger::error("Failed to write registers to target - " + exception.getMessage()); Logger::error("Failed to write registers to target - " + exception.getMessage());
this->emitErrorEvent(event->id); this->emitErrorEvent(event.id);
} }
} }
void TargetController::onReadMemoryEvent(EventPointer<Events::RetrieveMemoryFromTarget> event) { void TargetController::onReadMemoryEvent(EventRef<Events::RetrieveMemoryFromTarget> event) {
try { try {
auto memoryReadEvent = std::make_shared<Events::MemoryRetrievedFromTarget>(); auto memoryReadEvent = std::make_shared<Events::MemoryRetrievedFromTarget>();
memoryReadEvent->correlationId = event->id; memoryReadEvent->correlationId = event.id;
memoryReadEvent->data = this->target->readMemory(event->memoryType, event->startAddress, event->bytes); memoryReadEvent->data = this->target->readMemory(event.memoryType, event.startAddress, event.bytes);
this->eventManager.triggerEvent(memoryReadEvent); this->eventManager.triggerEvent(memoryReadEvent);
} catch (const Exception& exception) { } catch (const Exception& exception) {
Logger::error("Failed to read memory from target - " + exception.getMessage()); Logger::error("Failed to read memory from target - " + exception.getMessage());
this->emitErrorEvent(event->id); this->emitErrorEvent(event.id);
} }
} }
void TargetController::onWriteMemoryEvent(EventPointer<Events::WriteMemoryToTarget> event) { void TargetController::onWriteMemoryEvent(EventRef<Events::WriteMemoryToTarget> event) {
try { try {
this->target->writeMemory(event->memoryType, event->startAddress, event->buffer); this->target->writeMemory(event.memoryType, event.startAddress, event.buffer);
auto memoryWrittenEvent = std::make_shared<Events::MemoryWrittenToTarget>(); auto memoryWrittenEvent = std::make_shared<Events::MemoryWrittenToTarget>();
memoryWrittenEvent->correlationId = event->id; memoryWrittenEvent->correlationId = event.id;
this->eventManager.triggerEvent(memoryWrittenEvent); this->eventManager.triggerEvent(memoryWrittenEvent);
if (this->target->memoryAddressRangeClashesWithIoPortRegisters( if (this->target->memoryAddressRangeClashesWithIoPortRegisters(
event->memoryType, event.memoryType,
event->startAddress, event.startAddress,
static_cast<std::uint32_t>(event->startAddress + (event->buffer.size() - 1)) static_cast<std::uint32_t>(event.startAddress + (event.buffer.size() - 1))
)) { )) {
// This memory write has affected the target's IO port values // This memory write has affected the target's IO port values
this->eventManager.triggerEvent(std::make_shared<Events::TargetIoPortsUpdated>()); this->eventManager.triggerEvent(std::make_shared<Events::TargetIoPortsUpdated>());
@@ -532,59 +532,59 @@ void TargetController::onWriteMemoryEvent(EventPointer<Events::WriteMemoryToTarg
} catch (const Exception& exception) { } catch (const Exception& exception) {
Logger::error("Failed to write memory to target - " + exception.getMessage()); Logger::error("Failed to write memory to target - " + exception.getMessage());
this->emitErrorEvent(event->id); this->emitErrorEvent(event.id);
} }
} }
void TargetController::onSetBreakpointEvent(EventPointer<Events::SetBreakpointOnTarget> event) { void TargetController::onSetBreakpointEvent(EventRef<Events::SetBreakpointOnTarget> event) {
try { try {
this->target->setBreakpoint(event->breakpoint.address); this->target->setBreakpoint(event.breakpoint.address);
auto breakpointSetEvent = std::make_shared<Events::BreakpointSetOnTarget>(); auto breakpointSetEvent = std::make_shared<Events::BreakpointSetOnTarget>();
breakpointSetEvent->correlationId = event->id; breakpointSetEvent->correlationId = event.id;
this->eventManager.triggerEvent(breakpointSetEvent); this->eventManager.triggerEvent(breakpointSetEvent);
} catch (const Exception& exception) { } catch (const Exception& exception) {
Logger::error("Failed to set breakpoint on target - " + exception.getMessage()); Logger::error("Failed to set breakpoint on target - " + exception.getMessage());
this->emitErrorEvent(event->id); this->emitErrorEvent(event.id);
} }
} }
void TargetController::onRemoveBreakpointEvent(EventPointer<Events::RemoveBreakpointOnTarget> event) { void TargetController::onRemoveBreakpointEvent(EventRef<Events::RemoveBreakpointOnTarget> event) {
try { try {
this->target->removeBreakpoint(event->breakpoint.address); this->target->removeBreakpoint(event.breakpoint.address);
auto breakpointRemovedEvent = std::make_shared<Events::BreakpointRemovedOnTarget>(); auto breakpointRemovedEvent = std::make_shared<Events::BreakpointRemovedOnTarget>();
breakpointRemovedEvent->correlationId = event->id; breakpointRemovedEvent->correlationId = event.id;
this->eventManager.triggerEvent(breakpointRemovedEvent); this->eventManager.triggerEvent(breakpointRemovedEvent);
} catch (const Exception& exception) { } catch (const Exception& exception) {
Logger::error("Failed to remove breakpoint on target - " + exception.getMessage()); Logger::error("Failed to remove breakpoint on target - " + exception.getMessage());
this->emitErrorEvent(event->id); this->emitErrorEvent(event.id);
} }
} }
void TargetController::onSetProgramCounterEvent(EventPointer<Events::SetProgramCounterOnTarget> event) { void TargetController::onSetProgramCounterEvent(EventRef<Events::SetProgramCounterOnTarget> event) {
try { try {
if (this->target->getState() != TargetState::STOPPED) { if (this->target->getState() != TargetState::STOPPED) {
throw Exception("Invalid target state - target must be stopped before the program counter can be updated"); throw Exception("Invalid target state - target must be stopped before the program counter can be updated");
} }
this->target->setProgramCounter(event->address); this->target->setProgramCounter(event.address);
auto programCounterSetEvent = std::make_shared<Events::ProgramCounterSetOnTarget>(); auto programCounterSetEvent = std::make_shared<Events::ProgramCounterSetOnTarget>();
programCounterSetEvent->correlationId = event->id; programCounterSetEvent->correlationId = event.id;
this->eventManager.triggerEvent(programCounterSetEvent); this->eventManager.triggerEvent(programCounterSetEvent);
} catch (const Exception& exception) { } catch (const Exception& exception) {
Logger::error("Failed to set program counter on target - " + exception.getMessage()); Logger::error("Failed to set program counter on target - " + exception.getMessage());
this->emitErrorEvent(event->id); this->emitErrorEvent(event.id);
} }
} }
// TODO: remove this // TODO: remove this
void TargetController::onInsightStateChangedEvent(EventPointer<Events::InsightThreadStateChanged> event) { void TargetController::onInsightStateChangedEvent(EventRef<Events::InsightThreadStateChanged> event) {
if (event->getState() == ThreadState::READY) { if (event.getState() == ThreadState::READY) {
/* /*
* Insight has just started up. * Insight has just started up.
* *
@@ -595,45 +595,45 @@ void TargetController::onInsightStateChangedEvent(EventPointer<Events::InsightTh
} }
} }
void TargetController::onRetrieveTargetPinStatesEvent(EventPointer<Events::RetrieveTargetPinStates> event) { void TargetController::onRetrieveTargetPinStatesEvent(EventRef<Events::RetrieveTargetPinStates> event) {
try { try {
if (this->target->getState() != TargetState::STOPPED) { if (this->target->getState() != TargetState::STOPPED) {
throw Exception("Invalid target state - target must be stopped before pin states can be retrieved"); throw Exception("Invalid target state - target must be stopped before pin states can be retrieved");
} }
auto pinStatesRetrieved = std::make_shared<Events::TargetPinStatesRetrieved>(); auto pinStatesRetrieved = std::make_shared<Events::TargetPinStatesRetrieved>();
pinStatesRetrieved->correlationId = event->id; pinStatesRetrieved->correlationId = event.id;
pinStatesRetrieved->variantId = event->variantId; pinStatesRetrieved->variantId = event.variantId;
pinStatesRetrieved->pinSatesByNumber = this->target->getPinStates(event->variantId); pinStatesRetrieved->pinSatesByNumber = this->target->getPinStates(event.variantId);
this->eventManager.triggerEvent(pinStatesRetrieved); this->eventManager.triggerEvent(pinStatesRetrieved);
} catch (const Exception& exception) { } catch (const Exception& exception) {
Logger::error("Failed to retrieve target pin states - " + exception.getMessage()); Logger::error("Failed to retrieve target pin states - " + exception.getMessage());
this->emitErrorEvent(event->id); this->emitErrorEvent(event.id);
} }
} }
void TargetController::onSetPinStateEvent(EventPointer<Events::SetTargetPinState> event) { void TargetController::onSetPinStateEvent(EventRef<Events::SetTargetPinState> event) {
try { try {
if (this->target->getState() != TargetState::STOPPED) { if (this->target->getState() != TargetState::STOPPED) {
throw Exception("Invalid target state - target must be stopped before pin state can be set"); throw Exception("Invalid target state - target must be stopped before pin state can be set");
} }
this->target->setPinState(event->variantId, event->pinDescriptor, event->pinState); this->target->setPinState(event.variantId, event.pinDescriptor, event.pinState);
auto pinStatesUpdateEvent = std::make_shared<Events::TargetPinStatesRetrieved>(); auto pinStatesUpdateEvent = std::make_shared<Events::TargetPinStatesRetrieved>();
pinStatesUpdateEvent->correlationId = event->id; pinStatesUpdateEvent->correlationId = event.id;
pinStatesUpdateEvent->variantId = event->variantId; pinStatesUpdateEvent->variantId = event.variantId;
pinStatesUpdateEvent->pinSatesByNumber = { pinStatesUpdateEvent->pinSatesByNumber = {
{event->pinDescriptor.number, event->pinState} {event.pinDescriptor.number, event.pinState}
}; };
this->eventManager.triggerEvent(pinStatesUpdateEvent); this->eventManager.triggerEvent(pinStatesUpdateEvent);
} catch (const Exception& exception) { } catch (const Exception& exception) {
Logger::error("Failed to set target pin state for pin " + event->pinDescriptor.name + " - " Logger::error("Failed to set target pin state for pin " + event.pinDescriptor.name + " - "
+ exception.getMessage()); + exception.getMessage());
this->emitErrorEvent(event->id); this->emitErrorEvent(event.id);
} }
} }

View File

@@ -67,7 +67,7 @@ namespace Bloom
/** /**
* Constructs a mapping of supported debug tool names to lambdas. The lambdas should *only* instantiate * Constructs a mapping of supported debug tool names to lambdas. The lambdas should *only* instantiate
* and return an instance to the derived DebugTool class. They should never attempt to establish * and return an instance to the derived DebugTool class. They should not attempt to establish
* a connection to the device. * a connection to the device.
* *
* @return * @return
@@ -173,7 +173,7 @@ namespace Bloom
* to /etc/udev/rules.d/. This method will report an error if Bloom isn't running as root (as root privileges * to /etc/udev/rules.d/. This method will report an error if Bloom isn't running as root (as root privileges
* are required for writing to files in /etc/udev). * are required for writing to files in /etc/udev).
*/ */
void checkUdevRules(); static void checkUdevRules();
/** /**
* Because the TargetController hogs the thread, this method must be called in a dedicated thread. * Because the TargetController hogs the thread, this method must be called in a dedicated thread.
@@ -244,70 +244,70 @@ namespace Bloom
* *
* @param event * @param event
*/ */
void onStateReportRequest(Events::EventPointer<Events::ReportTargetControllerState> event); void onStateReportRequest(Events::EventRef<Events::ReportTargetControllerState> event);
/** /**
* Obtains a TargetDescriptor from the target and includes it in a TargetDescriptorExtracted event. * Obtains a TargetDescriptor from the target and includes it in a TargetDescriptorExtracted event.
* *
* @param event * @param event
*/ */
void onExtractTargetDescriptor(Events::EventPointer<Events::ExtractTargetDescriptor> event); void onExtractTargetDescriptor(Events::EventRef<Events::ExtractTargetDescriptor> event);
/** /**
* Will attempt to stop execution on the target and emit a TargetExecutionStopped event. * Will attempt to stop execution on the target and emit a TargetExecutionStopped event.
* *
* @param event * @param event
*/ */
void onStopTargetExecutionEvent(Events::EventPointer<Events::StopTargetExecution> event); void onStopTargetExecutionEvent(Events::EventRef<Events::StopTargetExecution> event);
/** /**
* Will attempt to step execution on the target and emit a TargetExecutionResumed event. * Will attempt to step execution on the target and emit a TargetExecutionResumed event.
* *
* @param event * @param event
*/ */
void onStepTargetExecutionEvent(Events::EventPointer<Events::StepTargetExecution> event); void onStepTargetExecutionEvent(Events::EventRef<Events::StepTargetExecution> event);
/** /**
* Will attempt to resume execution on the target and emit a TargetExecutionResumed event. * Will attempt to resume execution on the target and emit a TargetExecutionResumed event.
* *
* @param event * @param event
*/ */
void onResumeTargetExecutionEvent(Events::EventPointer<Events::ResumeTargetExecution> event); void onResumeTargetExecutionEvent(Events::EventRef<Events::ResumeTargetExecution> event);
/** /**
* Invokes a shutdown. * Invokes a shutdown.
* *
* @param event * @param event
*/ */
void onShutdownTargetControllerEvent(Events::EventPointer<Events::ShutdownTargetController> event); void onShutdownTargetControllerEvent(Events::EventRef<Events::ShutdownTargetController> event);
/** /**
* Will attempt to read the requested registers and emit a RegistersRetrievedFromTarget event. * Will attempt to read the requested registers and emit a RegistersRetrievedFromTarget event.
* *
* @param event * @param event
*/ */
void onReadRegistersEvent(Events::EventPointer<Events::RetrieveRegistersFromTarget> event); void onReadRegistersEvent(Events::EventRef<Events::RetrieveRegistersFromTarget> event);
/** /**
* Will attempt to write the specified register values and emit a RegistersWrittenToTarget event. * Will attempt to write the specified register values and emit a RegistersWrittenToTarget event.
* *
* @param event * @param event
*/ */
void onWriteRegistersEvent(Events::EventPointer<Events::WriteRegistersToTarget> event); void onWriteRegistersEvent(Events::EventRef<Events::WriteRegistersToTarget> event);
/** /**
* Will attempt to read memory from the target and include the data in a MemoryRetrievedFromTarget event. * Will attempt to read memory from the target and include the data in a MemoryRetrievedFromTarget event.
* *
* @param event * @param event
*/ */
void onReadMemoryEvent(Events::EventPointer<Events::RetrieveMemoryFromTarget> event); void onReadMemoryEvent(Events::EventRef<Events::RetrieveMemoryFromTarget> event);
/** /**
* Will attempt to write memory to the target. On success, a MemoryWrittenToTarget event is emitted. * Will attempt to write memory to the target. On success, a MemoryWrittenToTarget event is emitted.
* *
* @param event * @param event
*/ */
void onWriteMemoryEvent(Events::EventPointer<Events::WriteMemoryToTarget> event); void onWriteMemoryEvent(Events::EventRef<Events::WriteMemoryToTarget> event);
/** /**
* Will attempt to set the specific breakpoint on the target. On success, the BreakpointSetOnTarget event will * Will attempt to set the specific breakpoint on the target. On success, the BreakpointSetOnTarget event will
@@ -315,7 +315,7 @@ namespace Bloom
* *
* @param event * @param event
*/ */
void onSetBreakpointEvent(Events::EventPointer<Events::SetBreakpointOnTarget> event); void onSetBreakpointEvent(Events::EventRef<Events::SetBreakpointOnTarget> event);
/** /**
* Will attempt to remove a breakpoint at the specified address, on the target. On success, the * Will attempt to remove a breakpoint at the specified address, on the target. On success, the
@@ -323,21 +323,21 @@ namespace Bloom
* *
* @param event * @param event
*/ */
void onRemoveBreakpointEvent(Events::EventPointer<Events::RemoveBreakpointOnTarget> event); void onRemoveBreakpointEvent(Events::EventRef<Events::RemoveBreakpointOnTarget> event);
/** /**
* Will hold the target stopped at it's current state. * Will hold the target stopped at it's current state.
* *
* @param event * @param event
*/ */
void onDebugSessionStartedEvent(Events::EventPointer<Events::DebugSessionStarted> event); void onDebugSessionStartedEvent(Events::EventRef<Events::DebugSessionStarted> event);
/** /**
* Will simply kick off execution on the target. * Will simply kick off execution on the target.
* *
* @param event * @param event
*/ */
void onDebugSessionFinishedEvent(Events::EventPointer<Events::DebugSessionFinished> event); void onDebugSessionFinishedEvent(Events::EventRef<Events::DebugSessionFinished> event);
/** /**
* Will update the program counter value on the target. On success, a ProgramCounterSetOnTarget event is * Will update the program counter value on the target. On success, a ProgramCounterSetOnTarget event is
@@ -345,7 +345,7 @@ namespace Bloom
* *
* @param event * @param event
*/ */
void onSetProgramCounterEvent(Events::EventPointer<Events::SetProgramCounterOnTarget> event); void onSetProgramCounterEvent(Events::EventRef<Events::SetProgramCounterOnTarget> event);
/** /**
* Will automatically fire a target state update event. * Will automatically fire a target state update event.
@@ -353,14 +353,14 @@ namespace Bloom
* *
* @param event * @param event
*/ */
void onInsightStateChangedEvent(Events::EventPointer<Events::InsightThreadStateChanged> event); void onInsightStateChangedEvent(Events::EventRef<Events::InsightThreadStateChanged> event);
/** /**
* Will attempt to obtain the pin states from the target. Will emit a TargetPinStatesRetrieved event on success. * Will attempt to obtain the pin states from the target. Will emit a TargetPinStatesRetrieved event on success.
* *
* @param event * @param event
*/ */
void onRetrieveTargetPinStatesEvent(Events::EventPointer<Events::RetrieveTargetPinStates> event); void onRetrieveTargetPinStatesEvent(Events::EventRef<Events::RetrieveTargetPinStates> event);
/** /**
* Will update a pin state for a particular pin. Will emit a TargetPinStatesRetrieved with the new pin * Will update a pin state for a particular pin. Will emit a TargetPinStatesRetrieved with the new pin
@@ -368,6 +368,6 @@ namespace Bloom
* *
* @param event * @param event
*/ */
void onSetPinStateEvent(Events::EventPointer<Events::SetTargetPinState> event); void onSetPinStateEvent(Events::EventRef<Events::SetTargetPinState> event);
}; };
} }

View File

@@ -18,12 +18,12 @@ TargetControllerState TargetControllerConsole::getTargetControllerState() {
>(this->defaultTimeout, getStateEvent->id); >(this->defaultTimeout, getStateEvent->id);
if (!responseEvent.has_value() if (!responseEvent.has_value()
|| !std::holds_alternative<EventPointer<Events::TargetControllerStateReported>>(responseEvent.value()) || !std::holds_alternative<SharedEventPointer<Events::TargetControllerStateReported>>(responseEvent.value())
) { ) {
throw Exception("Unexpected response from TargetController"); throw Exception("Unexpected response from TargetController");
} }
auto stateReportedEvent = std::get<EventPointer<Events::TargetControllerStateReported>>(responseEvent.value()); auto stateReportedEvent = std::get<SharedEventPointer<Events::TargetControllerStateReported>>(responseEvent.value());
return stateReportedEvent->state; return stateReportedEvent->state;
} }
@@ -45,12 +45,12 @@ Targets::TargetDescriptor TargetControllerConsole::getTargetDescriptor() {
>(this->defaultTimeout, extractEvent->id); >(this->defaultTimeout, extractEvent->id);
if (!responseEvent.has_value() if (!responseEvent.has_value()
|| !std::holds_alternative<EventPointer<Events::TargetDescriptorExtracted>>(responseEvent.value()) || !std::holds_alternative<SharedEventPointer<Events::TargetDescriptorExtracted>>(responseEvent.value())
) { ) {
throw Exception("Unexpected response from TargetController"); throw Exception("Unexpected response from TargetController");
} }
auto descriptorExtracted = std::get<EventPointer<Events::TargetDescriptorExtracted>>(responseEvent.value()); auto descriptorExtracted = std::get<SharedEventPointer<Events::TargetDescriptorExtracted>>(responseEvent.value());
return descriptorExtracted->targetDescriptor; return descriptorExtracted->targetDescriptor;
} }
@@ -64,7 +64,7 @@ void TargetControllerConsole::stopTargetExecution() {
>(this->defaultTimeout, stopTargetEvent->id); >(this->defaultTimeout, stopTargetEvent->id);
if (!responseEvent.has_value() if (!responseEvent.has_value()
|| !std::holds_alternative<EventPointer<Events::TargetExecutionStopped>>(responseEvent.value()) || !std::holds_alternative<SharedEventPointer<Events::TargetExecutionStopped>>(responseEvent.value())
) { ) {
throw Exception("Unexpected response from TargetController"); throw Exception("Unexpected response from TargetController");
} }
@@ -84,7 +84,7 @@ void TargetControllerConsole::continueTargetExecution(std::optional<std::uint32_
>(this->defaultTimeout, resumeExecutionEvent->id); >(this->defaultTimeout, resumeExecutionEvent->id);
if (!responseEvent.has_value() if (!responseEvent.has_value()
|| !std::holds_alternative<EventPointer<Events::TargetExecutionResumed>>(responseEvent.value()) || !std::holds_alternative<SharedEventPointer<Events::TargetExecutionResumed>>(responseEvent.value())
) { ) {
throw Exception("Unexpected response from TargetController"); throw Exception("Unexpected response from TargetController");
} }
@@ -104,7 +104,7 @@ void TargetControllerConsole::stepTargetExecution(std::optional<std::uint32_t> f
>(this->defaultTimeout, stepExecutionEvent->id); >(this->defaultTimeout, stepExecutionEvent->id);
if (!responseEvent.has_value() if (!responseEvent.has_value()
|| !std::holds_alternative<EventPointer<Events::TargetExecutionResumed>>(responseEvent.value()) || !std::holds_alternative<SharedEventPointer<Events::TargetExecutionResumed>>(responseEvent.value())
) { ) {
throw Exception("Unexpected response from TargetController"); throw Exception("Unexpected response from TargetController");
} }
@@ -121,12 +121,14 @@ TargetRegisters TargetControllerConsole::readGeneralRegisters(TargetRegisterDesc
>(this->defaultTimeout, readRegistersEvent->id); >(this->defaultTimeout, readRegistersEvent->id);
if (!responseEvent.has_value() if (!responseEvent.has_value()
|| !std::holds_alternative<EventPointer<Events::RegistersRetrievedFromTarget>>(responseEvent.value()) || !std::holds_alternative<SharedEventPointer<Events::RegistersRetrievedFromTarget>>(responseEvent.value())
) { ) {
throw Exception("Unexpected response from TargetController"); throw Exception("Unexpected response from TargetController");
} }
auto retrievedRegistersEvent = std::get<EventPointer<Events::RegistersRetrievedFromTarget>>(responseEvent.value()); auto retrievedRegistersEvent = std::get<SharedEventPointer<Events::RegistersRetrievedFromTarget>>(
responseEvent.value()
);
return retrievedRegistersEvent->registers; return retrievedRegistersEvent->registers;
} }
@@ -141,7 +143,7 @@ void TargetControllerConsole::writeGeneralRegisters(TargetRegisters registers) {
>(this->defaultTimeout, event->id); >(this->defaultTimeout, event->id);
if (!responseEvent.has_value() if (!responseEvent.has_value()
|| !std::holds_alternative<EventPointer<Events::RegistersWrittenToTarget>>(responseEvent.value()) || !std::holds_alternative<SharedEventPointer<Events::RegistersWrittenToTarget>>(responseEvent.value())
) { ) {
throw Exception("Unexpected response from TargetController"); throw Exception("Unexpected response from TargetController");
} }
@@ -164,12 +166,14 @@ TargetMemoryBuffer TargetControllerConsole::readMemory(
>(this->defaultTimeout, readMemoryEvent->id); >(this->defaultTimeout, readMemoryEvent->id);
if (!responseEvent.has_value() if (!responseEvent.has_value()
|| !std::holds_alternative<EventPointer<Events::MemoryRetrievedFromTarget>>(responseEvent.value()) || !std::holds_alternative<SharedEventPointer<Events::MemoryRetrievedFromTarget>>(responseEvent.value())
) { ) {
throw Exception("Unexpected response from TargetController"); throw Exception("Unexpected response from TargetController");
} }
auto retrievedRegistersEvent = std::get<EventPointer<Events::MemoryRetrievedFromTarget>>(responseEvent.value()); auto retrievedRegistersEvent = std::get<SharedEventPointer<Events::MemoryRetrievedFromTarget>>(
responseEvent.value()
);
return retrievedRegistersEvent->data; return retrievedRegistersEvent->data;
} }
@@ -190,7 +194,7 @@ void TargetControllerConsole::writeMemory(
>(this->defaultTimeout, writeMemoryEvent->id); >(this->defaultTimeout, writeMemoryEvent->id);
if (!responseEvent.has_value() if (!responseEvent.has_value()
|| !std::holds_alternative<EventPointer<Events::MemoryWrittenToTarget>>(responseEvent.value()) || !std::holds_alternative<SharedEventPointer<Events::MemoryWrittenToTarget>>(responseEvent.value())
) { ) {
throw Exception("Unexpected response from TargetController"); throw Exception("Unexpected response from TargetController");
} }
@@ -207,7 +211,7 @@ void TargetControllerConsole::setBreakpoint(TargetBreakpoint breakpoint) {
>(this->defaultTimeout, event->id); >(this->defaultTimeout, event->id);
if (!responseEvent.has_value() if (!responseEvent.has_value()
|| !std::holds_alternative<EventPointer<Events::BreakpointSetOnTarget>>(responseEvent.value()) || !std::holds_alternative<SharedEventPointer<Events::BreakpointSetOnTarget>>(responseEvent.value())
) { ) {
throw Exception("Unexpected response from TargetController"); throw Exception("Unexpected response from TargetController");
} }
@@ -224,7 +228,7 @@ void TargetControllerConsole::removeBreakpoint(TargetBreakpoint breakpoint) {
>(this->defaultTimeout, event->id); >(this->defaultTimeout, event->id);
if (!responseEvent.has_value() if (!responseEvent.has_value()
|| !std::holds_alternative<EventPointer<Events::BreakpointRemovedOnTarget>>(responseEvent.value()) || !std::holds_alternative<SharedEventPointer<Events::BreakpointRemovedOnTarget>>(responseEvent.value())
) { ) {
throw Exception("Unexpected response from TargetController"); throw Exception("Unexpected response from TargetController");
} }
@@ -240,7 +244,7 @@ void TargetControllerConsole::requestPinStates(int variantId) {
void TargetControllerConsole::setPinState(int variantId, TargetPinDescriptor pinDescriptor, TargetPinState pinState) { void TargetControllerConsole::setPinState(int variantId, TargetPinDescriptor pinDescriptor, TargetPinState pinState) {
auto updateEvent = std::make_shared<Events::SetTargetPinState>(); auto updateEvent = std::make_shared<Events::SetTargetPinState>();
updateEvent->variantId = variantId; updateEvent->variantId = variantId;
updateEvent->pinDescriptor = pinDescriptor; updateEvent->pinDescriptor = std::move(pinDescriptor);
updateEvent->pinState = pinState; updateEvent->pinState = pinState;
this->eventManager.triggerEvent(updateEvent); this->eventManager.triggerEvent(updateEvent);