L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
event_buffer
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/re/event>
13#include <l4/re/event-sys.h>
14#include <l4/re/rm>
15
16#include <string.h>
17
18namespace L4Re { namespace Util {
19
24template< typename PAYLOAD >
25class Event_buffer_t : public L4Re::Event_buffer_t<PAYLOAD>
26{
27private:
28 void *_buf;
29public:
35 void *buf() const noexcept { return _buf; }
36
46 {
47 l4_addr_t sz = ds->size();
48 _buf = 0;
49
50 long r = rm->attach(&_buf, sz,
53 if (r < 0)
54 return r;
55
56 *static_cast<L4Re::Event_buffer_t<PAYLOAD> *>(this)
58 return 0;
59 }
60
68 long detach(L4::Cap<L4Re::Rm> rm) noexcept
69 {
71 if (_buf)
72 return rm->detach(_buf, &ds);
73 return 0;
74 }
75
76};
77
82template< typename PAYLOAD >
84{
85public:
86
93 template< typename CB, typename D >
94 void foreach_available_event(CB const &cb, D data = D())
95 {
97 while ((e = Event_buffer_t<PAYLOAD>::next()))
98 {
99 cb(e, data);
100 e->free();
101 }
102 }
103
114 template< typename CB, typename D >
116 L4::Cap<L4::Thread> thread,
117 CB const &cb, D data = D())
118 {
119
120 if (l4_error(irq->bind_thread(thread, 0)))
121 return;
122
123 while (1)
124 {
125 long r;
127 l4_utcb());
128 if (r)
129 continue;
130
131 foreach_available_event(cb, data);
132 }
133 }
134};
135
136typedef Event_buffer_t<Default_event_payload> Event_buffer;
137typedef Event_buffer_consumer_t<Default_event_payload> Event_buffer_consumer;
138
139}}
Event buffer class.
Definition event:247
An event buffer consumer.
Definition event_buffer:84
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
void foreach_available_event(CB const &cb, D data=D())
Call function on every available event.
Definition event_buffer:94
Event_buffer utility class.
Definition event_buffer:26
long detach(L4::Cap< L4Re::Rm > rm) noexcept
Detach event buffer from address space.
Definition event_buffer:68
long attach(L4::Cap< L4Re::Dataspace > ds, L4::Cap< L4Re::Rm > rm) noexcept
Attach event buffer from address space.
Definition event_buffer:45
void * buf() const noexcept
Return the buffer.
Definition event_buffer:35
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition capability.h:49
C++ interface for capabilities.
Definition capability.h:219
unsigned long l4_addr_t
Address type.
Definition l4int.h:34
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_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_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:309
#define L4_IPC_NEVER
never timeout
Definition __timeout.h:76
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:346
L4Re C++ Interfaces.
Definition cmd_control:14
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
Region mapper interface.
String.
Event structure used in buffer.
Definition event:254
void free() noexcept
Free the entry.
Definition event:261
@ RW
Readable and writable region.
Definition rm:139
@ Search_addr
Search for a suitable address range.
Definition rm:114