1// vi:set ft=cpp: -*- Mode: C++ -*-
2/**
3 * \internal
4 * \file
5 * \brief L4::Factory server interface
6 */
7/*
8 * (c) 2008-2009 Adam Lackorzynski <adam@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#include <l4/sys/factory.h>
25#include <l4/sys/types.h>
26#include <l4/cxx/ipc_stream>
27
28namespace L4kproxy {
29
30class Cap_allocator_interface
31{
32public:
33  virtual L4::Cap<void> cap_alloc() = 0;
34  virtual void cap_free(L4::Cap<void>) = 0;
35  virtual ~Cap_allocator_interface() {}
36};
37
38class Factory_interface
39{
40public:
41  virtual int create_task(L4::Cap<L4::Task> const &target_cap,
42                          l4_fpage_t const &utcb_area) = 0;
43
44  virtual int create_thread(L4::Cap<L4::Thread> const &target_cap) = 0;
45
46  virtual int create_factory(L4::Cap<L4::Factory> const &target_cap,
47                             unsigned long limit) = 0;
48
49  virtual int create_gate(L4::Cap<void> const &target_cap,
50                          L4::Cap<L4::Thread> const &thread_cap,
51                          l4_umword_t label) = 0;
52
53  virtual int create_irq(L4::Cap<L4::Irq>const &target_cap) = 0;
54
55  virtual int create_vm(L4::Cap<L4::Vm>const &target_cap) = 0;
56
57  virtual ~Factory_interface() {}
58};
59
60class Factory_svr
61{
62public:
63  Factory_svr(Factory_interface *factory, Cap_allocator_interface *capif)
64    : _factory(factory), _capif(capif) {}
65
66  int factory_dispatch(l4_umword_t, L4::Ipc::Iostream &ios);
67
68  virtual L4::Cap<L4::Thread> received_thread(L4::Ipc::Snd_fpage const &fp) = 0;
69
70  template< typename CT >
71  L4::Cap<CT> cap_alloc()
72  { return L4::cap_cast<CT>(_capif->cap_alloc()); }
73
74  template< typename CT >
75  void cap_alloc(L4::Cap<CT> x)
76  { _capif->cap_free(L4::cap_cast<CT>(x)); }
77
78  virtual ~Factory_svr() {}
79
80private:
81  Factory_interface *_factory;
82  Cap_allocator_interface *_capif;
83};
84
85}
86