Loading...
Searching...
No Matches
event
// vi:set ft=cpp: -*- Mode: C++ -*-
/*
* (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
* Alexander Warg <warg@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#pragma once
#include <l4/sys/capability>
#include <l4/sys/irq>
#include <l4/sys/cxx/ipc_iface>
#include <l4/sys/cxx/ipc_array>
#include <l4/re/dataspace>
#include <l4/re/event.h>
namespace L4Re {
typedef l4re_event_stream_id_t Event_stream_id;
typedef l4re_event_absinfo_t Event_absinfo;
class L4_EXPORT Event_stream_bitmap_h
{
protected:
static unsigned __get_idx(unsigned idx)
{ return idx / (sizeof(unsigned long)*8); }
static unsigned long __get_mask(unsigned idx)
{ return 1ul << (idx % (sizeof(unsigned long)*8)); }
static bool __get_bit(unsigned long const *bm, unsigned max, unsigned idx)
{
if (idx <= max)
return bm[__get_idx(idx)] & __get_mask(idx);
return false;
}
static void __set_bit(unsigned long *bm, unsigned max, unsigned idx, bool v)
{
if (idx > max)
return;
if (v)
bm[__get_idx(idx)] |= __get_mask(idx);
else
bm[__get_idx(idx)] &= ~__get_mask(idx);
}
};
class L4_EXPORT Event_stream_info
: public l4re_event_stream_info_t,
private Event_stream_bitmap_h
{
public:
bool get_propbit(unsigned idx) const
{ return __get_bit(propbits, L4RE_EVENT_PROP_MAX, idx); }
void set_propbit(unsigned idx, bool v)
{ __set_bit(propbits, L4RE_EVENT_PROP_MAX, idx, v); }
bool get_evbit(unsigned idx) const
{ return __get_bit(evbits, L4RE_EVENT_EV_MAX, idx); }
void set_evbit(unsigned idx, bool v)
{ __set_bit(evbits, L4RE_EVENT_EV_MAX, idx, v); }
bool get_keybit(unsigned idx) const
{ return __get_bit(keybits, L4RE_EVENT_KEY_MAX, idx); }
void set_keybit(unsigned idx, bool v)
{ __set_bit(keybits, L4RE_EVENT_KEY_MAX, idx, v); }
bool get_relbit(unsigned idx) const
{ return __get_bit(relbits, L4RE_EVENT_REL_MAX, idx); }
void set_relbit(unsigned idx, bool v)
{ __set_bit(relbits, L4RE_EVENT_REL_MAX, idx, v); }
bool get_absbit(unsigned idx) const
{ return __get_bit(absbits, L4RE_EVENT_ABS_MAX, idx); }
void set_absbit(unsigned idx, bool v)
{ __set_bit(absbits, L4RE_EVENT_ABS_MAX, idx, v); }
bool get_swbit(unsigned idx) const
{ return __get_bit(swbits, L4RE_EVENT_SW_MAX, idx); }
void set_swbit(unsigned idx, bool v)
{ __set_bit(swbits, L4RE_EVENT_SW_MAX, idx, v); }
};
class L4_EXPORT Event_stream_state
: public l4re_event_stream_state_t,
private Event_stream_bitmap_h
{
public:
bool get_keybit(unsigned idx) const
{ return __get_bit(keybits, L4RE_EVENT_KEY_MAX, idx); }
void set_keybit(unsigned idx, bool v)
{ __set_bit(keybits, L4RE_EVENT_KEY_MAX, idx, v); }
bool get_swbit(unsigned idx) const
{ return __get_bit(swbits, L4RE_EVENT_SW_MAX, idx); }
void set_swbit(unsigned idx, bool v)
{ __set_bit(swbits, L4RE_EVENT_SW_MAX, idx, v); }
};
class L4_EXPORT Event :
public L4::Kobject_t<Event, L4::Icu, L4RE_PROTO_EVENT>
{
public:
L4_RPC(long, get_buffer, (L4::Ipc::Out<L4::Cap<Dataspace> > ds));
L4_RPC(long, get_num_streams, ());
L4_RPC(long, get_stream_info, (int idx, Event_stream_info *info));
L4_RPC(long, get_stream_info_for_id, (l4_umword_t stream_id, Event_stream_info *info));
L4_RPC_NF(long, get_axis_info, (l4_umword_t stream_id,
L4::Ipc::Array<unsigned const, unsigned long> axes,
L4::Ipc::Array<Event_absinfo, unsigned long> &info));
long get_axis_info(l4_umword_t stream_id, unsigned naxes,
unsigned const *axis, Event_absinfo *info) const noexcept
{
L4::Ipc::Array<Event_absinfo, unsigned long> i(naxes, info);
return get_axis_info_t::call(c(), stream_id,
L4::Ipc::Array<unsigned const, unsigned long>(naxes, axis), i);
}
L4_RPC(long, get_stream_state_for_id, (l4_umword_t stream_id,
Event_stream_state *state));
typedef L4::Typeid::Rpcs<
get_buffer_t,
get_num_streams_t,
get_stream_info_t,
get_stream_info_for_id_t,
get_axis_info_t,
get_stream_state_for_id_t
> Rpcs;
};
struct L4_EXPORT Default_event_payload
{
unsigned short type;
unsigned short code;
int value;
l4_umword_t stream_id;
};
template< typename PAYLOAD = Default_event_payload >
class L4_EXPORT Event_buffer_t
{
public:
struct Event
{
long long time;
PAYLOAD payload;
void free() noexcept { l4_mb(); time = 0; }
};
private:
Event *_current;
Event *_begin;
Event const *_end;
void inc() noexcept
{
++_current;
if (_current == _end)
_current = _begin;
}
public:
Event_buffer_t() : _current(0), _begin(0), _end(0) {}
void reset()
{
for (Event *i = _begin; i != _end; ++i)
i->time = 0;
_current = _begin;
}
Event_buffer_t(void *buffer, l4_addr_t size)
: _current(static_cast<Event*>(buffer)), _begin(_current),
_end(_begin + size / sizeof(Event))
{ reset(); }
Event *next() noexcept
{
Event *c = _current;
if (c->time)
{
inc();
return c;
}
return 0;
}
bool put(Event const &ev) noexcept
{
Event *c = _current;
if (c->time)
return false;
inc();
c->payload = ev.payload;
l4_wmb();
c->time = ev.time;
return true;
}
};
typedef Event_buffer_t<Default_event_payload> Event_buffer;
}
capability
L4::Cap related definitions.
L4Re::Event_buffer_t::Event_buffer_t
Event_buffer_t(void *buffer, l4_addr_t size)
Initialize event buffer.
Definition event:293
L4Re::Event_buffer_t::next
Event * next() noexcept
Next event in buffer.
Definition event:303
L4Re::Event_buffer_t::put
bool put(Event const &ev) noexcept
Put event into buffer at current position.
Definition event:320
L4Re::Event
Event class.
Definition event:139
L4Re::Event::get_stream_info_for_id
long get_stream_info_for_id(l4_umword_t stream_id, Event_stream_info *info)
Get event stream infos.
L4Re::Event::get_num_streams
long get_num_streams()
Get number of event streams.
L4Re::Event::get_stream_info
long get_stream_info(int idx, Event_stream_info *info)
Get event stream infos.
L4Re::Event::get_axis_info
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
L4Re::Event::get_buffer
long get_buffer(L4::Ipc::Out< L4::Cap< Dataspace > > ds)
Get event signal buffer.
L4::Cap
C++ interface for capabilities.
Definition capability.h:224
L4::Icu::info
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
L4::Kobject_t
Helper class to create an L4Re interface class that is derived from a single base class.
Definition __typeinfo.h:750
L4::Kobject_t< Event, L4::Icu, L4RE_PROTO_EVENT >::c
L4::Cap< Class > c() const noexcept
Definition __typeinfo.h:769
dataspace
Dataspace interface.
event.h
Events.
l4_umword_t
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
l4_addr_t
unsigned long l4_addr_t
Address type.
Definition l4int.h:34
l4_wmb
void l4_wmb(void)
Write memory barrier.
Definition compiler.h:342
l4_mb
void l4_mb(void)
Memory barrier.
Definition compiler.h:337
L4_EXPORT
#define L4_EXPORT
Attribute to mark functions, variables, and data types as being exported from a library.
Definition compiler.h:214
ipc_iface
Interface Definition Language.
L4_RPC
#define L4_RPC(res, name, args, attr...)
Define an RPC call (type and callable).
Definition ipc_iface:541
L4_RPC_NF
#define L4_RPC_NF(res, name, args...)
Define an RPC call type (the type only, no callable).
Definition ipc_iface:510
irq
C++ Irq interface.
L4Re
L4Re C++ Interfaces.
Definition cmd_control:14
L4Re::Default_event_payload
Default event stream payload.
Definition event:233
L4Re::Default_event_payload::stream_id
l4_umword_t stream_id
Stream ID.
Definition event:237
L4Re::Default_event_payload::value
int value
Value of event.
Definition event:236
L4Re::Default_event_payload::code
unsigned short code
Code of event.
Definition event:235
L4Re::Default_event_payload::type
unsigned short type
Type of event.
Definition event:234
L4Re::Event_buffer_t::Event
Event structure used in buffer.
Definition event:254
L4Re::Event_buffer_t::Event::free
void free() noexcept
Free the entry.
Definition event:261
L4Re::Event_buffer_t::Event::time
long long time
Event time stamp.
Definition event:255
L4::Ipc::Array
Array data type for dynamically sized arrays in RPCs.
Definition ipc_array:82
L4::Ipc::Out
Mark an argument as a output value in an RPC signature.
Definition ipc_types:31
L4::Typeid::Rpcs
Standard list of RPCs of an interface.
Definition __typeinfo.h:428