1.1 --- a/pkg/devices/util/include/event-loop.h Fri May 18 22:34:51 2018 +0200
1.2 +++ b/pkg/devices/util/include/event-loop.h Fri May 18 23:41:51 2018 +0200
1.3 @@ -31,21 +31,16 @@
1.4 class Event_loop
1.5 {
1.6 protected:
1.7 - /* Private data for the handler. */
1.8 -
1.9 - void *_priv;
1.10 -
1.11 /* Thread properties. */
1.12
1.13 int _priority;
1.14 pthread_t _pthread;
1.15
1.16 public:
1.17 - /* Initialise the event loop with an event handler function and private data,
1.18 - plus thread priority. */
1.19 + /* Initialise the event loop with a thread priority. */
1.20
1.21 - explicit Event_loop(void *priv, int priority=0x20)
1.22 - : _priv(priv), _priority(priority)
1.23 + explicit Event_loop(int priority=0x20)
1.24 + : _priority(priority)
1.25 {
1.26 }
1.27
1.28 @@ -62,4 +57,40 @@
1.29 virtual void start();
1.30 };
1.31
1.32 +
1.33 +
1.34 +/* Event loop with handler. */
1.35 +
1.36 +template <class T>
1.37 +class Event_handler_loop : public Event_loop
1.38 +{
1.39 +protected:
1.40 + /* Event type. */
1.41 +
1.42 + typedef T Event_type;
1.43 +
1.44 + /* Handler function type. */
1.45 +
1.46 + typedef void (*Event_handler)(Event_type &);
1.47 +
1.48 + /* External handler function. */
1.49 +
1.50 + Event_handler _handler;
1.51 +
1.52 +public:
1.53 + /* Initialise the event loop with a thread priority. */
1.54 +
1.55 + explicit Event_handler_loop(int priority=0x20)
1.56 + : Event_loop(priority)
1.57 + {
1.58 + }
1.59 +
1.60 + /* Attach a handler to the loop. */
1.61 +
1.62 + virtual void attach(Event_handler handler)
1.63 + {
1.64 + _handler = handler;
1.65 + }
1.66 +};
1.67 +
1.68 #endif