L4Re - L4 Runtime Environment
event
Go to the documentation of this file.
1 // vi:set ft=cpp: -*- Mode: C++ -*-
5 /*
6  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
7  * Alexander Warg <warg@os.inf.tu-dresden.de>
8  * economic rights: Technische Universität Dresden (Germany)
9  *
10  * This file is part of TUD:OS and distributed under the terms of the
11  * GNU General Public License 2.
12  * Please see the COPYING-GPL-2 file for details.
13  *
14  * As a special exception, you may use this file as part of a free software
15  * library without restriction. Specifically, if other files instantiate
16  * templates or use macros or inline functions from this file, or you compile
17  * this file and link it with other files to produce an executable, this
18  * file does not by itself cause the resulting executable to be covered by
19  * the GNU General Public License. This exception does not however
20  * invalidate any other reasons why the executable file might be covered by
21  * the GNU General Public License.
22  */
23 #pragma once
24 
25 #include <l4/re/cap_alloc>
26 #include <l4/re/util/cap_alloc>
27 #include <l4/re/env>
28 #include <l4/re/rm>
29 #include <l4/re/util/event_buffer>
30 #include <l4/sys/factory>
31 
32 namespace L4Re { namespace Util {
33 
40 template< typename PAYLOAD >
41 class Event_t
42 {
43 public:
47  enum Mode
48  {
51  };
52 
67  template<typename IRQ_TYPE>
69  L4Re::Env const *env = L4Re::Env::env(),
71  {
73  if (!ev_ds.is_valid())
74  return -L4_ENOMEM;
75 
76  int r;
77 
78  typename Auto_del_cap<IRQ_TYPE>::Cap ev_irq;
79  ev_irq = ca->alloc<IRQ_TYPE>();
80  if (!ev_irq.is_valid())
81  return -L4_ENOMEM;
82 
83  if ((r = l4_error(env->factory()->create(ev_irq.get()))))
84  return r;
85 
86  if ((r = l4_error(event->bind(0, ev_irq.get()))))
87  return r;
88 
89  if ((r = event->get_buffer(ev_ds.get())))
90  return r;
91 
92  long sz = ev_ds->size();
93  if (sz < 0)
94  return sz;
95 
96  Rm::Auto_region<void*> buf;
97 
98  if ((r = env->rm()->attach(&buf, sz, L4Re::Rm::Search_addr,
99  L4::Ipc::make_cap_rw(ev_ds.get()))))
100  return r;
101 
102  _ev_buffer = L4Re::Event_buffer_t<PAYLOAD>(buf.get(), sz);
103  _ev_ds = ev_ds;
104  _ev_irq = ev_irq;
105  _buf = buf;
106 
107  return 0;
108  }
109 
122  L4Re::Env const *env = L4Re::Env::env(),
124  {
125  Auto_cap<L4Re::Dataspace>::Cap ev_ds = ca->alloc<L4Re::Dataspace>();
126  if (!ev_ds.is_valid())
127  return -L4_ENOMEM;
128 
129  int r;
130 
131  if ((r = event->get_buffer(ev_ds.get())))
132  return r;
133 
134  long sz = ev_ds->size();
135  if (sz < 0)
136  return sz;
137 
138  Rm::Auto_region<void*> buf;
139 
140  if ((r = env->rm()->attach(&buf, sz, L4Re::Rm::Search_addr,
141  L4::Ipc::make_cap_rw(ev_ds.get()))))
142  return r;
143 
144  _ev_buffer = L4Re::Event_buffer_t<PAYLOAD>(buf.get(), sz);
145  _ev_ds = ev_ds;
146  _buf = buf;
147 
148  return 0;
149  }
150 
156  L4Re::Event_buffer_t<PAYLOAD> &buffer() { return _ev_buffer; }
157 
163  L4::Cap<L4::Triggerable> irq() const { return _ev_irq.get(); }
164 
165 private:
169  Rm::Auto_region<void*> _buf;
170 };
171 
173 
174 }}
Smart capability class.
Automatic capability that implements automatic free and unmap of the capability selector.
Definition: cap_alloc:161
Create an IRQ and attach, to get notifications.
Definition: event:49
Abstract capability-allocator interface.
L4Re::Event_buffer_t< PAYLOAD > & buffer()
Get event buffer.
Definition: event:156
Capability allocator interface.
Definition: cap_alloc:40
Event buffer class.
Definition: event:187
Mode
Modes of operation.
Definition: event:47
int init(L4::Cap< L4Re::Event > event, L4Re::Env const *env=L4Re::Env::env(), L4Re::Cap_alloc *ca=L4Re::Cap_alloc::get_cap_alloc(L4Re::Util::cap_alloc))
Initialise an event object.
Definition: event:68
C++ interface of the initial environment that is provided to an L4 task.
Definition: env:82
static L4Re::Cap_alloc * get_cap_alloc(CAP_ALLOC &ca)
Construct an instance of a capability allocator.
Definition: cap_alloc:85
L4Re C++ Interfaces.
Definition: cmd_control:15
Search for a suitable address range.
Definition: rm:113
Environment interface.
L4::Cap< L4::Triggerable > irq() const
Get event IRQ.
Definition: event:163
Interface for memory-like objects.
Definition: dataspace:59
Region mapper interface.
l4_msgtag_t bind(unsigned irqnum, L4::Cap< Triggerable > irq, l4_utcb_t *utcb=l4_utcb())
Bind an interrupt line of an interrupt controller to an interrupt object.
Definition: irq:290
static Env const * env()
Returns the initial environment for the current task.
Definition: env:100
long get_buffer(L4::Ipc::Out< L4::Cap< Dataspace > > ds)
Get event signal buffer.
_Cap_alloc & cap_alloc
Capability allocator.
int init_poll(L4::Cap< L4Re::Event > event, L4Re::Env const *env=L4Re::Env::env(), L4Re::Cap_alloc *ca=L4Re::Cap_alloc::get_cap_alloc(L4Re::Util::cap_alloc))
Initialise an event object in polling mode.
Definition: event:121
Cap< T > make_cap_rw(L4::Cap< T > cap)
Make an L4::Ipc::Cap<T> for the given capability with L4_CAP_FPAGE_RW rights.
Definition: ipc_types:631
Automatic capability that implements automatic free and unmap+delete of the capability selector...
Definition: cap_alloc:196
No memory.
Definition: err.h:50
Do not use an IRQ.
Definition: event:50
bool is_valid() const
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
Definition: capability.h:59
long l4_error(l4_msgtag_t tag) L4_NOTHROW
Return error code of a system call return message tag.
Definition: ipc.h:517
Common factory related definitions.
Capability allocator.
Convenience wrapper for getting access to an event object.
Definition: event:41
C++ interface for capabilities.
Definition: capability.h:13