L4Re – L4 Runtime Environment
examples/clntsrv/client.cc

Client/Server example using C++ infrastructure – Client implementation.

/*
* (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
* Alexander Warg <warg@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
*
* This file is part of TUD:OS and distributed under the terms of the
* GNU General Public License 2.
* Please see the COPYING-GPL-2 file for details.
*/
#include <l4/sys/err.h>
#include <l4/sys/types.h>
#include <l4/re/env>
#include <stdio.h>
#include "shared.h"
int
main()
{
L4::Cap<Calc> server = L4Re::Env::env()->get_cap<Calc>("calc_server");
if (!server.is_valid())
{
printf("Could not get server capability!\n");
return 1;
}
l4_uint32_t val1 = 8;
l4_uint32_t val2 = 5;
printf("Asking for %d - %d\n", val1, val2);
if (server->sub(val1, val2, &val1))
{
printf("Error talking to server\n");
return 1;
}
printf("Result of subtract call: %d\n", val1);
printf("Asking for -%d\n", val1);
if (server->neg(val1, &val1))
{
printf("Error talking to server\n");
return 1;
}
printf("Result of negate call: %d\n", val1);
return 0;
}
static Env const * env() noexcept
Returns the initial environment for the current task.
Definition: env:103
L4::Cap< T > get_cap(char const *name, unsigned l) const noexcept
Get the capability selector for the object named name.
Definition: env:204
bool is_valid() const noexcept
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
Definition: capability.h:60
C++ interface for capabilities.
Definition: capability.h:219
Environment interface.
Error codes.
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition: l4int.h:40
Common L4 ABI Data Types.
Capability allocator.