Path: blob/master/core/debugger/remote_debugger_peer.h
11352 views
/**************************************************************************/1/* remote_debugger_peer.h */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#pragma once3132#include "core/io/stream_peer_tcp.h"33#include "core/io/stream_peer_uds.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"3839class RemoteDebuggerPeer : public RefCounted {40GDSOFTCLASS(RemoteDebuggerPeer, RefCounted);4142protected:43int max_queued_messages = 4096;4445public:46virtual bool is_peer_connected() = 0;47virtual int get_max_message_size() const = 0;48virtual bool has_message() = 0;49virtual Error put_message(const Array &p_arr) = 0;50virtual Array get_message() = 0;51virtual void close() = 0;52virtual void poll() = 0;53virtual bool can_block() const { return true; } // If blocking io is allowed on main thread (debug).5455RemoteDebuggerPeer();56};5758class RemoteDebuggerPeerTCP : public RemoteDebuggerPeer {59GDSOFTCLASS(RemoteDebuggerPeerTCP, RemoteDebuggerPeer);6061private:62Ref<StreamPeerSocket> tcp_client;63Mutex mutex;64Thread thread;65List<Array> in_queue;66List<Array> out_queue;67int out_left = 0;68int out_pos = 0;69Vector<uint8_t> out_buf;70int in_left = 0;71int in_pos = 0;72Vector<uint8_t> in_buf;73bool connected = false;74bool running = false;7576static void _thread_func(void *p_ud);7778void _poll();79void _write_out();80void _read_in();81static Error _try_connect(Ref<StreamPeerSocket> p_stream);8283public:84static RemoteDebuggerPeer *create_tcp(const String &p_uri);85static RemoteDebuggerPeer *create_unix(const String &p_uri);8687bool is_peer_connected() override;88int get_max_message_size() const override;89bool has_message() override;90Error put_message(const Array &p_arr) override;91Array get_message() override;92void poll() override;93void close() override;9495RemoteDebuggerPeerTCP(Ref<StreamPeerSocket> p_stream);96RemoteDebuggerPeerTCP();97~RemoteDebuggerPeerTCP();98};99100101