Skip to content

Commit

Permalink
genode_c_api: make usb devices report configurable
Browse files Browse the repository at this point in the history
To stay consistent with the configuration of the legacy usb_host_drv
and other components as well, do not report USB devices by default,
but when the following XML node is set within the component's
configuration:

  <report devices="yes"/>

Ref #4416
  • Loading branch information
skalk authored and nfeske committed Feb 21, 2022
1 parent a04d0b9 commit 938ac71
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions repos/os/src/lib/genode_c_api/usb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class Root : public Root_component<genode_usb_session>
Attached_rom_dataspace _config { _env, "config" };
Signal_handler<Root> _config_handler { _env.ep(), *this,
&Root::_announce_service };
Reporter _reporter { _env, "devices" };
Constructible<Reporter> _reporter { };
Constructible<Device> _devices[MAX_DEVICES];
List<List_element<genode_usb_session>> _sessions {};
Id_allocator _id_alloc {};
Expand Down Expand Up @@ -587,8 +587,11 @@ void ::Root::_report()
{
using Value = String<64>;

_reporter.enabled(true);
Reporter::Xml_generator xml(_reporter, [&] () {
if (!_reporter.constructed())
return;

_reporter->enabled(true);
Reporter::Xml_generator xml(*_reporter, [&] () {
_for_each_device([&] (Device & d) {
xml.node("device", [&] {
xml.attribute("label", d.label());
Expand All @@ -613,11 +616,23 @@ void ::Root::_announce_service()
*/
_config.update();

/*
* Check for report policy, and resp. con-/destruct device reporter
*/
_config.xml().with_sub_node("report", [&] (Xml_node node) {
if (node.attribute_value("devices", false)) {
if (!_reporter.constructed())
_reporter.construct(_env, "devices");
} else {
if (_reporter.constructed())
_reporter.destruct();
}
});

if (_announced)
return;

if (_config.xml().type() == "config") {
log(_config.xml());
_env.parent().announce(_env.ep().manage(*this));
_announced = true;
}
Expand Down

0 comments on commit 938ac71

Please sign in to comment.