2012-08-28 22:32:15 +02:00
|
|
|
#ifndef event_manager_hh_INCLUDED
|
|
|
|
#define event_manager_hh_INCLUDED
|
|
|
|
|
|
|
|
#include <poll.h>
|
2012-11-06 13:34:58 +01:00
|
|
|
#include <unordered_map>
|
2012-08-28 22:32:15 +02:00
|
|
|
|
|
|
|
#include "utils.hh"
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
using EventHandler = std::function<void (int fd)>;
|
|
|
|
|
|
|
|
class EventManager : public Singleton<EventManager>
|
|
|
|
{
|
|
|
|
public:
|
2012-10-27 15:01:13 +02:00
|
|
|
EventManager();
|
|
|
|
|
2012-08-28 22:32:15 +02:00
|
|
|
void watch(int fd, EventHandler handler);
|
|
|
|
void unwatch(int fd);
|
|
|
|
|
|
|
|
void handle_next_events();
|
|
|
|
|
2012-10-27 15:01:13 +02:00
|
|
|
void force_signal(int fd);
|
|
|
|
|
2012-08-28 22:32:15 +02:00
|
|
|
private:
|
|
|
|
std::vector<pollfd> m_events;
|
2012-11-06 13:34:58 +01:00
|
|
|
std::unordered_map<int, EventHandler> m_handlers;
|
2012-10-27 15:01:13 +02:00
|
|
|
std::vector<int> m_forced;
|
2012-08-28 22:32:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // event_manager_hh_INCLUDED
|
|
|
|
|