]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/examples/libs/l4re/streammap/server.cc
Update
[l4.git] / l4 / pkg / examples / libs / l4re / streammap / server.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 <stdio.h>
11 #include <l4/re/env>
12 #include <l4/re/util/cap_alloc>
13 #include <l4/re/util/object_registry>
14 #include <l4/cxx/ipc_server>
15
16 #include "shared.h"
17
18 static char page_to_map[L4_PAGESIZE] __attribute__((aligned(L4_PAGESIZE)));
19
20 static L4Re::Util::Registry_server<> server;
21
22 class Smap_server : public L4::Server_object_t<Mapper>
23 {
24 public:
25   int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios);
26 };
27
28 int
29 Smap_server::dispatch(l4_umword_t, L4::Ipc::Iostream &ios)
30 {
31   l4_msgtag_t t;
32   ios >> t;
33
34   // We're only talking the Map_example protocol
35   if (t.label() != Mapper::Protocol)
36     return -L4_EBADPROTO;
37
38   L4::Opcode opcode;
39   ios >> opcode;
40
41   switch (opcode)
42     {
43     case Mapper::Do_map:
44       l4_addr_t snd_base;
45       ios >> snd_base;
46       // put something into the page to read it out at the other side
47       snprintf(page_to_map, sizeof(page_to_map), "Hello from the server!");
48       printf("Sending to client\n");
49       // send page
50       ios << L4::Ipc::Snd_fpage::mem((l4_addr_t)page_to_map, L4_PAGESHIFT,
51                                 L4_FPAGE_RO, snd_base);
52       return L4_EOK;
53     default:
54       return -L4_ENOSYS;
55     }
56 }
57
58 int
59 main()
60 {
61   static Smap_server smap;
62
63   // Register server
64   if (!server.registry()->register_obj(&smap, "smap").is_valid())
65     {
66       printf("Could not register my service, read-only namespace?\n");
67       return 1;
68     }
69
70   printf("Welcome to the memory map example server!\n");
71
72   // Wait for client requests
73   server.loop();
74
75   return 0;
76 }