AuroraRuntime/Source/IO/FS/Async.NT.hpp
2024-01-06 04:32:54 +00:00

103 lines
3.1 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Async.NT.hpp
Date: 2021-9-13
Author: Reece
***/
#pragma once
namespace Aurora::IO::IPC
{
struct IPCPipeImpl;
}
namespace Aurora::IO::FS
{
struct NtAsyncFileStream : IAsyncFileStream
{
AuSPtr<IAsyncTransaction> NewTransaction() override;
bool BlockingTruncate(AuUInt64 length) override;
bool BlockingRead(AuUInt64 offset, const Memory::MemoryViewStreamWrite &parameters) override;
bool BlockingWrite(AuUInt64 offset, const Memory::MemoryViewStreamRead &parameters) override;
void Init(const AuSPtr<IIOHandle> &pHandle);
AuSPtr<IIOHandle> GetHandle();
private:
AuSPtr<IIOHandle> pHandle_;
};
struct NtAsyncFileTransaction :
IAsyncTransaction,
CompletionGroup::ICompletionGroupWorkItem,
AuEnableSharedFromThis<NtAsyncFileTransaction>
{
~NtAsyncFileTransaction();
bool Init(const AuSPtr<IIOHandle> &handle);
bool InitWeak(const AuSPtr<IIOHandle> &handle);
void ResetAIO();
bool StartRead(AuUInt64 offset, const AuSPtr<AuMemoryViewWrite> &memoryView) override;
bool StartWrite(AuUInt64 offset, const AuSPtr<AuMemoryViewRead> &memoryView) override;
bool isIrredeemable_ {};
bool HasCompleted() override;
bool Complete() override;
bool HasCompletedForGCWI() override;
void CleanupForGCWI() override;
bool CompleteEx(AuUInt completeRoutine, bool bForce = false);
bool HasFailed() override;
AuUInt GetOSErrorCode() override;
AuUInt32 GetLastPacketLength() override;
void SetCallback(const AuSPtr<IAsyncFinishedSubscriber> &sub) override;
void SetBaseOffset(AuUInt64 uBaseOffset) override;
bool Wait(AuUInt32 timeout) override;
AuSPtr<AuLoop::ILoopSource> NewLoopSource() override;
void Reset() override;
bool TryAttachToCompletionGroup(const AuSPtr<CompletionGroup::ICompletionGroup> &pCompletionGroup) override;
CompletionGroup::ICompletionGroupWorkHandle *ToCompletionGroupHandle() override;
AuSPtr<CompletionGroup::ICompletionGroup> GetCompletionGroup() override;
bool IDontWannaUsePorts();
void DispatchCb(AuUInt32 len);
HANDLE GetHandle();
AuSPtr<IIOHandle> GetFileHandle();
OVERLAPPED overlap {};
HANDLE event = INVALID_HANDLE_VALUE;
AuSPtr<NtAsyncFileTransaction> pPin;
AuUInt32 dwLastAbstractStat {};
AuUInt64 qwLastAbstractOffset {};
bool bLatch {};
AuUInt32 dwLastBytes {};
AuUInt32 dwOsErrorCode {};
bool bHasFailed {};
AuUInt64 uBaseOffset {};
AuWPtr<Aurora::IO::IPC::IPCPipeImpl> pNtIpcPipeImpl;
AuSPtr<void> pMemoryHold;
private:
AuSPtr<IIOHandle> pHandle_;
AuWPtr<IIOHandle> wpHandle_;
AuSPtr<IAsyncFinishedSubscriber> pSub_;
bool bOwnsEvent_ { true };
AuSPtr<CompletionGroup::ICompletionGroup> pCompletionGroup_;
};
}