mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-24 15:56:41 +00:00
init: add 'label' criterion for session routing
This patch introduces a shortcut for conditional session routes of the form '<if-arg key="label" value="..."/>'. With this change, the label can be directly specified as 'label' attribute of an '<any-service>' or a '<service>' node. The '<if-arg>' mechanism was not documented anyway and I hope to be able to ultimately remove it.
This commit is contained in:
parent
b26ac3c4fb
commit
a528aa097a
@ -22,6 +22,7 @@
|
||||
#include <cap_session/connection.h>
|
||||
#include <base/printf.h>
|
||||
#include <base/child.h>
|
||||
#include <os/session_policy.h>
|
||||
|
||||
/* init includes */
|
||||
#include <init/child_config.h>
|
||||
@ -122,19 +123,6 @@ namespace Init {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return true if service XML node matches the specified service name
|
||||
*/
|
||||
inline bool service_node_matches(Genode::Xml_node service_node, const char *service_name)
|
||||
{
|
||||
if (service_node.has_type("any-service"))
|
||||
return true;
|
||||
|
||||
return service_node.has_type("service")
|
||||
&& service_node.attribute("name").has_value(service_name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return sub string of label with the leading child name stripped out
|
||||
*
|
||||
@ -170,6 +158,40 @@ namespace Init {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return true if service XML node matches service request
|
||||
*
|
||||
* \param args session arguments, inspected for the session label
|
||||
* \param child_name name of the originator of the session request
|
||||
* \param service_name name of the requested service
|
||||
*/
|
||||
inline bool service_node_matches(Genode::Xml_node service_node,
|
||||
char const *args,
|
||||
char const *child_name,
|
||||
char const *service_name)
|
||||
{
|
||||
bool const service_matches =
|
||||
service_node.has_type("any-service") ||
|
||||
(service_node.has_type("service") &&
|
||||
service_node.attribute("name").has_value(service_name));
|
||||
|
||||
if (!service_matches)
|
||||
return false;
|
||||
|
||||
if (!service_node.has_attribute("label"))
|
||||
return true;
|
||||
|
||||
typedef Genode::String<160> Label;
|
||||
|
||||
Label const expected = service_node.attribute_value("label", Label());
|
||||
|
||||
Label const session_label =
|
||||
Label(skip_label_prefix(child_name, Genode::Session_label(args).string()));
|
||||
|
||||
return session_label == expected;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if arguments satisfy the condition specified for the route
|
||||
*/
|
||||
@ -651,7 +673,7 @@ class Init::Child : Genode::Child_policy
|
||||
|
||||
bool service_wildcard = service_node.has_type("any-service");
|
||||
|
||||
if (!service_node_matches(service_node, service_name))
|
||||
if (!service_node_matches(service_node, args, name(), service_name))
|
||||
continue;
|
||||
|
||||
if (!service_node_args_condition_satisfied(service_node, args, name()))
|
||||
|
Loading…
Reference in New Issue
Block a user