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)>;
|
|
|
|
|
2012-11-26 14:08:27 +01:00
|
|
|
// The EventManager provides an interface to file descriptor
|
|
|
|
// based event handling.
|
|
|
|
//
|
|
|
|
// The program main loop should call handle_next_events()
|
|
|
|
// until it's time to quit.
|
2012-08-28 22:32:15 +02:00
|
|
|
class EventManager : public Singleton<EventManager>
|
|
|
|
{
|
|
|
|
public:
|
2012-11-26 14:08:27 +01:00
|
|
|
// Watch the given file descriptor, when data becomes
|
|
|
|
// ready, handler will be called with fd as parameter.
|
|
|
|
// It is an error to register multiple handlers on the
|
|
|
|
// same file descriptor.
|
2012-08-28 22:32:15 +02:00
|
|
|
void watch(int fd, EventHandler handler);
|
2012-11-26 14:08:27 +01:00
|
|
|
|
|
|
|
// stop watching fd
|
2012-08-28 22:32:15 +02:00
|
|
|
void unwatch(int fd);
|
|
|
|
|
|
|
|
void handle_next_events();
|
|
|
|
|
2012-11-26 14:08:27 +01:00
|
|
|
// force the handler associated with fd to be executed
|
|
|
|
// on next handle_next_events call.
|
2012-10-27 15:01:13 +02:00
|
|
|
void force_signal(int fd);
|
|
|
|
|
2012-08-28 22:32:15 +02:00
|
|
|
private:
|
2012-11-26 14:08:27 +01:00
|
|
|
std::vector<pollfd> m_events;
|
2012-11-06 13:34:58 +01:00
|
|
|
std::unordered_map<int, EventHandler> m_handlers;
|
2012-11-26 14:08:27 +01:00
|
|
|
std::vector<int> m_forced;
|
|
|
|
std::vector<int> m_unwatched;
|
2012-08-28 22:32:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // event_manager_hh_INCLUDED
|
|
|
|
|