add 'connect' command & feat: disconnect-action

This commit is contained in:
MihailRis 2025-10-09 01:04:08 +03:00
parent a33e3068c8
commit 1a7bcf9865
2 changed files with 19 additions and 1 deletions

View File

@ -139,8 +139,9 @@ bool DebuggingServer::update() {
std::string message = connection->read(); std::string message = connection->read();
if (message.empty()) { if (message.empty()) {
if (!connection->alive()) { if (!connection->alive()) {
bool status = performCommand(disconnectAction, dv::object());
connection.reset(); connection.reset();
return true; return status;
} }
return false; return false;
} }
@ -165,6 +166,15 @@ bool DebuggingServer::update() {
bool DebuggingServer::performCommand( bool DebuggingServer::performCommand(
const std::string& type, const dv::value& map const std::string& type, const dv::value& map
) { ) {
if (type == "connect" && !connectionEstablished) {
map.at("disconnect-action").get(disconnectAction);
connectionEstablished = true;
logger.info() << "client connection established";
connection->sendResponse("success");
}
if (!connectionEstablished) {
return false;
}
if (type == "terminate") { if (type == "terminate") {
engine.quit(); engine.quit();
connection->sendResponse("success"); connection->sendResponse("success");
@ -272,3 +282,7 @@ void DebuggingServer::setClient(u64id_t client) {
std::vector<DebuggingEvent> DebuggingServer::pullEvents() { std::vector<DebuggingEvent> DebuggingServer::pullEvents() {
return std::move(breakpointEvents); return std::move(breakpointEvents);
} }
void DebuggingServer::setDisconnectAction(const std::string& action) {
disconnectAction = action;
}

View File

@ -83,11 +83,15 @@ namespace devtools {
void setClient(u64id_t client); void setClient(u64id_t client);
std::vector<DebuggingEvent> pullEvents(); std::vector<DebuggingEvent> pullEvents();
void setDisconnectAction(const std::string& action);
private: private:
Engine& engine; Engine& engine;
network::Server& server; network::Server& server;
std::unique_ptr<ClientConnection> connection; std::unique_ptr<ClientConnection> connection;
bool connectionEstablished = false;
std::vector<DebuggingEvent> breakpointEvents; std::vector<DebuggingEvent> breakpointEvents;
std::string disconnectAction = "resume";
bool performCommand( bool performCommand(
const std::string& type, const dv::value& map const std::string& type, const dv::value& map