3 * (c) 2008-2009 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.
11 * As a special exception, you may use this file as part of a free software
12 * library without restriction. Specifically, if other files instantiate
13 * templates or use macros or inline functions from this file, or you compile
14 * this file and link it with other files to produce an executable, this
15 * file does not by itself cause the resulting executable to be covered by
16 * the GNU General Public License. This exception does not however
17 * invalidate any other reasons why the executable file might be covered by
18 * the GNU General Public License.
23 #include <l4/sys/capability>
25 #include <l4/sys/cxx/ipc_iface>
26 #include <l4/sys/cxx/ipc_array>
27 #include <l4/re/dataspace>
28 #include <l4/re/event.h>
33 * \defgroup api_l4re_event Event API
35 * \brief Event interface.
38 typedef l4re_event_stream_id_t Event_stream_id;
39 typedef l4re_event_absinfo_t Event_absinfo;
41 class L4_EXPORT Event_stream_bitmap_h
44 static unsigned __get_idx(unsigned idx)
45 { return idx / (sizeof(unsigned long)*8); }
47 static unsigned long __get_mask(unsigned idx)
48 { return 1ul << (idx % (sizeof(unsigned long)*8)); }
50 static bool __get_bit(unsigned long const *bm, unsigned max, unsigned idx)
53 return bm[__get_idx(idx)] & __get_mask(idx);
57 static void __set_bit(unsigned long *bm, unsigned max, unsigned idx, bool v)
63 bm[__get_idx(idx)] |= __get_mask(idx);
65 bm[__get_idx(idx)] &= ~__get_mask(idx);
69 class L4_EXPORT Event_stream_info
70 : public l4re_event_stream_info_t,
71 private Event_stream_bitmap_h
74 bool get_propbit(unsigned idx) const
75 { return __get_bit(propbits, L4RE_EVENT_PROP_MAX, idx); }
77 void set_propbit(unsigned idx, bool v)
78 { __set_bit(propbits, L4RE_EVENT_PROP_MAX, idx, v); }
80 bool get_evbit(unsigned idx) const
81 { return __get_bit(evbits, L4RE_EVENT_EV_MAX, idx); }
83 void set_evbit(unsigned idx, bool v)
84 { __set_bit(evbits, L4RE_EVENT_EV_MAX, idx, v); }
86 bool get_keybit(unsigned idx) const
87 { return __get_bit(keybits, L4RE_EVENT_KEY_MAX, idx); }
89 void set_keybit(unsigned idx, bool v)
90 { __set_bit(keybits, L4RE_EVENT_KEY_MAX, idx, v); }
92 bool get_relbit(unsigned idx) const
93 { return __get_bit(relbits, L4RE_EVENT_REL_MAX, idx); }
95 void set_relbit(unsigned idx, bool v)
96 { __set_bit(relbits, L4RE_EVENT_REL_MAX, idx, v); }
98 bool get_absbit(unsigned idx) const
99 { return __get_bit(absbits, L4RE_EVENT_ABS_MAX, idx); }
101 void set_absbit(unsigned idx, bool v)
102 { __set_bit(absbits, L4RE_EVENT_ABS_MAX, idx, v); }
104 bool get_swbit(unsigned idx) const
105 { return __get_bit(swbits, L4RE_EVENT_SW_MAX, idx); }
107 void set_swbit(unsigned idx, bool v)
108 { __set_bit(swbits, L4RE_EVENT_SW_MAX, idx, v); }
111 class L4_EXPORT Event_stream_state
112 : public l4re_event_stream_state_t,
113 private Event_stream_bitmap_h
116 bool get_keybit(unsigned idx) const
117 { return __get_bit(keybits, L4RE_EVENT_KEY_MAX, idx); }
119 void set_keybit(unsigned idx, bool v)
120 { __set_bit(keybits, L4RE_EVENT_KEY_MAX, idx, v); }
122 bool get_swbit(unsigned idx) const
123 { return __get_bit(swbits, L4RE_EVENT_SW_MAX, idx); }
125 void set_swbit(unsigned idx, bool v)
126 { __set_bit(swbits, L4RE_EVENT_SW_MAX, idx, v); }
130 * \brief Event class.
131 * \ingroup api_l4re_event
133 class L4_EXPORT Event :
134 public L4::Kobject_t<Event, L4::Icu, L4RE_PROTO_EVENT>
138 * \brief Get event signal buffer.
140 * \retval ds Event buffer.
142 * \return 0 on success, negative error code otherwise.
144 L4_RPC(long, get_buffer, (L4::Ipc::Out<L4::Cap<Dataspace> > ds));
145 L4_RPC(long, get_num_streams, ());
146 L4_RPC(long, get_stream_info, (int idx, Event_stream_info *info));
147 L4_RPC(long, get_stream_info_for_id, (l4_umword_t stream_id, Event_stream_info *info));
148 L4_RPC_NF(long, get_axis_info, (l4_umword_t stream_id,
149 L4::Ipc::Array<unsigned const, unsigned long> axes,
150 L4::Ipc::Array<Event_absinfo, unsigned long> &info));
152 long get_axis_info(l4_umword_t stream_id, unsigned naxes,
153 unsigned const *axis, Event_absinfo *info) const throw()
155 L4::Ipc::Array<Event_absinfo, unsigned long> i(naxes, info);
156 return get_axis_info_t::call(c(), stream_id,
157 L4::Ipc::Array<unsigned const, unsigned long>(naxes, axis), i);
160 L4_RPC(long, get_stream_state_for_id, (l4_umword_t stream_id,
161 Event_stream_state *state));
163 typedef L4::Typeid::Rpcs<
167 get_stream_info_for_id_t,
169 get_stream_state_for_id_t
173 struct L4_EXPORT Default_event_payload
175 unsigned short type; /**< Type of event */
176 unsigned short code; /**< Code of event */
177 int value; /**< Value of event */
178 l4_umword_t stream_id; /**< Stream ID */
183 * \brief Event buffer class.
184 * \ingroup api_l4re_event
186 template< typename PAYLOAD = Default_event_payload >
187 class L4_EXPORT Event_buffer_t
192 * \brief Event structure used in buffer.
196 long long time; /**< Event time stamp */
200 * \brief Free the entry.
202 void free() throw() { l4_mb(); time = 0; }
213 if (_current == _end)
219 Event_buffer_t() : _current(0), _begin(0), _end(0) {}
223 for (Event *i = _begin; i != _end; ++i)
229 * \brief Initialize event buffer.
231 * \param buffer Pointer to buffer.
232 * \param size Size of buffer in bytes.
234 Event_buffer_t(void *buffer, l4_addr_t size)
235 : _current((Event*)buffer), _begin(_current),
236 _end(_begin + size / sizeof(Event))
240 * \brief Next event in buffer.
242 * \return 0 if no event available, event otherwise.
244 Event *next() throw()
256 * \brief Put event into buffer at current position.
258 * \param ev Event to put into the buffer.
259 * \return false if buffer is full and entry could not be added.
261 bool put(Event const &ev) throw()
268 c->payload = ev.payload;
275 typedef Event_buffer_t<Default_event_payload> Event_buffer;