/*** Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: AuIOHandle.hpp Date: 2023-7-28 Author: Reece ***/ #pragma once namespace Aurora::IO::IPC { struct IPCPipeImpl; } namespace Aurora::IO { struct AFileHandle : IIOHandle { ~AFileHandle(); bool InitFromHandle(AuSPtr pHandle) override; bool InitFromCopy(AuUInt64 uOSHandle) override; bool InitFromMove(AuUInt64 uOSHandle) override; bool InitFromPair(AuOptionalEx uOSReadHandle, AuOptionalEx uOSWriteHandle) override; bool InitFromPairMove(AuOptionalEx uOSReadHandle, AuOptionalEx uOSWriteHandle) override; bool InitFromStreamEnum(EStandardStream eStream) override; bool InitFromSharing(const AuString &handle) override; bool InitFromPath(HandleCreate create) override; AuUInt64 GetOSHandle() const override; AuOptionalEx GetOSHandleSafe() const override; AuUInt64 GetOSReadHandle() const override; AuOptionalEx GetOSReadHandleSafe() const override; AuUInt64 GetOSWriteHandle() const override; AuOptionalEx GetOSWriteHandleSafe() const override; bool IsValid() const override; bool HasUniqueWriteHandle()const override; bool IsAsync() const override; AuString GetPath() const override; bool IsFile() const override; bool IsTTY() const override; bool IsPipe() const override; bool IsFlushOnClose() const override; void SetFlushOnClose(bool bFlushOnClose) override; void InitStdIn(bool bSharing = false); void InitStdOut(bool bError = false, bool bSharing = false); bool SectionLock(AuUInt64 uOffset, AuUInt64 uLength, FS::EFileAdvisoryLockLevel level) override; bool SectionUnlock(AuUInt64 uOffset, AuUInt64 uLength) override; AuString SharingGetString() override; bool SharingIsShared() override; void SharingStop() override; AuOptionalEx uOSWriteHandle; AuOptionalEx uOSReadHandle; AuSPtr pThat; bool bIsAsync {}, bFlushOnClose {}; AuString path; IPC::IPCPipeImpl *pIPCPipe {}; bool bDirectIO {}; mutable AuOptional optIsFile; mutable AuOptional optIsPipe; mutable AuOptional optIsTTY; mutable AuSPtr pIPCString; protected: // Implement me: // bool InitFromPath(HandleCreate create) override; static AuUInt64 DupHandle(AuUInt64 uOSHandle, bool bWriteAccess); static AuUInt64 DupHandle(AuUInt64 uOSHandle, bool bWriteAccess, bool bShareAccess); static void CloseHandle(AuUInt64 uOSHandle, bool bFlushOnClose); inline void CloseHandle(AuUInt64 uOSHandle) { CloseHandle(uOSHandle, this->bFlushOnClose); } }; }