mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-18 02:40:08 +00:00
parent
d4047e9af7
commit
8698e693d5
@ -67,8 +67,9 @@ class Main
|
||||
Monitor_tree _monitors_0 { };
|
||||
Monitor_tree _monitors_1 { };
|
||||
bool _monitors_switch { false };
|
||||
Policy_tree _policies { };
|
||||
Policy _default_policy { _env, _trace, _config.default_policy_name };
|
||||
Policy_dict _policies { };
|
||||
Policy _default_policy { _env, _trace, _policies,
|
||||
_config.default_policy_name };
|
||||
unsigned long _report_id { 0 };
|
||||
|
||||
static void _print_monitors(Allocator &alloc, Monitor_tree const &,
|
||||
@ -181,15 +182,15 @@ class Main
|
||||
Policy_name const policy_name =
|
||||
session_policy.attribute_value("policy", _config.default_policy_name);
|
||||
|
||||
try {
|
||||
_trace.trace(id.id, _policies.find_by_name(policy_name).id(), buffer_sz);
|
||||
|
||||
}
|
||||
catch (Policy_tree::No_match) {
|
||||
Policy &policy = *new (_heap) Policy(_env, _trace, policy_name);
|
||||
_policies.insert(policy);
|
||||
_policies.with_element(policy_name,
|
||||
[&] (Policy const &policy) {
|
||||
_trace.trace(id.id, policy.id(), buffer_sz);
|
||||
},
|
||||
[&] /* no match */ {
|
||||
Policy &policy = *new (_heap) Policy(_env, _trace, _policies, policy_name);
|
||||
_trace.trace(id.id, policy.id(), buffer_sz);
|
||||
}
|
||||
);
|
||||
monitors.insert(new (_heap) Monitor(_trace, _env.rm(), id));
|
||||
}
|
||||
catch (Trace::Source_is_dead ) { warn_msg("Source_is_dead" ); return; }
|
||||
@ -215,8 +216,6 @@ class Main
|
||||
|
||||
Main(Env &env) : _env(env)
|
||||
{
|
||||
_policies.insert(_default_policy);
|
||||
|
||||
_update_monitors();
|
||||
}
|
||||
};
|
||||
|
@ -17,24 +17,10 @@
|
||||
using namespace Genode;
|
||||
|
||||
|
||||
/***********************
|
||||
** Policy_avl_member **
|
||||
***********************/
|
||||
|
||||
Policy_avl_member::Policy_avl_member(Policy_name const &name,
|
||||
::Policy &policy)
|
||||
Policy::Policy(Env &env, Trace::Connection &trace, Policy_dict &dict,
|
||||
Policy_name const &name)
|
||||
:
|
||||
Avl_string_base(name.string()), _policy(policy)
|
||||
{ }
|
||||
|
||||
|
||||
/************
|
||||
** Policy **
|
||||
************/
|
||||
|
||||
Policy::Policy(Env &env, Trace::Connection &trace, Policy_name const &name)
|
||||
:
|
||||
Policy_base(name), _avl_member(_name, *this), _env(env), _trace(trace)
|
||||
Policy_dict::Element(dict, name), _env(env), _trace(trace)
|
||||
{
|
||||
Dataspace_capability dst_ds = _trace.policy(_id);
|
||||
void *dst = _env.rm().attach(dst_ds);
|
||||
@ -43,26 +29,3 @@ Policy::Policy(Env &env, Trace::Connection &trace, Policy_name const &name)
|
||||
_env.rm().detach(dst);
|
||||
_env.rm().detach(src);
|
||||
}
|
||||
|
||||
|
||||
/*****************
|
||||
** Policy_tree **
|
||||
*****************/
|
||||
|
||||
Policy &Policy_tree::policy(Avl_string_base const &node)
|
||||
{
|
||||
return static_cast<Policy_avl_member const *>(&node)->policy();
|
||||
}
|
||||
|
||||
|
||||
Policy &Policy_tree::find_by_name(Policy_name name)
|
||||
{
|
||||
if (name == Policy_name() || !first()) {
|
||||
throw No_match(); }
|
||||
|
||||
Avl_string_base *node = first()->find_by_name(name.string());
|
||||
if (!node) {
|
||||
throw No_match(); }
|
||||
|
||||
return policy(*node);
|
||||
}
|
||||
|
@ -18,103 +18,36 @@
|
||||
#include <rom_session/connection.h>
|
||||
#include <trace_session/connection.h>
|
||||
#include <dataspace/client.h>
|
||||
#include <util/avl_string.h>
|
||||
|
||||
using Policy_name = Genode::String<40>;
|
||||
#include <util/dictionary.h>
|
||||
|
||||
class Policy;
|
||||
|
||||
|
||||
/**
|
||||
* Member of a policy that allows the policy to be managed in a tree
|
||||
*/
|
||||
class Policy_avl_member : public Genode::Avl_string_base
|
||||
{
|
||||
private:
|
||||
|
||||
::Policy &_policy;
|
||||
|
||||
public:
|
||||
|
||||
Policy_avl_member(Policy_name const &name,
|
||||
::Policy &policy);
|
||||
|
||||
|
||||
/***************
|
||||
** Accessors **
|
||||
***************/
|
||||
|
||||
::Policy &policy() const { return _policy; }
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Ensure that policy name is constructed before it is used as tree index
|
||||
*/
|
||||
class Policy_base
|
||||
{
|
||||
protected:
|
||||
|
||||
Policy_name const _name;
|
||||
|
||||
Policy_base(Policy_name const &name) : _name(name) { }
|
||||
};
|
||||
using Policy_name = Genode::String<40>;
|
||||
using Policy_dict = Genode::Dictionary<Policy, Policy_name>;
|
||||
|
||||
|
||||
/**
|
||||
* Installs and maintains a tracing policy
|
||||
*/
|
||||
class Policy : public Policy_base
|
||||
class Policy : public Policy_dict::Element
|
||||
{
|
||||
private:
|
||||
|
||||
Policy_avl_member _avl_member;
|
||||
Genode::Env &_env;
|
||||
Genode::Trace::Connection &_trace;
|
||||
Genode::Rom_connection _rom { _env, _name.string() };
|
||||
Genode::Rom_connection _rom { _env, name };
|
||||
Genode::Rom_dataspace_capability const _ds { _rom.dataspace() };
|
||||
Genode::size_t const _size { Genode::Dataspace_client(_ds).size() };
|
||||
Genode::Trace::Policy_id const _id { _trace.alloc_policy(_size) };
|
||||
|
||||
public:
|
||||
|
||||
|
||||
Policy(Genode::Env &env,
|
||||
Genode::Trace::Connection &trace,
|
||||
Policy_dict &dict,
|
||||
Policy_name const &name);
|
||||
|
||||
|
||||
/***************
|
||||
** Accessors **
|
||||
***************/
|
||||
|
||||
Genode::Trace::Policy_id id() const { return _id; }
|
||||
Policy_avl_member &avl_member() { return _avl_member; }
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* AVL tree of policies with their name as index
|
||||
*/
|
||||
struct Policy_tree : Genode::Avl_tree<Genode::Avl_string_base>
|
||||
{
|
||||
using Avl_tree = Genode::Avl_tree<Genode::Avl_string_base>;
|
||||
|
||||
struct No_match : Genode::Exception { };
|
||||
|
||||
static ::Policy &policy(Genode::Avl_string_base const &node);
|
||||
|
||||
::Policy &find_by_name(Policy_name name);
|
||||
|
||||
template <typename FUNC>
|
||||
void for_each(FUNC && functor) const {
|
||||
Avl_tree::for_each([&] (Genode::Avl_string_base const &node) {
|
||||
functor(policy(node));
|
||||
});
|
||||
}
|
||||
|
||||
void insert(::Policy &policy) { Avl_tree::insert(&policy.avl_member()); }
|
||||
};
|
||||
|
||||
|
||||
#endif /* _POLICY_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user