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