3 * (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
4 * Alexander Warg <warg@os.inf.tu-dresden.de>
5 * economic rights: Technische Universität Dresden (Germany)
7 * This file is part of TUD:OS and distributed under the terms of the
8 * GNU General Public License 2.
9 * Please see the COPYING-GPL-2 file for details.
13 #include <l4/mag/server/user_state>
14 #include <l4/mag/server/plugin>
16 #include <l4/re/event_enums.h>
18 namespace Mag_server {
20 template<int Max_axis>
24 unsigned long _changed;
34 Type axis_inf(unsigned char axis) const
35 { return Type((_changed >> (2*axis)) & 3); }
37 void set_axis_inf(unsigned char axis, Type t)
38 { _changed |= ((unsigned long)t) << (axis*2); }
41 Motion_merger() : _changed(0) {}
43 void reset() { _changed = 0; }
47 bool handle(User_state::Event const &e)
49 if (!(e.payload.type == L4RE_EV_REL || e.payload.type == L4RE_EV_ABS))
52 if (e.payload.code >= Max_axis)
55 unsigned char ax = e.payload.code;
57 if (axis_inf(ax) == T_none && e.payload.type == L4RE_EV_REL)
60 set_axis_inf(ax, T_rel);
63 switch (e.payload.type)
66 _v[ax] += e.payload.value;
69 _v[ax] = e.payload.value;
70 set_axis_inf(ax, T_abs);
77 bool set_event(unsigned char axis, User_state::Event *e)
79 unsigned i = axis_inf(axis);
84 e->payload.type = L4RE_EV_ABS;
86 e->payload.type = L4RE_EV_REL;
88 e->payload.code = axis;
89 e->payload.value = _v[axis];
94 template< typename I, typename T >
95 I merge(I const &s, I const &e, T *last_time)
97 for (I i = s; i != e; ++i)
100 *last_time = i->time;
109 template< typename E, typename I, typename F >
110 void process(I const &s, I const &end, F const &f)
112 for (I e = s; e != end; ++e)
115 me.payload.stream_id = e->payload.stream_id;
116 e = merge(e, end, &me.time);
118 for (unsigned i = 0; i < Max_axis; ++i)
119 if (set_event(i, &me))
137 template< /*typename E,*/ typename I, typename F >
138 void process(I const &s, I const &end, F const &f)
140 for (I e = s; e != end; ++e)
148 class Input_driver : public Plugin
154 Input_driver *_next_active;
157 explicit Input_driver(char const *name)
158 : Plugin(name), _core(0), _next_active(0)
161 char const *type() const { return "input-driver"; }
162 Input_driver *next_active() const { return _next_active; }
163 virtual void poll_events() = 0;
164 virtual int probe() = 0;
166 void start(Core_api *core)
171 _next_active = core->input_drivers();
172 core->add_input_driver(this);
176 virtual ~Input_driver() {}