]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re/include/impl/namespace_impl.h
update
[l4.git] / l4 / pkg / l4re / include / impl / namespace_impl.h
1 /**
2  * \file
3  * \brief  Namespace client stub implementation
4  */
5 /*
6  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
7  *               Alexander Warg <warg@os.inf.tu-dresden.de>
8  *     economic rights: Technische Universität Dresden (Germany)
9  *
10  * This file is part of TUD:OS and distributed under the terms of the
11  * GNU General Public License 2.
12  * Please see the COPYING-GPL-2 file for details.
13  *
14  * As a special exception, you may use this file as part of a free software
15  * library without restriction.  Specifically, if other files instantiate
16  * templates or use macros or inline functions from this file, or you compile
17  * this file and link it with other files to produce an executable, this
18  * file does not by itself cause the resulting executable to be covered by
19  * the GNU General Public License.  This exception does not however
20  * invalidate any other reasons why the executable file might be covered by
21  * the GNU General Public License.
22  */
23 #include <l4/re/namespace>
24 #include <l4/re/namespace-sys.h>
25 #include <l4/re/protocols>
26
27 #include <l4/util/util.h>
28
29 #include <l4/cxx/exceptions>
30 #include <l4/cxx/ipc_helper>
31 #include <l4/cxx/ipc_stream>
32
33 #include <l4/sys/err.h>
34
35 #include <cstring>
36
37 namespace L4Re {
38
39 long
40 Namespace::_query(char const *name, unsigned len,
41                   L4::Cap<void> const &target,
42                   l4_umword_t *local_id, bool iterate) const throw()
43 {
44   unsigned long res = len;
45   char const *n = name;
46   L4::Cap<Namespace> ns(cap());
47   while (res > 0)
48     {
49       L4::Ipc::Iostream io(l4_utcb());
50       io << L4::Opcode(L4Re::Namespace_::Query)
51          << L4::Ipc::buf_cp_out(n, res);
52       io << L4::Ipc::Small_buf(target.cap(), local_id ? L4_RCV_ITEM_LOCAL_ID : 0);
53       l4_msgtag_t r = io.call(ns.cap(), L4Re::Protocol::Namespace);
54       long err = l4_error(r);
55
56       if (err < 0)
57         return err;
58
59       bool const partly = err & Partly_resolved;
60       if (partly)
61         {
62           l4_umword_t dummy;
63           io >> dummy >> L4::Ipc::buf_in(n, res);
64         }
65
66       L4::Ipc::Snd_fpage cap;
67       io >> cap;
68       if (cap.id_received())
69         {
70           *local_id = cap.data();
71           return res;
72         }
73
74       if (partly && iterate)
75         ns = L4::cap_cast<Namespace>(target);
76       else
77         return err;
78     }
79
80   return res;
81 }
82
83 long
84 Namespace::query(char const *name, unsigned len, L4::Cap<void> const &target,
85                  int timeout, l4_umword_t *local_id, bool iterate) const throw()
86 {
87   long ret;
88   long rem = timeout;
89   long to = 0;
90
91   if (rem)
92     to = 10;
93   do
94     {
95       ret = _query(name, len, target, local_id, iterate);
96
97       if (ret >= 0)
98         return ret;
99
100       if (L4_UNLIKELY(ret < 0 && (ret != -L4_EAGAIN)))
101         return ret;
102
103       if (rem == to)
104         return ret;
105
106       l4_sleep(to);
107
108       rem -= to;
109       if (to < 100)
110         to += to;
111       if (to > rem)
112         to = rem;
113     }
114   while (486);
115 }
116
117 long
118 Namespace::query(char const *name, L4::Cap<void> const &target,
119                  int timeout, l4_umword_t *local_id,
120                  bool iterate) const throw()
121 { return query(name, strlen(name), target, timeout, local_id, iterate); }
122
123 long
124 Namespace::register_obj(char const *name, L4::Cap<void> const &o,
125                         unsigned flags) const throw()
126 {
127   L4::Ipc::Iostream io(l4_utcb());
128   io << L4::Opcode(L4Re::Namespace_::Register)
129      << flags << L4::Ipc::buf_cp_out(name, strlen(name));
130   if (o.is_valid())
131     io << L4::Ipc::Snd_fpage(o, L4_FPAGE_RWX & flags) ;
132   l4_msgtag_t res = io.call(cap(), L4Re::Protocol::Namespace);
133   return l4_error(res);
134 }
135
136 long
137 Namespace::unlink(char const *name) throw()
138 {
139   L4::Ipc::Iostream io(l4_utcb());
140   io << L4::Opcode(L4Re::Namespace_::Unlink) << name;
141   l4_msgtag_t res = io.call(cap(), L4Re::Protocol::Namespace);
142   return l4_error(res);
143 }
144
145 long
146 Namespace::link(char const *name, unsigned len,
147                 L4::Cap<L4Re::Namespace> src_dir,
148                 char const *src_name, unsigned src_len,
149                 unsigned flags) throw()
150 {
151   L4::Ipc::Iostream io(l4_utcb());
152   io << L4::Opcode(L4Re::Namespace_::Link)
153      << flags << L4::Ipc::buf_cp_out(name, len)
154      << L4::Ipc::buf_cp_out(src_name, src_len)
155      << L4::Ipc::Snd_fpage(src_dir.fpage());
156   l4_msgtag_t res = io.call(cap(), L4Re::Protocol::Namespace);
157   return l4_error(res);
158 }
159
160 };