/* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace IPC { class AutoCloseFileDescriptor : public RefCounted { public: AutoCloseFileDescriptor(int fd) : m_fd(fd) { } ~AutoCloseFileDescriptor() { if (m_fd != -1) close(m_fd); } int value() const { return m_fd; } private: int m_fd; }; class MessageBuffer { public: MessageBuffer(); ErrorOr extend_data_capacity(size_t capacity); ErrorOr append_data(u8 const* values, size_t count); ErrorOr append_file_descriptor(int fd); ErrorOr transfer_message(Transport& socket); private: Vector m_data; Vector, 1> m_fds; }; enum class ErrorCode : u32 { PeerDisconnected }; template using IPCErrorOr = ErrorOr; class Message { public: virtual ~Message() = default; virtual u32 endpoint_magic() const = 0; virtual int message_id() const = 0; virtual char const* message_name() const = 0; virtual bool valid() const = 0; virtual ErrorOr encode() const = 0; protected: Message() = default; }; }