L4Re - L4 Runtime Environment
ipc_server
Go to the documentation of this file.
1 // vi:set ft=cpp: -*- Mode: C++ -*-
6 /*
7  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
8  * Alexander Warg <warg@os.inf.tu-dresden.de>,
9  * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
10  * economic rights: Technische Universit├Ąt Dresden (Germany)
11  *
12  * This file is part of TUD:OS and distributed under the terms of the
13  * GNU General Public License 2.
14  * Please see the COPYING-GPL-2 file for details.
15  *
16  * As a special exception, you may use this file as part of a free software
17  * library without restriction. Specifically, if other files instantiate
18  * templates or use macros or inline functions from this file, or you compile
19  * this file and link it with other files to produce an executable, this
20  * file does not by itself cause the resulting executable to be covered by
21  * the GNU General Public License. This exception does not however
22  * invalidate any other reasons why the executable file might be covered by
23  * the GNU General Public License.
24  */
25 #pragma once
26 
27 #include <l4/sys/capability>
28 #include <l4/sys/typeinfo_svr>
29 #include <l4/sys/err.h>
30 #include <l4/cxx/ipc_stream>
31 #include <l4/sys/cxx/ipc_epiface>
32 #include <l4/sys/cxx/ipc_server_loop>
33 #include <l4/cxx/type_traits>
34 #include <l4/cxx/exceptions>
35 
36 namespace L4 {
37 
49 class Server_object : public Epiface
50 {
51 public:
69  virtual int dispatch(unsigned long rights, Ipc::Iostream &ios) = 0;
70 
71  l4_msgtag_t dispatch(l4_msgtag_t tag, unsigned rights, l4_utcb_t *utcb)
72  {
73  L4::Ipc::Iostream ios(utcb);
74  ios.tag() = tag;
75  int r = dispatch(rights, ios);
76  return ios.prepare_ipc(r);
77  }
78 
79  Cap<Kobject> obj_cap() const
80  { return cap_cast<Kobject>(Epiface::obj_cap()); }
81 };
82 
90 template<typename IFACE, typename BASE = L4::Server_object>
91 struct Server_object_t : BASE
92 {
94  typedef IFACE Interface;
95 
97  typename BASE::Demand get_buffer_demand() const
98  { return typename L4::Kobject_typeid<IFACE>::Demand(); }
99 
111  { return L4::Util::handle_meta_request<IFACE>(ios); }
112 
124  template<typename THIS>
125  static int proto_dispatch(THIS *self, l4_umword_t rights, L4::Ipc::Iostream &ios)
126  {
127  l4_msgtag_t t;
128  ios >> t;
129  return Kobject_typeid<IFACE>::proto_dispatch(self, t.label(), rights, ios);
130  }
131 };
132 
153 template<typename Derived, typename IFACE, typename BASE = L4::Server_object>
154 struct Server_object_x : Server_object_t<IFACE, BASE>
155 {
158  {
159  return Server_object_t<IFACE, BASE>::proto_dispatch(static_cast<Derived *>(this),
160  r, ios);
161  }
162 };
163 
172 struct Irq_handler_object : Server_object_t<Kobject> {};
173 
174 }
Abstract server object to be used with L4::Server and L4::Basic_registry.
Definition: ipc_server:49
Type information server template.
Input/Output stream for IPC [un]marshalling.
Definition: ipc_stream:802
Server object base class for handling IRQ messages.
Definition: ipc_server:172
L4 low-level kernel interface.
Base exceptions.
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition: utcb.h:67
Stored_cap obj_cap() const
Get the capability to the kernel object belonging to this object.
Definition: ipc_epiface:214
virtual int dispatch(unsigned long rights, Ipc::Iostream &ios)=0
The abstract handler for client requests to the object.
L4::Cap related definitions.
IFACE Interface
Data type of the IPC interface definition.
Definition: ipc_server:94
T::__Kobject_typeid::Demand Demand
Data type expressing the static demand of receive buffers in a server.
Definition: __typeinfo.h:632
Base class for all kinds of kernel objects and remote objects, referenced by capabilities.
Definition: kobject:46
Base class for interface implementations.
Definition: ipc_epiface:153
Error codes.
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
int dispatch_meta_request(L4::Ipc::Iostream &ios)
Implementation of the meta protocol based on IFACE.
Definition: ipc_server:110
int dispatch(l4_umword_t r, L4::Ipc::Iostream &ios)
Implementation forwarding to p_dispatch().
Definition: ipc_server:157
Helper class to implement p_dispatch based server objects.
Definition: ipc_server:154
IPC stream.
l4_msgtag_t dispatch(l4_msgtag_t tag, unsigned rights, l4_utcb_t *utcb)
The abstract handler for client requests to the object.
Definition: ipc_server:71
static int proto_dispatch(THIS *self, l4_umword_t rights, L4::Ipc::Iostream &ios)
Implementation of protocol-based dispatch for this server object.
Definition: ipc_server:125
Base class (template) for server implementing server objects.
Definition: ipc_server:91
C++ interface for capabilities.
Definition: capability.h:13
Message tag data structure.
Definition: types.h:159
BASE::Demand get_buffer_demand() const
Definition: ipc_server:97
Cap< T > cap_cast(Cap< F > const &c) noexcept
static_cast for capabilities.
Definition: capability.h:379
static int proto_dispatch(THIS *self, long proto, A1 a1, A2 &a2)
Protocol based server-side dispatch function.
Definition: __typeinfo.h:670