L4Re - L4 Runtime Environment
event_svr
1 // vi:set ft=cpp: -*- Mode: C++ -*-
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 #include <l4/cxx/minmax>
28 
29 #include <l4/sys/cxx/ipc_legacy>
30 
31 namespace L4Re { namespace Util {
32 
33 template< typename SVR >
34 class Event_svr : public Icu_cap_array_svr<SVR>
35 {
36 private:
37  typedef Icu_cap_array_svr<SVR> Icu_svr;
38 
39 protected:
40  L4::Cap<L4Re::Dataspace> _ds;
41  typename Icu_svr::Irq _irq;
42 
43 public:
44  Event_svr() : Icu_svr(1, &_irq) {}
45 
46  L4_RPC_LEGACY_DISPATCH(L4Re::Event);
47  L4_RPC_LEGACY_USING(Icu_svr);
48 
49  /// Handle L4Re::Event protocol
50  long op_get_buffer(L4Re::Event::Rights, L4::Ipc::Cap<L4Re::Dataspace> &ds)
51  {
52  static_cast<SVR*>(this)->reset_event_buffer();
53  ds = L4::Ipc::Cap<L4Re::Dataspace>(_ds, L4_CAP_FPAGE_RW);
54  return 0;
55  }
56 
57  long op_get_num_streams(L4Re::Event::Rights)
58  { return static_cast<SVR*>(this)->get_num_streams(); }
59 
60  long op_get_stream_info(L4Re::Event::Rights, int idx, Event_stream_info &info)
61  { return static_cast<SVR*>(this)->get_stream_info(idx, &info); }
62 
63  long op_get_stream_info_for_id(L4Re::Event::Rights, l4_umword_t id,
64  Event_stream_info &info)
65  { return static_cast<SVR*>(this)->get_stream_info_for_id(id, &info); }
66 
67  long op_get_axis_info(L4Re::Event::Rights, l4_umword_t id,
68  L4::Ipc::Array_in_buf<unsigned, unsigned long> const &axes,
69  L4::Ipc::Array_ref<Event_absinfo, unsigned long> &info)
70  {
71  unsigned naxes = cxx::min<unsigned>(L4RE_ABS_MAX, axes.length);
72 
73  info.length = 0;
74 
75  Event_absinfo _info[naxes];
76  int r = static_cast<SVR*>(this)->get_axis_info(id, naxes, axes.data, _info);
77  if (r < 0)
78  return r;
79 
80  for (unsigned i = 0; i < naxes; ++i)
81  info.data[i] = _info[i];
82 
83  info.length = naxes;
84  return r;
85  }
86 
87  long op_get_stream_state_for_id(L4Re::Event::Rights, l4_umword_t stream_id,
88  Event_stream_state &state)
89  { return static_cast<SVR*>(this)->get_stream_state_for_id(stream_id, &state); }
90 
91  int get_num_streams() const { return 0; }
92  int get_stream_info(int, L4Re::Event_stream_info *)
93  { return -L4_EINVAL; }
94  int get_stream_info_for_id(l4_umword_t, L4Re::Event_stream_info *)
95  { return -L4_EINVAL; }
96  int get_axis_info(l4_umword_t, unsigned /*naxes*/, unsigned const * /*axes*/,
97  L4Re::Event_absinfo *)
98  { return -L4_EINVAL; }
99  int get_stream_state_for_id(l4_umword_t, L4Re::Event_stream_state *)
100  { return -L4_EINVAL; }
101 };
102 
103 }}