Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/core/debugger/remote_debugger_peer.h
11352 views
1
/**************************************************************************/
2
/* remote_debugger_peer.h */
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
#pragma once
32
33
#include "core/io/stream_peer_tcp.h"
34
#include "core/io/stream_peer_uds.h"
35
#include "core/object/ref_counted.h"
36
#include "core/os/mutex.h"
37
#include "core/os/thread.h"
38
#include "core/string/ustring.h"
39
40
class RemoteDebuggerPeer : public RefCounted {
41
GDSOFTCLASS(RemoteDebuggerPeer, RefCounted);
42
43
protected:
44
int max_queued_messages = 4096;
45
46
public:
47
virtual bool is_peer_connected() = 0;
48
virtual int get_max_message_size() const = 0;
49
virtual bool has_message() = 0;
50
virtual Error put_message(const Array &p_arr) = 0;
51
virtual Array get_message() = 0;
52
virtual void close() = 0;
53
virtual void poll() = 0;
54
virtual bool can_block() const { return true; } // If blocking io is allowed on main thread (debug).
55
56
RemoteDebuggerPeer();
57
};
58
59
class RemoteDebuggerPeerTCP : public RemoteDebuggerPeer {
60
GDSOFTCLASS(RemoteDebuggerPeerTCP, RemoteDebuggerPeer);
61
62
private:
63
Ref<StreamPeerSocket> tcp_client;
64
Mutex mutex;
65
Thread thread;
66
List<Array> in_queue;
67
List<Array> out_queue;
68
int out_left = 0;
69
int out_pos = 0;
70
Vector<uint8_t> out_buf;
71
int in_left = 0;
72
int in_pos = 0;
73
Vector<uint8_t> in_buf;
74
bool connected = false;
75
bool running = false;
76
77
static void _thread_func(void *p_ud);
78
79
void _poll();
80
void _write_out();
81
void _read_in();
82
static Error _try_connect(Ref<StreamPeerSocket> p_stream);
83
84
public:
85
static RemoteDebuggerPeer *create_tcp(const String &p_uri);
86
static RemoteDebuggerPeer *create_unix(const String &p_uri);
87
88
bool is_peer_connected() override;
89
int get_max_message_size() const override;
90
bool has_message() override;
91
Error put_message(const Array &p_arr) override;
92
Array get_message() override;
93
void poll() override;
94
void close() override;
95
96
RemoteDebuggerPeerTCP(Ref<StreamPeerSocket> p_stream);
97
RemoteDebuggerPeerTCP();
98
~RemoteDebuggerPeerTCP();
99
};
100
101