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