]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/examples/libs/l4re/streammap/client.cc
update
[l4.git] / l4 / pkg / examples / libs / l4re / streammap / client.cc
1 /*
2  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3  *               Alexander Warg <warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  *
6  * This file is part of TUD:OS and distributed under the terms of the
7  * GNU General Public License 2.
8  * Please see the COPYING-GPL-2 file for details.
9  */
10 #include <l4/sys/err.h>
11 #include <l4/sys/types.h>
12 #include <l4/re/env>
13 #include <l4/re/util/cap_alloc>
14 #include <l4/cxx/ipc_stream>
15
16 #include <stdio.h>
17
18 #include "shared.h"
19
20 int
21 func_smap_call(L4::Cap<void> const &server)
22 {
23   L4::Ipc_iostream s(l4_utcb());
24   l4_addr_t addr = 0;
25   int err;
26
27   if ((err = L4Re::Env::env()->rm()->reserve_area(&addr, L4_PAGESIZE,
28                                                   L4Re::Rm::Search_addr)))
29     {
30       printf("The reservation of one page within our virtual memory failed with %d\n", err);
31       return 1;
32     }
33
34
35   s << l4_umword_t(Opcode::Do_map)
36     << (l4_addr_t)addr;
37   s << L4::Rcv_fpage::mem((l4_addr_t)addr, L4_PAGESHIFT, 0);
38   l4_msgtag_t res = s.call(server.cap(), Protocol::Map_example);
39   if (l4_ipc_error(res, l4_utcb()))
40     return 1; // failure
41
42   printf("String sent by server: %s\n", (char *)addr);
43
44   return 0; // ok
45 }
46
47 int
48 main()
49 {
50
51   L4::Cap<void> server = L4Re::Env::env()->get_cap<void>("smap");
52   if (!server.is_valid())
53     {
54       printf("Could not get capability slot!\n");
55       return 1;
56     }
57
58
59   printf("Asking for page from server\n");
60
61   if (func_smap_call(server))
62     {
63       printf("Error talking to server\n");
64       return 1;
65     }
66   printf("It worked!\n");
67
68   L4Re::Util::cap_alloc.free(server, L4Re::This_task);
69
70   return 0;
71 }