L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
event
1// vi:set ft=cpp: -*- Mode: C++ -*-
2/*
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)
6 *
7 * License: see LICENSE.spdx (in this directory or the directories above)
8 */
9
10#pragma once
11
12#include <l4/sys/capability>
13#include <l4/sys/irq>
14#include <l4/sys/cxx/ipc_iface>
15#include <l4/sys/cxx/ipc_array>
16#include <l4/re/dataspace>
17#include <l4/re/event.h>
18
19namespace L4Re {
20
40typedef l4re_event_stream_id_t Event_stream_id;
41typedef l4re_event_absinfo_t Event_absinfo;
42
43class L4_EXPORT Event_stream_bitmap_h
44{
45protected:
46 static unsigned __get_idx(unsigned idx)
47 { return idx / (sizeof(unsigned long)*8); }
48
49 static unsigned long __get_mask(unsigned idx)
50 { return 1ul << (idx % (sizeof(unsigned long)*8)); }
51
52 static bool __get_bit(unsigned long const *bm, unsigned max, unsigned idx)
53 {
54 if (idx <= max)
55 return bm[__get_idx(idx)] & __get_mask(idx);
56 return false;
57 }
58
59 static void __set_bit(unsigned long *bm, unsigned max, unsigned idx, bool v)
60 {
61 if (idx > max)
62 return;
63
64 if (v)
65 bm[__get_idx(idx)] |= __get_mask(idx);
66 else
67 bm[__get_idx(idx)] &= ~__get_mask(idx);
68 }
69};
70
71class L4_EXPORT Event_stream_info
72: public l4re_event_stream_info_t,
73 private Event_stream_bitmap_h
74{
75public:
76 bool get_propbit(unsigned idx) const
77 { return __get_bit(propbits, L4RE_EVENT_PROP_MAX, idx); }
78
79 void set_propbit(unsigned idx, bool v)
80 { __set_bit(propbits, L4RE_EVENT_PROP_MAX, idx, v); }
81
82 bool get_evbit(unsigned idx) const
83 { return __get_bit(evbits, L4RE_EVENT_EV_MAX, idx); }
84
85 void set_evbit(unsigned idx, bool v)
86 { __set_bit(evbits, L4RE_EVENT_EV_MAX, idx, v); }
87
88 bool get_keybit(unsigned idx) const
89 { return __get_bit(keybits, L4RE_EVENT_KEY_MAX, idx); }
90
91 void set_keybit(unsigned idx, bool v)
92 { __set_bit(keybits, L4RE_EVENT_KEY_MAX, idx, v); }
93
94 bool get_relbit(unsigned idx) const
95 { return __get_bit(relbits, L4RE_EVENT_REL_MAX, idx); }
96
97 void set_relbit(unsigned idx, bool v)
98 { __set_bit(relbits, L4RE_EVENT_REL_MAX, idx, v); }
99
100 bool get_absbit(unsigned idx) const
101 { return __get_bit(absbits, L4RE_EVENT_ABS_MAX, idx); }
102
103 void set_absbit(unsigned idx, bool v)
104 { __set_bit(absbits, L4RE_EVENT_ABS_MAX, idx, v); }
105
106 bool get_swbit(unsigned idx) const
107 { return __get_bit(swbits, L4RE_EVENT_SW_MAX, idx); }
108
109 void set_swbit(unsigned idx, bool v)
110 { __set_bit(swbits, L4RE_EVENT_SW_MAX, idx, v); }
111};
112
113class L4_EXPORT Event_stream_state
114: public l4re_event_stream_state_t,
115 private Event_stream_bitmap_h
116{
117public:
118 bool get_keybit(unsigned idx) const
119 { return __get_bit(keybits, L4RE_EVENT_KEY_MAX, idx); }
120
121 void set_keybit(unsigned idx, bool v)
122 { __set_bit(keybits, L4RE_EVENT_KEY_MAX, idx, v); }
123
124 bool get_swbit(unsigned idx) const
125 { return __get_bit(swbits, L4RE_EVENT_SW_MAX, idx); }
126
127 void set_swbit(unsigned idx, bool v)
128 { __set_bit(swbits, L4RE_EVENT_SW_MAX, idx, v); }
129};
130
138 public L4::Kobject_t<Event, L4::Icu, L4RE_PROTO_EVENT>
139{
140public:
149 L4_RPC(long, get_buffer, (L4::Ipc::Out<L4::Cap<Dataspace> > ds));
150
157 L4_RPC(long, get_num_streams, ());
158
170 L4_RPC(long, get_stream_info, (int idx, Event_stream_info *info));
171
181 L4_RPC(long, get_stream_info_for_id, (l4_umword_t stream_id, Event_stream_info *info));
182
194 L4_RPC_NF(long, get_axis_info, (l4_umword_t stream_id,
197
198 long get_axis_info(l4_umword_t stream_id, unsigned naxes,
199 unsigned const *axis, Event_absinfo *info) const noexcept
200 {
202 return get_axis_info_t::call(c(), stream_id,
204 }
205
215 L4_RPC(long, get_stream_state_for_id, (l4_umword_t stream_id,
216 Event_stream_state *state));
217
218 typedef L4::Typeid::Rpcs<
219 get_buffer_t,
220 get_num_streams_t,
221 get_stream_info_t,
222 get_stream_info_for_id_t,
223 get_axis_info_t,
224 get_stream_state_for_id_t
225 > Rpcs;
226};
227
233{
234 unsigned short type;
235 unsigned short code;
236 int value;
238};
239
240
245template< typename PAYLOAD = Default_event_payload >
247{
248public:
249
253 struct Event
254 {
255 long long time;
256 PAYLOAD payload;
257
261 void free() noexcept { l4_mb(); time = 0; }
262 };
263
264private:
265 Event *_current;
266 Event *_begin;
267 Event const *_end;
268
269 void inc() noexcept
270 {
271 ++_current;
272 if (_current == _end)
273 _current = _begin;
274 }
275
276public:
277
278 Event_buffer_t() : _current(0), _begin(0), _end(0) {}
279
280 void reset()
281 {
282 for (Event *i = _begin; i != _end; ++i)
283 i->time = 0;
284 _current = _begin;
285 }
286
293 Event_buffer_t(void *buffer, l4_addr_t size)
294 : _current(static_cast<Event*>(buffer)), _begin(_current),
295 _end(_begin + size / sizeof(Event))
296 { reset(); }
297
303 Event *next() noexcept
304 {
305 Event *c = _current;
306 if (c->time)
307 {
308 inc();
309 return c;
310 }
311 return 0;
312 }
313
320 bool put(Event const &ev) noexcept
321 {
322 Event *c = _current;
323 if (c->time)
324 return false;
325
326 inc();
327 c->payload = ev.payload;
328 l4_wmb();
329 c->time = ev.time;
330 return true;
331 }
332};
333
334typedef Event_buffer_t<Default_event_payload> Event_buffer;
335
336}
L4::Cap related definitions.
Event buffer class.
Definition event:247
Event_buffer_t(void *buffer, l4_addr_t size)
Initialize event buffer.
Definition event:293
Event * next() noexcept
Next event in buffer.
Definition event:303
bool put(Event const &ev) noexcept
Put event into buffer at current position.
Definition event:320
Event class.
Definition event:139
long get_axis_info(l4_umword_t stream_id, unsigned naxes, unsigned const *axis, Event_absinfo *info) const noexcept
Get event stream axis infos.
Definition event:198
C++ interface for capabilities.
Definition capability.h:219
Helper class to create an L4Re interface class that is derived from a single base class.
Definition __typeinfo.h:750
Dataspace interface.
Events.
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
unsigned long l4_addr_t
Address type.
Definition l4int.h:34
void l4_wmb(void)
Write memory barrier.
Definition compiler.h:333
void l4_mb(void)
Memory barrier.
Definition compiler.h:328
#define L4_EXPORT
Attribute to mark functions, variables, and data types as being exported from a library.
Definition compiler.h:210
Interface Definition Language.
#define L4_RPC(res, name, args, attr...)
Define an RPC call (type and callable).
Definition ipc_iface:535
#define L4_RPC_NF(res, name, args...)
Define an RPC call type (the type only, no callable).
Definition ipc_iface:504
C++ Irq interface.
L4Re C++ Interfaces.
Definition cmd_control:14
Default event stream payload.
Definition event:233
l4_umword_t stream_id
Stream ID.
Definition event:237
int value
Value of event.
Definition event:236
unsigned short code
Code of event.
Definition event:235
unsigned short type
Type of event.
Definition event:234
Event structure used in buffer.
Definition event:254
void free() noexcept
Free the entry.
Definition event:261
long long time
Event time stamp.
Definition event:255
Array data type for dynamically sized arrays in RPCs.
Definition ipc_array:82
Mark an argument as a output value in an RPC signature.
Definition ipc_types:31
Standard list of RPCs of an interface.
Definition __typeinfo.h:428