L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
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 * This file is part of TUD:OS and distributed under the terms of the
12 * GNU General Public License 2.
13 * Please see the COPYING-GPL-2 file for details.
14 *
15 * As a special exception, you may use this file as part of a free software
16 * library without restriction. Specifically, if other files instantiate
17 * templates or use macros or inline functions from this file, or you compile
18 * this file and link it with other files to produce an executable, this
19 * file does not by itself cause the resulting executable to be covered by
20 * the GNU General Public License. This exception does not however
21 * invalidate any other reasons why the executable file might be covered by
22 * the GNU General Public License.
23 */
24
25#pragma once
26
27#include <l4/sys/factory.h>
28#include <l4/sys/capability>
29#include <l4/sys/cxx/ipc_iface>
30#include <l4/sys/cxx/ipc_varg>
31
32namespace L4 {
33
48class Factory : public Kobject_t<Factory, Kobject, L4_PROTO_FACTORY>
49{
50public:
51
52 typedef l4_mword_t Proto;
53
57 struct Nil {};
58
64 struct Lstr
65 {
69 char const *s;
70
74 unsigned len;
75
80 Lstr(char const *s, unsigned len) noexcept : s(s), len(len) {}
81 };
82
89 class S
90 {
91 private:
92 l4_utcb_t *u;
95
96 template<typename T>
97 static T &&_move(T &c) { return static_cast<T &&>(c); }
98
99 public:
100 S(S const &) = delete;
101 S &operator = (S const &) & = delete;
102
108 S(S &&o) noexcept
109 : u(o.u), t(o.t), f(o.f)
110 { o.t.raw = 0; }
111
112 S &operator = (S &&o) & noexcept
113 {
114 u = o.u;
115 t = o.t;
116 f = o.f;
117 o.t.raw = 0;
118 return *this;
119 }
120
132 S(l4_cap_idx_t f, long obj, L4::Cap<void> target,
133 l4_utcb_t *utcb) noexcept
134 : u(utcb), t(l4_factory_create_start_u(obj, target.cap(), u)), f(f)
135 {}
136
141 ~S() noexcept
142 {
143 if (t.raw)
144 l4_factory_create_commit_u(f, t, u);
145 }
146
158 operator l4_msgtag_t () noexcept
159 {
160 l4_msgtag_t r = l4_factory_create_commit_u(f, t, u);
161 t.raw = 0;
162 return r;
163 }
164
170 void put(l4_mword_t i) noexcept
171 {
172 l4_factory_create_add_int_u(i, &t, u);
173 }
174
180 void put(l4_umword_t i) noexcept
181 {
182 l4_factory_create_add_uint_u(i, &t, u);
183 }
184
192 void put(char const *s) & noexcept
193 {
194 l4_factory_create_add_str_u(s, &t, u);
195 }
196
206 void put(Lstr const &s) & noexcept
207 {
208 l4_factory_create_add_lstr_u(s.s, s.len, &t, u);
209 }
210
214 void put(Nil) & noexcept
215 {
216 l4_factory_create_add_nil_u(&t, u);
217 }
218
224 void put(l4_fpage_t d) & noexcept
225 {
226 l4_factory_create_add_fpage_u(d, &t, u);
227 }
228
229 template<typename T>
230 S &operator << (T const &d) & noexcept
231 {
232 put(d);
233 return *this;
234 }
235
236 template<typename T>
237 S &&operator << (T const &d) && noexcept
238 {
239 put(d);
240 return _move(*this);
241 }
242 };
243
244
245public:
246
274 S create(Cap<void> target, long obj, l4_utcb_t *utcb = l4_utcb()) noexcept
275 {
276 return S(cap(), obj, target, utcb);
277 }
278
307 template<typename OBJ>
308 S create(Cap<OBJ> target, l4_utcb_t *utcb = l4_utcb()) noexcept
309 {
310 return S(cap(), OBJ::Protocol, target, utcb);
311 }
312
315 L4::Ipc::Varg const *args),
317
349 l4_fpage_t *utcb_area,
350 l4_utcb_t *utcb = l4_utcb()) noexcept
351 { return l4_factory_create_task_u(cap(), target_cap.cap(), utcb_area, utcb); }
352
382 unsigned long limit,
383 l4_utcb_t *utcb = l4_utcb()) noexcept
384 { return l4_factory_create_factory_u(cap(), target_cap.cap(), limit, utcb); }
385
415 Cap<Thread> const &thread_cap, l4_umword_t label,
416 l4_utcb_t *utcb = l4_utcb()) noexcept
417 { return l4_factory_create_gate_u(cap(), target_cap.cap(), thread_cap.cap(), label, utcb); }
418
420};
421
422}
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:90
S(S &&o) noexcept
Move ...
Definition factory:108
void put(Lstr const &s) &noexcept
Add a pascal string as next argument.
Definition factory:206
void put(l4_fpage_t d) &noexcept
Add a flex page as next argument.
Definition factory:224
void put(l4_umword_t i) noexcept
Put a single l4_umword_t as next argument.
Definition factory:180
~S() noexcept
Commit the operation in the destructor to have a cool syntax for create().
Definition factory:141
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:132
void put(Nil) &noexcept
Add an empty argument.
Definition factory:214
void put(char const *s) &noexcept
Add a zero-terminated string as next argument.
Definition factory:192
void put(l4_mword_t i) noexcept
Put a single l4_mword_t as next argument.
Definition factory:170
C++ Factory interface, see Factory for the C interface.
Definition factory:49
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:381
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:348
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:414
S create(Cap< void > target, long obj, l4_utcb_t *utcb=l4_utcb()) noexcept
Generic create call to the factory.
Definition factory:274
S create(Cap< OBJ > target, l4_utcb_t *utcb=l4_utcb()) noexcept
Create call for typed capabilities.
Definition factory:308
Variably sized RPC argument.
Definition ipc_varg:108
Helper class to create an L4Re interface class that is derived from a single base class.
Definition __typeinfo.h:761
L4::Cap< Class > c() const noexcept
Get the capability to ourselves.
Definition __typeinfo.h:780
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition kobject:79
Common factory related definitions.
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:51
signed long l4_mword_t
Signed machine word.
Definition l4int.h:48
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:359
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:67
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:340
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:440
L4 low-level kernel interface.
Definition io_regblock.h:19
Special type to add a pascal string into the factory create stream.
Definition factory:65
Lstr(char const *s, unsigned len) noexcept
Definition factory:80
unsigned len
The number of characters in the buffer.
Definition factory:74
char const * s
The character buffer.
Definition factory:69
Special type to add a void argument into the factory create stream.
Definition factory:57
RPC attribute for an RPC call with required rights.
Definition ipc_iface:258
Mark an argument as a output value in an RPC signature.
Definition ipc_types:42
List of RPCs of an interface using a single operation without an opcode.
Definition __typeinfo.h:465
Message tag data structure.
Definition types.h:164
l4_mword_t raw
raw value
Definition types.h:165
L4 flexpage type.
Definition __l4_fpage.h:85