2022-03-01 22:49:26 +00:00
|
|
|
//
|
|
|
|
// Created by oupson on 01/03/2022.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef FOOTERM_EVENTLOOP_HPP
|
|
|
|
#define FOOTERM_EVENTLOOP_HPP
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <sys/poll.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <libssh2.h>
|
2022-03-04 07:49:21 +00:00
|
|
|
#include <libssh2_sftp.h>
|
2022-03-01 22:49:26 +00:00
|
|
|
|
2022-03-04 07:49:21 +00:00
|
|
|
class FooTermWindow;
|
2022-03-01 22:49:26 +00:00
|
|
|
|
|
|
|
struct EventLoopEntry {
|
|
|
|
enum {
|
|
|
|
DESCRIPTOR,
|
|
|
|
CHANNEL
|
|
|
|
} entryType;
|
|
|
|
|
2022-03-04 07:49:21 +00:00
|
|
|
union {
|
|
|
|
LIBSSH2_CHANNEL *channel;
|
|
|
|
LIBSSH2_SFTP *sftp;
|
|
|
|
};
|
|
|
|
|
|
|
|
union {
|
|
|
|
int fdout;
|
|
|
|
};
|
2022-03-01 22:49:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class EventLoop {
|
|
|
|
private:
|
|
|
|
std::vector<pollfd> pfds;
|
|
|
|
std::vector<EventLoopEntry> outs;
|
|
|
|
bool isClosed{};
|
2022-03-04 07:49:21 +00:00
|
|
|
FooTermWindow* window;
|
|
|
|
|
2022-03-01 22:49:26 +00:00
|
|
|
public:
|
2022-03-04 07:49:21 +00:00
|
|
|
explicit EventLoop(FooTermWindow* window);
|
2022-03-01 22:49:26 +00:00
|
|
|
|
|
|
|
void registerFd(int fdin, EventLoopEntry entry);
|
|
|
|
|
2022-03-04 07:49:21 +00:00
|
|
|
[[noreturn]] void run();
|
2022-03-01 22:49:26 +00:00
|
|
|
|
|
|
|
static void start(EventLoop *self) {
|
|
|
|
self->run();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //FOOTERM_EVENTLOOP_HPP
|