Path: blob/master/editor/debugger/debug_adapter/debug_adapter_server.cpp
9906 views
/**************************************************************************/1/* debug_adapter_server.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "debug_adapter_server.h"3132#include "editor/editor_log.h"33#include "editor/editor_node.h"34#include "editor/settings/editor_settings.h"3536int DebugAdapterServer::port_override = -1;3738DebugAdapterServer::DebugAdapterServer() {39// TODO: Move to editor_settings.cpp40_EDITOR_DEF("network/debug_adapter/remote_port", remote_port);41_EDITOR_DEF("network/debug_adapter/request_timeout", protocol._request_timeout);42_EDITOR_DEF("network/debug_adapter/sync_breakpoints", protocol._sync_breakpoints);43}4445void DebugAdapterServer::_notification(int p_what) {46switch (p_what) {47case NOTIFICATION_ENTER_TREE: {48start();49} break;5051case NOTIFICATION_EXIT_TREE: {52stop();53} break;5455case NOTIFICATION_INTERNAL_PROCESS: {56// The main loop can be run again during request processing, which modifies internal state of the protocol.57// Thus, "polling" is needed to prevent it from parsing other requests while the current one isn't finished.58if (started && !polling) {59polling = true;60protocol.poll();61polling = false;62}63} break;6465case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {66if (!EditorSettings::get_singleton()->check_changed_settings_in_group("network/debug_adapter")) {67break;68}69protocol._request_timeout = EDITOR_GET("network/debug_adapter/request_timeout");70protocol._sync_breakpoints = EDITOR_GET("network/debug_adapter/sync_breakpoints");71int port = (DebugAdapterServer::port_override > -1) ? DebugAdapterServer::port_override : (int)_EDITOR_GET("network/debug_adapter/remote_port");72if (port != remote_port) {73stop();74start();75}76} break;77}78}7980void DebugAdapterServer::start() {81remote_port = (DebugAdapterServer::port_override > -1) ? DebugAdapterServer::port_override : (int)_EDITOR_GET("network/debug_adapter/remote_port");82if (protocol.start(remote_port, IPAddress("127.0.0.1")) == OK) {83EditorNode::get_log()->add_message("--- Debug adapter server started on port " + itos(remote_port) + " ---", EditorLog::MSG_TYPE_EDITOR);84set_process_internal(true);85started = true;86}87}8889void DebugAdapterServer::stop() {90protocol.stop();91started = false;92EditorNode::get_log()->add_message("--- Debug adapter server stopped ---", EditorLog::MSG_TYPE_EDITOR);93}949596