2025-02-15 09:35:58 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2026-06-11 11:52:59 -03:00
|
|
|
#include <AK/ByteBuffer.h>
|
2025-02-15 09:35:58 -03:00
|
|
|
#include <AK/Error.h>
|
|
|
|
|
#include <AK/Function.h>
|
|
|
|
|
#include <AK/NonnullOwnPtr.h>
|
|
|
|
|
#include <AK/NonnullRefPtr.h>
|
2026-06-11 11:52:59 -03:00
|
|
|
#include <AK/Optional.h>
|
2025-02-15 09:35:58 -03:00
|
|
|
#include <AK/RefCounted.h>
|
2026-06-04 11:16:10 -03:00
|
|
|
#include <AK/Weakable.h>
|
2025-02-15 09:35:58 -03:00
|
|
|
#include <LibCore/Socket.h>
|
|
|
|
|
#include <LibDevTools/Forward.h>
|
|
|
|
|
|
|
|
|
|
namespace DevTools {
|
|
|
|
|
|
2026-06-04 11:16:10 -03:00
|
|
|
class DEVTOOLS_API Connection
|
|
|
|
|
: public RefCounted<Connection>
|
|
|
|
|
, public Weakable<Connection> {
|
2025-02-15 09:35:58 -03:00
|
|
|
public:
|
|
|
|
|
static NonnullRefPtr<Connection> create(NonnullOwnPtr<Core::BufferedTCPSocket>);
|
|
|
|
|
~Connection();
|
|
|
|
|
|
|
|
|
|
Function<void()> on_connection_closed;
|
2025-03-12 09:01:23 -03:00
|
|
|
Function<void(JsonObject)> on_message_received;
|
2025-02-15 09:35:58 -03:00
|
|
|
|
|
|
|
|
void send_message(JsonValue const&);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
explicit Connection(NonnullOwnPtr<Core::BufferedTCPSocket>);
|
|
|
|
|
|
|
|
|
|
ErrorOr<void> on_ready_to_read();
|
2026-06-11 11:52:59 -03:00
|
|
|
ErrorOr<void> read_available_data();
|
|
|
|
|
ErrorOr<Optional<JsonValue>> read_message();
|
2025-02-15 09:35:58 -03:00
|
|
|
|
|
|
|
|
NonnullOwnPtr<Core::BufferedTCPSocket> m_socket;
|
2026-06-11 11:52:59 -03:00
|
|
|
ByteBuffer m_incoming_buffer;
|
2025-02-15 09:35:58 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|