mirror of
https://github.com/mmueller41/genode.git
synced 2026-01-21 12:32:56 +01:00
Extended hello tutorial with second client and configurable parameters.
This commit is contained in:
@@ -27,7 +27,14 @@ install_config {
|
||||
<provides> <service name="Hello"/> </provides>
|
||||
</start>
|
||||
<start name="hello_client">
|
||||
<binary name="hello_client"/>
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<config a="5" b="6"/>
|
||||
</start>
|
||||
<start name="hello_client2">
|
||||
<binary name="hello_client"/>
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<config a="7" b="8"/>
|
||||
</start>
|
||||
</config>}
|
||||
|
||||
|
||||
@@ -14,17 +14,57 @@
|
||||
|
||||
#include <base/component.h>
|
||||
#include <base/log.h>
|
||||
#include <base/attached_rom_dataspace.h>
|
||||
#include <hello_session/connection.h>
|
||||
|
||||
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<HelloClient> _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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user