Loading...
Searching...
No Matches
examples/libs/l4re/streammap/server.cc

Client/Server example showing how to map a page to another task – Server implementation.

Client/Server example showing how to map a page to another task – Server implementation. Note that there's also a shared memory library that supplies this functionality in more convenient way.

/*
* (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/cap_alloc>
#include <l4/re/util/object_registry>
#include <l4/cxx/ipc_server>
#include "shared.h"
static char page_to_map[L4_PAGESIZE] __attribute__((aligned(L4_PAGESIZE)));
static L4Re::Util::Registry_server<> server;
class Smap_server : public L4::Server_object_t<Mapper>
{
public:
int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios);
};
int
Smap_server::dispatch(l4_umword_t, L4::Ipc::Iostream &ios)
{
l4_msgtag_t t;
ios >> t;
// We're only talking the Map_example protocol
if (t.label() != Mapper::Protocol)
return -L4_EBADPROTO;
L4::Opcode opcode;
ios >> opcode;
switch (opcode)
{
case Mapper::Do_map:
l4_addr_t snd_base;
ios >> snd_base;
// put something into the page to read it out at the other side
snprintf(page_to_map, sizeof(page_to_map), "Hello from the server!");
printf("Sending to client\n");
// send page
ios << L4::Ipc::Snd_fpage::mem((l4_addr_t)page_to_map, L4_PAGESHIFT,
L4_FPAGE_RO, snd_base);
return L4_EOK;
default:
return -L4_ENOSYS;
}
}
int
main()
{
static Smap_server smap;
// Register server
if (!server.registry()->register_obj(&smap, "smap").is_valid())
{
printf("Could not register my service, read-only namespace?\n");
return 1;
}
printf("Welcome to the memory map example server!\n");
// Wait for client requests
server.loop();
return 0;
}
L4Re::Util::Registry_server
A server loop object which has a Object_registry included.
Definition object_registry:294
L4::Ipc::Iostream
Input/Output stream for IPC [un]marshalling.
Definition ipc_stream:790
L4::Ipc::Snd_fpage::mem
static Snd_fpage mem(l4_addr_t base, int order, unsigned char rights, l4_addr_t snd_base=0, Map_type map_type=Map, Cacheopt cache=None, Continue cont=Last) noexcept
Construct a send item for the memory space.
Definition ipc_types:424
L4::Server_object::dispatch
virtual int dispatch(unsigned long rights, Ipc::Iostream &ios)=0
The abstract handler for client requests to the object.
ipc_server
IPC server loop.
env
Environment interface.
l4_umword_t
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
l4_addr_t
unsigned long l4_addr_t
Address type.
Definition l4int.h:34
L4_ENOSYS
@ L4_ENOSYS
No sys.
Definition err.h:50
L4_EOK
@ L4_EOK
Ok.
Definition err.h:32
L4_EBADPROTO
@ L4_EBADPROTO
Unsupported protocol.
Definition err.h:51
L4_FPAGE_RO
@ L4_FPAGE_RO
Read-only flexpage.
Definition __l4_fpage.h:122
L4_PAGESIZE
#define L4_PAGESIZE
Minimal page size (in bytes).
Definition consts.h:391
L4_PAGESHIFT
#define L4_PAGESHIFT
Size of a page, log2-based.
Definition consts.h:26
L4::Opcode
int Opcode
Data type for RPC opcodes.
Definition __typeinfo.h:36
L4::Server_object_t
Base class (template) for server implementing server objects.
Definition ipc_server:81
l4_msgtag_t
Message tag data structure.
Definition types.h:154
l4_msgtag_t::label
long label() const L4_NOTHROW
Get the protocol value.
Definition types.h:158
cap_alloc
Capability allocator.