Tidying DebugServerComponent class
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#include "DebugServerComponent.hpp"
|
#include "DebugServerComponent.hpp"
|
||||||
|
|
||||||
#include <variant>
|
#include "src/EventManager/EventManager.hpp"
|
||||||
|
|
||||||
// Debug server implementations
|
// Debug server implementations
|
||||||
#include "Gdb/AvrGdb/AvrGdbRsp.hpp"
|
#include "Gdb/AvrGdb/AvrGdbRsp.hpp"
|
||||||
@@ -34,7 +34,10 @@ namespace Bloom::DebugServer
|
|||||||
this->shutdown();
|
this->shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, std::function<std::unique_ptr<ServerInterface>()>> DebugServerComponent::getAvailableServersByName() {
|
std::map<
|
||||||
|
std::string,
|
||||||
|
std::function<std::unique_ptr<ServerInterface>()>
|
||||||
|
> DebugServerComponent::getAvailableServersByName() {
|
||||||
return std::map<std::string, std::function<std::unique_ptr<ServerInterface>()>> {
|
return std::map<std::string, std::function<std::unique_ptr<ServerInterface>()>> {
|
||||||
{
|
{
|
||||||
"avr-gdb-rsp",
|
"avr-gdb-rsp",
|
||||||
@@ -47,6 +50,7 @@ namespace Bloom::DebugServer
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugServerComponent::startup() {
|
void DebugServerComponent::startup() {
|
||||||
this->setName("DS");
|
this->setName("DS");
|
||||||
Logger::info("Starting DebugServer");
|
Logger::info("Starting DebugServer");
|
||||||
@@ -87,6 +91,13 @@ namespace Bloom::DebugServer
|
|||||||
EventManager::deregisterListener(this->eventListener->getId());
|
EventManager::deregisterListener(this->eventListener->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DebugServerComponent::setThreadStateAndEmitEvent(ThreadState state) {
|
||||||
|
Thread::setThreadState(state);
|
||||||
|
EventManager::triggerEvent(
|
||||||
|
std::make_shared<Events::DebugServerThreadStateChanged>(state)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void DebugServerComponent::onShutdownDebugServerEvent(const Events::ShutdownDebugServer& event) {
|
void DebugServerComponent::onShutdownDebugServerEvent(const Events::ShutdownDebugServer& event) {
|
||||||
this->shutdown();
|
this->shutdown();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,11 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#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/Helpers/Thread.hpp"
|
||||||
#include "src/Targets/TargetDescriptor.hpp"
|
#include "src/ProjectConfig.hpp"
|
||||||
#include "src/Targets/TargetRegister.hpp"
|
#include "src/Helpers/EventNotifier.hpp"
|
||||||
#include "src/Targets/TargetBreakpoint.hpp"
|
#include "src/EventManager/EventListener.hpp"
|
||||||
|
#include "src/EventManager/Events/Events.hpp"
|
||||||
|
|
||||||
#include "ServerInterface.hpp"
|
#include "ServerInterface.hpp"
|
||||||
|
|
||||||
@@ -31,37 +27,57 @@ namespace Bloom::DebugServer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Entry point for the DebugServer. This must called from a dedicated thread.
|
* Entry point for the DebugServer. This must called from a dedicated thread.
|
||||||
|
*
|
||||||
|
* See Application::startDebugServer() for more.
|
||||||
*/
|
*/
|
||||||
void run();
|
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<EventListener>("DebugServerEventListener");
|
EventListenerPointer eventListener = std::make_shared<EventListener>("DebugServerEventListener");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project configuration for the debug server (extracted from the user project's bloom.json).
|
||||||
|
*/
|
||||||
DebugServerConfig debugServerConfig;
|
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();
|
EventNotifier interruptEventNotifier = EventNotifier();
|
||||||
|
|
||||||
private:
|
/**
|
||||||
|
* An instance to the selected server implementation. See DebugServerComponent::startup() for more.
|
||||||
|
*/
|
||||||
std::unique_ptr<ServerInterface> server = nullptr;
|
std::unique_ptr<ServerInterface> 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<std::string, std::function<std::unique_ptr<ServerInterface>()>> getAvailableServersByName();
|
std::map<std::string, std::function<std::unique_ptr<ServerInterface>()>> getAvailableServersByName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares the debug server thread and then calls init().
|
* Prepares the debug server thread and then calls this->server->init().
|
||||||
*
|
|
||||||
* Derived classes should not override this method - they should instead use init().
|
|
||||||
*/
|
*/
|
||||||
void startup();
|
void startup();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls close() and updates the thread state.
|
* Calls this->server->close() and updates the thread state.
|
||||||
*
|
|
||||||
* As with startup(), derived classes should not override this method. They should use close() instead.
|
|
||||||
*/
|
*/
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
|
||||||
@@ -71,12 +87,7 @@ namespace Bloom::DebugServer
|
|||||||
* @param state
|
* @param state
|
||||||
* @param emitEvent
|
* @param emitEvent
|
||||||
*/
|
*/
|
||||||
void setThreadStateAndEmitEvent(ThreadState state) {
|
void setThreadStateAndEmitEvent(ThreadState state);
|
||||||
Thread::setThreadState(state);
|
|
||||||
EventManager::triggerEvent(
|
|
||||||
std::make_shared<Events::DebugServerThreadStateChanged>(state)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a shutdown request.
|
* Handles a shutdown request.
|
||||||
|
|||||||
Reference in New Issue
Block a user