Polyphase Game Engine
Loading...
Searching...
No Matches
TerminalProcess_LinuxPty.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4#if PLATFORM_LINUX
5
7#include "ITerminalProcess.h"
8
9#include <atomic>
10#include <memory>
11#include <mutex>
12#include <sys/types.h>
13#include <thread>
14
28class TerminalProcess_LinuxPty : public ITerminalProcess
29{
30public:
31 TerminalProcess_LinuxPty();
32 ~TerminalProcess_LinuxPty() override;
33
34 bool Start(const TerminalLaunchConfig& cfg, std::string& outError) override;
35 bool WriteStdin(const char* data, size_t len) override;
36 void RequestStop() override;
37 void ForceKill() override;
38 bool IsRunning() const override { return mRunning.load(); }
39 int GetExitCode() const override { return mExitCode.load(); }
40 void Join() override;
41 bool IsTty() const override { return true; }
42
43private:
44 void ReaderLoop();
45 void WaitLoop();
46 void CloseFds();
47
48 pid_t mPid = -1;
49 int mPtyFd = -1; // master side of the PTY pair
50
51 std::unique_ptr<ITerminalOutputParser> mParser;
52
53 std::thread mReader;
54 std::thread mWaitThread;
55
56 std::atomic<bool> mRunning{ false };
57 std::atomic<bool> mStopRequested{ false };
58 std::atomic<int> mExitCode{ 0 };
59
60 std::mutex mStdinMutex;
61 std::mutex mLifecycleMutex;
62};
63
64#endif // PLATFORM_LINUX
65#endif // EDITOR