From e6b09edaca8578aec0a9108030af1d45f903994a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=BCller?= Date: Mon, 11 Jul 2022 11:57:05 +0200 Subject: [PATCH] Extended hello tutorial with second client and configurable parameters. --- repos/hello_tutorial/run/hello.run | 7 +++ repos/hello_tutorial/src/hello/client/main.cc | 52 ++++++++++++++++--- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/repos/hello_tutorial/run/hello.run b/repos/hello_tutorial/run/hello.run index f41fabc170..244550a19d 100644 --- a/repos/hello_tutorial/run/hello.run +++ b/repos/hello_tutorial/run/hello.run @@ -27,7 +27,14 @@ install_config { + + + + + + + } diff --git a/repos/hello_tutorial/src/hello/client/main.cc b/repos/hello_tutorial/src/hello/client/main.cc index 895c511e1f..eb4f12d569 100644 --- a/repos/hello_tutorial/src/hello/client/main.cc +++ b/repos/hello_tutorial/src/hello/client/main.cc @@ -14,17 +14,57 @@ #include #include +#include #include +struct HelloClient { + Genode::Env &_env; + Hello::Connection &_hello; -void Component::construct(Genode::Env &env) + int _a; + int _b; + + Genode::Attached_rom_dataspace _config{_env, "config"}; + + + void _handle_config() + { + Genode::log("Reading config"); + _config.update(); + + if (!_config.valid()) { + Genode::log("Config is invalid."); + return; + } + + _a = _config.xml().attribute_value("a", 2); + _b = _config.xml().attribute_value("b", 5); + } + + Genode::Signal_handler _config_handler { + _env.ep(), *this, &HelloClient::_handle_config + }; + + void run() + { + _hello.say_hello(); + + int const sum = _hello.add(_a, _b); + Genode::log("added ", _a, " + ", _b, " = ", sum); + + Genode::log("hello test completed."); + } + + HelloClient(Genode::Env &env, Hello::Connection &conn) : _env(env), _hello(conn) + {} +}; + +void +Component::construct(Genode::Env &env) { Hello::Connection hello(env); - hello.say_hello(); + HelloClient client(env, hello); + client.run(); - int const sum = hello.add(2, 5); - Genode::log("added 2 + 5 = ", sum); - - Genode::log("hello test completed"); }