Polyphase Game Engine
Loading...
Searching...
No Matches
TerminalProcess_Windows.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4#if PLATFORM_WINDOWS
5
6#include "ITerminalProcess.h"
7
8#include <atomic>
9#include <mutex>
10#include <thread>
11
23class TerminalProcess_Windows : public ITerminalProcess
24{
25public:
26 TerminalProcess_Windows();
27 ~TerminalProcess_Windows() override;
28
29 bool Start(const TerminalLaunchConfig& cfg, std::string& outError) override;
30 bool WriteStdin(const char* data, size_t len) override;
31 void RequestStop() override;
32 void ForceKill() override;
33 bool IsRunning() const override { return mRunning.load(); }
34 int GetExitCode() const override { return mExitCode.load(); }
35 void Join() override;
36 bool IsTty() const override { return false; }
37
38private:
39 void ReaderLoop(void* pipeHandle, TerminalEntryKind kind);
40 void WaitLoop();
41 void CloseAllHandles();
42
44 static std::string BuildCommandLine(const std::string& exe,
45 const std::vector<std::string>& args);
46
47 void* mProcess = nullptr; // HANDLE
48 unsigned long mProcessId = 0; // DWORD
49 void* mJob = nullptr; // HANDLE (Job Object)
50
51 void* mStdoutRead = nullptr;
52 void* mStdoutWrite = nullptr;
53 void* mStderrRead = nullptr;
54 void* mStderrWrite = nullptr;
55 void* mStdinRead = nullptr;
56 void* mStdinWrite = nullptr;
57
58 std::thread mStdoutReader;
59 std::thread mStderrReader;
60 std::thread mWaitThread;
61
62 std::atomic<bool> mRunning{ false };
63 std::atomic<bool> mStopRequested{ false };
64 std::atomic<int> mExitCode{ 0 };
65
66 std::mutex mStdinMutex;
67 std::mutex mLifecycleMutex; // protects Start/Join/CloseAllHandles
68};
69
70#endif // PLATFORM_WINDOWS
71#endif // EDITOR