godot-xterm/addons/godot_xterm/native/src/pseudoterminal.h

47 lines
957 B
C
Raw Normal View History

2020-07-11 12:45:21 +02:00
#ifndef PSEUDOTERMINAL_H
#define PSEUDOTERMINAL_H
#include <Godot.hpp>
#include <Node.hpp>
#include <thread>
#include <mutex>
2020-07-11 12:45:21 +02:00
namespace godot
{
class Pseudoterminal : public Node
{
GODOT_CLASS(Pseudoterminal, Node)
2020-07-11 12:45:21 +02:00
public:
static const int MAX_READ_BUFFER_LENGTH = 1024;
static const int MAX_WRITE_BUFFER_LENGTH = 1024;
private:
std::thread pty_thread;
bool should_process_pty;
char write_buffer[MAX_WRITE_BUFFER_LENGTH];
int bytes_to_write;
std::mutex write_buffer_mutex;
char read_buffer[MAX_READ_BUFFER_LENGTH];
int bytes_to_read;
std::mutex read_buffer_mutex;
void process_pty();
public:
static void _register_methods();
2020-07-11 12:45:21 +02:00
Pseudoterminal();
~Pseudoterminal();
2020-07-11 12:45:21 +02:00
void _init();
void _ready();
2020-07-11 12:45:21 +02:00
void put_data(PoolByteArray data);
};
2020-07-11 12:45:21 +02:00
} // namespace godot
#endif // PSEUDOTERMINAL_H