]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/examples/clntsrv/client.cc
48e110ce3caf93fccfec3d383002c905875d69f3
[l4.git] / l4 / pkg / examples / clntsrv / 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_neg_call(L4::Cap<void> const &server, l4_uint32_t *result,
22               l4_uint32_t val)
23 {
24   L4::Ipc_iostream s(l4_utcb());
25   s << l4_umword_t(Opcode::func_neg) << val;
26   l4_msgtag_t res = s.call(server.cap());
27   if (l4_ipc_error(res, l4_utcb()))
28     return 1; // failure
29   s >> *result;
30   return 0; // ok
31 }
32
33 int
34 func_sub_call(L4::Cap<void> const &server, l4_uint32_t *result,
35               l4_uint32_t val1, l4_uint32_t val2)
36 {
37   L4::Ipc_iostream s(l4_utcb());
38   s << l4_umword_t(Opcode::func_sub) << val1 << val2;
39   l4_msgtag_t res = s.call(server.cap(), Protocol::Calc);
40   if (l4_ipc_error(res, l4_utcb()))
41     return 1; // failure
42   s >> *result;
43   return 0; // ok
44 }
45
46 int
47 main()
48 {
49
50   L4::Cap<void> server = L4Re::Env::env()->get_cap<void>("calc_server");
51   if (!server.is_valid())
52     {
53       printf("Could not get server capability!\n");
54       return 1;
55     }
56
57   l4_uint32_t val1 = 8;
58   l4_uint32_t val2 = 5;
59
60   printf("Asking for %d - %d\n", val1, val2);
61
62   if (func_sub_call(server, &val1, val1, val2))
63     {
64       printf("Error talking to server\n");
65       return 1;
66     }
67   printf("Result of substract call: %d\n", val1);
68   printf("Asking for -%d\n", val1);
69   if (func_neg_call(server, &val1, val1))
70     {
71       printf("Error talking to server\n");
72       return 1;
73     }
74   printf("Result of negate call: %d\n", val1);
75
76   return 0;
77 }