From f98359cbe6b449a1fadc25c14dfcc6954ca6be44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=BCller?= Date: Mon, 11 Jul 2022 14:26:28 +0200 Subject: [PATCH] hello_tutorial: Made hello session stateful. --- .../include/hello_session/connection.h | 15 ++++++++------- .../include/hello_session/hello_session.h | 2 ++ repos/hello_tutorial/src/hello/client/main.cc | 5 +++-- repos/hello_tutorial/src/hello/server/main.cc | 19 +++++++++++++------ 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/repos/hello_tutorial/include/hello_session/connection.h b/repos/hello_tutorial/include/hello_session/connection.h index a21b0109fe..51b1e31f0a 100644 --- a/repos/hello_tutorial/include/hello_session/connection.h +++ b/repos/hello_tutorial/include/hello_session/connection.h @@ -22,14 +22,15 @@ namespace Hello { struct Connection; } struct Hello::Connection : Genode::Connection, Session_client { - Connection(Genode::Env &env) - : - /* create session */ - Genode::Connection(env, session(env.parent(), - "ram_quota=6K, cap_quota=4")), + Connection(Genode::Env &env, unsigned short id) + : /* create session */ + Genode::Connection(env, session(env.parent(), + "ram_quota=6K, cap_quota=4")), - /* initialize RPC interface */ - Session_client(cap()) { } + /* initialize RPC interface */ + Session_client(cap()) + { + } }; #endif /* _INCLUDE__HELLO_SESSION__CONNECTION_H_ */ diff --git a/repos/hello_tutorial/include/hello_session/hello_session.h b/repos/hello_tutorial/include/hello_session/hello_session.h index 8ff65e2ea8..db22c92084 100644 --- a/repos/hello_tutorial/include/hello_session/hello_session.h +++ b/repos/hello_tutorial/include/hello_session/hello_session.h @@ -24,6 +24,8 @@ struct Hello::Session : Genode::Session { static const char *service_name() { return "Hello"; } + unsigned short _id; + enum { CAP_QUOTA = 2 }; virtual void say_hello() = 0; diff --git a/repos/hello_tutorial/src/hello/client/main.cc b/repos/hello_tutorial/src/hello/client/main.cc index 55d25e2436..2716fc1f36 100644 --- a/repos/hello_tutorial/src/hello/client/main.cc +++ b/repos/hello_tutorial/src/hello/client/main.cc @@ -60,7 +60,7 @@ struct HelloClient { Genode::log("hello test completed."); } - HelloClient(Genode::Env &env, Hello::Connection &conn) : _env(env), _hello(conn), _a(5), _b(2) + HelloClient(Genode::Env &env, Hello::Connection &conn) : _env(env), _a(5), _b(2), _hello(conn) { _config.sigh(_config_handler); _handle_config(); @@ -70,7 +70,8 @@ struct HelloClient { void Component::construct(Genode::Env &env) { - Hello::Connection hello(env); + Timer::Connection timer(env); + Hello::Connection hello(env, (unsigned short)timer.elapsed_ms()); HelloClient client(env, hello); client.run(); diff --git a/repos/hello_tutorial/src/hello/server/main.cc b/repos/hello_tutorial/src/hello/server/main.cc index 267a8491b8..7add13c82d 100644 --- a/repos/hello_tutorial/src/hello/server/main.cc +++ b/repos/hello_tutorial/src/hello/server/main.cc @@ -18,7 +18,7 @@ #include #include #include - +#include namespace Hello { struct Session_component; struct Root_component; @@ -28,8 +28,12 @@ namespace Hello { struct Hello::Session_component : Genode::Rpc_object { + unsigned int _id; + + Session_component(unsigned short id) : Genode::Rpc_object(), _id(id) {} + void say_hello() override { - Genode::log("I am here... Hello."); } + Genode::log("I am here... Hello. My id is ", _id, "."); } int add(int a, int b) override { return a + b; } @@ -41,19 +45,21 @@ class Hello::Root_component public Genode::Root_component { protected: + Timer::Connection &_timer; Session_component *_create_session(const char *) override { Genode::log("creating hello session"); - return new (md_alloc()) Session_component(); + return new (md_alloc()) Session_component((unsigned short)_timer.elapsed_ms()); } public: Root_component(Genode::Entrypoint &ep, - Genode::Allocator &alloc) + Genode::Allocator &alloc, + Timer::Connection &timer) : - Genode::Root_component(ep, alloc) + Genode::Root_component(ep, alloc), _timer(timer) { Genode::log("creating root component"); } @@ -63,6 +69,7 @@ class Hello::Root_component struct Hello::Main { Genode::Env &env; + Timer::Connection _timer { env }; /* * A sliced heap is used for allocating session objects - thereby we @@ -70,7 +77,7 @@ struct Hello::Main */ Genode::Sliced_heap sliced_heap { env.ram(), env.rm() }; - Hello::Root_component root { env.ep(), sliced_heap }; + Hello::Root_component root { env.ep(), sliced_heap, _timer }; Main(Genode::Env &env) : env(env) {