#ifndef REMOTING_HOST_LINUX_EI_EVENT_WATCHER_GLIB_H_
#define REMOTING_HOST_LINUX_EI_EVENT_WATCHER_GLIB_H_
#include <glib.h>
#include "base/memory/raw_ptr.h"
struct ei;
struct ei_event;
constexpr int kPriorityFdWatch = G_PRIORITY_DEFAULT_IDLE - 10;
namespace remoting {
class EiEventWatcherGlib {
public:
class EiEventHandler {
public:
virtual ~EiEventHandler() = default;
virtual void HandleEiEvent(struct ei_event* event) = 0;
};
EiEventWatcherGlib(int fd, ei* ei, EiEventHandler* handler);
EiEventWatcherGlib(const EiEventWatcherGlib&) = delete;
EiEventWatcherGlib& operator=(const EiEventWatcherGlib&) = delete;
~EiEventWatcherGlib();
void StartProcessingEvents();
void StopProcessingEvents();
private:
struct GLibEiSource : public GSource {
raw_ptr<EiEventWatcherGlib> event_watcher;
GPollFD poll_fd;
};
static gboolean WatchSourcePrepare(GSource* source, gint* timeout_ms);
static gboolean WatchSourceCheck(GSource* source);
static gboolean WatchSourceDispatch(GSource* source,
GSourceFunc unused_func,
gpointer data);
static constexpr GSourceFuncs kWatchSourceFuncs = {
WatchSourcePrepare, WatchSourceCheck, WatchSourceDispatch, nullptr};
bool Prepare();
void Dispatch();
raw_ptr<GLibEiSource> ei_source_ = nullptr;
int fd_ = -1;
base::raw_ptr<ei> ei_ = nullptr;
base::raw_ptr<EiEventHandler> handler_ = nullptr;
};
}
#endif