Removed unnecessary use of std::string for event management, in an attempt to reduce memory consumption.

Now using 16 bit enums for event types.
This commit is contained in:
Nav
2021-08-19 22:06:59 +01:00
parent 11415ce99a
commit 3554960a19
42 changed files with 336 additions and 72 deletions

View File

@@ -9,8 +9,13 @@ namespace Bloom::Events
class BreakpointRemovedOnTarget: public Event
{
public:
static inline EventType type = EventType::BREAKPOINT_REMOVED_ON_TARGET;
static inline const std::string name = "BreakpointRemovedOnTarget";
[[nodiscard]] EventType getType() const override {
return BreakpointRemovedOnTarget::type;
}
[[nodiscard]] std::string getName() const override {
return BreakpointRemovedOnTarget::name;
}

View File

@@ -9,8 +9,13 @@ namespace Bloom::Events
class BreakpointSetOnTarget: public Event
{
public:
static inline EventType type = EventType::BREAKPOINT_SET_ON_TARGET;
static inline const std::string name = "BreakpointSetOnTarget";
[[nodiscard]] EventType getType() const override {
return BreakpointSetOnTarget::type;
}
[[nodiscard]] std::string getName() const override {
return BreakpointSetOnTarget::name;
}

View File

@@ -12,9 +12,14 @@ namespace Bloom::Events
private:
ThreadState state;
public:
static inline EventType type = EventType::DEBUG_SERVER_THREAD_STATE_CHANGED;
static inline const std::string name = "DebugServerThreadStateChanged";
explicit DebugServerThreadStateChanged(ThreadState state): state(state) {};
static inline const std::string name = "DebugServerThreadStateChanged";
[[nodiscard]] EventType getType() const override {
return DebugServerThreadStateChanged::type;
}
[[nodiscard]] std::string getName() const override {
return DebugServerThreadStateChanged::name;

View File

@@ -9,8 +9,13 @@ namespace Bloom::Events
class DebugSessionFinished: public Event
{
public:
static inline EventType type = EventType::DEBUG_SESSION_FINISHED;
static inline const std::string name = "DebugSessionFinished";
[[nodiscard]] EventType getType() const override {
return DebugSessionFinished::type;
}
[[nodiscard]] std::string getName() const override {
return DebugSessionFinished::name;
}

View File

@@ -9,8 +9,13 @@ namespace Bloom::Events
class DebugSessionStarted: public Event
{
public:
static inline EventType type = EventType::DEBUG_SESSION_STARTED;
static inline const std::string name = "DebugSessionStarted";
[[nodiscard]] EventType getType() const override {
return DebugSessionStarted::type;
}
[[nodiscard]] std::string getName() const override {
return DebugSessionStarted::name;
}

View File

@@ -4,6 +4,7 @@
#include <memory>
#include <atomic>
#include <optional>
#include <cstdint>
#include "src/Helpers/DateTime.hpp"
@@ -11,6 +12,48 @@ namespace Bloom::Events
{
static_assert(std::atomic<int>::is_always_lock_free);
enum EventType: std::uint16_t
{
GENERIC,
STOP_TARGET_EXECUTION,
RESUME_TARGET_EXECUTION,
RESET_TARGET,
DEBUG_SESSION_STARTED,
DEBUG_SESSION_FINISHED,
TARGET_CONTROLLER_THREAD_STATE_CHANGED,
REPORT_TARGET_CONTROLLER_STATE,
TARGET_CONTROLLER_STATE_REPORTED,
SHUTDOWN_TARGET_CONTROLLER,
TARGET_CONTROLLER_ERROR_OCCURRED,
SHUTDOWN_APPLICATION,
DEBUG_SERVER_THREAD_STATE_CHANGED,
SHUTDOWN_DEBUG_SERVER,
RETRIEVE_REGISTERS_FROM_TARGET,
REGISTERS_RETRIEVED_FROM_TARGET,
WRITE_REGISTERS_TO_TARGET,
REGISTERS_WRITTEN_TO_TARGET,
TARGET_EXECUTION_RESUMED,
TARGET_EXECUTION_STOPPED,
RETRIEVE_MEMORY_FROM_TARGET,
MEMORY_RETRIEVED_FROM_TARGET,
WRITE_MEMORY_TO_TARGET,
MEMORY_WRITTEN_TO_TARGET,
SET_BREAKPOINT_ON_TARGET,
REMOVE_BREAKPOINT_ON_TARGET,
BREAKPOINT_SET_ON_TARGET,
BREAKPOINT_REMOVED_ON_TARGET,
STEP_TARGET_EXECUTION,
SET_PROGRAM_COUNTER_ON_TARGET,
PROGRAM_COUNTER_SET_ON_TARGET,
EXTRACT_TARGET_DESCRIPTOR,
TARGET_DESCRIPTOR_EXTRACTED,
INSIGHT_THREAD_STATE_CHANGED,
RETRIEVE_TARGET_PIN_STATES,
TARGET_PIN_STATES_RETRIEVED,
SET_TARGET_PIN_STATE,
TARGET_IO_PORTS_UPDATED,
};
class Event
{
private:
@@ -21,10 +64,15 @@ namespace Bloom::Events
QDateTime createdTimestamp = DateTime::currentDateTime();
std::optional<int> correlationId;
static inline EventType type = EventType::GENERIC;
static inline const std::string name = "GenericEvent";
[[nodiscard]] virtual std::string getName() const {
return Event::name;
}
[[nodiscard]] virtual EventType getType() const {
return Event::type;
}
};
}

View File

@@ -46,5 +46,8 @@ namespace Bloom::Events
template <class EventType>
using SharedEventPointer = std::shared_ptr<const EventType>;
template <class EventType>
using SharedEventPointerNonConst = std::shared_ptr<EventType>;
using SharedGenericEventPointer = SharedEventPointer<Event>;
}

View File

@@ -4,13 +4,22 @@
#include "Event.hpp"
#include "TargetDescriptorExtracted.hpp"
namespace Bloom::Events
{
class ExtractTargetDescriptor: public Event
{
public:
using TargetControllerResponseType = TargetDescriptorExtracted;
static inline EventType type = EventType::EXTRACT_TARGET_DESCRIPTOR;
static inline const std::string name = "ExtractTargetDescriptor";
[[nodiscard]] EventType getType() const override {
return ExtractTargetDescriptor::type;
}
[[nodiscard]] std::string getName() const override {
return ExtractTargetDescriptor::name;
}

View File

@@ -11,11 +11,17 @@ namespace Bloom::Events
{
private:
ThreadState state;
public:
explicit InsightThreadStateChanged(ThreadState state): state(state) {};
static inline EventType type = EventType::INSIGHT_THREAD_STATE_CHANGED;
static inline const std::string name = "InsightThreadStateChanged";
[[nodiscard]] EventType getType() const override {
return InsightThreadStateChanged::type;
}
[[nodiscard]] std::string getName() const override {
return InsightThreadStateChanged::name;
}

View File

@@ -10,9 +10,14 @@ namespace Bloom::Events
class MemoryRetrievedFromTarget: public Event
{
public:
static inline EventType type = EventType::MEMORY_RETRIEVED_FROM_TARGET;
static inline const std::string name = "MemoryRetrievedFromTarget";
Targets::TargetMemoryBuffer data;
[[nodiscard]] EventType getType() const override {
return MemoryRetrievedFromTarget::type;
}
[[nodiscard]] std::string getName() const override {
return MemoryRetrievedFromTarget::name;
}

View File

@@ -10,12 +10,17 @@ namespace Bloom::Events
class MemoryWrittenToTarget: public Event
{
public:
static inline EventType type = EventType::MEMORY_WRITTEN_TO_TARGET;
static inline const std::string name = "MemoryWrittenToTarget";
MemoryWrittenToTarget() = default;
[[nodiscard]] EventType getType() const override {
return MemoryWrittenToTarget::type;
}
[[nodiscard]] std::string getName() const override {
return MemoryWrittenToTarget::name;
}
MemoryWrittenToTarget() = default;
};
}

View File

@@ -9,8 +9,13 @@ namespace Bloom::Events
class ProgramCounterSetOnTarget: public Event
{
public:
static inline EventType type = EventType::PROGRAM_COUNTER_SET_ON_TARGET;
static inline const std::string name = "ProgramCounterSetOnTarget";
[[nodiscard]] EventType getType() const override {
return ProgramCounterSetOnTarget::type;
}
[[nodiscard]] std::string getName() const override {
return ProgramCounterSetOnTarget::name;
}

View File

@@ -10,9 +10,14 @@ namespace Bloom::Events
class RegistersRetrievedFromTarget: public Event
{
public:
static inline EventType type = EventType::REGISTERS_RETRIEVED_FROM_TARGET;
static inline const std::string name = "RegistersRetrievedFromTarget";
Targets::TargetRegisters registers;
[[nodiscard]] EventType getType() const override {
return RegistersRetrievedFromTarget::type;
}
[[nodiscard]] std::string getName() const override {
return RegistersRetrievedFromTarget::name;
}

View File

@@ -9,8 +9,13 @@ namespace Bloom::Events
class RegistersWrittenToTarget: public Event
{
public:
static inline EventType type = EventType::REGISTERS_WRITTEN_TO_TARGET;
static inline const std::string name = "RegistersWrittenToTarget";
[[nodiscard]] EventType getType() const override {
return RegistersWrittenToTarget::type;
}
[[nodiscard]] std::string getName() const override {
return RegistersWrittenToTarget::name;
}

View File

@@ -11,9 +11,14 @@ namespace Bloom::Events
class RemoveBreakpointOnTarget: public Event
{
public:
static inline EventType type = EventType::REMOVE_BREAKPOINT_ON_TARGET;
static inline const std::string name = "RemoveBreakpointOnTarget";
Targets::TargetBreakpoint breakpoint;
[[nodiscard]] EventType getType() const override {
return RemoveBreakpointOnTarget::type;
}
[[nodiscard]] std::string getName() const override {
return RemoveBreakpointOnTarget::name;
}

View File

@@ -9,9 +9,14 @@ namespace Bloom::Events
class ReportTargetControllerState: public Event
{
public:
static inline EventType type = EventType::REPORT_TARGET_CONTROLLER_STATE;
static inline const std::string name = "ReportTargetControllerState";
ReportTargetControllerState() {};
static inline const std::string name = "ReportTargetControllerState";
[[nodiscard]] EventType getType() const override {
return ReportTargetControllerState::type;
}
[[nodiscard]] std::string getName() const override {
return ReportTargetControllerState::name;

View File

@@ -9,8 +9,13 @@ namespace Bloom::Events
class ResetTarget: public Event
{
public:
static inline EventType type = EventType::RESET_TARGET;
static inline const std::string name = "ResetTargetEvent";
[[nodiscard]] EventType getType() const override {
return ResetTarget::type;
}
[[nodiscard]] std::string getName() const override {
return ResetTarget::name;
}

View File

@@ -10,14 +10,19 @@ namespace Bloom::Events
class ResumeTargetExecution: public Event
{
public:
static inline EventType type = EventType::RESUME_TARGET_EXECUTION;
static inline const std::string name = "ResumeTargetExecutionEvent";
std::optional<std::uint32_t> fromProgramCounter;
ResumeTargetExecution() = default;
explicit ResumeTargetExecution(std::uint32_t fromProgramCounter): fromProgramCounter(fromProgramCounter) {};
[[nodiscard]] EventType getType() const override {
return ResumeTargetExecution::type;
}
[[nodiscard]] std::string getName() const override {
return ResumeTargetExecution::name;
}
ResumeTargetExecution() = default;
explicit ResumeTargetExecution(std::uint32_t fromProgramCounter): fromProgramCounter(fromProgramCounter) {};
};
}

View File

@@ -11,11 +11,16 @@ namespace Bloom::Events
class RetrieveMemoryFromTarget: public Event
{
public:
static inline EventType type = EventType::RETRIEVE_MEMORY_FROM_TARGET;
static inline const std::string name = "RetrieveMemoryFromTarget";
Targets::TargetMemoryType memoryType = Targets::TargetMemoryType::RAM;
std::uint32_t startAddress = 0;
std::uint32_t bytes = 0;
[[nodiscard]] EventType getType() const override {
return RetrieveMemoryFromTarget::type;
}
[[nodiscard]] std::string getName() const override {
return RetrieveMemoryFromTarget::name;
}

View File

@@ -10,9 +10,14 @@ namespace Bloom::Events
class RetrieveRegistersFromTarget: public Event
{
public:
static inline EventType type = EventType::RETRIEVE_REGISTERS_FROM_TARGET;
static inline const std::string name = "RetrieveRegistersFromTarget";
Targets::TargetRegisterDescriptors descriptors;
[[nodiscard]] EventType getType() const override {
return RetrieveRegistersFromTarget::type;
}
[[nodiscard]] std::string getName() const override {
return RetrieveRegistersFromTarget::name;
}

View File

@@ -9,9 +9,14 @@ namespace Bloom::Events
class RetrieveTargetPinStates: public Event
{
public:
static inline EventType type = EventType::RETRIEVE_TARGET_PIN_STATES;
static inline const std::string name = "RetrieveTargetPinStates";
int variantId = 0;
[[nodiscard]] EventType getType() const override {
return RetrieveTargetPinStates::type;
}
[[nodiscard]] std::string getName() const override {
return RetrieveTargetPinStates::name;
}

View File

@@ -11,9 +11,14 @@ namespace Bloom::Events
class SetBreakpointOnTarget: public Event
{
public:
static inline EventType type = EventType::SET_BREAKPOINT_ON_TARGET;
static inline const std::string name = "SetBreakpointOnTarget";
Targets::TargetBreakpoint breakpoint;
[[nodiscard]] EventType getType() const override {
return SetBreakpointOnTarget::type;
}
[[nodiscard]] std::string getName() const override {
return SetBreakpointOnTarget::name;
}

View File

@@ -10,9 +10,14 @@ namespace Bloom::Events
class SetProgramCounterOnTarget: public Event
{
public:
static inline EventType type = EventType::SET_PROGRAM_COUNTER_ON_TARGET;
static inline const std::string name = "SetProgramCounterOnTarget";
std::uint32_t address = 0;
[[nodiscard]] EventType getType() const override {
return SetProgramCounterOnTarget::type;
}
[[nodiscard]] std::string getName() const override {
return SetProgramCounterOnTarget::name;
}

View File

@@ -10,11 +10,16 @@ namespace Bloom::Events
class SetTargetPinState: public Event
{
public:
static inline EventType type = EventType::SET_TARGET_PIN_STATE;
static inline const std::string name = "SetTargetPinState";
int variantId = 0;
Targets::TargetPinDescriptor pinDescriptor;
Targets::TargetPinState pinState;
[[nodiscard]] EventType getType() const override {
return SetTargetPinState::type;
}
[[nodiscard]] std::string getName() const override {
return SetTargetPinState::name;
}

View File

@@ -9,8 +9,13 @@ namespace Bloom::Events
class ShutdownApplication: public Event
{
public:
static inline EventType type = EventType::SHUTDOWN_APPLICATION;
static inline const std::string name = "ShutdownApplicationEvent";
[[nodiscard]] EventType getType() const override {
return ShutdownApplication::type;
}
[[nodiscard]] std::string getName() const override {
return ShutdownApplication::name;
}

View File

@@ -9,8 +9,13 @@ namespace Bloom::Events
class ShutdownDebugServer: public Event
{
public:
static inline EventType type = EventType::SHUTDOWN_DEBUG_SERVER;
static inline const std::string name = "ShutdownDebugServer";
[[nodiscard]] EventType getType() const override {
return ShutdownDebugServer::type;
}
[[nodiscard]] std::string getName() const override {
return ShutdownDebugServer::name;
}

View File

@@ -9,8 +9,13 @@ namespace Bloom::Events
class ShutdownTargetController: public Event
{
public:
static inline EventType type = EventType::SHUTDOWN_TARGET_CONTROLLER;
static inline const std::string name = "ShutdownTargetControllerEvent";
[[nodiscard]] EventType getType() const override {
return ShutdownTargetController::type;
}
[[nodiscard]] std::string getName() const override {
return ShutdownTargetController::name;
}

View File

@@ -10,14 +10,19 @@ namespace Bloom::Events
class StepTargetExecution: public Event
{
public:
static inline EventType type = EventType::STEP_TARGET_EXECUTION;
static inline const std::string name = "StepTargetExecution";
std::optional<std::uint32_t> fromProgramCounter;
StepTargetExecution() = default;
explicit StepTargetExecution(std::uint32_t fromProgramCounter): fromProgramCounter(fromProgramCounter) {};
[[nodiscard]] EventType getType() const override {
return StepTargetExecution::type;
}
[[nodiscard]] std::string getName() const override {
return StepTargetExecution::name;
}
StepTargetExecution() = default;
explicit StepTargetExecution(std::uint32_t fromProgramCounter): fromProgramCounter(fromProgramCounter) {};
};
}

View File

@@ -9,7 +9,12 @@ namespace Bloom::Events
class StopTargetExecution: public Event
{
public:
static inline const std::string name = "StopTargetEvent";
static inline EventType type = EventType::STOP_TARGET_EXECUTION;
static inline const std::string name = "StopTargetExecution";
[[nodiscard]] EventType getType() const override {
return StopTargetExecution::type;
}
[[nodiscard]] std::string getName() const override {
return StopTargetExecution::name;

View File

@@ -9,10 +9,15 @@ namespace Bloom::Events
class TargetControllerErrorOccurred: public Event
{
public:
static inline EventType type = EventType::TARGET_CONTROLLER_ERROR_OCCURRED;
static inline const std::string name = "TargetControllerErrorOccurred";
TargetControllerErrorOccurred() = default;
[[nodiscard]] EventType getType() const override {
return TargetControllerErrorOccurred::type;
}
[[nodiscard]] std::string getName() const override {
return TargetControllerErrorOccurred::name;
}

View File

@@ -10,11 +10,15 @@ namespace Bloom::Events
class TargetControllerStateReported: public Event
{
public:
TargetControllerState state;
static inline EventType type = EventType::TARGET_CONTROLLER_STATE_REPORTED;
static inline const std::string name = "TargetControllerStateReported";
TargetControllerState state;
explicit TargetControllerStateReported(TargetControllerState state): state(state) {};
static inline const std::string name = "TargetControllerStateReported";
[[nodiscard]] EventType getType() const override {
return TargetControllerStateReported::type;
}
[[nodiscard]] std::string getName() const override {
return TargetControllerStateReported::name;

View File

@@ -13,9 +13,14 @@ namespace Bloom::Events
ThreadState state;
public:
static inline EventType type = EventType::TARGET_CONTROLLER_THREAD_STATE_CHANGED;
static inline const std::string name = "TargetControllerThreadStateChanged";
explicit TargetControllerThreadStateChanged(ThreadState state): state(state) {};
static inline const std::string name = "TargetControllerThreadStateChanged";
[[nodiscard]] EventType getType() const override {
return TargetControllerThreadStateChanged::type;
}
[[nodiscard]] std::string getName() const override {
return TargetControllerThreadStateChanged::name;

View File

@@ -10,9 +10,14 @@ namespace Bloom::Events
class TargetDescriptorExtracted: public Event
{
public:
static inline EventType type = EventType::TARGET_DESCRIPTOR_EXTRACTED;
static inline const std::string name = "TargetDescriptorExtracted";
Targets::TargetDescriptor targetDescriptor;
[[nodiscard]] EventType getType() const override {
return TargetDescriptorExtracted::type;
}
[[nodiscard]] std::string getName() const override {
return TargetDescriptorExtracted::name;
}

View File

@@ -9,10 +9,15 @@ namespace Bloom::Events
class TargetExecutionResumed: public Event
{
public:
static inline EventType type = EventType::TARGET_EXECUTION_RESUMED;
static inline const std::string name = "TargetExecutionResumed";
TargetExecutionResumed() = default;
[[nodiscard]] EventType getType() const override {
return TargetExecutionResumed::type;
}
[[nodiscard]] std::string getName() const override {
return TargetExecutionResumed::name;
}

View File

@@ -11,6 +11,7 @@ namespace Bloom::Events
class TargetExecutionStopped: public Event
{
public:
static inline EventType type = EventType::TARGET_EXECUTION_STOPPED;
static inline const std::string name = "TargetExecutionStopped";
std::uint32_t programCounter;
Targets::TargetBreakCause breakCause;
@@ -18,6 +19,10 @@ namespace Bloom::Events
TargetExecutionStopped(std::uint32_t programCounter, Targets::TargetBreakCause breakCause) :
programCounter(programCounter), breakCause(breakCause) {}
[[nodiscard]] EventType getType() const override {
return TargetExecutionStopped::type;
}
[[nodiscard]] std::string getName() const override {
return TargetExecutionStopped::name;
}

View File

@@ -9,8 +9,13 @@ namespace Bloom::Events
class TargetIoPortsUpdated: public Event
{
public:
static inline EventType type = EventType::TARGET_IO_PORTS_UPDATED;
static inline const std::string name = "TargetIoPortsUpdated";
[[nodiscard]] EventType getType() const override {
return TargetIoPortsUpdated::type;
}
[[nodiscard]] std::string getName() const override {
return TargetIoPortsUpdated::name;
}

View File

@@ -11,10 +11,15 @@ namespace Bloom::Events
class TargetPinStatesRetrieved: public Event
{
public:
static inline EventType type = EventType::TARGET_PIN_STATES_RETRIEVED;
static inline const std::string name = "TargetPinStatesRetrieved";
int variantId = 0;
std::map<int, Targets::TargetPinState> pinSatesByNumber;
[[nodiscard]] EventType getType() const override {
return TargetPinStatesRetrieved::type;
}
[[nodiscard]] std::string getName() const override {
return TargetPinStatesRetrieved::name;
}

View File

@@ -12,20 +12,25 @@ namespace Bloom::Events
class WriteMemoryToTarget: public Event
{
public:
static inline EventType type = EventType::WRITE_MEMORY_TO_TARGET;
static inline const std::string name = "WriteMemoryToTarget";
Targets::TargetMemoryType memoryType = Targets::TargetMemoryType::RAM;
std::uint32_t startAddress = 0;
Targets::TargetMemoryBuffer buffer;
[[nodiscard]] std::string getName() const override {
return WriteMemoryToTarget::name;
}
WriteMemoryToTarget() = default;
WriteMemoryToTarget(
Targets::TargetMemoryType memoryType,
std::uint32_t startAddress,
Targets::TargetMemoryBuffer buffer
): memoryType(memoryType), startAddress(startAddress), buffer(std::move(buffer)) {};
[[nodiscard]] EventType getType() const override {
return WriteMemoryToTarget::type;
}
[[nodiscard]] std::string getName() const override {
return WriteMemoryToTarget::name;
}
};
}

View File

@@ -11,14 +11,19 @@ namespace Bloom::Events
class WriteRegistersToTarget: public Event
{
public:
static inline EventType type = EventType::WRITE_REGISTERS_TO_TARGET;
static inline const std::string name = "WriteRegistersToTarget";
Targets::TargetRegisters registers;
WriteRegistersToTarget() = default;
explicit WriteRegistersToTarget(Targets::TargetRegisters registers): registers(std::move(registers)) {};
[[nodiscard]] EventType getType() const override {
return WriteRegistersToTarget::type;
}
[[nodiscard]] std::string getName() const override {
return WriteRegistersToTarget::name;
}
WriteRegistersToTarget() = default;
explicit WriteRegistersToTarget(Targets::TargetRegisters registers): registers(std::move(registers)) {};
};
}