Loading...
Searching...
No Matches
event
Go to the documentation of this file.
// 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/cap_alloc>
#include <l4/re/util/cap_alloc>
#include <l4/re/util/unique_cap>
#include <l4/re/env>
#include <l4/re/rm>
#include <l4/re/util/event_buffer>
#include <l4/sys/factory>
#include <l4/cxx/type_traits>
namespace L4Re { namespace Util {
template< typename PAYLOAD >
class Event_t
{
public:
enum Mode
{
Mode_irq,
Mode_polling,
};
template<typename IRQ_TYPE>
int init(L4::Cap<L4Re::Event> event,
L4Re::Env const *env = L4Re::Env::env(),
L4Re::Cap_alloc *ca = &L4Re::Util::cap_alloc)
{
Unique_cap<L4Re::Dataspace> ev_ds(ca->alloc<L4Re::Dataspace>());
if (!ev_ds.is_valid())
return -L4_ENOMEM;
int r;
Unique_del_cap<IRQ_TYPE> ev_irq(ca->alloc<IRQ_TYPE>());
if (!ev_irq.is_valid())
return -L4_ENOMEM;
if ((r = l4_error(env->factory()->create(ev_irq.get()))))
return r;
if ((r = l4_error(event->bind(0, ev_irq.get()))))
return r;
if ((r = event->get_buffer(ev_ds.get())))
return r;
long sz = ev_ds->size();
if (sz < 0)
return sz;
Rm::Unique_region<void*> buf;
if ((r = env->rm()->attach(&buf, sz,
L4Re::Rm::F::Search_addr | L4Re::Rm::F::RW,
L4::Ipc::make_cap_rw(ev_ds.get()))))
return r;
_ev_buffer = L4Re::Event_buffer_t<PAYLOAD>(buf.get(), sz);
_ev_ds = cxx::move(ev_ds);
_ev_irq = cxx::move(ev_irq);
_buf = cxx::move(buf);
return 0;
}
int init_poll(L4::Cap<L4Re::Event> event,
L4Re::Env const *env = L4Re::Env::env(),
L4Re::Cap_alloc *ca = &L4Re::Util::cap_alloc)
{
Unique_cap<L4Re::Dataspace> ev_ds(ca->alloc<L4Re::Dataspace>());
if (!ev_ds.is_valid())
return -L4_ENOMEM;
int r;
if ((r = event->get_buffer(ev_ds.get())))
return r;
long sz = ev_ds->size();
if (sz < 0)
return sz;
Rm::Unique_region<void*> buf;
if ((r = env->rm()->attach(&buf, sz,
L4Re::Rm::F::Search_addr | L4Re::Rm::F::RW,
L4::Ipc::make_cap_rw(ev_ds.get()))))
return r;
_ev_buffer = L4Re::Event_buffer_t<PAYLOAD>(buf.get(), sz);
_ev_ds = cxx::move(ev_ds);
_buf = cxx::move(buf);
return 0;
}
L4Re::Event_buffer_t<PAYLOAD> &buffer() { return _ev_buffer; }
L4::Cap<L4::Triggerable> irq() const { return _ev_irq.get(); }
private:
Unique_cap<L4Re::Dataspace> _ev_ds;
Unique_del_cap<L4::Triggerable> _ev_irq;
L4Re::Event_buffer_t<PAYLOAD> _ev_buffer;
Rm::Unique_region<void*> _buf;
};
typedef Event_t<Default_event_payload> Event;
}}
cap_alloc
Abstract capability-allocator interface.
L4Re::Cap_alloc
Capability allocator interface.
Definition cap_alloc:31
L4Re::Dataspace
Interface for memory-like objects.
Definition dataspace:53
L4Re::Env
C++ interface of the initial environment that is provided to an L4 task.
Definition env:79
L4Re::Env::env
static Env const * env() noexcept
Returns the initial environment for the current task.
Definition env:96
L4Re::Event_buffer_t
Event buffer class.
Definition event:247
L4Re::Event
Event class.
Definition event:139
L4Re::Rm::Unique_region
Unique region.
Definition rm:436
L4Re::Rm::Unique_region::get
T get() const noexcept
Return the address.
Definition rm:509
L4Re::Util::Event_t
Convenience wrapper for getting access to an event object.
Definition event:33
L4Re::Util::Event_t::init_poll
int init_poll(L4::Cap< L4Re::Event > event, L4Re::Env const *env=L4Re::Env::env(), L4Re::Cap_alloc *ca=&L4Re::Util::cap_alloc)
Initialise an event object in polling mode.
Definition event:112
L4Re::Util::Event_t::irq
L4::Cap< L4::Triggerable > irq() const
Get event IRQ.
Definition event:155
L4Re::Util::Event_t::init
int init(L4::Cap< L4Re::Event > event, L4Re::Env const *env=L4Re::Env::env(), L4Re::Cap_alloc *ca=&L4Re::Util::cap_alloc)
Initialise an event object.
Definition event:59
L4Re::Util::Event_t::Mode
Mode
Modes of operation.
Definition event:39
L4Re::Util::Event_t< Default_event_payload >::Mode_irq
@ Mode_irq
Definition event:40
L4Re::Util::Event_t< Default_event_payload >::Mode_polling
@ Mode_polling
Definition event:41
L4Re::Util::Event_t::buffer
L4Re::Event_buffer_t< PAYLOAD > & buffer()
Get event buffer.
Definition event:148
L4::Cap_base::is_valid
bool is_valid() const noexcept
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
Definition capability.h:57
L4::Cap
C++ interface for capabilities.
Definition capability.h:224
env
Environment interface.
factory
Common factory related definitions.
L4_ENOMEM
@ L4_ENOMEM
No memory.
Definition err.h:39
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
L4Re::Util::cap_alloc
_Cap_alloc & cap_alloc
Capability allocator.
L4Re::Util
Documentation of the L4 Runtime Environment utility functionality in C++.
Definition l4re.dox:21
L4Re::Util::Unique_cap
L4::Detail::Unique_cap_impl< T, Smart_cap_auto< L4_FP_ALL_SPACES > > Unique_cap
Unique capability that implements automatic free and unmap of the capability selector.
Definition unique_cap:43
L4Re::Util::Unique_del_cap
L4::Detail::Unique_cap_impl< T, Smart_cap_auto< L4_FP_DELETE_OBJ > > Unique_del_cap
Unique capability that implements automatic free and unmap+delete of the capability selector.
Definition unique_cap:86
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.
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
cap_alloc
Capability allocator.
unique_cap
Unique_cap / Unique_del_cap.