]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/moe/server/src/name_space.h
update
[l4.git] / l4 / pkg / moe / server / src / name_space.h
1 /*
2  * (c) 2008-2009 Alexander Warg <warg@os.inf.tu-dresden.de>
3  *     economic rights: Technische Universität Dresden (Germany)
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  */
9 #pragma once
10
11 #include <l4/cxx/avl_tree>
12 #include <l4/cxx/std_ops>
13 #include <l4/cxx/ipc_server>
14
15 #include <l4/sys/capability>
16 #include <l4/re/util/name_space_svr>
17
18 #include "server_obj.h"
19 #include "slab_alloc.h"
20 #include <l4/cxx/string>
21
22 #include <cstring>
23 #include <cstdlib>
24 #include <gc.h>
25
26
27 namespace Moe {
28
29 namespace Names { using namespace L4Re::Util::Names; }
30
31 class Entry : public Names::Entry
32 {
33 public:
34   Entry(Names::Name const &n, Names::Obj const &o, bool dyn = false)
35   : Names::Entry(n, o, dyn) {}
36
37   void * operator new (size_t s) { return GC_MALLOC(s); }
38   void operator delete(void *) { /*free(b);*/ }
39 };
40
41 class Name_space : public Moe::Server_object,
42                    public Names::Name_space
43 {
44 public:
45
46   int dispatch(l4_umword_t obj, L4::Ipc_iostream &ios)
47   {
48     enum { Max_name = 2048 };
49     static char buffer[Max_name];
50
51     return Names::Name_space::dispatch(obj, ios, buffer, Max_name);
52   }
53
54   Name_space();
55   ~Name_space();
56
57   // server support ----------------------------------------
58   int get_capability(L4::Snd_fpage const &cap_fp, L4::Cap<void> *cap,
59                      L4::Server_object **lo);
60   int save_capability(L4::Cap<void> *cap);
61   void free_capability(L4::Cap<void> cap);
62   Entry *alloc_dynamic_entry(Names::Name const &n, unsigned flags);
63   void free_dynamic_entry(Names::Entry *e);
64
65   // internally used to register bootfs files, name spaces...
66   int register_obj(Names::Name const &name, Names::Obj const &o,
67                    bool dyn = false)
68   {
69     Entry *n = new Entry(name, o, dyn);
70     bool b = insert(n);
71     if (!b)
72       {
73         delete n;
74         return -L4_EEXIST;
75       }
76
77     return 0;
78   }
79
80   void *operator new (size_t size) throw();
81   void operator delete (void *p, size_t size) throw();
82 };
83
84 }
85
86 Moe::Name_space *root_name_space();
87
88 inline
89 L4::BasicOStream &operator << (L4::BasicOStream &s, L4Re::Util::Names::Name const &n)
90 {
91   for (int l = 0; l < n.len(); ++l)
92     s << n.name()[l];
93
94   return s;
95 }