2023-07-29 07:02:47 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: AuIOHandle.hpp
|
|
|
|
Date: 2023-7-28
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
namespace Aurora::IO::IPC
|
|
|
|
{
|
|
|
|
struct IPCPipeImpl;
|
|
|
|
}
|
|
|
|
|
2023-07-29 07:02:47 +00:00
|
|
|
namespace Aurora::IO
|
|
|
|
{
|
|
|
|
struct AFileHandle : IIOHandle
|
|
|
|
{
|
2023-12-18 05:32:38 +00:00
|
|
|
~AFileHandle();
|
2023-07-29 07:02:47 +00:00
|
|
|
|
|
|
|
bool InitFromHandle(AuSPtr<IIOHandle> pHandle) override;
|
|
|
|
|
|
|
|
bool InitFromCopy(AuUInt64 uOSHandle) override;
|
|
|
|
|
|
|
|
bool InitFromMove(AuUInt64 uOSHandle) override;
|
|
|
|
|
2023-12-18 08:52:51 +00:00
|
|
|
bool InitFromPair(AuOptionalEx<AuUInt64> uOSReadHandle,
|
|
|
|
AuOptionalEx<AuUInt64> uOSWriteHandle) override;
|
2023-07-29 07:02:47 +00:00
|
|
|
|
2023-12-18 08:52:51 +00:00
|
|
|
bool InitFromPairMove(AuOptionalEx<AuUInt64> uOSReadHandle,
|
|
|
|
AuOptionalEx<AuUInt64> uOSWriteHandle) override;
|
2023-07-29 07:02:47 +00:00
|
|
|
|
2023-09-13 01:50:53 +00:00
|
|
|
bool InitFromStreamEnum(EStandardStream eStream) override;
|
|
|
|
|
2024-01-03 02:39:54 +00:00
|
|
|
bool InitFromSharing(const AuString &handle) override;
|
|
|
|
|
2023-09-28 10:53:42 +00:00
|
|
|
bool InitFromPath(HandleCreate create) override;
|
|
|
|
|
2023-12-18 05:32:38 +00:00
|
|
|
AuUInt64 GetOSHandle() const override;
|
2023-07-29 07:02:47 +00:00
|
|
|
|
2023-12-18 08:52:51 +00:00
|
|
|
AuOptionalEx<AuUInt64> GetOSHandleSafe() const override;
|
2023-08-15 13:41:49 +00:00
|
|
|
|
2023-12-18 05:32:38 +00:00
|
|
|
AuUInt64 GetOSReadHandle() const override;
|
2023-07-29 07:02:47 +00:00
|
|
|
|
2023-12-18 08:52:51 +00:00
|
|
|
AuOptionalEx<AuUInt64> GetOSReadHandleSafe() const override;
|
2023-07-29 07:02:47 +00:00
|
|
|
|
2023-12-18 05:32:38 +00:00
|
|
|
AuUInt64 GetOSWriteHandle() const override;
|
2023-07-29 07:02:47 +00:00
|
|
|
|
2023-12-18 08:52:51 +00:00
|
|
|
AuOptionalEx<AuUInt64> GetOSWriteHandleSafe() const override;
|
2023-07-29 07:02:47 +00:00
|
|
|
|
2023-12-18 05:32:38 +00:00
|
|
|
bool IsValid() const override;
|
2023-07-29 07:02:47 +00:00
|
|
|
|
2023-12-18 05:32:38 +00:00
|
|
|
bool HasUniqueWriteHandle()const override;
|
2023-07-29 07:02:47 +00:00
|
|
|
|
2023-12-18 05:32:38 +00:00
|
|
|
bool IsAsync() const override;
|
2023-07-29 07:02:47 +00:00
|
|
|
|
2023-12-18 05:32:38 +00:00
|
|
|
AuString GetPath() const override;
|
2023-07-29 07:02:47 +00:00
|
|
|
|
2023-12-18 05:32:38 +00:00
|
|
|
bool IsFile() const override;
|
|
|
|
bool IsTTY() const override;
|
|
|
|
bool IsPipe() const override;
|
2023-08-29 00:24:52 +00:00
|
|
|
|
2024-01-02 00:00:47 +00:00
|
|
|
bool IsFlushOnClose() const override;
|
|
|
|
void SetFlushOnClose(bool bFlushOnClose) override;
|
|
|
|
|
2023-09-13 01:50:53 +00:00
|
|
|
void InitStdIn(bool bSharing = false);
|
|
|
|
void InitStdOut(bool bError = false, bool bSharing = false);
|
|
|
|
|
2023-09-23 03:38:26 +00:00
|
|
|
bool SectionLock(AuUInt64 uOffset,
|
|
|
|
AuUInt64 uLength,
|
|
|
|
FS::EFileAdvisoryLockLevel level) override;
|
|
|
|
|
|
|
|
bool SectionUnlock(AuUInt64 uOffset,
|
|
|
|
AuUInt64 uLength) override;
|
2024-01-03 02:39:54 +00:00
|
|
|
|
|
|
|
AuString SharingGetString() override;
|
|
|
|
bool SharingIsShared() override;
|
|
|
|
void SharingStop() override;
|
2023-09-23 03:38:26 +00:00
|
|
|
|
2023-12-18 08:52:51 +00:00
|
|
|
AuOptionalEx<AuUInt64> uOSWriteHandle;
|
|
|
|
AuOptionalEx<AuUInt64> uOSReadHandle;
|
2023-07-29 07:02:47 +00:00
|
|
|
AuSPtr<IIOHandle> pThat;
|
2024-01-02 00:00:47 +00:00
|
|
|
bool bIsAsync {}, bFlushOnClose {};
|
2023-07-29 07:02:47 +00:00
|
|
|
AuString path;
|
2023-08-11 15:51:42 +00:00
|
|
|
IPC::IPCPipeImpl *pIPCPipe {};
|
|
|
|
bool bDirectIO {};
|
2023-12-18 05:32:38 +00:00
|
|
|
mutable AuOptional<bool> optIsFile;
|
|
|
|
mutable AuOptional<bool> optIsPipe;
|
|
|
|
mutable AuOptional<bool> optIsTTY;
|
2024-01-03 02:39:54 +00:00
|
|
|
mutable AuSPtr<AuString> pIPCString;
|
2023-07-29 07:02:47 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Implement me:
|
|
|
|
|
|
|
|
// bool InitFromPath(HandleCreate create) override;
|
|
|
|
|
|
|
|
static AuUInt64 DupHandle(AuUInt64 uOSHandle, bool bWriteAccess);
|
2023-09-13 01:27:18 +00:00
|
|
|
static AuUInt64 DupHandle(AuUInt64 uOSHandle, bool bWriteAccess, bool bShareAccess);
|
2024-01-02 00:00:47 +00:00
|
|
|
static void CloseHandle(AuUInt64 uOSHandle, bool bFlushOnClose);
|
|
|
|
|
|
|
|
inline void CloseHandle(AuUInt64 uOSHandle)
|
|
|
|
{
|
|
|
|
CloseHandle(uOSHandle, this->bFlushOnClose);
|
|
|
|
}
|
2023-07-29 07:02:47 +00:00
|
|
|
};
|
|
|
|
}
|