L4Re Operating System Framework – Interface and Usage Documentation
Loading...
Searching...
No Matches
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 * 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.
10 *
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.
19 */
20
21#pragma once
22
23#include <l4/sys/capability>
24#include <l4/sys/irq>
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>
29
30namespace L4Re {
31
51typedef l4re_event_stream_id_t Event_stream_id;
52typedef l4re_event_absinfo_t Event_absinfo;
53
54class L4_EXPORT Event_stream_bitmap_h
55{
56protected:
57 static unsigned __get_idx(unsigned idx)
58 { return idx / (sizeof(unsigned long)*8); }
59
60 static unsigned long __get_mask(unsigned idx)
61 { return 1ul << (idx % (sizeof(unsigned long)*8)); }
62
63 static bool __get_bit(unsigned long const *bm, unsigned max, unsigned idx)
64 {
65 if (idx <= max)
66 return bm[__get_idx(idx)] & __get_mask(idx);
67 return false;
68 }
69
70 static void __set_bit(unsigned long *bm, unsigned max, unsigned idx, bool v)
71 {
72 if (idx > max)
73 return;
74
75 if (v)
76 bm[__get_idx(idx)] |= __get_mask(idx);
77 else
78 bm[__get_idx(idx)] &= ~__get_mask(idx);
79 }
80};
81
82class L4_EXPORT Event_stream_info
83: public l4re_event_stream_info_t,
84 private Event_stream_bitmap_h
85{
86public:
87 bool get_propbit(unsigned idx) const
88 { return __get_bit(propbits, L4RE_EVENT_PROP_MAX, idx); }
89
90 void set_propbit(unsigned idx, bool v)
91 { __set_bit(propbits, L4RE_EVENT_PROP_MAX, idx, v); }
92
93 bool get_evbit(unsigned idx) const
94 { return __get_bit(evbits, L4RE_EVENT_EV_MAX, idx); }
95
96 void set_evbit(unsigned idx, bool v)
97 { __set_bit(evbits, L4RE_EVENT_EV_MAX, idx, v); }
98
99 bool get_keybit(unsigned idx) const
100 { return __get_bit(keybits, L4RE_EVENT_KEY_MAX, idx); }
101
102 void set_keybit(unsigned idx, bool v)
103 { __set_bit(keybits, L4RE_EVENT_KEY_MAX, idx, v); }
104
105 bool get_relbit(unsigned idx) const
106 { return __get_bit(relbits, L4RE_EVENT_REL_MAX, idx); }
107
108 void set_relbit(unsigned idx, bool v)
109 { __set_bit(relbits, L4RE_EVENT_REL_MAX, idx, v); }
110
111 bool get_absbit(unsigned idx) const
112 { return __get_bit(absbits, L4RE_EVENT_ABS_MAX, idx); }
113
114 void set_absbit(unsigned idx, bool v)
115 { __set_bit(absbits, L4RE_EVENT_ABS_MAX, idx, v); }
116
117 bool get_swbit(unsigned idx) const
118 { return __get_bit(swbits, L4RE_EVENT_SW_MAX, idx); }
119
120 void set_swbit(unsigned idx, bool v)
121 { __set_bit(swbits, L4RE_EVENT_SW_MAX, idx, v); }
122};
123
124class L4_EXPORT Event_stream_state
125: public l4re_event_stream_state_t,
126 private Event_stream_bitmap_h
127{
128public:
129 bool get_keybit(unsigned idx) const
130 { return __get_bit(keybits, L4RE_EVENT_KEY_MAX, idx); }
131
132 void set_keybit(unsigned idx, bool v)
133 { __set_bit(keybits, L4RE_EVENT_KEY_MAX, idx, v); }
134
135 bool get_swbit(unsigned idx) const
136 { return __get_bit(swbits, L4RE_EVENT_SW_MAX, idx); }
137
138 void set_swbit(unsigned idx, bool v)
139 { __set_bit(swbits, L4RE_EVENT_SW_MAX, idx, v); }
140};
141
149 public L4::Kobject_t<Event, L4::Icu, L4RE_PROTO_EVENT>
150{
151public:
160 L4_RPC(long, get_buffer, (L4::Ipc::Out<L4::Cap<Dataspace> > ds));
161
168 L4_RPC(long, get_num_streams, ());
169
181 L4_RPC(long, get_stream_info, (int idx, Event_stream_info *info));
182
192 L4_RPC(long, get_stream_info_for_id, (l4_umword_t stream_id, Event_stream_info *info));
193
204 L4_RPC_NF(long, get_axis_info, (l4_umword_t stream_id,
207
208 long get_axis_info(l4_umword_t stream_id, unsigned naxes,
209 unsigned const *axis, Event_absinfo *info) const noexcept
210 {
212 return get_axis_info_t::call(c(), stream_id,
214 }
215
225 L4_RPC(long, get_stream_state_for_id, (l4_umword_t stream_id,
226 Event_stream_state *state));
227
228 typedef L4::Typeid::Rpcs<
229 get_buffer_t,
230 get_num_streams_t,
231 get_stream_info_t,
232 get_stream_info_for_id_t,
233 get_axis_info_t,
234 get_stream_state_for_id_t
235 > Rpcs;
236};
237
243{
244 unsigned short type;
245 unsigned short code;
246 int value;
248};
249
250
255template< typename PAYLOAD = Default_event_payload >
257{
258public:
259
263 struct Event
264 {
265 long long time;
266 PAYLOAD payload;
267
271 void free() noexcept { l4_mb(); time = 0; }
272 };
273
274private:
275 Event *_current;
276 Event *_begin;
277 Event const *_end;
278
279 void inc() noexcept
280 {
281 ++_current;
282 if (_current == _end)
283 _current = _begin;
284 }
285
286public:
287
288 Event_buffer_t() : _current(0), _begin(0), _end(0) {}
289
290 void reset()
291 {
292 for (Event *i = _begin; i != _end; ++i)
293 i->time = 0;
294 _current = _begin;
295 }
296
303 Event_buffer_t(void *buffer, l4_addr_t size)
304 : _current((Event*)buffer), _begin(_current),
305 _end(_begin + size / sizeof(Event))
306 { reset(); }
307
313 Event *next() noexcept
314 {
315 Event *c = _current;
316 if (c->time)
317 {
318 inc();
319 return c;
320 }
321 return 0;
322 }
323
330 bool put(Event const &ev) noexcept
331 {
332 Event *c = _current;
333 if (c->time)
334 return false;
335
336 inc();
337 c->payload = ev.payload;
338 l4_wmb();
339 c->time = ev.time;
340 return true;
341 }
342};
343
344typedef Event_buffer_t<Default_event_payload> Event_buffer;
345
346}
347
348
L4::Cap related definitions.
Event buffer class.
Definition event:257
Event_buffer_t(void *buffer, l4_addr_t size)
Initialize event buffer.
Definition event:303
Event * next() noexcept
Next event in buffer.
Definition event:313
bool put(Event const &ev) noexcept
Put event into buffer at current position.
Definition event:330
Event class.
Definition event:150
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:208
C++ interface for capabilities.
Definition capability.h:222
Helper class to create an L4Re interface class that is derived from a single base class.
Definition __typeinfo.h:760
Dataspace interface.
Events.
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:51
unsigned long l4_addr_t
Address type.
Definition l4int.h:45
void l4_wmb(void)
Write memory barrier.
Definition compiler.h:337
void l4_mb(void)
Memory barrier.
Definition compiler.h:332
#define L4_EXPORT
Attribute to mark functions, variables, and data types as being exported from a library.
Definition compiler.h:221
Interface Definition Language.
#define L4_RPC(res, name, args, attr...)
Define an RPC call (type and callable).
Definition ipc_iface:528
#define L4_RPC_NF(res, name, args...)
Define an RPC call type (the type only, no callable).
Definition ipc_iface:497
C++ Irq interface.
L4Re C++ Interfaces.
Definition cmd_control:15
Default event stream payload.
Definition event:243
l4_umword_t stream_id
Stream ID.
Definition event:247
int value
Value of event.
Definition event:246
unsigned short code
Code of event.
Definition event:245
unsigned short type
Type of event.
Definition event:244
Event structure used in buffer.
Definition event:264
void free() noexcept
Free the entry.
Definition event:271
long long time
Event time stamp.
Definition event:265
Array data type for dynamically sized arrays in RPCs.
Definition ipc_array:93
Mark an argument as a output value in an RPC signature.
Definition ipc_types:42
Standard list of RPCs of an interface.
Definition __typeinfo.h:438