2015-06-08 09:05:32 +02:00
|
|
|
/*
|
|
|
|
* \brief Connection to Platform service
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2008-08-22
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2008-2017 Genode Labs GmbH
|
2015-06-08 09:05:32 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2015-06-08 09:05:32 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
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 22:03:22 +02:00
|
|
|
#include <util/retry.h>
|
2015-06-08 09:05:32 +02:00
|
|
|
#include <base/connection.h>
|
|
|
|
#include <platform_session/client.h>
|
|
|
|
|
|
|
|
namespace Platform { struct Connection; }
|
|
|
|
|
|
|
|
|
|
|
|
struct Platform::Connection : Genode::Connection<Session>, Client
|
|
|
|
{
|
2016-05-10 17:24:51 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
Connection(Genode::Env &env)
|
|
|
|
:
|
2019-01-30 17:27:46 +01:00
|
|
|
Genode::Connection<Session>(env, session(env.parent(),
|
|
|
|
"ram_quota=16K, cap_quota=%u",
|
2017-05-07 22:03:25 +02:00
|
|
|
CAP_QUOTA)),
|
2016-05-10 17:24:51 +02:00
|
|
|
Client(cap())
|
|
|
|
{ }
|
|
|
|
|
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 22:03:22 +02:00
|
|
|
template <typename FUNC>
|
|
|
|
auto with_upgrade(FUNC func) -> decltype(func())
|
|
|
|
{
|
|
|
|
return Genode::retry<Genode::Out_of_ram>(
|
|
|
|
[&] () {
|
|
|
|
return Genode::retry<Genode::Out_of_caps>(
|
|
|
|
[&] () { return func(); },
|
|
|
|
[&] () { this->upgrade_caps(2); });
|
|
|
|
},
|
|
|
|
[&] () { this->upgrade_ram(4096); }
|
|
|
|
);
|
|
|
|
}
|
2015-06-08 09:05:32 +02:00
|
|
|
};
|