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-27 13:57:03 +01:00
|
|
|
std::vector<pollfd> m_events;
|
|
|
|
std::vector<std::unique_ptr<EventHandler>> m_handlers;
|
|
|
|
std::vector<std::unique_ptr<EventHandler>> m_handlers_trash;
|
|
|
|
std::vector<int> m_forced;
|
2012-08-28 22:32:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // event_manager_hh_INCLUDED
|
|
|
|
|