Loading...
Searching...
No Matches
event_buffer
// 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/re/event>
#include <l4/re/event-sys.h>
#include <l4/re/rm>
#include <string.h>
namespace L4Re { namespace Util {
template< typename PAYLOAD >
class Event_buffer_t : public L4Re::Event_buffer_t<PAYLOAD>
{
private:
void *_buf;
public:
void *buf() const noexcept { return _buf; }
long attach(L4::Cap<L4Re::Dataspace> ds, L4::Cap<L4Re::Rm> rm) noexcept
{
l4_addr_t sz = ds->size();
_buf = 0;
long r = rm->attach(&_buf, sz,
L4Re::Rm::F::Search_addr | L4Re::Rm::F::RW,
L4::Ipc::make_cap_rw(ds));
if (r < 0)
return r;
*static_cast< L4Re::Event_buffer_t<PAYLOAD> *>(this)
= L4Re::Event_buffer_t<PAYLOAD>(_buf, sz);
return 0;
}
long detach(L4::Cap<L4Re::Rm> rm) noexcept
{
L4::Cap<L4Re::Dataspace> ds;
if (_buf)
return rm->detach(_buf, &ds);
return 0;
}
};
template< typename PAYLOAD >
class Event_buffer_consumer_t : public Event_buffer_t<PAYLOAD>
{
public:
template< typename CB, typename D >
void foreach_available_event(CB const &cb, D data = D())
{
typename Event_buffer_t<PAYLOAD>::Event *e;
while ((e = Event_buffer_t<PAYLOAD>::next()))
{
cb(e, data);
e->free();
}
}
template< typename CB, typename D >
void process(L4::Cap<L4::Irq> irq,
L4::Cap<L4::Thread> thread,
CB const &cb, D data = D())
{
if (l4_error(irq->bind_thread(thread, 0)))
return;
while (1)
{
long r;
r = l4_ipc_error(l4_irq_receive(irq.cap(), L4_IPC_NEVER),
l4_utcb());
if (r)
continue;
foreach_available_event(cb, data);
}
}
};
typedef Event_buffer_t<Default_event_payload> Event_buffer;
typedef Event_buffer_consumer_t<Default_event_payload> Event_buffer_consumer;
}}
L4Re::Event_buffer_t
Event buffer class.
Definition event:247
L4Re::Event_buffer_t< PAYLOAD >::next
Event * next() noexcept
Definition event:303
L4Re::Util::Event_buffer_consumer_t
An event buffer consumer.
Definition event_buffer:84
L4Re::Util::Event_buffer_consumer_t::process
void process(L4::Cap< L4::Irq > irq, L4::Cap< L4::Thread > thread, CB const &cb, D data=D())
Continuously wait for events and process them.
Definition event_buffer:115
L4Re::Util::Event_buffer_consumer_t::foreach_available_event
void foreach_available_event(CB const &cb, D data=D())
Call function on every available event.
Definition event_buffer:94
L4Re::Util::Event_buffer_t
Event_buffer utility class.
Definition event_buffer:26
L4Re::Util::Event_buffer_t::detach
long detach(L4::Cap< L4Re::Rm > rm) noexcept
Detach event buffer from address space.
Definition event_buffer:68
L4Re::Util::Event_buffer_t::attach
long attach(L4::Cap< L4Re::Dataspace > ds, L4::Cap< L4Re::Rm > rm) noexcept
Attach event buffer from address space.
Definition event_buffer:45
L4Re::Util::Event_buffer_t::buf
void * buf() const noexcept
Return the buffer.
Definition event_buffer:35
L4::Cap_base::cap
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition capability.h:49
L4::Cap
C++ interface for capabilities.
Definition capability.h:224
l4_addr_t
unsigned long l4_addr_t
Address type.
Definition l4int.h:34
l4_error
long l4_error(l4_msgtag_t tag) L4_NOTHROW
Get IPC error code if any or message tag label otherwise for an IPC call.
Definition ipc.h:646
l4_ipc_error
l4_umword_t l4_ipc_error(l4_msgtag_t tag, l4_utcb_t *utcb) L4_NOTHROW
Get the IPC error code for an IPC operation.
Definition ipc.h:629
l4_irq_receive
l4_msgtag_t l4_irq_receive(l4_cap_idx_t irq, l4_timeout_t to) L4_NOTHROW
Unmask and wait for specified IRQ.
Definition irq.h:313
L4_IPC_NEVER
#define L4_IPC_NEVER
never timeout
Definition __timeout.h:76
l4_utcb
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:346
L4Re::Util
Documentation of the L4 Runtime Environment utility functionality in C++.
Definition l4re.dox:21
L4Re
L4Re C++ Interfaces.
Definition cmd_control:14
L4::Ipc::make_cap_rw
Cap< T > make_cap_rw(L4::Cap< T > cap) noexcept
Make an L4::Ipc::Cap<T> for the given capability with L4_CAP_FPAGE_RW rights.
Definition ipc_types:795
rm
Region mapper interface.
string.h
String.
L4Re::Rm::F::RW
@ RW
Readable and writable region.
Definition rm:139
L4Re::Rm::F::Search_addr
@ Search_addr
Search for a suitable address range.
Definition rm:114