mirror of
https://github.com/RGBCube/serenity
synced 2025-05-25 12:35:07 +00:00

The C_OBJECT macro now also inserts a static construct(...) helper into the class. Now we can make the constructor(s) private and instead call: auto socket = CTCPSocket::construct(arguments); construct() returns an ObjectPtr<T>, which we'll later switch to being a NonnullRefPtr<T>, once everything else in in place for ref-counting.
43 lines
1 KiB
C++
43 lines
1 KiB
C++
#pragma once
|
|
|
|
#include <AK/String.h>
|
|
#include <AK/StringView.h>
|
|
#include <AK/Types.h>
|
|
#include <LibCore/CNotifier.h>
|
|
#include <LibCore/CTCPSocket.h>
|
|
|
|
#include "Command.h"
|
|
#include "Parser.h"
|
|
|
|
class Client : public RefCounted<Client> {
|
|
public:
|
|
static NonnullRefPtr<Client> create(int id, ObjectPtr<CTCPSocket> socket, int ptm_fd)
|
|
{
|
|
return adopt(*new Client(id, move(socket), ptm_fd));
|
|
}
|
|
|
|
Function<void()> on_exit;
|
|
|
|
protected:
|
|
Client(int id, ObjectPtr<CTCPSocket> socket, int ptm_fd);
|
|
|
|
void drain_socket();
|
|
void drain_pty();
|
|
void handle_data(const StringView&);
|
|
void handle_command(const Command& command);
|
|
void handle_error();
|
|
void send_data(StringView str);
|
|
void send_command(Command command);
|
|
void send_commands(Vector<Command> commands);
|
|
void quit();
|
|
|
|
private:
|
|
// client id
|
|
int m_id { 0 };
|
|
// client resources
|
|
ObjectPtr<CTCPSocket> m_socket;
|
|
Parser m_parser;
|
|
// pty resources
|
|
int m_ptm_fd { -1 };
|
|
ObjectPtr<CNotifier> m_ptm_notifier;
|
|
};
|