]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re/util/include/event
1c95dd9a2ba8242f39dd64234ce075a58428901d
[l4.git] / l4 / pkg / l4re / util / include / event
1 // vi:ft=cpp:
2 /**
3  * \file
4  */
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
31 namespace L4Re { namespace Util {
32
33 /**
34  * \brief Convenience wrapper for getting access to an event object.
35  *
36  * After calling init() the class supplies the event-buffer and the
37  * associated IRQ object.
38  */
39 class Event
40 {
41 public:
42   /**
43    * \brief Modes of operation.
44    */
45   enum Mode
46   {
47     Mode_irq,      ///< Create an IRQ and attach, to get notifications.
48     Mode_polling,  ///< Do not use an IRQ.
49   };
50
51   /**
52    * \brief Initialise an event object.
53    *
54    * \param event   Capability to event.
55    * \param env     Optional: Pointer to L4Re-Environment
56    * \param ca      Optional: Pointer to capability allocator.
57    * \return 0 on success, error code on error
58    */
59   int init(L4::Cap<L4Re::Event> event, Mode mode = Mode_irq,
60            L4Re::Env const *env = L4Re::Env::env(),
61            L4Re::Cap_alloc *ca = L4Re::Cap_alloc::get_cap_alloc(L4Re::Util::cap_alloc));
62
63   /**
64    * \brief Get event buffer.
65    * \return Event buffer object.
66    */
67   L4Re::Event_buffer &buffer() { return _ev_buffer; }
68
69   /**
70    * \brief Get event IRQ.
71    * \return Event IRQ.
72    */
73   L4::Cap<L4::Irq> irq() const { return _ev_irq.get(); }
74
75 private:
76   Auto_cap<L4Re::Dataspace>::Cap _ev_ds;
77   Auto_del_cap<L4::Irq>::Cap _ev_irq;
78   L4Re::Event_buffer _ev_buffer;
79   Rm::Auto_region<void*> _buf;
80 };
81
82 }}