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)
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.
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.
25 #include <l4/re/cap_alloc>
26 #include <l4/re/util/cap_alloc>
29 #include <l4/re/util/event_buffer>
30 #include <l4/sys/factory>
32 namespace L4Re { namespace Util {
35 * \brief Convenience wrapper for getting access to an event object.
37 * After calling init() the class supplies the event-buffer and the
38 * associated IRQ object.
40 template< typename PAYLOAD >
45 * \brief Modes of operation.
49 Mode_irq, ///< Create an IRQ and attach, to get notifications.
50 Mode_polling, ///< Do not use an IRQ.
54 * \brief Initialise an event object.
56 * \param event Capability to event.
57 * \param env Optional: Pointer to L4Re-Environment
58 * \param ca Optional: Pointer to capability allocator.
59 * \return 0 on success, error code on error
61 int init(L4::Cap<L4Re::Event> event, Mode mode = Mode_irq,
62 L4Re::Env const *env = L4Re::Env::env(),
63 L4Re::Cap_alloc *ca = L4Re::Cap_alloc::get_cap_alloc(L4Re::Util::cap_alloc))
65 Auto_cap<L4Re::Dataspace>::Cap ev_ds = ca->alloc<L4Re::Dataspace>();
66 if (!ev_ds.is_valid())
71 Auto_del_cap<L4::Irq>::Cap ev_irq;
75 ev_irq = ca->alloc<L4::Irq>();
76 if (!ev_irq.is_valid())
79 if ((r = l4_error(env->factory()->create_irq(ev_irq.get()))))
82 if ((r = l4_error(event->bind(0, ev_irq.get()))))
86 if ((r = event->get_buffer(ev_ds.get())))
89 long sz = ev_ds->size();
93 Rm::Auto_region<void*> buf;
95 if ((r = env->rm()->attach(&buf, sz, L4Re::Rm::Search_addr, ev_ds.get())))
98 _ev_buffer = L4Re::Event_buffer_t<PAYLOAD>(buf.get(), sz);
107 * \brief Get event buffer.
108 * \return Event buffer object.
110 L4Re::Event_buffer_t<PAYLOAD> &buffer() { return _ev_buffer; }
113 * \brief Get event IRQ.
116 L4::Cap<L4::Irq> irq() const { return _ev_irq.get(); }
119 Auto_cap<L4Re::Dataspace>::Cap _ev_ds;
120 Auto_del_cap<L4::Irq>::Cap _ev_irq;
121 L4Re::Event_buffer_t<PAYLOAD> _ev_buffer;
122 Rm::Auto_region<void*> _buf;
125 typedef Event_t<Default_event_payload> Event;