mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-17 18:29:55 +00:00
Remove Xml_node::attribute accessors
This patch removes the two 'Xml_node::attribute' accessors along with the 'Nonexistent_attribute' exception. Issue #5245 Fixes #5246
This commit is contained in:
parent
84bbde2879
commit
7de2f57ef2
@ -649,13 +649,14 @@ Main::Main(Env &env) : env(env)
|
||||
{
|
||||
log("testing base-nova platform");
|
||||
|
||||
try {
|
||||
{
|
||||
Attached_rom_dataspace config(env, "config");
|
||||
config.xml().attribute("check_pat").value(check_pat);
|
||||
} catch (...) {
|
||||
Genode::error("no check_pat attribute found");
|
||||
env.parent().exit(-__LINE__);
|
||||
return;
|
||||
if (!config.xml().has_attribute("check_pat")) {
|
||||
Genode::error("no check_pat attribute found");
|
||||
env.parent().exit(-__LINE__);
|
||||
return;
|
||||
}
|
||||
check_pat = config.xml().attribute_value("check_pat", check_pat);
|
||||
}
|
||||
|
||||
Thread * myself = Thread::myself();
|
||||
|
@ -93,7 +93,7 @@ class Genode::Xml_attribute
|
||||
explicit Xml_attribute(Token t) : _tokens(t)
|
||||
{
|
||||
if (_tokens.name.type() != Token::IDENT)
|
||||
throw Nonexistent_attribute();
|
||||
throw Invalid_syntax();
|
||||
|
||||
if (!_tokens.valid())
|
||||
throw Invalid_syntax();
|
||||
@ -110,8 +110,7 @@ class Genode::Xml_attribute
|
||||
** Exception types **
|
||||
*********************/
|
||||
|
||||
class Invalid_syntax : public Exception { };
|
||||
class Nonexistent_attribute : public Exception { };
|
||||
class Invalid_syntax : public Exception { };
|
||||
|
||||
|
||||
typedef String<64> Name;
|
||||
@ -121,7 +120,7 @@ class Genode::Xml_attribute
|
||||
/**
|
||||
* Return true if attribute has specified type
|
||||
*/
|
||||
bool has_type(char const *type) {
|
||||
bool has_type(char const *type) const {
|
||||
return strlen(type) == _tokens.name.len() &&
|
||||
strcmp(type, _tokens.name.start(), _tokens.name.len()) == 0; }
|
||||
|
||||
@ -221,9 +220,7 @@ class Genode::Xml_node
|
||||
** Exception types **
|
||||
*********************/
|
||||
|
||||
typedef Genode::Exception Exception;
|
||||
typedef Xml_attribute::Nonexistent_attribute Nonexistent_attribute;
|
||||
typedef Xml_attribute::Invalid_syntax Invalid_syntax;
|
||||
typedef Xml_attribute::Invalid_syntax Invalid_syntax;
|
||||
|
||||
class Nonexistent_sub_node : public Exception { };
|
||||
|
||||
@ -885,41 +882,6 @@ class Genode::Xml_node
|
||||
for_each_sub_node(nullptr, fn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Nth attribute of XML node
|
||||
*
|
||||
* \param idx attribute index,
|
||||
* first attribute has index 0
|
||||
* \throw Nonexistent_attribute no such attribute exists
|
||||
* \return XML attribute
|
||||
*/
|
||||
Xml_attribute attribute(unsigned idx) const
|
||||
{
|
||||
Xml_attribute attr = _tags.start.attribute();
|
||||
for (unsigned i = 0; i < idx; i++)
|
||||
attr = Xml_attribute(attr._next_token());
|
||||
|
||||
return attr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return attribute of specified type
|
||||
*
|
||||
* \param type name of attribute type
|
||||
* \throw Nonexistent_attribute no such attribute exists
|
||||
* \return XML attribute
|
||||
*/
|
||||
Xml_attribute attribute(char const *type) const
|
||||
{
|
||||
for (Xml_attribute attr = _tags.start.attribute(); ;) {
|
||||
if (attr.has_type(type))
|
||||
return attr;
|
||||
|
||||
attr = Xml_attribute(attr._next_token());
|
||||
}
|
||||
throw Nonexistent_attribute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read attribute value from XML node
|
||||
*
|
||||
|
@ -243,11 +243,8 @@ struct Formatted_xml_attribute
|
||||
*/
|
||||
static void print_xml_attr_info(Output &output, Xml_node node, int indent = 0)
|
||||
{
|
||||
try {
|
||||
for (Xml_node::Attribute a = node.attribute(0U); ; a = a.next())
|
||||
print(output, Formatted_xml_attribute(a, indent), "\n");
|
||||
|
||||
} catch (Xml_node::Nonexistent_attribute) { }
|
||||
node.for_each_attribute([&] (Xml_attribute const &a) {
|
||||
print(output, Formatted_xml_attribute(a, indent), "\n"); });
|
||||
}
|
||||
|
||||
|
||||
|
@ -90,15 +90,12 @@ struct Main
|
||||
usb_config = config_rom.xml().attribute_value("configuration", 0ul);
|
||||
|
||||
/* retrieve possible MAC */
|
||||
try {
|
||||
Nic::Mac_address mac;
|
||||
Xml_node::Attribute mac_node = config_rom.xml().attribute("mac");
|
||||
mac_node.value(mac);
|
||||
use_mac_address = config_rom.xml().has_attribute("mac");
|
||||
if (use_mac_address) {
|
||||
auto const mac = config_rom.xml().attribute_value("mac", Nic::Mac_address{});
|
||||
mac.copy(mac_address);
|
||||
use_mac_address = true;
|
||||
log("Trying to use configured mac: ", mac);
|
||||
} catch (...) {
|
||||
use_mac_address = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1619,34 +1619,31 @@ class Vfs::Lxip_file_system : public Vfs::File_system,
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Addr ip_addr = config.attribute_value("ip_addr", Addr());
|
||||
Addr netmask = config.attribute_value("netmask", Addr());
|
||||
Addr gateway = config.attribute_value("gateway", Addr());
|
||||
Addr nameserver = config.attribute_value("nameserver", Addr());
|
||||
|
||||
Addr ip_addr = config.attribute_value("ip_addr", Addr());
|
||||
Addr netmask = config.attribute_value("netmask", Addr());
|
||||
Addr gateway = config.attribute_value("gateway", Addr());
|
||||
Addr nameserver = config.attribute_value("nameserver", Addr());
|
||||
if (ip_addr == "") {
|
||||
warning("Missing \"ip_addr\" attribute. Ignoring network interface config.");
|
||||
return;
|
||||
} else if (netmask == "") {
|
||||
warning("Missing \"netmask\" attribute. Ignoring network interface config.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ip_addr == "") {
|
||||
warning("Missing \"ip_addr\" attribute. Ignoring network interface config.");
|
||||
throw Genode::Xml_node::Nonexistent_attribute();
|
||||
} else if (netmask == "") {
|
||||
warning("Missing \"netmask\" attribute. Ignoring network interface config.");
|
||||
throw Genode::Xml_node::Nonexistent_attribute();
|
||||
}
|
||||
log("static network interface: ip_addr=",ip_addr," netmask=",netmask);
|
||||
|
||||
log("static network interface: ip_addr=",ip_addr," netmask=",netmask);
|
||||
genode_socket_config address_config = {
|
||||
.dhcp = false,
|
||||
.ip_addr = ip_addr.string(),
|
||||
.netmask = netmask.string(),
|
||||
.gateway = gateway.string(),
|
||||
.nameserver = nameserver.string(),
|
||||
};
|
||||
|
||||
genode_socket_config address_config = {
|
||||
.dhcp = false,
|
||||
.ip_addr = ip_addr.string(),
|
||||
.netmask = netmask.string(),
|
||||
.gateway = gateway.string(),
|
||||
.nameserver = nameserver.string(),
|
||||
};
|
||||
|
||||
genode_socket_config_address(&address_config);
|
||||
} catch (...) { }
|
||||
}
|
||||
genode_socket_config_address(&address_config);
|
||||
}
|
||||
|
||||
|
||||
/*************************
|
||||
|
@ -54,10 +54,10 @@ class Anchor
|
||||
if (!node.has_attribute(attr))
|
||||
return;
|
||||
|
||||
Xml_node::Attribute const anchor = node.attribute(attr);
|
||||
auto const v = node.attribute_value(attr, Genode::String<16>());
|
||||
|
||||
for (Value const *value = _values; value->value; value++) {
|
||||
if (anchor.has_value(value->value)) {
|
||||
if (v == value->value) {
|
||||
horizontal = value->horizontal;
|
||||
vertical = value->vertical;
|
||||
return;
|
||||
|
@ -169,6 +169,8 @@ static Surface_base::Area calc_scaled_size(Xml_node operation,
|
||||
if (!operation.has_attribute(attr))
|
||||
return image_size;
|
||||
|
||||
auto const value = operation.attribute_value("scale", String<16>());
|
||||
|
||||
/* prevent division by zero, below */
|
||||
if (image_size.count() == 0)
|
||||
return image_size;
|
||||
@ -176,14 +178,13 @@ static Surface_base::Area calc_scaled_size(Xml_node operation,
|
||||
/*
|
||||
* Determine scale ratio (in 16.16 fixpoint format)
|
||||
*/
|
||||
unsigned const ratio =
|
||||
operation.attribute(attr).has_value("fit") ?
|
||||
min((mode_size.w << 16) / image_size.w,
|
||||
(mode_size.h << 16) / image_size.h) :
|
||||
operation.attribute(attr).has_value("zoom") ?
|
||||
max((mode_size.w << 16) / image_size.w,
|
||||
(mode_size.h << 16) / image_size.h) :
|
||||
1 << 16;
|
||||
unsigned const ratio = (value == "fit")
|
||||
? min((mode_size.w << 16) / image_size.w,
|
||||
(mode_size.h << 16) / image_size.h)
|
||||
: (value == "zoom")
|
||||
? max((mode_size.w << 16) / image_size.w,
|
||||
(mode_size.h << 16) / image_size.h)
|
||||
: 1 << 16;
|
||||
|
||||
/*
|
||||
* We add 0.5 (1 << 15) to round instead of truncating the fractional
|
||||
|
@ -219,11 +219,9 @@ class Decorator::Config
|
||||
if (node.has_type("maximizer")) type = Window_control::TYPE_MAXIMIZER;
|
||||
if (node.has_type("minimizer")) type = Window_control::TYPE_MINIMIZER;
|
||||
|
||||
if (node.has_attribute("align")) {
|
||||
Genode::Xml_attribute attr = node.attribute("align");
|
||||
if (attr.has_value("left")) align = Window_control::ALIGN_LEFT;
|
||||
if (attr.has_value("right")) align = Window_control::ALIGN_RIGHT;
|
||||
}
|
||||
auto const align_attr = node.attribute_value("align", Genode::String<16>());
|
||||
if (align_attr == "left") align = Window_control::ALIGN_LEFT;
|
||||
if (align_attr == "right") align = Window_control::ALIGN_RIGHT;
|
||||
|
||||
_window_controls[_num_window_controls++] =
|
||||
new (_alloc) Window_control(type, align);
|
||||
|
@ -1121,19 +1121,15 @@ Log_event::~Log_event()
|
||||
|
||||
Log_prefix Log_event::_init_log_prefix(Xml_node const &xml)
|
||||
{
|
||||
if (!xml.has_attribute("log_prefix"))
|
||||
auto const log_prefix = xml.attribute_value("log_prefix", Log_prefix { });
|
||||
if (log_prefix.length() <= 1)
|
||||
return Log_prefix { };
|
||||
|
||||
char buf[Log_prefix::size()];
|
||||
size_t buf_str_size { 0 };
|
||||
xml.attribute("log_prefix").with_raw_value([&] (char const *src_ptr, size_t src_size) {
|
||||
char buf[Log_prefix::size()] { }; /* mutable buffer for filter operation */
|
||||
memcpy(buf, log_prefix.string(), log_prefix.length());
|
||||
size_t const filtered_len = pattern_filters.apply_to(buf, log_prefix.length());
|
||||
|
||||
size_t const cpy_size = min(src_size, sizeof(buf) - 1);
|
||||
memcpy(buf, src_ptr, cpy_size);
|
||||
buf[cpy_size] = 0;
|
||||
buf_str_size = pattern_filters.apply_to(buf, cpy_size + 1);
|
||||
});
|
||||
return Cstring { buf, buf_str_size };
|
||||
return Log_prefix { Cstring { buf, filtered_len } };
|
||||
}
|
||||
|
||||
|
||||
|
@ -442,18 +442,16 @@ Main_window::Main_window(Genode::Env &env)
|
||||
|
||||
using namespace Genode;
|
||||
|
||||
Attached_rom_dataspace config(env, "config");
|
||||
try {
|
||||
Xml_node config_node = config.xml();
|
||||
_verbose = config_node.attribute("verbose").has_value("yes");
|
||||
} catch (...) { _verbose = false; }
|
||||
|
||||
try {
|
||||
Xml_node node = config.xml().sub_node("default");
|
||||
_default_out_volume = node.attribute_value<long>("out_volume", 0);
|
||||
_default_volume = node.attribute_value<long>("volume", 0);
|
||||
_default_muted = node.attribute_value<long>("muted", 1);
|
||||
} catch (...) { Genode::warning("no <default> node found, fallback is 'muted=1'"); }
|
||||
Attached_rom_dataspace const config(env, "config");
|
||||
_verbose = config.xml().attribute_value("verbose", false);
|
||||
config.xml().with_sub_node("default",
|
||||
[&] (Xml_node const &node) {
|
||||
_default_out_volume = node.attribute_value("out_volume", 0L);
|
||||
_default_volume = node.attribute_value("volume", 0L);
|
||||
_default_muted = node.attribute_value("muted", 1L);
|
||||
},
|
||||
[&] { warning("no <default> node found, fallback is 'muted=1'"); }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
@ -86,17 +86,15 @@ class Scene : public Nano3d::Scene<PT>
|
||||
{
|
||||
_config.update();
|
||||
|
||||
try {
|
||||
_shape = SHAPE_DODECAHEDRON;
|
||||
if (_config.xml().attribute("shape").has_value("cube"))
|
||||
_shape = SHAPE_CUBE;
|
||||
} catch (...) { }
|
||||
using Value = Genode::String<32>;
|
||||
|
||||
try {
|
||||
_painter = PAINTER_TEXTURED;
|
||||
if (_config.xml().attribute("painter").has_value("shaded"))
|
||||
_painter = PAINTER_SHADED;
|
||||
} catch (...) { }
|
||||
_shape = SHAPE_DODECAHEDRON;
|
||||
if (_config.xml().attribute_value("shape", Value()) == "cube")
|
||||
_shape = SHAPE_CUBE;
|
||||
|
||||
_painter = PAINTER_TEXTURED;
|
||||
if (_config.xml().attribute_value("painter", Value()) == "shaded")
|
||||
_painter = PAINTER_SHADED;
|
||||
}
|
||||
|
||||
Genode::Signal_handler<Scene> _config_handler;
|
||||
|
@ -33,30 +33,32 @@ struct Sculpt::Wifi_connection
|
||||
/**
|
||||
* Create 'Wifi_connection' object from 'state' report
|
||||
*/
|
||||
static Wifi_connection from_xml(Xml_node node)
|
||||
static Wifi_connection from_xml(Xml_node const &node)
|
||||
{
|
||||
bool const connected =
|
||||
node.has_sub_node("accesspoint") &&
|
||||
node.sub_node("accesspoint").attribute("state").has_value("connected");
|
||||
bool const connecting =
|
||||
node.has_sub_node("accesspoint") &&
|
||||
node.sub_node("accesspoint").attribute("state").has_value("connecting");
|
||||
bool const auth_failed =
|
||||
node.has_sub_node("accesspoint") &&
|
||||
node.sub_node("accesspoint").attribute_value("auth_failure", false);
|
||||
Wifi_connection result { };
|
||||
|
||||
if (!connected && !connecting)
|
||||
return { .state = DISCONNECTED,
|
||||
.auth_failed = auth_failed,
|
||||
.bssid = Access_point::Bssid{},
|
||||
.ssid = Access_point::Bssid{} };
|
||||
bool connected = false;
|
||||
bool connecting = false;
|
||||
bool auth_failed = false;
|
||||
|
||||
Xml_node const ap = node.sub_node("accesspoint");
|
||||
node.with_optional_sub_node("accesspoint", [&] (Xml_node const &ap) {
|
||||
connected = (ap.attribute_value("state", String<32>()) == "connected");
|
||||
connecting = (ap.attribute_value("state", String<32>()) == "connecting");
|
||||
auth_failed = ap.attribute_value("auth_failed", false);
|
||||
|
||||
return { .state = connected ? CONNECTED : CONNECTING,
|
||||
.auth_failed = false,
|
||||
.bssid = ap.attribute_value("bssid", Access_point::Bssid()),
|
||||
.ssid = ap.attribute_value("ssid", Access_point::Ssid()) };
|
||||
if (!connected && !connecting)
|
||||
result = { .state = DISCONNECTED,
|
||||
.auth_failed = auth_failed,
|
||||
.bssid = Access_point::Bssid{},
|
||||
.ssid = Access_point::Bssid{} };
|
||||
|
||||
else
|
||||
result = { .state = connected ? CONNECTED : CONNECTING,
|
||||
.auth_failed = false,
|
||||
.bssid = ap.attribute_value("bssid", Access_point::Bssid()),
|
||||
.ssid = ap.attribute_value("ssid", Access_point::Ssid()) };
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
static Wifi_connection disconnected_wifi_connection()
|
||||
|
@ -216,15 +216,16 @@ struct Tresor_tester::Request_node : Noncopyable
|
||||
Operation read_op_attr(Xml_node const &node)
|
||||
{
|
||||
ASSERT(node.has_attribute("op"));
|
||||
if (node.attribute("op").has_value("read")) return Operation::READ;
|
||||
if (node.attribute("op").has_value("write")) return Operation::WRITE;
|
||||
if (node.attribute("op").has_value("sync")) return Operation::SYNC;
|
||||
if (node.attribute("op").has_value("create_snapshot")) return Operation::CREATE_SNAPSHOT;
|
||||
if (node.attribute("op").has_value("discard_snapshot")) return Operation::DISCARD_SNAPSHOT;
|
||||
if (node.attribute("op").has_value("extend_ft")) return Operation::EXTEND_FREE_TREE;
|
||||
if (node.attribute("op").has_value("extend_vbd")) return Operation::EXTEND_VBD;
|
||||
if (node.attribute("op").has_value("rekey")) return Operation::REKEY;
|
||||
if (node.attribute("op").has_value("deinitialize")) return Operation::DEINITIALIZE;
|
||||
auto const value = node.attribute_value("op", String<32>());
|
||||
if (value == "read") return Operation::READ;
|
||||
if (value == "write") return Operation::WRITE;
|
||||
if (value == "sync") return Operation::SYNC;
|
||||
if (value == "create_snapshot") return Operation::CREATE_SNAPSHOT;
|
||||
if (value == "discard_snapshot") return Operation::DISCARD_SNAPSHOT;
|
||||
if (value == "extend_ft") return Operation::EXTEND_FREE_TREE;
|
||||
if (value == "extend_vbd") return Operation::EXTEND_VBD;
|
||||
if (value == "rekey") return Operation::REKEY;
|
||||
if (value == "deinitialize") return Operation::DEINITIALIZE;
|
||||
ASSERT_NEVER_REACHED;
|
||||
}
|
||||
|
||||
|
@ -500,11 +500,9 @@ void Gui_fader::Main::handle_config_update()
|
||||
{
|
||||
config.update();
|
||||
|
||||
Genode::Xml_node config_xml = config.xml();
|
||||
Genode::Xml_node const config_xml = config.xml();
|
||||
|
||||
unsigned new_alpha = alpha;
|
||||
if (config_xml.has_attribute("alpha"))
|
||||
config_xml.attribute("alpha").value(new_alpha);
|
||||
unsigned const new_alpha = config_xml.attribute_value("alpha", 255u);
|
||||
|
||||
fade_in_steps = config_xml.attribute_value("fade_in_steps", 20U);
|
||||
fade_out_steps = config_xml.attribute_value("fade_out_steps", 50U);
|
||||
|
@ -1191,18 +1191,11 @@ class Wm::Gui::Root : public Genode::Rpc_object<Genode::Typed_root<Gui::Session>
|
||||
Genode::Xml_node policy =
|
||||
Genode::Session_policy(session_label, _config.xml());
|
||||
|
||||
char const *role_attr = "role";
|
||||
if (policy.has_attribute(role_attr)) {
|
||||
auto const value = policy.attribute_value("role", String<16>());
|
||||
|
||||
if (policy.attribute(role_attr).has_value("layouter"))
|
||||
role = ROLE_LAYOUTER;
|
||||
|
||||
if (policy.attribute(role_attr).has_value("decorator"))
|
||||
role = ROLE_DECORATOR;
|
||||
|
||||
if (policy.attribute(role_attr).has_value("direct"))
|
||||
role = ROLE_DIRECT;
|
||||
}
|
||||
if (value == "layouter") role = ROLE_LAYOUTER;
|
||||
if (value == "decorator") role = ROLE_DECORATOR;
|
||||
if (value == "direct") role = ROLE_DIRECT;
|
||||
}
|
||||
catch (...) { }
|
||||
|
||||
|
@ -68,24 +68,21 @@ struct Wm::Main : Pointer::Tracker
|
||||
|
||||
void handle_focus_update()
|
||||
{
|
||||
try {
|
||||
focus_rom.update();
|
||||
if (!focus_rom.valid())
|
||||
return;
|
||||
focus_rom.update();
|
||||
|
||||
unsigned win_id = 0;
|
||||
focus_rom.xml().with_optional_sub_node("window", [&] (Xml_node const &window) {
|
||||
|
||||
Xml_node(focus_rom.local_addr<char>()).sub_node("window")
|
||||
.attribute("id").value(win_id);
|
||||
unsigned const win_id = window.attribute_value("id", 0u);
|
||||
|
||||
if (win_id) {
|
||||
Gui::Session_capability session_cap =
|
||||
gui_root.lookup_gui_session(win_id);
|
||||
try {
|
||||
Gui::Session_capability session_cap =
|
||||
gui_root.lookup_gui_session(win_id);
|
||||
|
||||
focus_gui_session.focus(session_cap);
|
||||
focus_gui_session.focus(session_cap);
|
||||
} catch (...) { }
|
||||
}
|
||||
|
||||
} catch (...) { }
|
||||
});
|
||||
}
|
||||
|
||||
Genode::Signal_handler<Main> focus_handler = {
|
||||
|
@ -26,6 +26,13 @@ static void populate_args_and_env(Libc::Env &env, int &argc, char **&argv, char
|
||||
using Genode::Xml_node;
|
||||
using Genode::Xml_attribute;
|
||||
|
||||
auto with_raw_attr = [] (Xml_node const &node, auto const attr_name, auto const &fn)
|
||||
{
|
||||
node.for_each_attribute([&] (Xml_attribute const &attr) {
|
||||
if (attr.has_type(attr_name))
|
||||
attr.with_raw_value(fn); });
|
||||
};
|
||||
|
||||
env.config([&] (Xml_node const &node) {
|
||||
|
||||
int envc = 0;
|
||||
@ -62,9 +69,7 @@ static void populate_args_and_env(Libc::Env &env, int &argc, char **&argv, char
|
||||
|
||||
/* insert an argument */
|
||||
if (node.has_type("arg")) {
|
||||
|
||||
Xml_attribute attr = node.attribute("value");
|
||||
attr.with_raw_value([&] (char const *start, size_t length) {
|
||||
with_raw_attr(node, "value", [&] (char const *start, size_t length) {
|
||||
|
||||
size_t const size = length + 1; /* for null termination */
|
||||
|
||||
@ -72,7 +77,6 @@ static void populate_args_and_env(Libc::Env &env, int &argc, char **&argv, char
|
||||
|
||||
Genode::copy_cstring(argv[arg_i], start, size);
|
||||
});
|
||||
|
||||
++arg_i;
|
||||
}
|
||||
else
|
||||
@ -87,17 +91,15 @@ static void populate_args_and_env(Libc::Env &env, int &argc, char **&argv, char
|
||||
check_attr(node, "key");
|
||||
check_attr(node, "value");
|
||||
|
||||
Xml_attribute const key = node.attribute("key");
|
||||
Xml_attribute const value = node.attribute("value");
|
||||
|
||||
using namespace Genode;
|
||||
|
||||
/*
|
||||
* An environment variable has the form <key>=<value>, followed
|
||||
* by a terminating zero.
|
||||
*/
|
||||
size_t const var_size = key .value_size() + 1
|
||||
+ value.value_size() + 1;
|
||||
size_t var_size = 1 + 1;
|
||||
with_raw_attr(node, "key", [&] (char const *, size_t l) { var_size += l; });
|
||||
with_raw_attr(node, "value", [&] (char const *, size_t l) { var_size += l; });
|
||||
|
||||
envp[env_i] = (char*)malloc(var_size);
|
||||
|
||||
@ -116,19 +118,18 @@ static void populate_args_and_env(Libc::Env &env, int &argc, char **&argv, char
|
||||
pos += len;
|
||||
};
|
||||
|
||||
key.with_raw_value([&] (char const *start, size_t length) {
|
||||
with_raw_attr(node, "key", [&] (char const *start, size_t length) {
|
||||
append(start, length); });
|
||||
|
||||
append("=", 1);
|
||||
|
||||
value.with_raw_value([&] (char const *start, size_t length) {
|
||||
with_raw_attr(node, "value", [&] (char const *start, size_t length) {
|
||||
append(start, length); });
|
||||
|
||||
++env_i;
|
||||
|
||||
}
|
||||
catch (Xml_node::Nonexistent_sub_node) { }
|
||||
catch (Xml_node::Nonexistent_attribute) { }
|
||||
});
|
||||
|
||||
/* argv and envp are both NULL terminated */
|
||||
|
@ -290,10 +290,9 @@ extern "C" FILE *fopen(const char *path, const char *mode)
|
||||
seek_offset);
|
||||
});
|
||||
|
||||
gcov_env->fs.close(annotate_file_handle);
|
||||
gcov_env->fs.close(annotate_file_handle);
|
||||
}
|
||||
catch (Xml_node::Nonexistent_sub_node) { }
|
||||
catch (Xml_attribute::Nonexistent_attribute) { }
|
||||
|
||||
return &gcov_env->file;
|
||||
}
|
||||
|
@ -41,30 +41,21 @@ struct Test_failed : Genode::Exception { };
|
||||
}
|
||||
|
||||
|
||||
static void test_write_read(Genode::Xml_node node)
|
||||
static void test_write_read(Genode::Xml_node const &config)
|
||||
{
|
||||
size_t rounds = 4;
|
||||
size_t rounds = 4u;
|
||||
size_t size = 4*1024*1024;
|
||||
size_t buffer_size = 32*1024;
|
||||
|
||||
try {
|
||||
Genode::Xml_node config = node.sub_node("write-read");
|
||||
config.with_optional_sub_node("write-read", [&] (Genode::Xml_node const &node) {
|
||||
using Num_bytes = Genode::Number_of_bytes;
|
||||
rounds = node.attribute_value("rounds", rounds);
|
||||
size = node.attribute_value("size", Num_bytes{size});
|
||||
buffer_size = node.attribute_value("buffer_size", Num_bytes{buffer_size});
|
||||
});
|
||||
|
||||
rounds = config.attribute_value("rounds", rounds);
|
||||
|
||||
Genode::Number_of_bytes n { };
|
||||
try {
|
||||
config.attribute("size").value(n);
|
||||
size = n;
|
||||
} catch (...) { }
|
||||
try {
|
||||
config.attribute("buffer_size").value(n);
|
||||
buffer_size = n;
|
||||
} catch (...) { }
|
||||
} catch (...) { }
|
||||
|
||||
void *buf = malloc(buffer_size);
|
||||
char const *file_name = "write_read.tst";
|
||||
void * const buf = malloc(buffer_size);
|
||||
char const * const file_name = "write_read.tst";
|
||||
|
||||
printf("write-read test: %zu rounds of %zu MiB (buffer size %zu)\n",
|
||||
rounds, size/(1024*1024), buffer_size);
|
||||
@ -112,9 +103,8 @@ static void test(Genode::Xml_node node)
|
||||
|
||||
unsigned int iterations = 1;
|
||||
|
||||
try {
|
||||
node.sub_node("iterations").attribute("value").value(iterations);
|
||||
} catch(...) { }
|
||||
node.with_optional_sub_node("iterations", [&] (Genode::Xml_node const &iter) {
|
||||
iterations = iter.attribute_value("value", iterations); });
|
||||
|
||||
for (unsigned int i = 0; i < iterations; i++) {
|
||||
|
||||
|
@ -30,8 +30,6 @@ struct Send_failed : Genode::Exception { };
|
||||
struct Receive_failed : Genode::Exception { };
|
||||
struct Bind_failed : Genode::Exception { };
|
||||
|
||||
struct Read_port_attr_failed : Genode::Exception { };
|
||||
|
||||
|
||||
static void test(Libc::Env & env)
|
||||
{
|
||||
@ -42,12 +40,9 @@ static void test(Libc::Env & env)
|
||||
}
|
||||
/* read server port */
|
||||
unsigned port = 0;
|
||||
env.config([&] (Xml_node config_node) {
|
||||
try { config_node.attribute("port").value(port); }
|
||||
catch (...) {
|
||||
throw Read_port_attr_failed();
|
||||
}
|
||||
});
|
||||
env.config([&] (Xml_node const &config_node) {
|
||||
port = config_node.attribute_value("port", 0u); });
|
||||
|
||||
/* create server socket address */
|
||||
struct sockaddr_in in_addr;
|
||||
in_addr.sin_family = AF_INET;
|
||||
|
@ -394,18 +394,7 @@ class Vfs::Dir_file_system : public File_system
|
||||
continue;
|
||||
}
|
||||
|
||||
Genode::error("failed to create <", sub_node.type(), "> VFS node");
|
||||
try {
|
||||
for (unsigned i = 0; i < 16; ++i) {
|
||||
|
||||
Xml_attribute const attr = sub_node.attribute(i);
|
||||
|
||||
String<64> value { };
|
||||
attr.value(value);
|
||||
|
||||
Genode::error("\t", attr.name(), "=\"", value, "\"");
|
||||
}
|
||||
} catch (Xml_node::Nonexistent_attribute) { }
|
||||
Genode::error("failed to create VFS node: ", sub_node);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,12 +40,10 @@ struct Sequence::Child : Genode::Child_policy
|
||||
|
||||
Binary_name _start_binary()
|
||||
{
|
||||
Binary_name name;
|
||||
try {
|
||||
_start_node.sub_node("binary").attribute("name").value(name);
|
||||
return name != "" ? name : _name;
|
||||
}
|
||||
catch (...) { return _name; }
|
||||
Binary_name name = _name;
|
||||
_start_node.with_optional_sub_node("binary", [&] (Xml_node const &binary) {
|
||||
name = binary.attribute_value("name", _name); });
|
||||
return name;
|
||||
}
|
||||
|
||||
Binary_name const _binary_name = _start_binary();
|
||||
|
@ -205,9 +205,9 @@ class Dynamic_rom::Root : public Genode::Root_component<Session_component>
|
||||
{
|
||||
/* lookup ROM module in config */
|
||||
for (unsigned i = 0; i < _config_node.num_sub_nodes(); i++) {
|
||||
Xml_node node = _config_node.sub_node(i);
|
||||
if (node.has_attribute("name")
|
||||
&& node.attribute("name").has_value(name.string()))
|
||||
Xml_node const node = _config_node.sub_node(i);
|
||||
|
||||
if (node.attribute_value("name", Genode::String<64>()) == name)
|
||||
return node;
|
||||
}
|
||||
throw Nonexistent_rom_module();
|
||||
|
@ -25,14 +25,13 @@ namespace Genode {
|
||||
char const *name,
|
||||
uint64_t const default_sec);
|
||||
|
||||
template <typename FUNC>
|
||||
void xml_node_with_attribute(Xml_node const node,
|
||||
void xml_node_with_attribute(Xml_node const &node,
|
||||
char const *name,
|
||||
FUNC && func)
|
||||
auto const &fn)
|
||||
{
|
||||
if (node.has_attribute(name)) {
|
||||
func(node.attribute(name));
|
||||
}
|
||||
node.for_each_attribute([&] (Xml_attribute const &attr) {
|
||||
if (attr.has_type(name))
|
||||
fn(attr); });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ void Global_keys::apply_config(Xml_node config, Session_list &session_list)
|
||||
|
||||
/* assign policy to matching client session */
|
||||
for (Gui_session *s = session_list.first(); s; s = s->next())
|
||||
if (node.attribute("label").has_value(s->label().string()))
|
||||
if (node.attribute_value("label", String<128>()) == s->label().string())
|
||||
policy->client(s);
|
||||
}
|
||||
|
||||
|
@ -327,16 +327,17 @@ class Block::Main : Rpc_object<Typed_root<Session>>,
|
||||
/* sessions are not writeable by default */
|
||||
writeable = policy.attribute_value("writeable", false);
|
||||
|
||||
} catch (Xml_node::Nonexistent_attribute) {
|
||||
error("policy does not define partition number for for '",
|
||||
label, "'");
|
||||
throw Service_denied();
|
||||
} catch (Session_policy::No_policy_defined) {
|
||||
error("rejecting session request, no matching policy for '",
|
||||
label, "'");
|
||||
throw Service_denied();
|
||||
}
|
||||
|
||||
if (num == -1) {
|
||||
error("policy does not define partition number for for '", label, "'");
|
||||
throw Service_denied();
|
||||
}
|
||||
|
||||
if (!_partition_table.partition_valid(num)) {
|
||||
error("Partition ", num, " unavailable for '", label, "'");
|
||||
throw Service_denied();
|
||||
|
@ -195,7 +195,8 @@ struct Test_tracing
|
||||
|
||||
Constructible<Trace_buffer_monitor> test_monitor { };
|
||||
|
||||
typedef Genode::String<64> String;
|
||||
using String = Genode::String<64>;
|
||||
|
||||
String policy_label { };
|
||||
String policy_module { };
|
||||
String policy_thread { };
|
||||
@ -210,12 +211,13 @@ struct Test_tracing
|
||||
|
||||
log("test Tracing");
|
||||
|
||||
try {
|
||||
Xml_node policy = config.xml().sub_node("trace_policy");
|
||||
policy.attribute("label").value(policy_label);
|
||||
policy.attribute("module").value(policy_module);
|
||||
policy.attribute("thread").value(policy_thread);
|
||||
config.xml().with_optional_sub_node("trace_policy", [&] (Xml_node const &policy) {
|
||||
policy_label = policy.attribute_value("label", String());
|
||||
policy_module = policy.attribute_value("module", String());
|
||||
policy_thread = policy.attribute_value("thread", String());
|
||||
});
|
||||
|
||||
try {
|
||||
Rom_connection policy_rom(env, policy_module.string());
|
||||
policy_module_rom_ds = policy_rom.dataspace();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user