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 * 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
39
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:
150
158
170 L4_RPC(l4_ret_t, get_stream_info, (int idx, Event_stream_info *info));
171
181 L4_RPC(l4_ret_t, get_stream_info_for_id, (l4_umword_t stream_id, Event_stream_info *info));
182
195 L4::Ipc::Array<unsigned const,
196 unsigned long> axes,
197 L4::Ipc::Array<Event_absinfo,
198 unsigned long> &info));
199
200 l4_ret_t get_axis_info(l4_umword_t stream_id, unsigned naxes,
201 unsigned const *axis, Event_absinfo *info) const noexcept
202 {
204 return get_axis_info_t::call(c(), stream_id,
206 }
207
217 L4_RPC(l4_ret_t, get_stream_state_for_id, (l4_umword_t stream_id,
218 Event_stream_state *state));
219
220 typedef L4::Typeid::Rpcs<
221 get_buffer_t,
222 get_num_streams_t,
223 get_stream_info_t,
224 get_stream_info_for_id_t,
225 get_axis_info_t,
226 get_stream_state_for_id_t
227 > Rpcs;
228};
229
235{
236 unsigned short type;
237 unsigned short code;
238 int value;
240};
241
242
247template< typename PAYLOAD = Default_event_payload >
248class L4_EXPORT Event_buffer_t
249{
250public:
251
255 struct Event
256 {
257 long long time;
258 PAYLOAD payload;
259
263 void free() noexcept { l4_mb(); time = 0; }
264 };
265
266private:
267 Event *_current;
268 Event *_begin;
269 Event const *_end;
270
271 void inc() noexcept
272 {
273 ++_current;
274 if (_current == _end)
275 _current = _begin;
276 }
277
278public:
279
280 Event_buffer_t() : _current(0), _begin(0), _end(0) {}
281
282 void reset()
283 {
284 for (Event *i = _begin; i != _end; ++i)
285 i->time = 0;
286 _current = _begin;
287 }
288
295 Event_buffer_t(void *buffer, l4_addr_t size)
296 : _current(static_cast<Event*>(buffer)), _begin(_current),
297 _end(_begin + size / sizeof(Event))
298 { reset(); }
299
305 Event *next() noexcept
306 {
307 Event *c = _current;
308 if (c->time)
309 {
310 inc();
311 return c;
312 }
313 return 0;
314 }
315
322 bool put(Event const &ev) noexcept
323 {
324 Event *c = _current;
325 if (c->time)
326 return false;
327
328 inc();
329 c->payload = ev.payload;
330 l4_wmb();
331 c->time = ev.time;
332 return true;
333 }
334};
335
336typedef Event_buffer_t<Default_event_payload> Event_buffer;
337
338}
L4::Cap related definitions.
Event_buffer_t(void *buffer, l4_addr_t size)
Initialize event buffer.
Definition event:295
Event * next() noexcept
Next event in buffer.
Definition event:305
bool put(Event const &ev) noexcept
Put event into buffer at current position.
Definition event:322
Event class.
Definition event:139
l4_ret_t get_stream_info(int idx, Event_stream_info *info)
Get event stream infos.
l4_ret_t 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:200
l4_ret_t get_buffer(L4::Ipc::Out< L4::Cap< Dataspace > > ds)
Get event signal buffer.
l4_ret_t get_num_streams()
Get number of event streams.
l4_ret_t get_stream_info_for_id(l4_umword_t stream_id, Event_stream_info *info)
Get event stream infos.
C++ interface for capabilities.
Definition capability.h:224
l4_msgtag_t info(l4_icu_info_t *info, l4_utcb_t *utcb=l4_utcb()) noexcept
Get information about the ICU features.
Definition irq:345
Helper class to create an L4Re interface class that is derived from a single base class.
Definition __typeinfo.h:750
L4::Cap< Class > c() const noexcept
Definition __typeinfo.h:769
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:347
void l4_mb(void)
Memory barrier.
Definition compiler.h:342
#define L4_EXPORT
Attribute to mark functions, variables, and data types as being exported from a library.
Definition compiler.h:214
Interface Definition Language.
#define L4_RPC(res, name, args, attr...)
Define an RPC call (type and callable).
Definition ipc_iface:542
#define L4_RPC_NF(res, name, args...)
Define an RPC call type (the type only, no callable).
Definition ipc_iface:511
C++ Irq interface.
l4_int16_t l4_ret_t
Return value of an IPC call as well as an RPC call.
Definition types.h:28
L4Re C++ Interfaces.
Definition cmd_control:14
Default event stream payload.
Definition event:235
l4_umword_t stream_id
Stream ID.
Definition event:239
int value
Value of event.
Definition event:238
unsigned short code
Code of event.
Definition event:237
unsigned short type
Type of event.
Definition event:236
Event structure used in buffer.
Definition event:256
void free() noexcept
Free the entry.
Definition event:263
long long time
Event time stamp.
Definition event:257
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