Path: blob/master/core/debugger/remote_debugger_peer.h
10277 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/object/ref_counted.h"34#include "core/os/mutex.h"35#include "core/os/thread.h"36#include "core/string/ustring.h"3738class RemoteDebuggerPeer : public RefCounted {39protected:40int max_queued_messages = 4096;4142public:43virtual bool is_peer_connected() = 0;44virtual int get_max_message_size() const = 0;45virtual bool has_message() = 0;46virtual Error put_message(const Array &p_arr) = 0;47virtual Array get_message() = 0;48virtual void close() = 0;49virtual void poll() = 0;50virtual bool can_block() const { return true; } // If blocking io is allowed on main thread (debug).5152RemoteDebuggerPeer();53};5455class RemoteDebuggerPeerTCP : public RemoteDebuggerPeer {56private:57Ref<StreamPeerTCP> tcp_client;58Mutex mutex;59Thread thread;60List<Array> in_queue;61List<Array> out_queue;62int out_left = 0;63int out_pos = 0;64Vector<uint8_t> out_buf;65int in_left = 0;66int in_pos = 0;67Vector<uint8_t> in_buf;68bool connected = false;69bool running = false;7071static void _thread_func(void *p_ud);7273void _poll();74void _write_out();75void _read_in();7677public:78static RemoteDebuggerPeer *create(const String &p_uri);7980Error connect_to_host(const String &p_host, uint16_t p_port);8182bool is_peer_connected() override;83int get_max_message_size() const override;84bool has_message() override;85Error put_message(const Array &p_arr) override;86Array get_message() override;87void poll() override;88void close() override;8990RemoteDebuggerPeerTCP(Ref<StreamPeerTCP> p_stream = Ref<StreamPeerTCP>());91~RemoteDebuggerPeerTCP();92};939495