L4Re - L4 Runtime Environment
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
factory
1 // vi:ft=cpp
7 /*
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)
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 
26 #pragma once
27 
28 #include <l4/sys/factory.h>
29 #include <l4/sys/capability>
30 
31 namespace L4 {
32 
41 class Factory : public Kobject_t<Factory, Kobject, L4_PROTO_FACTORY>
42 {
44 
45 public:
46 
47  typedef l4_mword_t Proto;
48 
53  struct Nil {};
54 
61  struct Lstr
62  {
66  char const *s;
67 
71  int len;
72 
73  Lstr(char const *s, int len) : s(s), len(len) {}
74  };
75 
82  class S
83  {
84  private:
85  l4_utcb_t *u;
86  l4_msgtag_t t;
87  l4_cap_idx_t f;
88 
89  public:
93  S(S const &o)
94  : u(o.u), t(o.t), f(o.f)
95  { const_cast<S&>(o).t.raw = 0; }
96 
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)
108  {}
109 
114  ~S()
115  {
116  if (t.raw)
117  l4_factory_create_commit_u(f, t, u);
118  }
119 
124  operator l4_msgtag_t ()
125  {
126  l4_msgtag_t r = l4_factory_create_commit_u(f, t, u);
127  t.raw = 0;
128  return r;
129  }
130 
136  {
137  l4_factory_create_add_int_u(i, &t, u);
138  return *this;
139  }
140 
146  {
147  l4_factory_create_add_uint_u(i, &t, u);
148  return *this;
149  }
150 
155  S &operator << (char const *s)
156  {
157  l4_factory_create_add_str_u(s, &t, u);
158  return *this;
159  }
160 
165  S &operator << (Lstr const &s)
166  {
167  l4_factory_create_add_lstr_u(s.s, s.len, &t, u);
168  return *this;
169  }
170 
175  {
176  l4_factory_create_add_nil_u(&t, u);
177  return *this;
178  }
179 
185  {
186  l4_factory_create_add_fpage_u(d, &t, u);
187  return *this;
188  }
189  };
190 
191 
192 public:
193 
213  S create(Cap<Kobject> target, long obj, l4_utcb_t *utcb = l4_utcb()) throw()
214  {
215  return S(cap(), obj, target, utcb);
216  }
217 
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); }
226 
232  l4_utcb_t *utcb = l4_utcb()) throw()
233  { return l4_factory_create_thread_u(cap(), target_cap.cap(), utcb); }
234 
240  unsigned long limit,
241  l4_utcb_t *utcb = l4_utcb()) throw()
242  { return l4_factory_create_factory_u(cap(), target_cap.cap(), limit, utcb); }
243 
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); }
252 
257  l4_msgtag_t create_irq(Cap<Irq>const &target_cap,
258  l4_utcb_t *utcb = l4_utcb()) throw()
259  { return l4_factory_create_irq_u(cap(), target_cap.cap(), utcb); }
260 
265  l4_msgtag_t create_vm(Cap<Vm>const &target_cap,
266  l4_utcb_t *utcb = l4_utcb()) throw()
267  { return l4_factory_create_vm_u(cap(), target_cap.cap(), utcb); }
268 };
269 
270 }
L4Re - L4 Runtime Environment