AuroraRuntime/Source/IO/IPC/AuIPCHandle.hpp

94 lines
1.7 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuIPCHandle.hpp
Date: 2022-4-13
Author: Reece
***/
#pragma once
namespace Aurora::IO::IPC
{
AUE_DEFINE(EIPCHandleType, (
eIPCPipe,
eIPCMemory,
eIPCSharedFd,
eIPCPrimitiveSemaphore,
eIPCPrimitiveMutex,
eIPCPrimitiveEvent,
eIPCPipeEnd
));
struct IPCToken
{
IPCToken();
AuUInt word {};
AuUInt32 pid {};
union
{
char path[16];
struct
{
AuUInt32 cookie;
};
};
void NewId();
AuString ToNTPath() const;
AuUInt32 ToUnixServerCookie() const;
#if defined(AURORA_IS_POSIX_DERIVED)
pid_t ToUnixPid() const;
#endif
};
struct IPCValue
{
EIPCHandleType subtype;
IPCToken token;
};
#pragma pack(push)
#pragma pack(1)
struct IPCHeader
{
union
{
struct
{
AuUInt8 bmType : 3;
AuUInt8 bmHasWord : 1;
AuUInt8 bmHasPid : 1;
AuUInt8 bmArray : 3;
};
AuUInt8 bValue;
};
};
#pragma pack(pop)
static_assert(sizeof(IPCHeader) == 1);
struct IPCHandle
{
IPCHandle();
bool IsTopEq(EIPCHandleType type) const;
bool PushId(EIPCHandleType type, const IPCToken &token);
IPCValue *GetToken(EIPCHandleType type, int id);
AuUInt32 pid {};
AuList<IPCValue> values;
bool FromString(const AuROString &in);
AuString ToString() const;
#if defined(AURORA_IS_POSIX_DERIVED)
pid_t ToUnixPid() const;
#endif
};
}