/* * Copyright (c) 2025, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include namespace DevTools { using ActorRegistry = HashMap>; class DevToolsServer { public: static ErrorOr> create(DevToolsDelegate&, u16 port); ~DevToolsServer(); RefPtr& connection() { return m_connection; } DevToolsDelegate const& delegate() const { return m_delegate; } ActorRegistry const& actor_registry() const { return m_actor_registry; } template ActorType& register_actor(Args&&... args) { String name; auto id = m_actor_count++; if constexpr (IsSame) { name = String::from_utf8_without_validation(ActorType::base_name.bytes()); } else { name = MUST(String::formatted("server{}-{}{}", m_server_id, ActorType::base_name, id)); } auto actor = ActorType::create(*this, name, forward(args)...); m_actor_registry.set(name, actor); return actor; } void refresh_tab_list(); private: explicit DevToolsServer(DevToolsDelegate&, NonnullRefPtr); ErrorOr on_new_client(); void on_message_received(JsonObject); void close_connection(); NonnullRefPtr m_server; RefPtr m_connection; DevToolsDelegate& m_delegate; ActorRegistry m_actor_registry; RefPtr m_root_actor { nullptr }; u64 m_server_id { 0 }; u64 m_actor_count { 0 }; }; }