diff --git a/src/DebugServer/DebugServerComponent.cpp b/src/DebugServer/DebugServerComponent.cpp index 926a1572..335f1103 100644 --- a/src/DebugServer/DebugServerComponent.cpp +++ b/src/DebugServer/DebugServerComponent.cpp @@ -1,6 +1,6 @@ #include "DebugServerComponent.hpp" -#include +#include "src/EventManager/EventManager.hpp" // Debug server implementations #include "Gdb/AvrGdb/AvrGdbRsp.hpp" @@ -34,7 +34,10 @@ namespace Bloom::DebugServer this->shutdown(); } - std::map()>> DebugServerComponent::getAvailableServersByName() { + std::map< + std::string, + std::function()> + > DebugServerComponent::getAvailableServersByName() { return std::map()>> { { "avr-gdb-rsp", @@ -47,6 +50,7 @@ namespace Bloom::DebugServer }, }; } + void DebugServerComponent::startup() { this->setName("DS"); Logger::info("Starting DebugServer"); @@ -87,6 +91,13 @@ namespace Bloom::DebugServer EventManager::deregisterListener(this->eventListener->getId()); } + void DebugServerComponent::setThreadStateAndEmitEvent(ThreadState state) { + Thread::setThreadState(state); + EventManager::triggerEvent( + std::make_shared(state) + ); + } + void DebugServerComponent::onShutdownDebugServerEvent(const Events::ShutdownDebugServer& event) { this->shutdown(); } diff --git a/src/DebugServer/DebugServerComponent.hpp b/src/DebugServer/DebugServerComponent.hpp index 594cc71b..009a0180 100644 --- a/src/DebugServer/DebugServerComponent.hpp +++ b/src/DebugServer/DebugServerComponent.hpp @@ -5,15 +5,11 @@ #include #include -#include "src/TargetController/TargetControllerConsole.hpp" -#include "src/EventManager/Events/Events.hpp" -#include "src/EventManager/EventManager.hpp" -#include "src/Exceptions/DebugServerInterrupted.hpp" -#include "src/ProjectConfig.hpp" #include "src/Helpers/Thread.hpp" -#include "src/Targets/TargetDescriptor.hpp" -#include "src/Targets/TargetRegister.hpp" -#include "src/Targets/TargetBreakpoint.hpp" +#include "src/ProjectConfig.hpp" +#include "src/Helpers/EventNotifier.hpp" +#include "src/EventManager/EventListener.hpp" +#include "src/EventManager/Events/Events.hpp" #include "ServerInterface.hpp" @@ -31,37 +27,57 @@ namespace Bloom::DebugServer /** * Entry point for the DebugServer. This must called from a dedicated thread. + * + * See Application::startDebugServer() for more. */ void run(); - protected: + private: + /** + * The DebugServer's event listener. + * + * If a server implementation needs access to events, they should use this event listener as opposed to + * creating their own. See the AVR GDB server implementation for an example - there, we inject this event + * listener via AvrGdbRsp's constructor (see DebugServerComponent::getAvailableServersByName()). + */ EventListenerPointer eventListener = std::make_shared("DebugServerEventListener"); + /** + * Project configuration for the debug server (extracted from the user project's bloom.json). + */ DebugServerConfig debugServerConfig; - TargetControllerConsole targetControllerConsole = TargetControllerConsole(*(this->eventListener)); - /** - * Enables the interruption of any blocking file IO. + * This EventNotifier is injected into this->eventListener. It can be used by server implementations to + * interrupt blocking I/O calls upon an event being triggered. For more, see the "Servicing events" section in + * the DebugServer documentation (src/DebugServer/README.md). */ EventNotifier interruptEventNotifier = EventNotifier(); - private: + /** + * An instance to the selected server implementation. See DebugServerComponent::startup() for more. + */ std::unique_ptr server = nullptr; + /** + * Returns a mapping of server configuration names to lambdas/std::functions. + * + * The server configuration name is what the user will use in their project configuration (bloom.json), when + * selecting a debug server. It *must* be lower-case. + * + * The lambda should return an instance of the server implementation. + * + * @return + */ std::map()>> getAvailableServersByName(); /** - * Prepares the debug server thread and then calls init(). - * - * Derived classes should not override this method - they should instead use init(). + * Prepares the debug server thread and then calls this->server->init(). */ void startup(); /** - * Calls close() and updates the thread state. - * - * As with startup(), derived classes should not override this method. They should use close() instead. + * Calls this->server->close() and updates the thread state. */ void shutdown(); @@ -71,12 +87,7 @@ namespace Bloom::DebugServer * @param state * @param emitEvent */ - void setThreadStateAndEmitEvent(ThreadState state) { - Thread::setThreadState(state); - EventManager::triggerEvent( - std::make_shared(state) - ); - } + void setThreadStateAndEmitEvent(ThreadState state); /** * Handles a shutdown request.