]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/mag/plugins/input_event/input_event.cc
update
[l4.git] / l4 / pkg / mag / plugins / input_event / input_event.cc
1 /*
2  * (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3  *          Alexander Warg <warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  *
6  * This file is part of TUD:OS and distributed under the terms of the
7  * GNU General Public License 2.
8  * Please see the COPYING-GPL-2 file for details.
9  */
10 #include <l4/mag/server/input_driver>
11 #include <l4/mag/server/input_source>
12
13 #include <l4/sys/capability>
14 #include <l4/re/console>
15 #include <l4/re/util/event>
16
17 namespace Mag_server {
18
19 class Input_source_event : public Input_source
20 {
21 public:
22   L4::Cap<L4Re::Event> _ev_cap;
23   L4Re::Util::Event _event;
24
25   void core(Core_api *c) { _core = c; }
26
27   void poll_events()
28   {
29     while (L4Re::Event_buffer::Event *e = _event.buffer().next())
30       {
31         post_event(e);
32         e->free();
33       }
34   }
35
36   int get_stream_info(l4_umword_t stream_id, L4Re::Event_stream_info *info)
37   { return _ev_cap->get_stream_info_for_id(stream_id, info); }
38
39   int get_axis_info(l4_umword_t stream_id, unsigned naxes, unsigned *axes,
40                     L4Re::Event_absinfo *info)
41   { return _ev_cap->get_axis_info(stream_id, naxes, axes, info); }
42 };
43
44 class Input_driver_event : public Input_driver
45 {
46 private:
47   Input_source_event _source_be, _source_ev;
48
49 public:
50   Input_driver_event() : Input_driver("L4Re::Event") {}
51
52   void start(Core_api *core)
53   {
54     L4::Cap<L4Re::Event> c =
55       L4::cap_dynamic_cast<L4Re::Event>(core->backend_fb());
56
57     _source_be.core(core);
58     _source_ev.core(core);
59
60     if (c && !_source_be._event.init(c, L4Re::Util::Event::Mode_polling))
61       {
62         _source_be._ev_cap = c;
63         core->add_input_source(&_source_be);
64       }
65
66     c = L4Re::Env::env()->get_cap<L4Re::Event>("ev");
67     if (c && !_source_ev._event.init(c, L4Re::Util::Event::Mode_polling))
68       {
69         _source_ev._ev_cap = c;
70         core->add_input_source(&_source_ev);
71       }
72   }
73 };
74
75 static Input_driver_event _evinput;
76
77 }