1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pkg/devices/input/include/input-event-loop.h Thu May 17 22:49:35 2018 +0200
1.3 @@ -0,0 +1,88 @@
1.4 +/*
1.5 + * Input event loop functionality.
1.6 + *
1.7 + * (c) 2018 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#pragma once
1.26 +
1.27 +#ifdef __cplusplus
1.28 +
1.29 +#include <l4/re/event>
1.30 +#include <l4/sys/capability>
1.31 +#include <l4/sys/icu>
1.32 +
1.33 +#include <pthread.h>
1.34 +#include <pthread-l4.h>
1.35 +
1.36 +/* POSIX-thread-compatible handler function type. */
1.37 +
1.38 +typedef void (*Event_handler)(L4Re::Event_buffer::Event &, void *);
1.39 +
1.40 +/* Input event loop abstraction. */
1.41 +
1.42 +class Input_event_loop
1.43 +{
1.44 + /* Notification interrupt capability. */
1.45 +
1.46 + L4::Cap<L4::Irq> _irq;
1.47 +
1.48 + /* External handler function. */
1.49 +
1.50 + Event_handler _handler;
1.51 +
1.52 + /* Private data for the handler. */
1.53 +
1.54 + void *_priv;
1.55 +
1.56 + /* Event buffer and notification interrupt capability. */
1.57 +
1.58 + L4Re::Event_buffer _event_buffer;
1.59 +
1.60 + /* Thread properties. */
1.61 +
1.62 + int _priority;
1.63 + pthread_t _pthread;
1.64 +
1.65 +public:
1.66 + /* Initialise the event loop with a notification interrupt, thread priority,
1.67 + event handler function and private data, and an event buffer. */
1.68 +
1.69 + explicit Input_event_loop(L4::Cap<L4::Irq> irq,
1.70 + Event_handler handler, void *priv,
1.71 + L4Re::Event_buffer event_buffer,
1.72 + int priority=0x20)
1.73 + : _irq(irq), _handler(handler), _priv(priv), _event_buffer(event_buffer),
1.74 + _priority(priority)
1.75 + {
1.76 + }
1.77 +
1.78 + /* Static main loop function for event-handling thread. */
1.79 +
1.80 + static void *event_loop(void *data);
1.81 +
1.82 + /* Event handler method. */
1.83 +
1.84 + void handle();
1.85 +
1.86 + /* Initiation function. */
1.87 +
1.88 + void start();
1.89 +};
1.90 +
1.91 +#endif