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