L4Re - L4 Runtime Environment
examples/clntsrv/server.cc

Client/Server example using C++ infrastructure – Server 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 <stdio.h>
#include <l4/re/env>
#include <l4/re/util/object_registry>
#include <l4/re/util/br_manager>
#include <l4/sys/cxx/ipc_epiface>
#include "shared.h"
class Calculation_server : public L4::Epiface_t<Calculation_server, Calc>
{
public:
int op_sub(Calc::Rights, l4_uint32_t a, l4_uint32_t b, l4_uint32_t &res)
{
res = a - b;
return 0;
}
int op_neg(Calc::Rights, l4_uint32_t a, l4_uint32_t &res)
{
res = -a;
return 0;
}
};
int
main()
{
static Calculation_server calc;
// Register calculation server
if (!server.registry()->register_obj(&calc, "calc_server").is_valid())
{
printf("Could not register my service, is there a 'calc_server' in the caps table?\n");
return 1;
}
printf("Welcome to the calculation server!\n"
"I can do substractions and negations.\n");
// Wait for client requests
server.loop();
return 0;
}