Polyphase Game Engine
Loading...
Searching...
No Matches
TerminalProcess_WindowsConPTY.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4#if PLATFORM_WINDOWS
5
7#include "ITerminalProcess.h"
8
9#include <atomic>
10#include <memory>
11#include <mutex>
12#include <thread>
13
35class TerminalProcess_WindowsConPTY : public ITerminalProcess
36{
37public:
38 TerminalProcess_WindowsConPTY();
39 ~TerminalProcess_WindowsConPTY() override;
40
41 bool Start(const TerminalLaunchConfig& cfg, std::string& outError) override;
42 bool WriteStdin(const char* data, size_t len) override;
43 void RequestStop() override;
44 void ForceKill() override;
45 bool IsRunning() const override { return mRunning.load(); }
46 int GetExitCode() const override { return mExitCode.load(); }
47 void Join() override;
48 bool IsTty() const override { return true; }
49
51 static bool IsConPtyAvailable();
52
53private:
54 void ReaderLoop();
55 void WaitLoop();
56 void CloseAllHandles();
57
58 void* mProcess = nullptr; // HANDLE
59 unsigned long mProcessId = 0; // DWORD
60 void* mPseudoConsole = nullptr; // HPCON
61
62 void* mInputWrite = nullptr; // we WRITE here -> ConPTY child stdin
63 void* mOutputRead = nullptr; // we READ here <- ConPTY child stdout
64
65 void* mAttributeListMem = nullptr; // HeapAlloc'd PROC_THREAD_ATTRIBUTE_LIST*
66
67 std::unique_ptr<ITerminalOutputParser> mParser;
68
69 std::thread mReader;
70 std::thread mWaitThread;
71
72 std::atomic<bool> mRunning{ false };
73 std::atomic<bool> mStopRequested{ false };
74 std::atomic<int> mExitCode{ 0 };
75
76 std::mutex mStdinMutex;
77 std::mutex mLifecycleMutex;
78};
79
80#endif // PLATFORM_WINDOWS
81#endif // EDITOR