2022-04-14 16:13:19 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
2022-12-14 05:03:37 +00:00
|
|
|
File: AuIPCHandle.hpp
|
2022-04-14 16:13:19 +00:00
|
|
|
Date: 2022-4-13
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
2022-06-11 23:52:46 +00:00
|
|
|
namespace Aurora::IO::IPC
|
2022-04-14 16:13:19 +00:00
|
|
|
{
|
2022-07-21 06:18:53 +00:00
|
|
|
AUE_DEFINE(EIPCHandleType, (
|
|
|
|
eIPCPipe,
|
|
|
|
eIPCMemory,
|
|
|
|
eIPCSharedFd,
|
|
|
|
eIPCPrimitiveSemaphore,
|
|
|
|
eIPCPrimitiveMutex,
|
2022-08-02 04:52:17 +00:00
|
|
|
eIPCPrimitiveEvent,
|
|
|
|
eIPCPipeEnd
|
2022-07-21 06:18:53 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
struct IPCToken
|
2022-04-14 16:13:19 +00:00
|
|
|
{
|
2022-07-21 06:18:53 +00:00
|
|
|
IPCToken();
|
|
|
|
|
|
|
|
AuUInt word {};
|
|
|
|
AuUInt32 pid {};
|
2022-04-14 16:13:19 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
char path[16];
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
AuUInt32 cookie;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-04-15 10:01:43 +00:00
|
|
|
void NewId();
|
2022-04-15 14:46:07 +00:00
|
|
|
|
2022-04-14 16:13:19 +00:00
|
|
|
AuString ToNTPath() const;
|
|
|
|
AuUInt32 ToUnixServerCookie() const;
|
2022-08-02 04:52:17 +00:00
|
|
|
|
|
|
|
#if defined(AURORA_IS_POSIX_DERIVED)
|
|
|
|
pid_t ToUnixPid() const;
|
|
|
|
#endif
|
2022-07-21 06:18:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
2022-08-02 04:52:17 +00:00
|
|
|
bool PushId(EIPCHandleType type, const IPCToken &token);
|
2022-07-21 06:18:53 +00:00
|
|
|
|
|
|
|
IPCValue *GetToken(EIPCHandleType type, int id);
|
|
|
|
|
|
|
|
AuUInt32 pid {};
|
|
|
|
|
|
|
|
AuList<IPCValue> values;
|
|
|
|
|
|
|
|
bool FromString(const AuString &in);
|
|
|
|
|
|
|
|
AuString ToString() const;
|
2022-04-14 16:13:19 +00:00
|
|
|
|
2022-07-21 06:18:53 +00:00
|
|
|
#if defined(AURORA_IS_POSIX_DERIVED)
|
2022-04-14 16:13:19 +00:00
|
|
|
pid_t ToUnixPid() const;
|
2022-07-21 06:18:53 +00:00
|
|
|
#endif
|
2022-04-14 16:13:19 +00:00
|
|
|
};
|
|
|
|
}
|