AuroraRuntime/Include/Aurora/IO/IOHandle.hpp
Jamie Reece Wilson b4d5f4c127 [+] AuIO::IO::EStandardStream
[+] AuIO::IOHandle::InitFromStreamEnum(...)
2023-09-13 02:50:59 +01:00

145 lines
4.3 KiB
C++

/***
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IOHandle.hpp
Date: 2023-7-28
Author: Reece
***/
#pragma once
#include "FS/EFileAdvisoryLockLevel.hpp"
#include "FS/EFileOpenMode.hpp"
namespace Aurora::IO
{
// Note: A handle is never disposable to prevent IO fd use after close
// You must ensure RAII and/or shared ownership release to dispose of the IO handle.
// This class is only intended to be an handle view; therefore, it is not possible to close the handle.
struct IIOHandle
{
struct HandleCreate
{
/**
* "Create"
*/
bool bFailIfNonEmptyFile {};
/**
* Lock level
*/
FS::EFileAdvisoryLockLevel eAdvisoryLevel;
/**
* Path
*/
const AuString &path;
/**
* Mode
*/
FS::EFileOpenMode eMode;
/**
*
*/
bool bAlwaysCreateDirTree { true };
/**
* Indicates the handle will be for use with IAsyncTransactions as opposed to IFileStream and AuProcess
*/
bool bAsyncHandle { false };
/**
* Indicates the handle will only ever directly interface with the disk hardware as opposed to leveraging kernel assigned user shared memory
*/
bool bDirectIOMode { false };
cstatic HandleCreate Create(const AuString &path)
{
HandleCreate create(path);
create.bFailIfNonEmptyFile = true;
create.eMode = FS::EFileOpenMode::eReadWrite;
create.eAdvisoryLevel = FS::EFileAdvisoryLockLevel::eBlockReadWrite;
return AuMove(create);
}
cstatic HandleCreate ReadWrite(const AuString &path)
{
HandleCreate create(path);
create.eMode = FS::EFileOpenMode::eReadWrite;
create.eAdvisoryLevel = FS::EFileAdvisoryLockLevel::eBlockReadWrite;
return AuMove(create);
}
cstatic HandleCreate Read(const AuString &path)
{
HandleCreate read(path);
read.eMode = FS::EFileOpenMode::eRead;
read.eAdvisoryLevel = FS::EFileAdvisoryLockLevel::eBlockWrite;
return AuMove(read);
}
cstatic HandleCreate Open(const AuString &path)
{
HandleCreate read(path);
read.eMode = FS::EFileOpenMode::eRead;
read.eAdvisoryLevel = FS::EFileAdvisoryLockLevel::eBlockReadWrite;
return AuMove(read);
}
inline HandleCreate(const AuString &path) :
path(path)
{
}
};
virtual bool InitFromHandle(AuSPtr<IIOHandle> pHandle) = 0;
virtual bool InitFromPath(HandleCreate create) = 0;
virtual bool InitFromCopy(AuUInt64 uOSHandle) = 0;
virtual bool InitFromMove(AuUInt64 uOSHandle) = 0;
virtual bool InitFromPair(AuUInt64 uOSReadHandle, AuUInt64 uOSWriteHandle) = 0;
virtual bool InitFromPairMove(AuOptionalEx<AuUInt64> uOSReadHandle,
AuOptionalEx<AuUInt64> uOSWriteHandle) = 0;
virtual bool InitFromStreamEnum(EStandardStream eStream) = 0;
virtual AuUInt64 GetOSHandle() = 0;
virtual AuOptionalEx<AuUInt64> GetOSHandleSafe() = 0;
virtual AuUInt64 GetOSReadHandle() = 0;
virtual AuOptionalEx<AuUInt64> GetOSReadHandleSafe() = 0;
virtual AuUInt64 GetOSWriteHandle() = 0;
virtual AuOptionalEx<AuUInt64> GetOSWriteHandleSafe() = 0;
virtual bool IsValid() = 0;
virtual bool HasUniqueWriteHandle() = 0;
virtual bool IsAsync() = 0;
virtual AuString GetPath() = 0;
virtual bool IsFile() = 0;
virtual bool IsTTY() = 0;
virtual bool IsPipe() = 0;
};
AUKN_SHARED_SOO_NC(IOHandle, IIOHandle, 256);
AUKN_SYM bool IsHandleTTY(AuUInt uHandle);
AUKN_SYM bool IsHandlePipe(AuUInt uHandle);
AUKN_SYM bool IsHandleFile(AuUInt uHandle);
}