]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re/util/include/event_svr
87211a34f1ed9ad164a400c5bbda703c76f80a57
[l4.git] / l4 / pkg / l4re / util / include / event_svr
1 // vi:ft=cpp
2 /*
3  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
4  *               Alexander Warg <warg@os.inf.tu-dresden.de>
5  *     economic rights: Technische Universität Dresden (Germany)
6  *
7  * This file is part of TUD:OS and distributed under the terms of the
8  * GNU General Public License 2.
9  * Please see the COPYING-GPL-2 file for details.
10  *
11  * As a special exception, you may use this file as part of a free software
12  * library without restriction.  Specifically, if other files instantiate
13  * templates or use macros or inline functions from this file, or you compile
14  * this file and link it with other files to produce an executable, this
15  * file does not by itself cause the resulting executable to be covered by
16  * the GNU General Public License.  This exception does not however
17  * invalidate any other reasons why the executable file might be covered by
18  * the GNU General Public License.
19  */
20
21 #pragma once
22
23 #include <l4/re/event_enums.h>
24 #include <l4/re/event>
25 #include <l4/re/event-sys.h>
26 #include <l4/re/util/icu_svr>
27
28 namespace L4Re { namespace Util {
29
30 template< typename SVR >
31 class Event_svr : public Icu_cap_array_svr<SVR>
32 {
33 private:
34   typedef Icu_cap_array_svr<SVR> Icu_svr;
35
36 protected:
37   L4::Cap<L4Re::Dataspace> _ds;
38   typename Icu_svr::Irq _irq;
39
40 public:
41   Event_svr() : Icu_svr(1, &_irq) {}
42   int dispatch(l4_umword_t obj, L4::Ipc_iostream &ios);
43   int get_num_streams() const { return 0; }
44   int get_stream_info(int, L4Re::Event_stream_info *)
45   { return -L4_EINVAL; }
46   int get_stream_info_for_id(l4_umword_t, L4Re::Event_stream_info *)
47   { return -L4_EINVAL; }
48   int get_axis_info(l4_umword_t, unsigned /*naxes*/, unsigned * /*axes*/,
49                     L4Re::Event_absinfo *infos)
50   { return -L4_EINVAL; }
51 };
52
53 template<typename SVR>
54 inline
55 int
56 Event_svr<SVR>::dispatch(l4_umword_t obj, L4::Ipc_iostream &ios)
57 {
58   l4_msgtag_t tag;
59   ios >> tag;
60
61   if (tag.label() == L4_PROTO_IRQ)
62     return Icu_svr::dispatch(obj, ios);
63   else if (tag.label() != L4Re::Protocol::Event)
64     return -L4_EBADPROTO;
65
66   L4::Opcode op;
67   ios >> op;
68   switch (op)
69     {
70     case L4Re::Event_::Get:
71       ios << _ds;
72       return L4_EOK;
73     case L4Re::Event_::Get_num_streams:
74       ios << (l4_umword_t)static_cast<SVR*>(this)->get_num_streams();
75       return L4_EOK;
76     case L4Re::Event_::Get_stream_info:
77         {
78           int idx;
79           ios >> idx;
80           Event_stream_info si;
81           int r = static_cast<SVR*>(this)->get_stream_info(idx, &si);
82           ios.put(si);
83           return r;
84         }
85     case L4Re::Event_::Get_stream_info_for_id:
86         {
87           l4_umword_t stream_id;
88           ios >> stream_id;
89           Event_stream_info si;
90           int r = static_cast<SVR*>(this)->get_stream_info_for_id(stream_id, &si);
91           ios.put(si);
92           return r;
93         }
94     case L4Re::Event_::Get_axis_info:
95         {
96           l4_umword_t stream_id;
97           long unsigned naxes = L4RE_ABS_MAX;
98           unsigned axes[L4RE_ABS_MAX];
99           ios >> stream_id >> L4::Ipc::buf_cp_in(axes, naxes);
100
101           Event_absinfo infos[naxes];
102           int r = static_cast<SVR*>(this)->get_axis_info(stream_id, naxes, axes, infos);
103           if (r < 0)
104             return r;
105
106           ios << L4::Ipc::buf_cp_out(infos, naxes);
107           return r;
108         }
109     default:
110       return -L4_ENOSYS;
111     }
112 }
113
114 }}