4 * \brief Common factory related definitions.
8 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
9 * Alexander Warg <warg@os.inf.tu-dresden.de>
10 * economic rights: Technische Universität Dresden (Germany)
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.
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.
28 #include <l4/sys/factory.h>
29 #include <l4/sys/capability>
34 * \brief C++ L4 Factory, to create all kinds of kernel objects.
35 * \ingroup l4_factory_api
37 * <c>\#include <l4/sys/factory></c>
39 * \see \ref l4_factory_api for an overview and C bindings.
41 class Factory : public Kobject_t<Factory, Kobject, L4_PROTO_FACTORY>
47 typedef l4_mword_t Proto;
50 * \brief Special type to add a void argument into the factory create
56 * \brief Special type to add a pascal string into the factory create
59 * This encapsulates a string that has an explicit length.
64 * \brief The character buffer.
69 * \brief The number of characters in the buffer.
73 Lstr(char const *s, int len) : s(s), len(len) {}
77 * \brief Stream class for the create() argument stream.
79 * This stream allows a variable number of arguments to be
80 * added to a create() call.
91 * \brief create a copy.
94 : u(o.u), t(o.t), f(o.f)
95 { const_cast<S&>(o).t.raw = 0; }
98 * \brief create a stream for a specific create() call.
99 * \param f is the capability for the factory object (L4::Factory).
100 * \param obj is the protocol ID to describe the type of the object that
102 * \param target is the capabilit selector for the new object.
103 * \param utcb is the UTCB that shall be used for the operation.
105 S(l4_cap_idx_t f, long obj, L4::Cap<L4::Kobject> target,
106 l4_utcb_t *utcb) throw()
107 : u(utcb), t(l4_factory_create_start_u(obj, target.cap(), u)), f(f)
111 * \brief Commit the operation in the destructor to have a cool syntax
117 l4_factory_create_commit_u(f, t, u);
121 * \brief Explicitely commits the operation and returns the result.
122 * \return The result of the create() operation.
124 operator l4_msgtag_t ()
126 l4_msgtag_t r = l4_factory_create_commit_u(f, t, u);
132 * \brief Put a single l4_mword_t as next argument.
133 * \param i is the value to add as next argument.
135 S &operator << (l4_mword_t i)
137 l4_factory_create_add_int_u(i, &t, u);
142 * \brief Put a single l4_umword_t as next argument.
143 * \param i is the value to add as next argument.
145 S &operator << (l4_umword_t i)
147 l4_factory_create_add_uint_u(i, &t, u);
152 * \brief Add a zero-terminated string as next argument.
153 * \param s is the string to add as next argument.
155 S &operator << (char const *s)
157 l4_factory_create_add_str_u(s, &t, u);
162 * \brief Add a pascal string as next argument.
163 * \param s is the string to add as next argument.
165 S &operator << (Lstr const &s)
167 l4_factory_create_add_lstr_u(s.s, s.len, &t, u);
172 * \brief Add an empty argument.
176 l4_factory_create_add_nil_u(&t, u);
181 * \brief Add a flex page as next argument.
182 * \param d is the flex page to add (there will be no map operation).
184 S &operator << (l4_fpage_t d)
186 l4_factory_create_add_fpage_u(d, &t, u);
195 * \brief Generic create call to the factory.
196 * \param target is the target capability selector where the new
197 * object shall be received.
198 * \param obj is the protocol ID that specifies which kind of object
200 * \param utcb is the UTCB to use for the operation.
201 * \return a create stream that allows adding additional arguments to the
204 * This method does currently not directly invoke the factory. It returns a
205 * stream that shall invoke the factory after adding all additional arguments.
209 * L4::Cap<L4Re::Namespace> ns = L4Re::Util::cap_alloc.alloc<L4Re::Namespace>();
210 * factory->create(ns, L4Re::Namespace::Protocol) << "Argument text";
213 S create(Cap<Kobject> target, long obj, l4_utcb_t *utcb = l4_utcb()) throw()
215 return S(cap(), obj, target, utcb);
219 * \copydoc l4_factory_create_task()
220 * \note \a factory is the implicit \a this pointer.
222 l4_msgtag_t create_task(Cap<Task> const & target_cap,
223 l4_fpage_t const &utcb_area,
224 l4_utcb_t *utcb = l4_utcb()) throw()
225 { return l4_factory_create_task_u(cap(), target_cap.cap(), utcb_area, utcb); }
228 * \copydoc l4_factory_create_thread()
229 * \note \a factory is the implicit \a this pointer.
231 l4_msgtag_t create_thread(Cap<Thread> const &target_cap,
232 l4_utcb_t *utcb = l4_utcb()) throw()
233 { return l4_factory_create_thread_u(cap(), target_cap.cap(), utcb); }
236 * \copydoc l4_factory_create_factory()
237 * \note \a factory is the implicit \a this pointer.
239 l4_msgtag_t create_factory(Cap<Factory> const &target_cap,
241 l4_utcb_t *utcb = l4_utcb()) throw()
242 { return l4_factory_create_factory_u(cap(), target_cap.cap(), limit, utcb); }
245 * \copydoc l4_factory_create_gate()
246 * \note \a factory is the implicit \a this pointer.
248 l4_msgtag_t create_gate(Cap<Kobject> const &target_cap,
249 Cap<Thread> const &thread_cap, l4_umword_t label,
250 l4_utcb_t *utcb = l4_utcb()) throw()
251 { return l4_factory_create_gate_u(cap(), target_cap.cap(), thread_cap.cap(), label, utcb); }
254 * \copydoc l4_factory_create_semaphore()
255 * \note \a factory is the implicit \a this pointer.
257 l4_msgtag_t create_semaphore(Cap<K_semaphore> const &target_cap,
258 l4_utcb_t *utcb = l4_utcb()) throw()
259 { return l4_factory_create_semaphore_u(cap(), target_cap.cap(), utcb); }
262 * \copydoc l4_factory_create_irq()
263 * \note \a factory is the implicit \a this pointer.
265 l4_msgtag_t create_irq(Cap<Irq>const &target_cap,
266 l4_utcb_t *utcb = l4_utcb()) throw()
267 { return l4_factory_create_irq_u(cap(), target_cap.cap(), utcb); }
270 * \copydoc l4_factory_create_vm()
271 * \note \a factory is the implicit \a this pointer.
273 l4_msgtag_t create_vm(Cap<Vm>const &target_cap,
274 l4_utcb_t *utcb = l4_utcb()) throw()
275 { return l4_factory_create_vm_u(cap(), target_cap.cap(), utcb); }