]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re/util/libs/event.cc
update
[l4.git] / l4 / pkg / l4re / util / libs / event.cc
1 /*
2  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
3  *     economic rights: Technische Universität Dresden (Germany)
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  *
9  * As a special exception, you may use this file as part of a free software
10  * library without restriction.  Specifically, if other files instantiate
11  * templates or use macros or inline functions from this file, or you compile
12  * this file and link it with other files to produce an executable, this
13  * file does not by itself cause the resulting executable to be covered by
14  * the GNU General Public License.  This exception does not however
15  * invalidate any other reasons why the executable file might be covered by
16  * the GNU General Public License.
17  */
18
19 #include <l4/re/util/event>
20 #include <l4/sys/factory>
21
22 namespace L4Re { namespace Util {
23
24 int
25 Event::init(L4::Cap<L4Re::Event> event, Mode mode,
26             L4Re::Env const *env, L4Re::Cap_alloc *ca)
27 {
28   Auto_cap<L4Re::Dataspace>::Cap ev_ds = ca->alloc<L4Re::Dataspace>();
29   if (!ev_ds.is_valid())
30     return -L4_ENOMEM;
31
32   int r;
33
34   Auto_del_cap<L4::Irq>::Cap ev_irq;
35
36   if (mode == Mode_irq)
37     {
38       ev_irq = ca->alloc<L4::Irq>();
39       if (!ev_irq.is_valid())
40         return -L4_ENOMEM;
41
42       if ((r = l4_error(env->factory()->create_irq(ev_irq.get()))))
43         return r;
44
45       if ((r = l4_error(event->bind(0, ev_irq.get()))))
46         return r;
47     }
48
49   if ((r = event->get_buffer(ev_ds.get())))
50     return r;
51
52   long sz = ev_ds->size();
53   if (sz < 0)
54     return sz;
55
56   Rm::Auto_region<void*> buf;
57
58   if ((r = env->rm()->attach(&buf, sz, L4Re::Rm::Search_addr, ev_ds.get())))
59     return r;
60
61   _ev_buffer = L4Re::Event_buffer(buf.get(), sz);
62   _ev_ds     = ev_ds;
63   _ev_irq    = ev_irq;
64   _buf       = buf;
65
66   return 0;
67 }
68
69 }}