Polyphase Game Engine
Loading...
Searching...
No Matches
TerminalProcess_Posix.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4#if PLATFORM_LINUX
5
6#include "ITerminalProcess.h"
7
8#include <atomic>
9#include <mutex>
10#include <sys/types.h>
11#include <thread>
12
21class TerminalProcess_Posix : public ITerminalProcess
22{
23public:
24 TerminalProcess_Posix();
25 ~TerminalProcess_Posix() override;
26
27 bool Start(const TerminalLaunchConfig& cfg, std::string& outError) override;
28 bool WriteStdin(const char* data, size_t len) override;
29 void RequestStop() override;
30 void ForceKill() override;
31 bool IsRunning() const override { return mRunning.load(); }
32 int GetExitCode() const override { return mExitCode.load(); }
33 void Join() override;
34 bool IsTty() const override { return false; }
35
36private:
37 void ReaderLoop(int fd, TerminalEntryKind kind);
38 void WaitLoop();
39 void CloseAllFds();
40
41 pid_t mPid = -1;
42 pid_t mPgid = -1;
43
44 int mStdoutPipe[2] = { -1, -1 };
45 int mStderrPipe[2] = { -1, -1 };
46 int mStdinPipe[2] = { -1, -1 };
47
48 std::thread mStdoutReader;
49 std::thread mStderrReader;
50 std::thread mWaitThread;
51
52 std::atomic<bool> mRunning{ false };
53 std::atomic<bool> mStopRequested{ false };
54 std::atomic<int> mExitCode{ 0 };
55
56 std::mutex mStdinMutex;
57 std::mutex mLifecycleMutex;
58};
59
60#endif // PLATFORM_LINUX
61#endif // EDITOR