2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-08-03 15:29:40 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-12-30 21:02:46 +03:30
|
|
|
#include <AK/Function.h>
|
2021-05-02 12:28:20 +02:00
|
|
|
#include <AK/RefPtr.h>
|
2020-02-14 21:41:10 +01:00
|
|
|
#include <AK/Vector.h>
|
2021-05-02 12:28:20 +02:00
|
|
|
#include <unistd.h>
|
2019-12-30 02:41:45 +01:00
|
|
|
|
2020-02-05 19:57:18 +01:00
|
|
|
namespace IPC {
|
2019-08-03 15:29:40 +02:00
|
|
|
|
2021-05-02 12:28:20 +02:00
|
|
|
class AutoCloseFileDescriptor : public RefCounted<AutoCloseFileDescriptor> {
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-21 21:59:12 +03:00
|
|
|
struct MessageBuffer {
|
|
|
|
|
Vector<u8, 1024> data;
|
2021-05-02 12:28:20 +02:00
|
|
|
Vector<RefPtr<AutoCloseFileDescriptor>> fds;
|
2020-11-21 21:59:12 +03:00
|
|
|
};
|
2020-02-05 19:57:18 +01:00
|
|
|
|
|
|
|
|
class Message {
|
2019-08-03 15:29:40 +02:00
|
|
|
public:
|
2020-02-05 19:57:18 +01:00
|
|
|
virtual ~Message();
|
2019-08-03 15:29:40 +02:00
|
|
|
|
2021-04-25 13:19:53 +02:00
|
|
|
virtual u32 endpoint_magic() const = 0;
|
2019-12-02 11:07:05 +01:00
|
|
|
virtual int message_id() const = 0;
|
2020-02-15 11:16:45 +01:00
|
|
|
virtual const char* message_name() const = 0;
|
2021-05-02 05:20:28 +02:00
|
|
|
virtual bool valid() const = 0;
|
2020-02-05 19:57:18 +01:00
|
|
|
virtual MessageBuffer encode() const = 0;
|
2019-08-03 15:29:40 +02:00
|
|
|
|
|
|
|
|
protected:
|
2020-02-05 19:57:18 +01:00
|
|
|
Message();
|
2019-08-03 15:29:40 +02:00
|
|
|
};
|
2020-02-05 19:57:18 +01:00
|
|
|
|
|
|
|
|
}
|