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/util/unique_cap>
28 #include <l4/re/env>
29 #include <l4/re/rm>
30 #include <l4/re/util/event_buffer>
31 #include <l4/sys/factory>
32 #include <l4/cxx/type_traits>
33 
34 namespace L4Re { namespace Util {
35 
42 template< typename PAYLOAD >
43 class Event_t
44 {
45 public:
49  enum Mode
50  {
53  };
54 
69  template<typename IRQ_TYPE>
71  L4Re::Env const *env = L4Re::Env::env(),
73  {
74  Unique_cap<L4Re::Dataspace> ev_ds(ca->alloc<L4Re::Dataspace>());
75  if (!ev_ds.is_valid())
76  return -L4_ENOMEM;
77 
78  int r;
79 
80  Unique_del_cap<IRQ_TYPE> ev_irq(ca->alloc<IRQ_TYPE>());
81  if (!ev_irq.is_valid())
82  return -L4_ENOMEM;
83 
84  if ((r = l4_error(env->factory()->create(ev_irq.get()))))
85  return r;
86 
87  if ((r = l4_error(event->bind(0, ev_irq.get()))))
88  return r;
89 
90  if ((r = event->get_buffer(ev_ds.get())))
91  return r;
92 
93  long sz = ev_ds->size();
94  if (sz < 0)
95  return sz;
96 
97  Rm::Unique_region<void*> buf;
98 
99  if ((r = env->rm()->attach(&buf, sz, L4Re::Rm::Search_addr,
100  L4::Ipc::make_cap_rw(ev_ds.get()))))
101  return r;
102 
103  _ev_buffer = L4Re::Event_buffer_t<PAYLOAD>(buf.get(), sz);
104  _ev_ds = cxx::move(ev_ds);
105  _ev_irq = cxx::move(ev_irq);
106  _buf = cxx::move(buf);
107 
108  return 0;
109  }
110 
123  L4Re::Env const *env = L4Re::Env::env(),
125  {
126  Unique_cap<L4Re::Dataspace> ev_ds(ca->alloc<L4Re::Dataspace>());
127  if (!ev_ds.is_valid())
128  return -L4_ENOMEM;
129 
130  int r;
131 
132  if ((r = event->get_buffer(ev_ds.get())))
133  return r;
134 
135  long sz = ev_ds->size();
136  if (sz < 0)
137  return sz;
138 
139  Rm::Unique_region<void*> buf;
140 
141  if ((r = env->rm()->attach(&buf, sz, L4Re::Rm::Search_addr,
142  L4::Ipc::make_cap_rw(ev_ds.get()))))
143  return r;
144 
145  _ev_buffer = L4Re::Event_buffer_t<PAYLOAD>(buf.get(), sz);
146  _ev_ds = cxx::move(ev_ds);
147  _buf = cxx::move(buf);
148 
149  return 0;
150  }
151 
157  L4Re::Event_buffer_t<PAYLOAD> &buffer() { return _ev_buffer; }
158 
164  L4::Cap<L4::Triggerable> irq() const { return _ev_irq.get(); }
165 
166 private:
170  Rm::Unique_region<void*> _buf;
171 };
172 
174 
175 }}
Unique_cap / Unique_del_cap.
Create an IRQ and attach, to get notifications.
Definition: event:51
Abstract capability-allocator interface.
L4Re::Event_buffer_t< PAYLOAD > & buffer()
Get event buffer.
Definition: event:157
Capability allocator interface.
Definition: cap_alloc:41
Event buffer class.
Definition: event:198
Mode
Modes of operation.
Definition: event:49
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:70
C++ interface of the initial environment that is provided to an L4 task.
Definition: env:85
static L4Re::Cap_alloc * get_cap_alloc(CAP_ALLOC &ca)
Construct an instance of a capability allocator.
Definition: cap_alloc:90
L4Re C++ Interfaces.
Definition: cmd_control:15
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:97
Search for a suitable address range.
Definition: rm:115
Environment interface.
L4::Cap< L4::Triggerable > irq() const
Get event IRQ.
Definition: event:164
Interface for memory-like objects.
Definition: dataspace:59
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:54
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:310
static Env const * env()
Returns the initial environment for the current task.
Definition: env:103
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:122
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:634
No memory.
Definition: err.h:50
Do not use an IRQ.
Definition: event:52
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:43
C++ interface for capabilities.
Definition: capability.h:13