95 lines
2.9 KiB
C++
95 lines
2.9 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: AuProcess.NT.hpp
|
|
Date: 2022-1-29
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
#include <Source/IO/FS/Async.NT.hpp>
|
|
|
|
namespace Aurora::Processes
|
|
{
|
|
struct ProcessImpl :
|
|
IProcess,
|
|
IO::CompletionGroup::ICompletionGroupWorkItem
|
|
{
|
|
ProcessImpl(StartupParameters &¶ms);
|
|
~ProcessImpl();
|
|
|
|
bool TermWinEnumProcesses();
|
|
|
|
bool TryKill() override;
|
|
bool HasExited() override;
|
|
|
|
AuUInt GetProcessId() override;
|
|
|
|
bool Terminate() override;
|
|
AuSPtr<Threading::IWaitable> AsWaitable() override;
|
|
AuSPtr<AuLoop::ILoopSource> AsLoopSource() override;
|
|
AuSInt GetExitCode() override;
|
|
|
|
void ShutdownPipes();
|
|
|
|
bool Read(EStandardHandle stream, const AuMemoryViewStreamWrite &destination, bool nonblock) override;
|
|
bool Write(const AuMemoryViewStreamRead &source) override;
|
|
|
|
AuSPtr<IO::IAsyncTransaction> NewAsyncTransaction() override;
|
|
AuSPtr<IO::IAsyncTransaction> NewErrorStreamAsyncTransaction() override;
|
|
AuSPtr<IO::IIOHandle> GetOutputAndInputHandles() override;
|
|
AuSPtr<IO::IIOHandle> GetErrorStreamHandle() override;
|
|
|
|
AuSPtr<IO::IStreamReader> ToStreamReader(EStandardHandle stream) override;
|
|
AuSPtr<IO::IStreamWriter> ToStreamWriter() override;
|
|
|
|
bool Start() override;
|
|
|
|
bool TryAttachProcessExitToCompletionGroup(const AuSPtr<IO::CompletionGroup::ICompletionGroup> &pCompletionGroup) override;
|
|
IO::CompletionGroup::ICompletionGroupWorkHandle *ToCompletionGroupHandle() override;
|
|
|
|
bool HasCompletedForGCWI() override;
|
|
void CleanupForGCWI() override;
|
|
|
|
bool Init();
|
|
void RestLeakyMem();
|
|
void RelOtherHandles();
|
|
|
|
private:
|
|
PROCESS_INFORMATION processInfo_ {};
|
|
HANDLE process_ {INVALID_HANDLE_VALUE};
|
|
|
|
HANDLE pipeStdOutRead_ {INVALID_HANDLE_VALUE};
|
|
HANDLE pipeStdOutWrite_ {INVALID_HANDLE_VALUE};
|
|
HANDLE pipeStdErrRead_ {INVALID_HANDLE_VALUE};
|
|
HANDLE pipeStdErrWrite_ {INVALID_HANDLE_VALUE};
|
|
HANDLE pipeStdInRead_ {INVALID_HANDLE_VALUE};
|
|
HANDLE pipeStdInWrite_ {INVALID_HANDLE_VALUE};
|
|
|
|
|
|
bool bDontRelOut_ {};
|
|
bool bDontRelIn_ {};
|
|
bool bDontRelErr_ {};
|
|
|
|
|
|
AuSPtr<AuLoop::ILoopSource> loopSource_;
|
|
|
|
AuSPtr<IO::IIOHandle> fsHandle_;
|
|
AuSPtr<IO::FS::NtAsyncFileStream> fsStream_;
|
|
|
|
AuSPtr<IO::IIOHandle> fsErrorHandle_;
|
|
AuSPtr<IO::FS::NtAsyncFileStream> fsErrorStream_;
|
|
|
|
StartupParameters startup_;
|
|
ESpawnType type_;
|
|
|
|
AuList<const char *> cargs_;
|
|
AuString windowsCli_;
|
|
|
|
AuThreads::ThreadUnique_t thread_;
|
|
HANDLE poke_ {INVALID_HANDLE_VALUE};
|
|
AuSInt exitCode_;
|
|
bool bHasTerminated {};
|
|
AuSPtr<IO::CompletionGroup::ICompletionGroup> pCompletionGroup_;
|
|
};
|
|
} |