logmeow/logcat_thread.h

33 lines
704 B
C++

#pragma once
#include <thread>
#include <variant>
#include "arb.h"
typedef std::variant<std::string> LogcatThreadItem;
class LogcatThread {
public:
// https://stackoverflow.com/a/2173764
LogcatThread(const LogcatThread&) = delete;
LogcatThread& operator=(const LogcatThread&) = delete;
LogcatThread();
~LogcatThread();
void request_stop();
void join();
AtomicRingBuffer<LogcatThreadItem> atomic_ring_buffer;
private:
void _run(std::stop_token stoken);
int _epoll_fd = -1;
int _stdout_read_fd = -1;
int _stdout_write_fd = -1;
int _stderr_read_fd = -1;
int _stderr_write_fd = -1;
std::stop_source _stop_source;
std::thread _thread;
};