AuroraRuntime/Source/IO/IPC/IPCHandle.hpp

89 lines
1.6 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IPCHandle.hpp
Date: 2022-4-13
Author: Reece
***/
#pragma once
namespace Aurora::IO::IPC
{
AUE_DEFINE(EIPCHandleType, (
eIPCPipe,
eIPCMemory,
eIPCSharedFd,
eIPCPrimitiveSemaphore,
eIPCPrimitiveMutex,
eIPCPrimitiveEvent
));
struct IPCToken
{
IPCToken();
AuUInt word {};
AuUInt32 pid {};
union
{
char path[16];
struct
{
AuUInt32 cookie;
};
};
void NewId();
AuString ToNTPath() const;
AuUInt32 ToUnixServerCookie() const;
};
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, IPCToken &token);
IPCValue *GetToken(EIPCHandleType type, int id);
AuUInt32 pid {};
AuList<IPCValue> values;
bool FromString(const AuString &in);
AuString ToString() const;
#if defined(AURORA_IS_POSIX_DERIVED)
pid_t ToUnixPid() const;
#endif
};
}