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