Argentum Online - Servidor
blocking_th_event_handler.h
1 #ifndef BLOCKING_TH_EVENT_HANDLER_H
2 #define BLOCKING_TH_EVENT_HANDLER_H
3 
4 #include <stdexcept>
5 
6 #include "blocking_queue.h"
7 #include "event.h"
8 #include "event_handler.h"
9 #include "thread.h"
10 
11 class EventHandlerStoppedException : public std::exception {
12  public:
14 
15  virtual const char* what() const noexcept override {
16  return "The Event Handler has been stopped";
17  }
18 
20 };
21 
22 class BlockingThEventHandler : public Thread, public EventHandler {
23  private:
24  BlockingQueue<Event> event_queue;
25 
26  protected:
27  Event pop_event();
28 
29  virtual void handle(Event& ev) = 0;
30 
31  public:
33  virtual ~BlockingThEventHandler();
34 
37 
38  bool is_threaded() const override;
39 
40  bool is_done() const;
41 
42  void push_event(const Event& ev) override;
43 
44  virtual void run() override;
45 
46  virtual void stop();
47 };
48 
49 #endif // BLOCKING_TH_EVENT_HANDLER_H
BlockingThEventHandler::is_threaded
bool is_threaded() const override
Verificar si un EventHandler tiene un thread dedicado.
Definition: blocking_th_event_handler.cpp:26
BlockingThEventHandler::run
virtual void run() override
Function to be called by the thread.
Definition: blocking_th_event_handler.cpp:38
Event
Definition: event.h:55
BlockingQueue< Event >
BlockingThEventHandler
Definition: blocking_th_event_handler.h:22
EventHandler
Clase abstracta para el manejo de eventos.
Definition: event_handler.h:10
Thread
Definition: thread.h:9
EventHandlerStoppedException
Definition: blocking_th_event_handler.h:11