genode/repos/hello_tutorial/src/hello/server/main.cc

90 lines
1.7 KiB
C++
Raw Normal View History

2011-12-22 15:19:25 +00:00
/*
* \brief Main program of the Hello server
* \author Björn Döbel
2016-05-20 12:49:45 +00:00
* \author Norman Feske
2011-12-22 15:19:25 +00:00
* \date 2008-03-20
*/
/*
2016-05-20 12:49:45 +00:00
* Copyright (C) 2008-2016 Genode Labs GmbH
2011-12-22 15:19:25 +00:00
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
2016-05-20 12:49:45 +00:00
#include <base/component.h>
#include <base/log.h>
#include <base/heap.h>
2011-12-22 15:19:25 +00:00
#include <root/component.h>
#include <hello_session/hello_session.h>
#include <base/rpc_server.h>
namespace Hello {
2016-05-20 12:49:45 +00:00
struct Session_component;
struct Root_component;
struct Main;
}
2011-12-22 15:19:25 +00:00
2016-05-20 12:49:45 +00:00
struct Hello::Session_component : Genode::Rpc_object<Session>
{
void say_hello() {
Genode::log("I am here... Hello."); }
2011-12-22 15:19:25 +00:00
2016-05-20 12:49:45 +00:00
int add(int a, int b) {
return a + b; }
};
class Hello::Root_component
:
public Genode::Root_component<Session_component>
{
protected:
Session_component *_create_session(const char *args)
{
Genode::log("creating hello session");
return new (md_alloc()) Session_component();
}
2011-12-22 15:19:25 +00:00
2016-05-20 12:49:45 +00:00
public:
2011-12-22 15:19:25 +00:00
2016-05-20 12:49:45 +00:00
Root_component(Genode::Entrypoint &ep,
Genode::Allocator &alloc)
:
Genode::Root_component<Session_component>(ep, alloc)
{
Genode::log("creating root component");
}
};
2011-12-22 15:19:25 +00:00
2016-05-20 12:49:45 +00:00
struct Hello::Main
2011-12-22 15:19:25 +00:00
{
2016-05-20 12:49:45 +00:00
Genode::Env &env;
2011-12-22 15:19:25 +00:00
/*
* A sliced heap is used for allocating session objects - thereby we
* can release objects separately.
*/
2016-05-20 12:49:45 +00:00
Genode::Sliced_heap sliced_heap { env.ram(), env.rm() };
2011-12-22 15:19:25 +00:00
2016-05-20 12:49:45 +00:00
Hello::Root_component root { env.ep(), sliced_heap };
Main(Genode::Env &env) : env(env)
{
/*
* Create a RPC object capability for the root interface and
* announce the service to our parent.
*/
env.parent().announce(env.ep().manage(root));
}
};
2011-12-22 15:19:25 +00:00
2016-05-20 12:49:45 +00:00
void Component::construct(Genode::Env &env)
{
static Hello::Main main(env);
2011-12-22 15:19:25 +00:00
}