2013-06-13 08:39:59 +00:00
|
|
|
/*
|
|
|
|
* \brief Regulator-session component
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2013-06-13
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2013-2017 Genode Labs GmbH
|
2013-06-13 08:39:59 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2013-06-13 08:39:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__REGULATOR__COMPONENT_H_
|
|
|
|
#define _INCLUDE__REGULATOR__COMPONENT_H_
|
|
|
|
|
|
|
|
#include <root/component.h>
|
|
|
|
#include <regulator_session/rpc_object.h>
|
|
|
|
#include <regulator/driver.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Regulator {
|
|
|
|
class Session_component;
|
|
|
|
class Root;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Regulator::Session_component : public Regulator::Session_rpc_object
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2017-01-04 12:47:20 +00:00
|
|
|
Driver_factory & _driver_factory;
|
|
|
|
Driver & _driver;
|
2013-06-13 08:39:59 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-01-04 12:47:20 +00:00
|
|
|
Session_component(Regulator_id regulator_id,
|
|
|
|
Driver_factory & driver_factory)
|
2013-06-13 08:39:59 +00:00
|
|
|
: Session_rpc_object(regulator_id),
|
|
|
|
_driver_factory(driver_factory),
|
|
|
|
_driver(_driver_factory.create(regulator_id)) { }
|
|
|
|
|
2013-06-28 12:24:34 +00:00
|
|
|
~Session_component()
|
|
|
|
{
|
|
|
|
_driver.state(_id, false);
|
|
|
|
_driver_factory.destroy(_driver);
|
|
|
|
}
|
2013-06-13 08:39:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************
|
|
|
|
** Regulator session interface **
|
|
|
|
***********************************/
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void level(unsigned long level) override { _driver.level(_id, level); }
|
|
|
|
unsigned long level() override { return _driver.level(_id); }
|
|
|
|
void state(bool enable) override { _driver.state(_id, enable); }
|
|
|
|
bool state() override { return _driver.state(_id); }
|
2013-06-13 08:39:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Regulator::Root :
|
|
|
|
public Genode::Root_component<Regulator::Session_component>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2017-01-04 12:47:20 +00:00
|
|
|
Regulator::Driver_factory & _driver_factory;
|
2013-06-13 08:39:59 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
Session_component *_create_session(const char *args) override
|
2013-06-13 08:39:59 +00:00
|
|
|
{
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
char reg_name[64];
|
|
|
|
Arg_string::find_arg(args, "regulator").string(reg_name,
|
|
|
|
sizeof(reg_name), 0);
|
|
|
|
size_t ram_quota =
|
|
|
|
Arg_string::find_arg(args, "ram_quota").ulong_value(0);
|
|
|
|
|
|
|
|
/* delete ram quota by the memory needed for the session */
|
|
|
|
size_t session_size = max((size_t)4096,
|
|
|
|
sizeof(Session_component));
|
|
|
|
if (ram_quota < session_size)
|
2017-05-08 12:32:03 +00:00
|
|
|
throw Insufficient_ram_quota();
|
2013-06-13 08:39:59 +00:00
|
|
|
|
|
|
|
if (!strlen(reg_name))
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 20:03:22 +00:00
|
|
|
throw Service_denied();
|
2013-06-13 08:39:59 +00:00
|
|
|
|
|
|
|
return new (md_alloc())
|
|
|
|
Session_component(regulator_id_by_name(reg_name),
|
|
|
|
_driver_factory);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-01-04 12:47:20 +00:00
|
|
|
Root(Genode::Env & env,
|
|
|
|
Genode::Allocator & md_alloc,
|
|
|
|
Regulator::Driver_factory & driver_factory)
|
|
|
|
: Genode::Root_component<Regulator::Session_component>(env.ep(),
|
2013-06-13 08:39:59 +00:00
|
|
|
md_alloc),
|
2017-01-04 12:47:20 +00:00
|
|
|
_driver_factory(driver_factory) { }
|
2013-06-13 08:39:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__REGULATOR__COMPONENT_H_ */
|