2015-09-23 17:08:53 +02:00
|
|
|
/*
|
|
|
|
* \brief Clipboard used for copy and paste between domains
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2015-09-23
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2015-2017 Genode Labs GmbH
|
2015-09-23 17:08:53 +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-09-23 17:08:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/heap.h>
|
2016-07-07 10:13:39 +02:00
|
|
|
#include <base/component.h>
|
2017-01-10 14:13:35 +01:00
|
|
|
#include <base/attached_rom_dataspace.h>
|
2015-09-23 17:08:53 +02:00
|
|
|
#include <report_rom/rom_service.h>
|
|
|
|
#include <report_rom/report_service.h>
|
|
|
|
|
2016-07-07 10:13:39 +02:00
|
|
|
namespace Clipboard { struct Main; }
|
2015-09-23 17:08:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The clipboard uses a single ROM module for all clients
|
|
|
|
*/
|
|
|
|
struct Rom::Registry : Rom::Registry_for_reader, Rom::Registry_for_writer
|
|
|
|
{
|
|
|
|
Module module;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rom::Registry_for_writer interface
|
|
|
|
*/
|
2015-10-28 16:14:11 +01:00
|
|
|
Module &lookup(Writer &writer, Module::Name const &) override
|
|
|
|
{
|
|
|
|
module._register(writer);
|
|
|
|
return module;
|
|
|
|
}
|
|
|
|
|
|
|
|
void release(Writer &writer, Module &) override
|
|
|
|
{
|
|
|
|
module._unregister(writer);
|
|
|
|
}
|
2015-09-23 17:08:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Rom::Registry_for_reader interface
|
|
|
|
*/
|
|
|
|
Module &lookup(Reader &reader, Module::Name const &) override
|
|
|
|
{
|
|
|
|
module._register(reader);
|
|
|
|
return module;
|
|
|
|
}
|
|
|
|
|
|
|
|
void release(Reader &reader, Readable_module &) override
|
|
|
|
{
|
|
|
|
module._unregister(reader);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2019-01-21 10:48:39 +01:00
|
|
|
Registry(Genode::Ram_allocator &ram, Genode::Region_map &rm,
|
2016-10-07 15:36:23 +02:00
|
|
|
Module::Read_policy const &read_policy,
|
2015-09-23 17:08:53 +02:00
|
|
|
Module::Write_policy const &write_policy)
|
|
|
|
:
|
2016-10-07 15:36:23 +02:00
|
|
|
module(ram, rm, "clipboard", read_policy, write_policy)
|
2015-09-23 17:08:53 +02:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-07-07 10:13:39 +02:00
|
|
|
struct Clipboard::Main : Rom::Module::Read_policy, Rom::Module::Write_policy
|
2015-09-23 17:08:53 +02:00
|
|
|
{
|
2016-07-07 10:13:39 +02:00
|
|
|
Genode::Env &_env;
|
2015-09-23 17:08:53 +02:00
|
|
|
|
2017-01-10 14:13:35 +01:00
|
|
|
Genode::Sliced_heap _sliced_heap = { _env.ram(), _env.rm() };
|
2016-07-07 10:13:39 +02:00
|
|
|
|
|
|
|
Genode::Attached_rom_dataspace _config { _env, "config" };
|
|
|
|
|
2015-09-23 17:08:53 +02:00
|
|
|
bool _verbose_config()
|
|
|
|
{
|
|
|
|
char const *attr = "verbose";
|
2016-07-07 10:13:39 +02:00
|
|
|
return _config.xml().attribute_value(attr, false);
|
2015-09-23 17:08:53 +02:00
|
|
|
}
|
|
|
|
|
2019-02-09 16:25:43 +01:00
|
|
|
bool verbose { _verbose_config() };
|
2015-09-23 17:08:53 +02:00
|
|
|
|
|
|
|
typedef Genode::String<100> Domain;
|
|
|
|
|
2017-01-10 14:13:35 +01:00
|
|
|
Genode::Attached_rom_dataspace _focus_ds { _env, "focus" };
|
2015-09-23 17:08:53 +02:00
|
|
|
|
2019-02-09 16:25:43 +01:00
|
|
|
Genode::Signal_handler<Main> _config_handler =
|
|
|
|
{ _env.ep(), *this, &Main::_handle_config };
|
2016-07-07 10:13:39 +02:00
|
|
|
Genode::Signal_handler<Main> _focus_handler =
|
|
|
|
{ _env.ep(), *this, &Main::_handle_focus };
|
2015-09-23 17:08:53 +02:00
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
Domain _focused_domain { };
|
2015-09-23 17:08:53 +02:00
|
|
|
|
2019-02-09 16:25:43 +01:00
|
|
|
/**
|
|
|
|
* Handle configuration changes
|
|
|
|
*/
|
|
|
|
void _handle_config()
|
|
|
|
{
|
|
|
|
_config.update();
|
|
|
|
verbose = _verbose_config();
|
|
|
|
}
|
|
|
|
|
2015-09-23 17:08:53 +02:00
|
|
|
/**
|
|
|
|
* Handle the change of the current nitpicker focus
|
|
|
|
*
|
|
|
|
* We only accept reports from the currently focused domain.
|
|
|
|
*/
|
2016-07-07 10:13:39 +02:00
|
|
|
void _handle_focus()
|
2015-09-23 17:08:53 +02:00
|
|
|
{
|
|
|
|
_focus_ds.update();
|
|
|
|
|
|
|
|
_focused_domain = Domain();
|
|
|
|
|
|
|
|
try {
|
|
|
|
Genode::Xml_node focus(_focus_ds.local_addr<char>(), _focus_ds.size());
|
|
|
|
|
2016-06-09 15:55:13 +02:00
|
|
|
if (focus.attribute_value("active", false))
|
2015-09-23 17:08:53 +02:00
|
|
|
_focused_domain = focus.attribute_value("domain", Domain());
|
|
|
|
|
|
|
|
} catch (...) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
Domain _domain(Genode::Session_label const &label) const
|
|
|
|
{
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
try {
|
2016-07-07 10:13:39 +02:00
|
|
|
return Session_policy(label, _config.xml()).attribute_value("domain", Domain());
|
2015-09-23 17:08:53 +02:00
|
|
|
} catch (Session_policy::No_policy_defined) { }
|
|
|
|
|
|
|
|
return Domain();
|
|
|
|
}
|
|
|
|
|
|
|
|
Domain _domain(Rom::Reader const &reader) const
|
|
|
|
{
|
|
|
|
Rom::Session_component const &rom_session =
|
|
|
|
static_cast<Rom::Session_component const &>(reader);
|
|
|
|
|
|
|
|
return _domain(rom_session.label());
|
|
|
|
}
|
|
|
|
|
|
|
|
Domain _domain(Rom::Writer const &writer) const
|
|
|
|
{
|
|
|
|
Report::Session_component const &report_session =
|
|
|
|
static_cast<Report::Session_component const &>(writer);
|
|
|
|
|
|
|
|
return _domain(report_session.label());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _flow_defined(Domain const &from, Domain const &to) const
|
|
|
|
{
|
|
|
|
if (!from.valid() || !to.valid())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Search config for flow node with matching 'from' and 'to'
|
|
|
|
* attributes.
|
|
|
|
*/
|
|
|
|
bool result = false;
|
|
|
|
try {
|
|
|
|
|
|
|
|
auto match_flow = [&] (Genode::Xml_node flow) {
|
|
|
|
if (flow.attribute_value("from", Domain()) == from
|
|
|
|
&& flow.attribute_value("to", Domain()) == to)
|
2016-07-07 10:13:39 +02:00
|
|
|
result = true; };
|
2015-09-23 17:08:53 +02:00
|
|
|
|
2016-07-07 10:13:39 +02:00
|
|
|
_config.xml().for_each_sub_node("flow", match_flow);
|
2015-09-23 17:08:53 +02:00
|
|
|
|
|
|
|
} catch (Genode::Xml_node::Nonexistent_sub_node) { }
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rom::Module::Read_policy interface
|
|
|
|
*/
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
bool read_permitted(Rom::Module const &,
|
2015-09-23 17:08:53 +02:00
|
|
|
Rom::Writer const &writer,
|
|
|
|
Rom::Reader const &reader) const override
|
|
|
|
{
|
|
|
|
Domain const from_domain = _domain(writer);
|
|
|
|
Domain const to_domain = _domain(reader);
|
|
|
|
|
|
|
|
if (from_domain == to_domain)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (_flow_defined(from_domain, to_domain))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rom::Module::Write_policy interface
|
|
|
|
*/
|
|
|
|
bool write_permitted(Rom::Module const &module,
|
|
|
|
Rom::Writer const &writer) const override
|
|
|
|
{
|
|
|
|
if (_focused_domain.valid() && _domain(writer) == _focused_domain)
|
|
|
|
return true;
|
|
|
|
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
warning("unexpected attempt by '", writer.label(), "' "
|
|
|
|
"to write to '", module.name(), "'");
|
2015-09-23 17:08:53 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-07 10:13:39 +02:00
|
|
|
|
2016-10-07 15:36:23 +02:00
|
|
|
Rom::Registry _rom_registry { _env.ram(), _env.rm(), *this, *this };
|
2015-09-23 17:08:53 +02:00
|
|
|
|
2016-07-07 10:13:39 +02:00
|
|
|
Report::Root report_root = { _env, _sliced_heap, _rom_registry, verbose };
|
|
|
|
Rom ::Root rom_root = { _env, _sliced_heap, _rom_registry };
|
2015-09-23 17:08:53 +02:00
|
|
|
|
2016-07-07 10:13:39 +02:00
|
|
|
Main(Genode::Env &env) : _env(env)
|
2015-09-23 17:08:53 +02:00
|
|
|
{
|
2016-07-07 10:13:39 +02:00
|
|
|
_focus_ds.sigh(_focus_handler);
|
2015-09-23 17:08:53 +02:00
|
|
|
|
2018-01-05 17:17:02 +01:00
|
|
|
_handle_focus();
|
2016-07-07 10:13:39 +02:00
|
|
|
env.parent().announce(env.ep().manage(report_root));
|
|
|
|
env.parent().announce(env.ep().manage(rom_root));
|
2015-09-23 17:08:53 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-11-28 15:13:14 +01:00
|
|
|
void Component::construct(Genode::Env &env) { static Clipboard::Main main(env); }
|