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