L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
factory
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 * economic rights: Technische Universität Dresden (Germany)
10 *
11 * License: see LICENSE.spdx (in this directory or the directories above)
12 */
13
14#pragma once
15
16#include <l4/sys/factory.h>
17#include <l4/sys/capability>
18#include <l4/sys/cxx/ipc_iface>
19#include <l4/sys/cxx/ipc_varg>
20
21namespace L4 {
22
37class Factory : public Kobject_t<Factory, Kobject, L4_PROTO_FACTORY>
38{
39public:
40
41 typedef l4_mword_t Proto;
42
46 struct Nil {};
47
53 struct Lstr
54 {
58 char const *s;
59
63 unsigned len;
64
69 Lstr(char const *s, unsigned len) noexcept : s(s), len(len) {}
70 };
71
78 class S
79 {
80 private:
81 l4_utcb_t *u;
84
85 template<typename T>
86 static T &&_move(T &c) { return static_cast<T &&>(c); }
87
88 public:
89 S(S const &) = delete;
90 S &operator = (S const &) & = delete;
91
97 S(S &&o) noexcept
98 : u(o.u), t(o.t), f(o.f)
99 { o.t.raw = 0; }
100
101 S &operator = (S &&o) & noexcept
102 {
103 u = o.u;
104 t = o.t;
105 f = o.f;
106 o.t.raw = 0;
107 return *this;
108 }
109
121 S(l4_cap_idx_t f, long obj, L4::Cap<void> target,
122 l4_utcb_t *utcb) noexcept
123 : u(utcb), t(l4_factory_create_start_u(obj, target.cap(), u)), f(f)
124 {}
125
130 ~S() noexcept
131 {
132 if (t.raw)
133 l4_factory_create_commit_u(f, t, u);
134 }
135
147 operator l4_msgtag_t () noexcept
148 {
149 l4_msgtag_t r = l4_factory_create_commit_u(f, t, u);
150 t.raw = 0;
151 return r;
152 }
153
159 void put(l4_mword_t i) noexcept
160 {
161 l4_factory_create_add_int_u(i, &t, u);
162 }
163
169 void put(l4_umword_t i) noexcept
170 {
171 l4_factory_create_add_uint_u(i, &t, u);
172 }
173
181 void put(char const *s) & noexcept
182 {
183 l4_factory_create_add_str_u(s, &t, u);
184 }
185
195 void put(Lstr const &s) & noexcept
196 {
197 l4_factory_create_add_lstr_u(s.s, s.len, &t, u);
198 }
199
203 void put(Nil) & noexcept
204 {
205 l4_factory_create_add_nil_u(&t, u);
206 }
207
213 void put(l4_fpage_t d) & noexcept
214 {
215 l4_factory_create_add_fpage_u(d, &t, u);
216 }
217
218 template<typename T>
219 S &operator << (T const &d) & noexcept
220 {
221 put(d);
222 return *this;
223 }
224
225 template<typename T>
226 S &&operator << (T const &d) && noexcept
227 {
228 put(d);
229 return _move(*this);
230 }
231 };
232
233
234public:
235
263 S create(Cap<void> target, long obj, l4_utcb_t *utcb = l4_utcb()) noexcept
264 {
265 return S(cap(), obj, target, utcb);
266 }
267
296 template<typename OBJ>
297 S create(Cap<OBJ> target, l4_utcb_t *utcb = l4_utcb()) noexcept
298 {
299 return S(cap(), OBJ::Protocol, target, utcb);
300 }
301
304 L4::Ipc::Varg const *args),
306
338 l4_fpage_t *utcb_area,
339 l4_utcb_t *utcb = l4_utcb()) noexcept
340 { return l4_factory_create_task_u(cap(), target_cap.cap(), utcb_area, utcb); }
341
371 unsigned long limit,
372 l4_utcb_t *utcb = l4_utcb()) noexcept
373 { return l4_factory_create_factory_u(cap(), target_cap.cap(), limit, utcb); }
374
404 Cap<Thread> const &thread_cap, l4_umword_t label,
405 l4_utcb_t *utcb = l4_utcb()) noexcept
406 { return l4_factory_create_gate_u(cap(), target_cap.cap(), thread_cap.cap(), label, utcb); }
407
409};
410
411}
L4::Cap related definitions.
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition capability.h:49
C++ interface for capabilities.
Definition capability.h:219
Stream class for the create() argument stream.
Definition factory:79
S(S &&o) noexcept
Move ...
Definition factory:97
void put(Lstr const &s) &noexcept
Add a pascal string as next argument.
Definition factory:195
void put(l4_fpage_t d) &noexcept
Add a flexpage as next argument.
Definition factory:213
void put(l4_umword_t i) noexcept
Put a single l4_umword_t as next argument.
Definition factory:169
~S() noexcept
Commit the operation in the destructor to have a cool syntax for create().
Definition factory:130
S(l4_cap_idx_t f, long obj, L4::Cap< void > target, l4_utcb_t *utcb) noexcept
Create a stream for a specific create() call.
Definition factory:121
void put(Nil) &noexcept
Add an empty argument.
Definition factory:203
void put(char const *s) &noexcept
Add a zero-terminated string as next argument.
Definition factory:181
void put(l4_mword_t i) noexcept
Put a single l4_mword_t as next argument.
Definition factory:159
C++ Factory interface, see Factory for the C interface.
Definition factory:38
l4_msgtag_t create_factory(Cap< Factory > const &target_cap, unsigned long limit, l4_utcb_t *utcb=l4_utcb()) noexcept
Create a new factory.
Definition factory:370
l4_msgtag_t create_task(Cap< Task > const &target_cap, l4_fpage_t *utcb_area, l4_utcb_t *utcb=l4_utcb()) noexcept
Create a new task.
Definition factory:337
l4_msgtag_t create_gate(Cap< void > const &target_cap, Cap< Thread > const &thread_cap, l4_umword_t label, l4_utcb_t *utcb=l4_utcb()) noexcept
Create a new IPC gate.
Definition factory:403
S create(Cap< void > target, long obj, l4_utcb_t *utcb=l4_utcb()) noexcept
Generic create call to the factory.
Definition factory:263
S create(Cap< OBJ > target, l4_utcb_t *utcb=l4_utcb()) noexcept
Create call for typed capabilities.
Definition factory:297
Variably sized RPC argument.
Definition ipc_varg:97
Helper class to create an L4Re interface class that is derived from a single base class.
Definition __typeinfo.h:750
L4::Cap< Class > c() const noexcept
Get the capability to ourselves.
Definition __typeinfo.h:769
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition kobject:69
Common factory related definitions.
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
signed long l4_mword_t
Signed machine word.
Definition l4int.h:37
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:335
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:56
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:346
Interface Definition Language.
#define L4_INLINE_RPC_NF(res, name, args...)
Define an inline RPC call type (the type only, no callable).
Definition ipc_iface:447
L4 low-level kernel interface.
Special type to add a pascal string into the factory create stream.
Definition factory:54
Lstr(char const *s, unsigned len) noexcept
Definition factory:69
unsigned len
The number of characters in the buffer.
Definition factory:63
char const * s
The character buffer.
Definition factory:58
Special type to add a void argument into the factory create stream.
Definition factory:46
RPC attribute for an RPC call with required rights.
Definition ipc_iface:265
Mark an argument as a output value in an RPC signature.
Definition ipc_types:31
List of RPCs of an interface using a single operation without an opcode.
Definition __typeinfo.h:454
Message tag data structure.
Definition types.h:153
l4_mword_t raw
raw value
Definition types.h:154
L4 flexpage type.
Definition __l4_fpage.h:76