Deprecate Genode::config()

Issue #1959
This commit is contained in:
Norman Feske 2016-11-25 16:54:49 +01:00
parent 3d7b92ea50
commit 3315294f2d
43 changed files with 1158 additions and 1278 deletions

View File

@ -231,7 +231,7 @@ class Launchpad
/**
* Process launchpad XML configuration
*/
void process_config();
void process_config(Genode::Xml_node);
/*************************

View File

@ -12,6 +12,7 @@
*/
#include <base/component.h>
#include <base/attached_rom_dataspace.h>
#include <scout/platform.h>
#include <scout/tick.h>
@ -25,7 +26,6 @@
#include <base/env.h>
#include <init/child_config.h>
#include <os/config.h>
/**
@ -77,16 +77,6 @@ class Avail_quota_update : public Scout::Tick
};
static long read_int_attr_from_config(const char *attr, long default_value)
{
long result = default_value;
try {
Genode::config()->xml_node().attribute(attr).value(&result);
} catch (...) { }
return result;
}
struct Main : Scout::Event_handler
{
Scout::Platform &_pf;
@ -134,10 +124,12 @@ void Component::construct(Genode::Env &env)
static Nitpicker::Connection nitpicker(env);
static Platform pf(env, *nitpicker.input());
long initial_x = read_int_attr_from_config("xpos", 550);
long initial_y = read_int_attr_from_config("ypos", 150);
long initial_w = read_int_attr_from_config("width", 400);
long initial_h = read_int_attr_from_config("height", 400);
static Genode::Attached_rom_dataspace config(env, "config");
long const initial_x = config.xml().attribute_value("xpos", 550U);
long const initial_y = config.xml().attribute_value("ypos", 150U);
long const initial_w = config.xml().attribute_value("width", 400U);
long const initial_h = config.xml().attribute_value("height", 400U);
Area const max_size (530, 620);
Point const initial_position(initial_x, initial_y);
@ -152,7 +144,7 @@ void Component::construct(Genode::Env &env)
max_size, env.ram().avail());
/* request config file from ROM service */
try { launchpad.process_config(); } catch (...) { }
try { launchpad.process_config(config.xml()); } catch (...) { }
static Avail_quota_update avail_quota_update(&launchpad);

View File

@ -1,5 +1,5 @@
TARGET = launchpad
LIBS = launchpad scout_widgets config
LIBS = launchpad scout_widgets
SRC_CC = launchpad_window.cc \
launcher.cc \
main.cc

View File

@ -1,5 +1,5 @@
TARGET = scout
LIBS = libpng_static libz_static mini_c launchpad scout_widgets config
LIBS = libpng_static libz_static mini_c launchpad scout_widgets
SRC_CC = main.cc doc.cc \
browser_window.cc png_image.cc \
navbar.cc about.cc \

View File

@ -17,7 +17,6 @@
#include <base/service.h>
#include <base/snprintf.h>
#include <base/attached_dataspace.h>
#include <os/config.h>
#include <launchpad/launchpad.h>
using namespace Genode;
@ -91,12 +90,10 @@ Launchpad::_get_unique_child_name(Launchpad_child::Name const &binary_name)
/**
* Process launchpad XML configuration
*/
void Launchpad::process_config()
void Launchpad::process_config(Genode::Xml_node config_node)
{
using namespace Genode;
Xml_node config_node = config()->xml_node();
/*
* Iterate through all entries of the config file and create
* launchpad entries as specified.

View File

@ -20,6 +20,7 @@
#define _INCLUDE__NANO3D__SCENE_H_
/* Genode includes */
#include <base/entrypoint.h>
#include <timer_session/connection.h>
#include <nitpicker_session/connection.h>
#include <os/surface.h>
@ -54,7 +55,7 @@ class Nano3d::Scene
private:
Genode::Signal_receiver &_sig_rec;
Genode::Env &_env;
/**
* Position and size of nitpicker view
@ -62,7 +63,7 @@ class Nano3d::Scene
Nitpicker::Point const _pos;
Nitpicker::Area const _size;
Nitpicker::Connection _nitpicker;
Nitpicker::Connection _nitpicker { _env };
struct Mapped_framebuffer
{
@ -186,28 +187,28 @@ class Nano3d::Scene
bool _do_sync = false;
Timer::Connection _timer;
Timer::Connection _timer { _env };
Genode::Attached_dataspace _input_ds { _nitpicker.input()->dataspace() };
Input_handler *_input_handler = nullptr;
Input_handler *_input_handler_callback = nullptr;
void _handle_input(unsigned)
void _handle_input()
{
if (!_input_handler)
if (!_input_handler_callback)
return;
while (int num = _nitpicker.input()->flush()) {
auto const *ev_buf = _input_ds.local_addr<Input::Event>();
if (_input_handler)
_input_handler->handle_input(ev_buf, num);
if (_input_handler_callback)
_input_handler_callback->handle_input(ev_buf, num);
}
}
Genode::Signal_dispatcher<Scene> _input_dispatcher {
_sig_rec, *this, &Scene::_handle_input };
Genode::Signal_handler<Scene> _input_handler {
_env.ep(), *this, &Scene::_handle_input };
void _swap_back_and_front_surfaces()
{
@ -223,7 +224,7 @@ class Nano3d::Scene
_surface_front = tmp;
}
void _handle_period(unsigned)
void _handle_period()
{
if (_do_sync)
return;
@ -238,10 +239,10 @@ class Nano3d::Scene
_do_sync = true;
}
Genode::Signal_dispatcher<Scene> _periodic_dispatcher {
_sig_rec, *this, &Scene::_handle_period };
Genode::Signal_handler<Scene> _periodic_handler {
_env.ep(), *this, &Scene::_handle_period };
void _handle_sync(unsigned)
void _handle_sync()
{
/* rendering of scene is not complete, yet */
if (!_do_sync)
@ -263,42 +264,29 @@ class Nano3d::Scene
_do_sync = false;
}
Genode::Signal_dispatcher<Scene> _sync_dispatcher {
_sig_rec, *this, &Scene::_handle_sync };
Genode::Signal_handler<Scene> _sync_handler {
_env.ep(), *this, &Scene::_handle_sync };
typedef Nitpicker::Session::Command Command;
public:
Scene(Genode::Signal_receiver &sig_rec, unsigned update_rate_ms,
Scene(Genode::Env &env, unsigned update_rate_ms,
Nitpicker::Point pos, Nitpicker::Area size)
:
_sig_rec(sig_rec), _pos(pos), _size(size)
_env(env), _pos(pos), _size(size)
{
Nitpicker::Rect rect(_pos, _size);
_nitpicker.enqueue<Command::Geometry>(_view_handle, rect);
_nitpicker.enqueue<Command::To_front>(_view_handle);
_nitpicker.execute();
_nitpicker.input()->sigh(_input_dispatcher);
_nitpicker.input()->sigh(_input_handler);
_timer.sigh(_periodic_dispatcher);
_timer.sigh(_periodic_handler);
_timer.trigger_periodic(1000*update_rate_ms);
_framebuffer.framebuffer.sync_sigh(_sync_dispatcher);
}
static void dispatch_signals_loop(Genode::Signal_receiver &sig_rec)
{
while (1) {
Genode::Signal signal = sig_rec.wait_for_signal();
Genode::Signal_dispatcher_base *dispatcher =
static_cast<Genode::Signal_dispatcher_base *>(signal.context());
dispatcher->dispatch(signal.num());
}
_framebuffer.framebuffer.sync_sigh(_sync_handler);
}
unsigned long elapsed_ms() const { return _timer.elapsed_ms(); }
@ -306,7 +294,7 @@ class Nano3d::Scene
void input_handler(Input_handler *input_handler)
{
_framebuffer.input_mask(input_handler ? true : false);
_input_handler = input_handler;
_input_handler_callback = input_handler;
}
};

View File

@ -12,7 +12,7 @@
*/
/* Genode includes */
#include <os/config.h>
#include <base/component.h>
#include <os/attached_rom_dataspace.h>
#include <polygon_gfx/shaded_polygon_painter.h>
#include <polygon_gfx/interpolate_rgb565.h>
@ -274,14 +274,15 @@ class Cpu_load_display::Scene : public Nano3d::Scene<PT>
{
private:
Genode::Env &_env;
Nitpicker::Area const _size;
void _handle_config(unsigned)
{
Genode::config()->reload();
}
Genode::Attached_rom_dataspace _config { _env, "config" };
Genode::Signal_dispatcher<Scene> _config_dispatcher;
void _handle_config() { _config.update(); }
Genode::Signal_handler<Scene> _config_handler;
Genode::Attached_rom_dataspace _trace_subjects { "trace_subjects" };
@ -289,7 +290,7 @@ class Cpu_load_display::Scene : public Nano3d::Scene<PT>
Cpu_registry _cpu_registry;
void _handle_trace_subjects(unsigned)
void _handle_trace_subjects()
{
_trace_subjects.update();
@ -304,21 +305,22 @@ class Cpu_load_display::Scene : public Nano3d::Scene<PT>
} catch (...) { Genode::error("failed to import trace subjects"); }
}
Genode::Signal_dispatcher<Scene> _trace_subjects_dispatcher;
Genode::Signal_handler<Scene> _trace_subjects_handler;
public:
Scene(Genode::Signal_receiver &sig_rec, unsigned update_rate_ms,
Scene(Genode::Env &env, unsigned update_rate_ms,
Nitpicker::Point pos, Nitpicker::Area size)
:
Nano3d::Scene<PT>(sig_rec, update_rate_ms, pos, size), _size(size),
_config_dispatcher(sig_rec, *this, &Scene::_handle_config),
_trace_subjects_dispatcher(sig_rec, *this, &Scene::_handle_trace_subjects)
Nano3d::Scene<PT>(env, update_rate_ms, pos, size),
_env(env), _size(size),
_config_handler(env.ep(), *this, &Scene::_handle_config),
_trace_subjects_handler(env.ep(), *this, &Scene::_handle_trace_subjects)
{
Genode::config()->sigh(_config_dispatcher);
_handle_config(0);
_config.sigh(_config_handler);
_handle_config();
_trace_subjects.sigh(_trace_subjects_dispatcher);
_trace_subjects.sigh(_trace_subjects_handler);
}
private:
@ -456,17 +458,11 @@ class Cpu_load_display::Scene : public Nano3d::Scene<PT>
};
int main(int argc, char **argv)
void Component::construct(Genode::Env &env)
{
static Genode::Signal_receiver sig_rec;
enum { UPDATE_RATE_MS = 250 };
static Cpu_load_display::Scene<Genode::Pixel_rgb565>
scene(sig_rec, UPDATE_RATE_MS,
scene(env, UPDATE_RATE_MS,
Nitpicker::Point(0, 0), Nitpicker::Area(400, 400));
scene.dispatch_signals_loop(sig_rec);
return 0;
}

View File

@ -24,64 +24,68 @@
struct Menu_view::Main
{
Nitpicker::Connection nitpicker;
Env &_env;
Constructible<Nitpicker_buffer> buffer;
Nitpicker::Connection _nitpicker { _env };
Nitpicker::Session::View_handle view_handle = nitpicker.create_view();
Constructible<Nitpicker_buffer> _buffer;
Point position;
Nitpicker::Session::View_handle _view_handle = _nitpicker.create_view();
Point _position;
Rect _view_geometry;
void _update_view()
{
if (_view_geometry.p1() == position
&& _view_geometry.area() == buffer->size())
return;
if (_view_geometry.p1() == _position
&& _view_geometry.area() == _buffer->size())
return;
/* display view behind all others */
typedef Nitpicker::Session::Command Command;
_view_geometry = Rect(position, buffer->size());
nitpicker.enqueue<Command::Geometry>(view_handle, _view_geometry);
nitpicker.enqueue<Command::To_front>(view_handle);
nitpicker.execute();
_view_geometry = Rect(_position, _buffer->size());
_nitpicker.enqueue<Command::Geometry>(_view_handle, _view_geometry);
_nitpicker.enqueue<Command::To_front>(_view_handle);
_nitpicker.execute();
}
Signal_receiver &sig_rec;
/**
* Function called on config change or mode change
*/
void handle_dialog_update(unsigned);
void _handle_dialog_update();
Signal_dispatcher<Main> dialog_update_dispatcher = {
sig_rec, *this, &Main::handle_dialog_update};
Signal_handler<Main> _dialog_update_handler = {
_env.ep(), *this, &Main::_handle_dialog_update};
Style_database styles;
Style_database _styles;
Animator animator;
Animator _animator;
Widget_factory widget_factory { *env()->heap(), styles, animator };
Heap _heap { _env.ram(), _env.rm() };
Root_widget root_widget { widget_factory, Xml_node("<dialog/>"), Widget::Unique_id() };
Widget_factory _widget_factory { _heap, _styles, _animator };
Attached_rom_dataspace dialog_rom { "dialog" };
Root_widget _root_widget { _widget_factory, Xml_node("<dialog/>"), Widget::Unique_id() };
Attached_dataspace input_ds { nitpicker.input()->dataspace() };
Attached_rom_dataspace _dialog_rom { _env, "dialog" };
Widget::Unique_id hovered;
Attached_dataspace _input_ds { _nitpicker.input()->dataspace() };
void handle_config(unsigned);
Widget::Unique_id _hovered;
Signal_dispatcher<Main> config_dispatcher = {
sig_rec, *this, &Main::handle_config};
Attached_rom_dataspace _config { _env, "config" };
void handle_input(unsigned);
void _handle_config();
Signal_dispatcher<Main> input_dispatcher = {
sig_rec, *this, &Main::handle_input};
Signal_handler<Main> _config_handler = {
_env.ep(), *this, &Main::_handle_config};
void _handle_input();
Signal_handler<Main> _input_handler = {
_env.ep(), *this, &Main::_handle_input};
/*
* Timer used for animating widgets
@ -94,21 +98,23 @@ struct Menu_view::Main
void schedule() { trigger_once(Frame_timer::PERIOD*1000); }
} timer;
Frame_timer(Env &env) : Timer::Connection(env) { }
void handle_frame_timer(unsigned);
} _timer { _env };
Signal_dispatcher<Main> frame_timer_dispatcher = {
sig_rec, *this, &Main::handle_frame_timer};
void _handle_frame_timer();
Genode::Reporter hover_reporter = { "hover" };
Signal_handler<Main> _frame_timer_handler = {
_env.ep(), *this, &Main::_handle_frame_timer};
bool schedule_redraw = false;
Genode::Reporter _hover_reporter = { "hover" };
bool _schedule_redraw = false;
/**
* Frame of last call of 'handle_frame_timer'
*/
unsigned last_frame = 0;
unsigned _last_frame = 0;
/**
* Number of frames between two redraws
@ -120,86 +126,86 @@ struct Menu_view::Main
* period, wraps at 'REDRAW_PERIOD'. The redraw is performed when the
* counter wraps.
*/
unsigned frame_cnt = 0;
unsigned _frame_cnt = 0;
Main(Signal_receiver &sig_rec) : sig_rec(sig_rec)
Main(Env &env) : _env(env)
{
dialog_rom.sigh(dialog_update_dispatcher);
config()->sigh(config_dispatcher);
_dialog_rom.sigh(_dialog_update_handler);
_config.sigh(_config_handler);
nitpicker.input()->sigh(input_dispatcher);
_nitpicker.input()->sigh(_input_handler);
timer.sigh(frame_timer_dispatcher);
_timer.sigh(_frame_timer_handler);
/* apply initial configuration */
handle_config(0);
_handle_config();
}
};
void Menu_view::Main::handle_dialog_update(unsigned)
void Menu_view::Main::_handle_dialog_update()
{
try {
position = Decorator::point_attribute(config()->xml_node());
_position = Decorator::point_attribute(_config.xml());
} catch (...) { }
dialog_rom.update();
_dialog_rom.update();
try {
Xml_node dialog_xml(dialog_rom.local_addr<char>());
Xml_node dialog_xml(_dialog_rom.local_addr<char>());
root_widget.update(dialog_xml);
root_widget.size(root_widget.min_size());
_root_widget.update(dialog_xml);
_root_widget.size(_root_widget.min_size());
} catch (...) {
Genode::error("failed to construct widget tree");
}
schedule_redraw = true;
_schedule_redraw = true;
/*
* If we have not processed a period for at least one frame, perform the
* processing immediately. This way, we avoid latencies when the dialog
* model is updated sporadically.
*/
if (timer.curr_frame() != last_frame)
handle_frame_timer(0);
if (_timer.curr_frame() != _last_frame)
_handle_frame_timer();
else
timer.schedule();
_timer.schedule();
}
void Menu_view::Main::handle_config(unsigned)
void Menu_view::Main::_handle_config()
{
config()->reload();
_config.update();
try {
hover_reporter.enabled(config()->xml_node().sub_node("report")
.attribute_value("hover", false));
_hover_reporter.enabled(_config.xml().sub_node("report")
.attribute_value("hover", false));
} catch (...) {
hover_reporter.enabled(false);
_hover_reporter.enabled(false);
}
handle_dialog_update(0);
_handle_dialog_update();
}
void Menu_view::Main::handle_input(unsigned)
void Menu_view::Main::_handle_input()
{
nitpicker.input()->for_each_event([&] (Input::Event const &ev) {
_nitpicker.input()->for_each_event([&] (Input::Event const &ev) {
if (ev.absolute_motion()) {
Point const at = Point(ev.ax(), ev.ay()) - position;
Widget::Unique_id const new_hovered = root_widget.hovered(at);
Point const at = Point(ev.ax(), ev.ay()) - _position;
Widget::Unique_id const new_hovered = _root_widget.hovered(at);
if (hovered != new_hovered) {
if (_hovered != new_hovered) {
if (hover_reporter.enabled()) {
Genode::Reporter::Xml_generator xml(hover_reporter, [&] () {
root_widget.gen_hover_model(xml, at);
if (_hover_reporter.enabled()) {
Genode::Reporter::Xml_generator xml(_hover_reporter, [&] () {
_root_widget.gen_hover_model(xml, at);
});
}
hovered = new_hovered;
_hovered = new_hovered;
}
}
@ -209,74 +215,74 @@ void Menu_view::Main::handle_input(unsigned)
if ((ev.type() == Input::Event::FOCUS && ev.code() == 0)
|| (ev.type() == Input::Event::LEAVE)) {
hovered = Widget::Unique_id();
_hovered = Widget::Unique_id();
if (hover_reporter.enabled()) {
Genode::Reporter::Xml_generator xml(hover_reporter, [&] () { });
if (_hover_reporter.enabled()) {
Genode::Reporter::Xml_generator xml(_hover_reporter, [&] () { });
}
}
});
}
void Menu_view::Main::handle_frame_timer(unsigned)
void Menu_view::Main::_handle_frame_timer()
{
frame_cnt++;
_frame_cnt++;
unsigned const curr_frame = timer.curr_frame();
unsigned const curr_frame = _timer.curr_frame();
if (animator.active()) {
if (_animator.active()) {
unsigned const passed_frames = curr_frame - last_frame;
unsigned const passed_frames = curr_frame - _last_frame;
if (passed_frames > 0) {
for (unsigned i = 0; i < passed_frames; i++)
animator.animate();
_animator.animate();
schedule_redraw = true;
_schedule_redraw = true;
}
}
last_frame = curr_frame;
_last_frame = curr_frame;
if (schedule_redraw && frame_cnt >= REDRAW_PERIOD) {
if (_schedule_redraw && _frame_cnt >= REDRAW_PERIOD) {
frame_cnt = 0;
_frame_cnt = 0;
Area const old_size = buffer.constructed() ? buffer->size() : Area();
Area const size = root_widget.min_size();
Area const old_size = _buffer.constructed() ? _buffer->size() : Area();
Area const size = _root_widget.min_size();
if (!buffer.constructed() || size != old_size)
buffer.construct(nitpicker, size, *env()->ram_session());
if (!_buffer.constructed() || size != old_size)
_buffer.construct(_nitpicker, size, _env.ram());
else
buffer->reset_surface();
_buffer->reset_surface();
root_widget.size(size);
root_widget.position(Point(0, 0));
_root_widget.size(size);
_root_widget.position(Point(0, 0));
Surface<Pixel_rgb888> pixel_surface = buffer->pixel_surface();
Surface<Pixel_alpha8> alpha_surface = buffer->alpha_surface();
Surface<Pixel_rgb888> pixel_surface = _buffer->pixel_surface();
Surface<Pixel_alpha8> alpha_surface = _buffer->alpha_surface();
// XXX restrict redraw to dirty regions
// don't perform a full dialog update
root_widget.draw(pixel_surface, alpha_surface, Point(0, 0));
_root_widget.draw(pixel_surface, alpha_surface, Point(0, 0));
buffer->flush_surface();
nitpicker.framebuffer()->refresh(0, 0, buffer->size().w(), buffer->size().h());
_buffer->flush_surface();
_nitpicker.framebuffer()->refresh(0, 0, _buffer->size().w(), _buffer->size().h());
_update_view();
schedule_redraw = false;
_schedule_redraw = false;
}
/*
* Deactivate timer periods when idle, activate timer when an animation is
* in progress or a redraw is pending.
*/
bool const redraw_pending = schedule_redraw && frame_cnt != 0;
bool const redraw_pending = _schedule_redraw && _frame_cnt != 0;
if (animator.active() || redraw_pending)
timer.schedule();
if (_animator.active() || redraw_pending)
_timer.schedule();
}
@ -285,21 +291,6 @@ void Menu_view::Main::handle_frame_timer(unsigned)
*/
extern "C" void _sigprocmask() { }
int main(int argc, char **argv)
{
static Genode::Signal_receiver sig_rec;
static Menu_view::Main application(sig_rec);
void Libc::Component::construct(Genode::Env &env) { static Menu_view::Main main(env); }
/* process incoming signals */
for (;;) {
using namespace Genode;
Signal sig = sig_rec.wait_for_signal();
Signal_dispatcher_base *dispatcher =
dynamic_cast<Signal_dispatcher_base *>(sig.context());
if (dispatcher)
dispatcher->dispatch(sig.num());
}
}

View File

@ -92,31 +92,13 @@ class Menu_view::Style_database
/*
* Assemble path name 'styles/<widget>/<style>/<name>.<extension>'
*/
static Path _construct_path(Xml_node node,
char const *name, char const *extension)
static Path _construct_path(Xml_node node, char const *name,
char const *extension)
{
char widget[64];
node.type_name(widget, sizeof(widget));
typedef String<64> Style;
Style const style = node.attribute_value("style", Style("default"));
char style[PATH_MAX_LEN];
style[0] = 0;
try {
node.attribute("style").value(style, sizeof(style));
}
catch (Xml_node::Nonexistent_attribute) {
/* no style defined */
Genode::strncpy(style, "default", sizeof(style));
}
char path[PATH_MAX_LEN];
path[0] = 0;
Genode::snprintf(path, sizeof(path), "/styles/%s/%s/%s.%s",
widget, style, name, extension);
return Path(path);
return Path("/styles/", node.type(), "/", style, "/", name, ".", extension);
}
public:
@ -140,11 +122,11 @@ class Menu_view::Style_database
} catch (File::Reading_failed) {
PWRN("could not read texture data from file \"%s\"", path.string());
return 0;
warning("could not read texture data from file \"", path.string(), "\"");
return nullptr;
}
return 0;
return nullptr;
}
Text_painter::Font const *font(Xml_node node, char const *tff_name) const
@ -166,11 +148,11 @@ class Menu_view::Style_database
} catch (File::Reading_failed) {
PWRN("could not read font from file \"%s\"", path.string());
return 0;
warning("could not read font from file \"", path.string(), "\"");
return nullptr;
}
return 0;
return nullptr;
}
};

View File

@ -1,6 +1,6 @@
TARGET = menu_view
SRC_CC = main.cc
LIBS = base config posix libpng zlib blit file
LIBS = base libc libm libpng zlib blit file
INC_DIR += $(PRG_DIR)
.PHONY: menu_view_styles.tar

View File

@ -16,19 +16,18 @@
/* Genode includes */
#include <nitpicker_session/connection.h>
#include <base/printf.h>
#include <util/misc_math.h>
#include <os/config.h>
#include <decorator/xml_utils.h>
#include <nitpicker_gfx/box_painter.h>
#include <nitpicker_gfx/texture_painter.h>
#include <os/attached_dataspace.h>
#include <os/attached_rom_dataspace.h>
#include <base/attached_rom_dataspace.h>
#include <base/heap.h>
#include <os/pixel_rgb565.h>
#include <os/pixel_alpha8.h>
#include <os/texture_rgb888.h>
#include <util/reconstructible.h>
#include <nitpicker_gfx/text_painter.h>
#include <libc/component.h>
namespace Menu_view {

View File

@ -833,10 +833,7 @@ Menu_view::Widget_factory::create(Xml_node node)
if (node.has_type("frame")) w = new (alloc) Frame_widget (*this, node, unique_id);
if (!w) {
char type[64];
type[0] = 0;
node.type_name(type, sizeof(type));
Genode::error("unknown widget type '", Cstring(type), "'");
Genode::error("unknown widget type '", node.type(), "'");
return 0;
}

View File

@ -12,7 +12,8 @@
*/
/* Genode includes */
#include <os/config.h>
#include <base/component.h>
#include <base/attached_rom_dataspace.h>
#include <polygon_gfx/shaded_polygon_painter.h>
#include <polygon_gfx/interpolate_rgb565.h>
#include <polygon_gfx/textured_polygon_painter.h>
@ -32,6 +33,8 @@ class Scene : public Nano3d::Scene<PT>
private:
Genode::Env &_env;
Nitpicker::Area const _size;
struct Radial_texture
@ -75,35 +78,38 @@ class Scene : public Nano3d::Scene<PT>
Shape _shape = SHAPE_DODECAHEDRON;
Painter _painter = PAINTER_TEXTURED;
void _handle_config(unsigned)
Genode::Attached_rom_dataspace _config { _env, "config" };
void _handle_config()
{
Genode::config()->reload();
_config.update();
try {
_shape = SHAPE_DODECAHEDRON;
if (Genode::config()->xml_node().attribute("shape").has_value("cube"))
if (_config.xml().attribute("shape").has_value("cube"))
_shape = SHAPE_CUBE;
} catch (...) { }
try {
_painter = PAINTER_TEXTURED;
if (Genode::config()->xml_node().attribute("painter").has_value("shaded"))
if (_config.xml().attribute("painter").has_value("shaded"))
_painter = PAINTER_SHADED;
} catch (...) { }
}
Genode::Signal_dispatcher<Scene> _config_dispatcher;
Genode::Signal_handler<Scene> _config_handler;
public:
Scene(Genode::Signal_receiver &sig_rec, unsigned update_rate_ms,
Scene(Genode::Env &env, unsigned update_rate_ms,
Nitpicker::Point pos, Nitpicker::Area size)
:
Nano3d::Scene<PT>(sig_rec, update_rate_ms, pos, size), _size(size),
_config_dispatcher(sig_rec, *this, &Scene::_handle_config)
Nano3d::Scene<PT>(env, update_rate_ms, pos, size),
_env(env), _size(size),
_config_handler(env.ep(), *this, &Scene::_handle_config)
{
Genode::config()->sigh(_config_dispatcher);
_handle_config(0);
_config.sigh(_config_handler);
_handle_config();
}
private:
@ -219,17 +225,11 @@ class Scene : public Nano3d::Scene<PT>
};
int main(int argc, char **argv)
void Component::construct(Genode::Env &env)
{
static Genode::Signal_receiver sig_rec;
enum { UPDATE_RATE_MS = 20 };
static Scene<Genode::Pixel_rgb565>
scene(sig_rec, UPDATE_RATE_MS,
scene(env, UPDATE_RATE_MS,
Nitpicker::Point(-200, -200), Nitpicker::Area(400, 400));
scene.dispatch_signals_loop(sig_rec);
return 0;
}

View File

@ -1,4 +1,4 @@
TARGET = nano3d
SRC_CC = main.cc
LIBS = base config
LIBS = base
INC_DIR += $(PRG_DIR)

View File

@ -13,7 +13,7 @@
/* Genode includes */
#include <libc/component.h>
#include <base/env.h>
#include <base/attached_rom_dataspace.h>
extern int genode_argc;
extern char **genode_argv;
@ -65,9 +65,9 @@ void Libc::Component::construct(Genode::Env &env)
static Qt_launchpad launchpad(local_env, env.ram().avail());
try {
launchpad.process_config();
} catch (...) { }
static Genode::Attached_rom_dataspace config(env, "config");
try { launchpad.process_config(config.xml()); } catch (...) { }
launchpad.move(300,100);
launchpad.show();

View File

@ -12,30 +12,33 @@
*/
/* Genode includes */
#include <os/config.h>
#include <base/component.h>
#include <base/attached_rom_dataspace.h>
#include <timer_session/connection.h>
struct Cpu_burner
{
Timer::Connection _timer;
Genode::Env &_env;
Timer::Connection _timer { _env };
unsigned long _percent = 100;
void _handle_config(unsigned)
{
Genode::config()->reload();
Genode::Attached_rom_dataspace _config { _env, "config" };
_percent = 100;
try {
Genode::config()->xml_node().attribute("percent").value(&_percent);
} catch (...) { }
void _handle_config()
{
_config.update();
_percent = _config.xml().attribute_value("percent", 100L);
}
Genode::Signal_dispatcher<Cpu_burner> _config_dispatcher;
Genode::Signal_handler<Cpu_burner> _config_handler {
_env.ep(), *this, &Cpu_burner::_handle_config };
unsigned _burn_per_iteration = 10;
void _handle_period(unsigned)
void _handle_period()
{
unsigned long const start_ms = _timer.elapsed_ms();
@ -62,36 +65,21 @@ struct Cpu_burner
_burn_per_iteration /= 2;
}
Genode::Signal_dispatcher<Cpu_burner> _period_dispatcher;
Genode::Signal_handler<Cpu_burner> _period_handler {
_env.ep(), *this, &Cpu_burner::_handle_period };
Cpu_burner(Genode::Signal_receiver &sig_rec)
:
_config_dispatcher(sig_rec, *this, &Cpu_burner::_handle_config),
_period_dispatcher(sig_rec, *this, &Cpu_burner::_handle_period)
Cpu_burner(Genode::Env &env) : _env(env)
{
Genode::config()->sigh(_config_dispatcher);
_handle_config(0);
_config.sigh(_config_handler);
_handle_config();
_timer.sigh(_period_dispatcher);
_timer.sigh(_period_handler);
_timer.trigger_periodic(1000*1000);
}
};
int main(int argc, char **argv)
void Component::construct(Genode::Env &env)
{
static Genode::Signal_receiver sig_rec;
static Cpu_burner cpu_burner(sig_rec);
while (1) {
Genode::Signal signal = sig_rec.wait_for_signal();
Genode::Signal_dispatcher_base *dispatcher =
static_cast<Genode::Signal_dispatcher_base *>(signal.context());
dispatcher->dispatch(signal.num());
}
static Cpu_burner cpu_burner(env);
}

View File

@ -1,3 +1,3 @@
TARGET = cpu_burner
SRC_CC = main.cc
LIBS = base config
LIBS = base

View File

@ -14,13 +14,10 @@
/* Genode includes */
#include <trace_session/connection.h>
#include <timer_session/connection.h>
#include <base/component.h>
#include <base/attached_rom_dataspace.h>
#include <base/heap.h>
#include <os/reporter.h>
#include <os/server.h>
#include <os/config.h>
#include <base/env.h>
namespace Server { struct Main; }
struct Trace_subject_registry
@ -143,98 +140,95 @@ struct Trace_subject_registry
};
struct Server::Main
namespace App {
struct Main;
using namespace Genode;
}
struct App::Main
{
Entrypoint &ep;
Env &_env;
Genode::Trace::Connection trace { 512*1024, 32*1024, 0 };
Trace::Connection _trace { _env, 512*1024, 32*1024, 0 };
Genode::Reporter reporter { "trace_subjects", "trace_subjects", 64*1024 };
Reporter _reporter { "trace_subjects", "trace_subjects", 64*1024 };
static unsigned long default_period_ms() { return 5000; }
static unsigned long _default_period_ms() { return 5000; }
unsigned long period_ms = default_period_ms();
unsigned long _period_ms = _default_period_ms();
bool report_affinity = false;
bool report_activity = false;
bool _report_affinity = false;
bool _report_activity = false;
bool config_report_attribute_enabled(char const *attr) const
Attached_rom_dataspace _config { _env, "config" };
bool _config_report_attribute_enabled(char const *attr) const
{
try {
return Genode::config()->xml_node().sub_node("report")
.attribute_value(attr, false);
return _config.xml().sub_node("report").attribute_value(attr, false);
} catch (...) { return false; }
}
Timer::Connection timer;
Timer::Connection _timer { _env };
Trace_subject_registry trace_subject_registry;
Heap _heap { _env.ram(), _env.rm() };
void handle_config(unsigned);
Trace_subject_registry _trace_subject_registry;
Signal_rpc_member<Main> config_dispatcher = {
ep, *this, &Main::handle_config};
void _handle_config();
void handle_period(unsigned);
Signal_handler<Main> _config_handler = {
_env.ep(), *this, &Main::_handle_config};
Signal_rpc_member<Main> periodic_dispatcher = {
ep, *this, &Main::handle_period};
void _handle_period();
Main(Entrypoint &ep) : ep(ep)
Signal_handler<Main> _periodic_handler = {
_env.ep(), *this, &Main::_handle_period};
Main(Env &env) : _env(env)
{
Genode::config()->sigh(config_dispatcher);
handle_config(0);
_config.sigh(_config_handler);
_handle_config();
timer.sigh(periodic_dispatcher);
_timer.sigh(_periodic_handler);
reporter.enabled(true);
_reporter.enabled(true);
}
};
void Server::Main::handle_config(unsigned)
void App::Main::_handle_config()
{
Genode::config()->reload();
_config.update();
try {
period_ms = default_period_ms();
Genode::config()->xml_node().attribute("period_ms").value(&period_ms);
} catch (...) { }
_period_ms = _config.xml().attribute_value("period_ms", _default_period_ms());
report_affinity = config_report_attribute_enabled("affinity");
report_activity = config_report_attribute_enabled("activity");
_report_affinity = _config_report_attribute_enabled("affinity");
_report_activity = _config_report_attribute_enabled("activity");
log("period_ms=", period_ms, ", "
"report_activity=", report_activity, ", "
"report_affinity=", report_affinity);
log("period_ms=", _period_ms, ", "
"report_activity=", _report_activity, ", "
"report_affinity=", _report_affinity);
timer.trigger_periodic(1000*period_ms);
_timer.trigger_periodic(1000*_period_ms);
}
void Server::Main::handle_period(unsigned)
void App::Main::_handle_period()
{
/* update subject information */
trace_subject_registry.update(trace, *Genode::env()->heap());
_trace_subject_registry.update(_trace, _heap);
/* generate report */
reporter.clear();
Genode::Reporter::Xml_generator xml(reporter, [&] ()
_reporter.clear();
Genode::Reporter::Xml_generator xml(_reporter, [&] ()
{
trace_subject_registry.report(xml, report_affinity, report_activity);
_trace_subject_registry.report(xml, _report_affinity, _report_activity);
});
}
namespace Server {
char const *name() { return "trace_subject_reporter"; }
size_t stack_size() { return 16*1024*sizeof(long); }
void construct(Entrypoint &ep)
{
static Main main(ep);
}
}
void Component::construct(Genode::Env &env) { static App::Main main(env); }

View File

@ -1,3 +1,3 @@
TARGET = trace_subject_reporter
SRC_CC = main.cc
LIBS += base server config
LIBS += base

View File

@ -20,7 +20,7 @@ class Input_driver
virtual void handle_event() = 0;
virtual bool event_pending() = 0;
virtual bool event_pending() const = 0;
virtual ~Input_driver() { }
};

View File

@ -15,9 +15,8 @@
#define _DRIVERS__INPUT__SPEC__PS2__IRQ_HANDLER_H_
/* Genode includes */
#include <base/thread.h>
#include <irq_session/connection.h>
#include <os/server.h>
#include <base/entrypoint.h>
#include <irq_session/client.h>
/* local includes */
#include "input_driver.h"
@ -26,11 +25,11 @@ class Irq_handler
{
private:
Genode::Irq_session_client _irq;
Genode::Signal_rpc_member<Irq_handler> _dispatcher;
Input_driver &_input_driver;
Genode::Irq_session_client _irq;
Genode::Signal_handler<Irq_handler> _handler;
Input_driver &_input_driver;
void _handle(unsigned)
void _handle()
{
_irq.ack_irq();
@ -40,14 +39,14 @@ class Irq_handler
public:
Irq_handler(Server::Entrypoint &ep, Input_driver &input_driver,
Irq_handler(Genode::Entrypoint &ep, Input_driver &input_driver,
Genode::Irq_session_capability irq_cap)
:
_irq(irq_cap),
_dispatcher(ep, *this, &Irq_handler::_handle),
_handler(ep, *this, &Irq_handler::_handle),
_input_driver(input_driver)
{
_irq.sigh(_dispatcher);
_irq.sigh(_handler);
_irq.ack_irq();
}
};

View File

@ -28,7 +28,6 @@ class Irq_handler
Genode::Irq_connection _irq;
Genode::Signal_rpc_member<Irq_handler> _dispatcher;
Serial_interface *_channel;
Input_driver &_input_driver;
void _handle(unsigned)
@ -42,13 +41,11 @@ class Irq_handler
public:
Irq_handler(Server::Entrypoint &ep,
int irq_number, Serial_interface *channel,
Input_driver &input_driver)
Irq_handler(Server::Entrypoint &ep, int irq_number,
Serial_interface &, Input_driver &input_driver)
:
_irq(irq_number),
_dispatcher(ep, *this, &Irq_handler::_handle),
_channel(channel),
_input_driver(input_driver)
{
_irq.sigh(_dispatcher);

View File

@ -12,14 +12,10 @@
*/
/* Genode includes */
#include <base/env.h>
#include <base/printf.h>
#include <base/sleep.h>
#include <base/component.h>
#include <base/attached_rom_dataspace.h>
#include <input/component.h>
#include <input/root.h>
#include <cap_session/connection.h>
#include <os/config.h>
#include <os/server.h>
/* local includes */
#include "ps2_keyboard.h"
@ -27,49 +23,33 @@
#include "irq_handler.h"
#include "pl050.h"
using namespace Genode;
namespace Ps2 { struct Main; }
struct Main
struct Ps2::Main
{
Server::Entrypoint &ep;
Genode::Env &_env;
Pl050 pl050;
Input::Session_component session;
Input::Root_component root;
Pl050 _pl050;
Input::Session_component _session;
Input::Root_component _root { _env.ep().rpc_ep(), _session };
Ps2_mouse ps2_mouse;
Ps2_keyboard ps2_keybd;
Genode::Attached_rom_dataspace _config { _env, "config" };
Irq_handler ps2_mouse_irq;
Irq_handler ps2_keybd_irq;
Verbose _verbose { _config.xml() };
bool _check_verbose(const char * verbose)
Mouse _mouse { _pl050.aux_interface(), _session.event_queue(), _verbose };
Keyboard _keyboard { _pl050.kbd_interface(), _session.event_queue(), true, _verbose };
Irq_handler _mouse_irq { _env.ep(), PL050_MOUSE_IRQ, _pl050.aux_interface(), _mouse };
Irq_handler _keyboard_irq { _env.ep(), PL050_KEYBD_IRQ, _pl050.kbd_interface(), _keyboard };
Main(Genode::Env &env) : _env(env)
{
return Genode::config()->xml_node().attribute_value(verbose, false);
}
Main(Server::Entrypoint &ep)
: ep(ep), root(ep.rpc_ep(), session),
ps2_mouse(*pl050.aux_interface(), session.event_queue(),
_check_verbose("verbose_mouse")),
ps2_keybd(*pl050.kbd_interface(), session.event_queue(), true,
_check_verbose("verbose_keyboard"),
_check_verbose("verbose_scancodes")),
ps2_mouse_irq(ep, PL050_MOUSE_IRQ, pl050.aux_interface(), ps2_mouse),
ps2_keybd_irq(ep, PL050_KEYBD_IRQ, pl050.kbd_interface(), ps2_keybd)
{
env()->parent()->announce(ep.manage(root));
env.parent().announce(env.ep().manage(_root));
}
};
/************
** Server **
************/
void Component::construct(Genode::Env &env) { static Ps2::Main main(env); }
namespace Server {
char const *name() { return "ps2_drv_ep"; }
size_t stack_size() { return 8*1024*sizeof(long); }
void construct(Entrypoint &ep) { static Main server(ep); }
}

View File

@ -148,12 +148,12 @@ class Pl050
/**
* Request serial keyboard interface
*/
Serial_interface *kbd_interface() { return &_kbd; }
Serial_interface &kbd_interface() { return _kbd; }
/**
* Request serial mouse interface
*/
Serial_interface *aux_interface() { return &_aux; }
Serial_interface &aux_interface() { return _aux; }
};
#endif /* _DRIVERS__INPUT__SPEC__PS2__PL050__PL050_H_ */

View File

@ -1,6 +1,6 @@
TARGET = ps2_drv
REQUIRES = pl050
SRC_CC = main.cc
LIBS = base server config
LIBS = base
INC_DIR += $(PRG_DIR) $(PRG_DIR)/..

View File

@ -22,23 +22,24 @@
#include "serial_interface.h"
#include "scan_code_set_1.h"
#include "scan_code_set_2.h"
#include "verbose.h"
class Ps2_keyboard : public Input_driver
namespace Ps2 { class Keyboard; }
class Ps2::Keyboard : public Input_driver
{
private:
Serial_interface &_kbd;
Input::Event_queue &_ev_queue;
bool _xlate_mode;
bool _verbose;
bool _verbose_scan_codes;
bool const _xlate_mode;
Verbose const &_verbose;
/**
* Array for tracking the current keyboard state
*/
bool _key_state[Input::KEY_MAX + 1];
/**
* Interface for keyboard-packet state machine
*/
@ -66,17 +67,17 @@ class Ps2_keyboard : public Input_driver
/**
* Return true if packet is complete
*/
virtual bool ready() = 0;
virtual bool ready() const = 0;
/**
* Return true if event is a press event
*/
virtual bool press() = 0;
virtual bool press() const = 0;
/**
* Return key code of current packet
*/
virtual unsigned int key_code() = 0;
virtual unsigned int key_code() const = 0;
};
@ -121,9 +122,9 @@ class Ps2_keyboard : public Input_driver
_key_code = 0;
}
void process(unsigned char v, bool verbose_scan_codes)
void process(unsigned char v, bool verbose)
{
if (verbose_scan_codes)
if (verbose)
Genode::log("process ", Genode::Hex(v), " scan code set 1");
switch (_state) {
@ -202,11 +203,13 @@ class Ps2_keyboard : public Input_driver
_ready = true;
}
bool ready() { return _ready; }
bool ready() const { return _ready; }
bool press() const { return _press; }
bool press() { return _press; }
unsigned int key_code() { return ready() ? _key_code : Input::KEY_UNKNOWN; }
unsigned int key_code() const
{
return ready() ? _key_code : Input::KEY_UNKNOWN;
}
} _scan_code_set_1_state_machine;
@ -254,9 +257,9 @@ class Ps2_keyboard : public Input_driver
_key_code = 0;
}
void process(unsigned char v, bool verbose_scan_codes)
void process(unsigned char v, bool verbose)
{
if (verbose_scan_codes)
if (verbose)
Genode::log("process ", Genode::Hex(v), " scan code set 2");
enum {
@ -338,12 +341,13 @@ class Ps2_keyboard : public Input_driver
_key_code = (_extended ? scan_code_set_2_ext : scan_code_set_2)[v];
}
bool ready() { return _ready; }
bool ready() const { return _ready; }
bool press() const { return _press; }
bool press() { return _press; }
unsigned int key_code() {
return ready() ? _key_code : Input::KEY_UNKNOWN; }
unsigned int key_code() const
{
return ready() ? _key_code : Input::KEY_UNKNOWN;
}
} _scan_code_set_2_state_machine;
@ -362,12 +366,11 @@ class Ps2_keyboard : public Input_driver
* If 'xlate_mode' is true, we do not attempt to manually switch the
* keyboard to scan code set 2 but just decode the scan-code set 1.
*/
Ps2_keyboard(Serial_interface &kbd, Input::Event_queue &ev_queue,
bool xlate_mode, bool verbose, bool verbose_scancodes)
Keyboard(Serial_interface &kbd, Input::Event_queue &ev_queue,
bool xlate_mode, Verbose const &verbose)
:
_kbd(kbd), _ev_queue(ev_queue), _xlate_mode(xlate_mode),
_verbose(verbose),
_verbose_scan_codes(verbose_scancodes)
_verbose(verbose)
{
for (int i = 0; i <= Input::KEY_MAX; i++)
_key_state[i] = false;
@ -422,7 +425,7 @@ class Ps2_keyboard : public Input_driver
void handle_event()
{
_state_machine->process(_kbd.read(), _verbose_scan_codes);
_state_machine->process(_kbd.read(), _verbose.scancodes);
if (!_state_machine->ready())
return;
@ -442,7 +445,7 @@ class Ps2_keyboard : public Input_driver
/* remember new key state */
_key_state[key_code] = _state_machine->press();
if (_verbose)
if (_verbose.keyboard)
Genode::log("post ", press ? "PRESS" : "RELEASE", ", "
"key_code = ", key_code);
@ -460,7 +463,7 @@ class Ps2_keyboard : public Input_driver
_state_machine->reset();
}
bool event_pending() { return _kbd.data_read_ready(); }
bool event_pending() const { return _kbd.data_read_ready(); }
};
#endif /* _DRIVERS__INPUT__SPEC__PS2__PS2_KEYBOARD_H_ */

View File

@ -14,13 +14,15 @@
#ifndef _DRIVERS__INPUT__SPEC__PS2__PS2_MOUSE_H_
#define _DRIVERS__INPUT__SPEC__PS2__PS2_MOUSE_H_
#include <base/printf.h>
#include <base/log.h>
#include <input/event_queue.h>
#include <input/keycodes.h>
#include "input_driver.h"
class Ps2_mouse : public Input_driver
namespace Ps2 { class Mouse; }
class Ps2::Mouse : public Input_driver
{
enum Command
{
@ -72,21 +74,21 @@ class Ps2_mouse : public Input_driver
Serial_interface &_aux;
Input::Event_queue &_ev_queue;
Type _type;
Type _type { PS2 };
bool _verbose;
Verbose const &_verbose;
bool _button_state[NUM_BUTTONS];
unsigned char _packet[MAX_PACKET_LEN];
int _packet_len;
int _packet_idx;
int _packet_len { PS2_PACKET_LEN };
int _packet_idx = 0;
void _check_for_event_queue_overflow()
{
if (_ev_queue.avail_capacity())
return;
PWRN("event queue overflow - dropping events");
Genode::warning("event queue overflow - dropping events");
_ev_queue.reset();
}
@ -102,8 +104,9 @@ class Ps2_mouse : public Input_driver
{
if (*old_state == new_state) return;
if (_verbose)
Genode::printf("post %s, key_code = %d\n", new_state ? "PRESS" : "RELEASE", key_code);
if (_verbose.mouse)
Genode::log("post ", new_state ? "PRESS" : "RELEASE", ", "
"key_code=", key_code);
_check_for_event_queue_overflow();
@ -159,12 +162,10 @@ class Ps2_mouse : public Input_driver
public:
Ps2_mouse(Serial_interface &aux, Input::Event_queue &ev_queue,
bool verbose)
Mouse(Serial_interface &aux, Input::Event_queue &ev_queue,
Verbose const &verbose)
:
_aux(aux),
_ev_queue(ev_queue), _type(PS2), _verbose(verbose),
_packet_len(PS2_PACKET_LEN), _packet_idx(0)
_aux(aux), _ev_queue(ev_queue), _verbose(verbose)
{
for (unsigned i = 0; i < NUM_BUTTONS; ++i)
_button_state[i] = false;
@ -175,21 +176,21 @@ class Ps2_mouse : public Input_driver
{
_aux.write(CMD_SET_DEFAULTS);
if (_aux.read() != RET_ACK)
PWRN("Could not set defaults");
Genode::warning("could not set defaults");
_aux.write(CMD_ENABLE_STREAM);
if (_aux.read() != RET_ACK)
PWRN("Could not enable stream");
Genode::warning("could not enable stream");
/* probe for protocol extensions */
if (_probe_exps2()) {
_type = EXPS2;
_packet_len = EXPS2_PACKET_LEN;
Genode::printf("Detected ExPS/2 mouse - activating scroll-wheel and 5-button support.\n");
Genode::log("detected ExPS/2 mouse - activating scroll-wheel and 5-button support");
} else if (_probe_imps2()) {
_type = IMPS2;
_packet_len = IMPS2_PACKET_LEN;
Genode::printf("Detected ImPS/2 mouse - activating scroll-wheel support.\n");
Genode::log("detected ImPS/2 mouse - activating scroll-wheel support");
}
/* set sane sample rate */
@ -231,8 +232,8 @@ class Ps2_mouse : public Input_driver
/* mirror y axis to make the movement correspond to screen coordinates */
rel_y = -rel_y;
if (_verbose)
Genode::printf("post MOTION, rel_x = %d, rel_y = %d\n", rel_x, rel_y);
if (_verbose.mouse)
Genode::log("post MOTION, rel_x=", rel_x, ", rel_y=", rel_y);
_check_for_event_queue_overflow();
@ -253,8 +254,8 @@ class Ps2_mouse : public Input_driver
/* mirror y axis to make "scroll up" generate positive values */
rel_z = -rel_z;
if (_verbose)
Genode::printf("post WHEEL, rel_z = %d\n", rel_z);
if (_verbose.mouse)
Genode::log("post WHEEL, rel_z=", rel_z);
_check_for_event_queue_overflow();
@ -277,7 +278,7 @@ class Ps2_mouse : public Input_driver
_packet_idx = 0;
}
bool event_pending() { return _aux.data_read_ready(); }
bool event_pending() const { return _aux.data_read_ready(); }
};
#endif /* _DRIVERS__INPUT__SPEC__PS2__PS2_MOUSE_H_ */

View File

@ -0,0 +1,37 @@
/*
* \brief PS/2 driver
* \author Norman Feske
* \date 2017-01-02
*/
/*
* Copyright (C) 2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _DRIVERS__INPUT__SPEC__PS2__VERBOSE_H_
#define _DRIVERS__INPUT__SPEC__PS2__VERBOSE_H_
#include <util/xml_node.h>
namespace Ps2 { struct Verbose; }
struct Ps2::Verbose
{
bool const keyboard;
bool const scancodes;
bool const mouse;
Verbose(Genode::Xml_node config)
:
keyboard (config.attribute_value("verbose_keyboard", false)),
scancodes(config.attribute_value("verbose_scancodes", false)),
mouse (config.attribute_value("verbose_mouse", false))
{ }
};
#endif /* _DRIVERS__INPUT__SPEC__PS2__VERBOSE_H_ */

View File

@ -14,8 +14,7 @@
#ifndef _DRIVERS__INPUT__SPEC__PS2__X86__I8042_H_
#define _DRIVERS__INPUT__SPEC__PS2__X86__I8042_H_
#include <io_port_session/connection.h>
#include <base/env.h>
#include <io_port_session/client.h>
#include <os/ring_buffer.h>
#include "serial_interface.h"
@ -161,7 +160,8 @@ class I8042
Genode::Io_port_session_client _data_port; /* data port */
Genode::Io_port_session_client _stat_port; /* status/command port */
bool _kbd_xlate; /* translation mode to scan-code set 1 */
bool _kbd_xlate = false; /* translation mode to scan-code set 1 */
/**
* Read controller status
@ -246,7 +246,8 @@ class I8042
* Constructor
*/
I8042(Genode::Io_port_session_capability cap_data,
Genode::Io_port_session_capability cap_status) :
Genode::Io_port_session_capability cap_status)
:
_data_port(cap_data),
_stat_port(cap_status),
_kbd_interface(*this, false),
@ -317,12 +318,12 @@ class I8042
/**
* Request serial keyboard interface
*/
Serial_interface *kbd_interface() { return &_kbd_interface; }
Serial_interface &kbd_interface() { return _kbd_interface; }
/**
* Request serial mouse interface
*/
Serial_interface *aux_interface() { return &_aux_interface; }
Serial_interface &aux_interface() { return _aux_interface; }
};
#endif /* _DRIVERS__INPUT__SPEC__PS2__X86__I8042_H_ */

View File

@ -12,14 +12,13 @@
*/
/* base includes */
#include <base/env.h>
#include <base/component.h>
#include <base/attached_rom_dataspace.h>
#include <util/retry.h>
/* os includes */
#include <input/component.h>
#include <input/root.h>
#include <os/config.h>
#include <os/server.h>
#include <platform_session/connection.h>
/* local includes */
@ -27,67 +26,52 @@
#include "ps2_keyboard.h"
#include "ps2_mouse.h"
#include "irq_handler.h"
#include "verbose.h"
using namespace Genode;
namespace Ps2 { struct Main; }
struct Main
struct Ps2::Main
{
Server::Entrypoint &ep;
Genode::Env &_env;
Input::Session_component session;
Input::Root_component root;
Input::Session_component _session;
Input::Root_component _root { _env.ep().rpc_ep(), _session };
Platform::Connection platform;
Platform::Connection _platform { _env };
Platform::Device_capability cap_ps2()
Platform::Device_capability _ps2_device_cap()
{
return Genode::retry<Platform::Session::Out_of_metadata>(
[&] () { return platform.device("PS2"); },
[&] () { platform.upgrade_ram(4096); });
[&] () { return _platform.device("PS2"); },
[&] () { _platform.upgrade_ram(4096); });
}
Platform::Device_client device_ps2;
Platform::Device_client _device_ps2 { _ps2_device_cap() };
I8042 i8042;
enum { REG_IOPORT_DATA = 0, REG_IOPORT_STATUS };
Ps2_keyboard ps2_keybd;
Ps2_mouse ps2_mouse;
I8042 _i8042 { _device_ps2.io_port(REG_IOPORT_DATA),
_device_ps2.io_port(REG_IOPORT_STATUS) };
Irq_handler ps2_keybd_irq;
Irq_handler ps2_mouse_irq;
Genode::Attached_rom_dataspace _config { _env, "config" };
enum { REG_IOPORT_DATA = 0, REG_IOPORT_STATUS};
Verbose _verbose { _config.xml() };
bool _check_verbose(const char * verbose)
Keyboard _keyboard { _i8042.kbd_interface(), _session.event_queue(),
_i8042.kbd_xlate(), _verbose };
Mouse _mouse { _i8042.aux_interface(), _session.event_queue(), _verbose };
Irq_handler _keyboard_irq { _env.ep(), _keyboard, _device_ps2.irq(0) };
Irq_handler _mouse_irq { _env.ep(), _mouse, _device_ps2.irq(1) };
Main(Genode::Env &env) : _env(env)
{
return Genode::config()->xml_node().attribute_value(verbose, false);
}
Main(Server::Entrypoint &ep)
: ep(ep), root(ep.rpc_ep(), session),
device_ps2(cap_ps2()),
i8042(device_ps2.io_port(REG_IOPORT_DATA),
device_ps2.io_port(REG_IOPORT_STATUS)),
ps2_keybd(*i8042.kbd_interface(), session.event_queue(),
i8042.kbd_xlate(), _check_verbose("verbose_keyboard"),
_check_verbose("verbose_scancodes")),
ps2_mouse(*i8042.aux_interface(), session.event_queue(),
_check_verbose("verbose_mouse")),
ps2_keybd_irq(ep, ps2_keybd, device_ps2.irq(0)),
ps2_mouse_irq(ep, ps2_mouse, device_ps2.irq(1))
{
env()->parent()->announce(ep.manage(root));
env.parent().announce(env.ep().manage(_root));
}
};
/************
** Server **
************/
void Component::construct( Genode::Env &env) { static Ps2::Main ps2(env); }
namespace Server {
char const *name() { return "ps2_drv_ep"; }
size_t stack_size() { return 8*1024*sizeof(long); }
void construct(Entrypoint &ep) { static Main server(ep); }
}

View File

@ -1,6 +1,6 @@
TARGET = ps2_drv
REQUIRES = x86 ps2
REQUIRES = x86
SRC_CC = main.cc
LIBS = base server config
LIBS = base
INC_DIR = $(PRG_DIR)/..

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
TARGET = ram_fs
SRC_CC = main.cc
LIBS = base config server
LIBS = base
INC_DIR += $(PRG_DIR)

View File

@ -16,10 +16,7 @@
/* Genode includes */
#include <util/xml_node.h>
#include <os/attached_rom_dataspace.h>
#include <os/config.h>
#include <os/attached_ram_dataspace.h>
#include <os/server.h>
#include <base/attached_rom_dataspace.h>
#include <base/allocator.h>
namespace Rom_filter {
@ -36,7 +33,7 @@ namespace Rom_filter {
using Genode::env;
using Genode::Signal_context_capability;
using Genode::Signal_rpc_member;
using Genode::Signal_handler;
using Genode::Xml_node;
}
@ -64,34 +61,30 @@ class Rom_filter::Input_rom_registry
{
private:
Server::Entrypoint &_ep;
Genode::Env &_env;
Input_rom_name _name;
Input_rom_changed_fn &_input_rom_changed_fn;
Genode::Attached_rom_dataspace _rom_ds { _name.string() };
Genode::Attached_rom_dataspace _rom_ds { _env, _name.string() };
Xml_node _top_level { "<empty/>" };
void _handle_rom_changed(unsigned)
void _handle_rom_changed()
{
_rom_ds.update();
if (!_rom_ds.valid())
return;
try {
_top_level = Xml_node(_rom_ds.local_addr<char>());
} catch (...) {
_top_level = Xml_node("<empty/>");
}
_top_level = _rom_ds.xml();
/* trigger re-evaluation of the inputs */
_input_rom_changed_fn.input_rom_changed();
}
Genode::Signal_rpc_member<Entry> _rom_changed_dispatcher =
{ _ep, *this, &Entry::_handle_rom_changed };
Genode::Signal_handler<Entry> _rom_changed_handler =
{ _env.ep(), *this, &Entry::_handle_rom_changed };
/**
* Query value from XML-structured ROM content
@ -155,13 +148,13 @@ class Rom_filter::Input_rom_registry
/**
* Constructor
*/
Entry(Input_rom_name const &name, Server::Entrypoint &ep,
Entry(Genode::Env &env, Input_rom_name const &name,
Input_rom_changed_fn &input_rom_changed_fn)
:
_ep(ep), _name(name),
_env(env), _name(name),
_input_rom_changed_fn(input_rom_changed_fn)
{
_rom_ds.sigh(_rom_changed_dispatcher);
_rom_ds.sigh(_rom_changed_handler);
}
Input_rom_name name() const { return _name; }
@ -202,7 +195,7 @@ class Rom_filter::Input_rom_registry
Genode::Allocator &_alloc;
Server::Entrypoint &_ep;
Genode::Env &_env;
Genode::List<Entry> _input_roms;
@ -310,10 +303,10 @@ class Rom_filter::Input_rom_registry
* \param sigh signal context capability to install in ROM sessions
* for the inputs
*/
Input_rom_registry(Genode::Allocator &alloc, Server::Entrypoint &ep,
Input_rom_registry(Genode::Env &env, Genode::Allocator &alloc,
Input_rom_changed_fn &input_rom_changed_fn)
:
_alloc(alloc), _ep(ep), _input_rom_changed_fn(input_rom_changed_fn)
_alloc(alloc), _env(env), _input_rom_changed_fn(input_rom_changed_fn)
{ }
void update_config(Xml_node config)
@ -342,7 +335,7 @@ class Rom_filter::Input_rom_registry
return;
Entry *entry =
new (_alloc) Entry(name, _ep, _input_rom_changed_fn);
new (_alloc) Entry(_env, name, _input_rom_changed_fn);
_input_roms.insert(entry);
};

View File

@ -16,17 +16,17 @@
#include <util/arg_string.h>
#include <util/xml_generator.h>
#include <base/heap.h>
#include <base/env.h>
#include <base/component.h>
#include <base/attached_ram_dataspace.h>
#include <root/component.h>
/* local includes */
#include "input_rom_registry.h"
namespace Rom_filter {
using Server::Entrypoint;
using Genode::Entrypoint;
using Genode::Rpc_object;
using Genode::Sliced_heap;
using Genode::env;
using Genode::Constructible;
using Genode::Xml_generator;
using Genode::size_t;
@ -55,6 +55,8 @@ class Rom_filter::Session_component : public Rpc_object<Genode::Rom_session>,
{
private:
Genode::Env &_env;
Signal_context_capability _sigh;
Output_buffer const &_output_buffer;
@ -65,9 +67,10 @@ class Rom_filter::Session_component : public Rpc_object<Genode::Rom_session>,
public:
Session_component(Session_list &sessions, Output_buffer const &output_buffer)
Session_component(Genode::Env &env, Session_list &sessions,
Output_buffer const &output_buffer)
:
_output_buffer(output_buffer), _sessions(sessions)
_env(env), _output_buffer(output_buffer), _sessions(sessions)
{
_sessions.insert(this);
}
@ -90,7 +93,7 @@ class Rom_filter::Session_component : public Rpc_object<Genode::Rom_session>,
if (!_ram_ds.constructed()
|| _output_buffer.content_size() > _ram_ds->size()) {
_ram_ds.construct(env()->ram_session(), _output_buffer.content_size());
_ram_ds.construct(_env.ram(), _env.rm(), _output_buffer.content_size());
}
char *dst = _ram_ds->local_addr<char>();
@ -118,6 +121,7 @@ class Rom_filter::Root : public Genode::Root_component<Session_component>
{
private:
Genode::Env &_env;
Output_buffer &_output_buffer;
Session_list _sessions;
@ -128,16 +132,17 @@ class Rom_filter::Root : public Genode::Root_component<Session_component>
/*
* We ignore the name of the ROM module requested
*/
return new (md_alloc()) Session_component(_sessions, _output_buffer);
return new (md_alloc()) Session_component(_env, _sessions, _output_buffer);
}
public:
Root(Entrypoint &ep, Output_buffer &output_buffer,
Root(Genode::Env &env,
Output_buffer &output_buffer,
Genode::Allocator &md_alloc)
:
Genode::Root_component<Session_component>(&ep.rpc_ep(), &md_alloc),
_output_buffer(output_buffer)
Genode::Root_component<Session_component>(&env.ep().rpc_ep(), &md_alloc),
_env(env), _output_buffer(output_buffer)
{ }
void notify_clients()
@ -151,11 +156,13 @@ class Rom_filter::Root : public Genode::Root_component<Session_component>
struct Rom_filter::Main : Input_rom_registry::Input_rom_changed_fn,
Output_buffer
{
Entrypoint &_ep;
Genode::Env &_env;
Sliced_heap _sliced_heap = { env()->ram_session(), env()->rm_session() };
Sliced_heap _sliced_heap { _env.ram(), _env.rm() };
Input_rom_registry _input_rom_registry { *env()->heap(), _ep, *this };
Genode::Heap _heap { _env.ram(), _env.rm() };
Input_rom_registry _input_rom_registry { _env, _heap, *this };
Genode::Constructible<Genode::Attached_ram_dataspace> _xml_ds;
@ -164,30 +171,32 @@ struct Rom_filter::Main : Input_rom_registry::Input_rom_changed_fn,
void _evaluate_node(Xml_node node, Xml_generator &xml);
void _evaluate();
Root _root = { _ep, *this, _sliced_heap };
Root _root = { _env, *this, _sliced_heap };
Genode::Signal_rpc_member<Main> _config_dispatcher =
{ _ep, *this, &Main::_handle_config };
Genode::Attached_rom_dataspace _config { _env, "config" };
void _handle_config(unsigned)
Genode::Signal_handler<Main> _config_handler =
{ _env.ep(), *this, &Main::_handle_config };
void _handle_config()
{
Genode::config()->reload();
_config.update();
/*
* Create buffer for generated XML data
*/
Genode::Number_of_bytes xml_ds_size = 4096;
xml_ds_size = Genode::config()->xml_node().attribute_value("buffer", xml_ds_size);
xml_ds_size = _config.xml().attribute_value("buffer", xml_ds_size);
if (!_xml_ds.constructed() || xml_ds_size != _xml_ds->size())
_xml_ds.construct(env()->ram_session(), xml_ds_size);
_xml_ds.construct(_env.ram(), _env.rm(), xml_ds_size);
/*
* Obtain inputs
*/
try {
_input_rom_registry.update_config(Genode::config()->xml_node());
_input_rom_registry.update_config(_config.xml());
} catch (Xml_node::Nonexistent_sub_node) { }
/*
@ -209,10 +218,7 @@ struct Rom_filter::Main : Input_rom_registry::Input_rom_changed_fn,
/**
* Output_buffer interface
*/
size_t content_size() const override
{
return _xml_output_len;
}
size_t content_size() const override { return _xml_output_len; }
/**
* Output_buffer interface
@ -224,13 +230,11 @@ struct Rom_filter::Main : Input_rom_registry::Input_rom_changed_fn,
return len;
}
Main(Entrypoint &ep) : _ep(ep)
Main(Genode::Env &env) : _env(env)
{
env()->parent()->announce(_ep.manage(_root));
Genode::config()->sigh(_config_dispatcher);
_handle_config(0);
_env.parent().announce(_env.ep().manage(_root));
_config.sigh(_config_handler);
_handle_config();
}
};
@ -257,10 +261,8 @@ void Rom_filter::Main::_evaluate_node(Xml_node node, Xml_generator &xml)
has_value_node.attribute_value("value", Input_value());
try {
Xml_node config = Genode::config()->xml_node();
Input_value const input_value =
_input_rom_registry.query_value(config, input_name);
_input_rom_registry.query_value(_config.xml(), input_name);
if (input_value == expected_input_value)
condition_satisfied = true;
@ -310,7 +312,7 @@ void Rom_filter::Main::_evaluate_node(Xml_node node, Xml_generator &xml)
void Rom_filter::Main::_evaluate()
{
try {
Xml_node output = Genode::config()->xml_node().sub_node("output");
Xml_node output = _config.xml().sub_node("output");
if (!output.has_attribute("node")) {
Genode::error("missing 'node' attribute in '<output>' node");
@ -333,14 +335,5 @@ void Rom_filter::Main::_evaluate()
}
namespace Server {
void Component::construct(Genode::Env &env) { static Rom_filter::Main main(env); }
char const *name() { return "conditional_rom_ep"; }
size_t stack_size() { return 16*1024*sizeof(long); }
void construct(Entrypoint &ep)
{
static Rom_filter::Main main(ep);
}
}

View File

@ -1,3 +1,3 @@
TARGET = rom_filter
SRC_CC = main.cc
LIBS = base server config
LIBS = base

View File

@ -12,26 +12,27 @@
*/
/* Genode includes */
#include <rom_session/connection.h>
#include <cap_session/connection.h>
#include <root/component.h>
#include <dataspace/client.h>
#include <base/rpc_server.h>
#include <base/component.h>
#include <base/log.h>
#include <base/env.h>
#include <base/sleep.h>
#include <base/heap.h>
#include <os/config.h>
#include <base/attached_rom_dataspace.h>
#include <timer_session/connection.h>
#include <base/session_label.h>
namespace Rom_prefetcher {
class Rom_session_component;
class Rom_root;
struct Main;
}
volatile int dummy;
static void prefetch_dataspace(Genode::Dataspace_capability ds)
static void prefetch_dataspace(Genode::Region_map &rm, Genode::Dataspace_capability cap)
{
char *mapped = Genode::env()->rm_session()->attach(ds);
Genode::size_t size = Genode::Dataspace_client(ds).size();
Genode::Attached_dataspace ds(rm, cap);
/*
* Modify global volatile 'dummy' variable to prevent the compiler
@ -39,14 +40,12 @@ static void prefetch_dataspace(Genode::Dataspace_capability ds)
*/
enum { PREFETCH_STEP = 4096 };
for (Genode::size_t i = 0; i < size; i += PREFETCH_STEP)
dummy += mapped[i];
Genode::env()->rm_session()->detach(mapped);
for (Genode::size_t i = 0; i < ds.size(); i += PREFETCH_STEP)
dummy += ds.local_addr<char>()[i];
}
class Rom_session_component : public Genode::Rpc_object<Genode::Rom_session>
class Rom_prefetcher::Rom_session_component : public Genode::Rpc_object<Genode::Rom_session>
{
private:
@ -59,99 +58,85 @@ class Rom_session_component : public Genode::Rpc_object<Genode::Rom_session>
*
* \param filename name of the requested file
*/
Rom_session_component(const char *filename) : _rom(filename)
Rom_session_component(Genode::Env &env, Genode::Session_label const &label)
:
_rom(label.string())
{
prefetch_dataspace(_rom.dataspace());
prefetch_dataspace(env.rm(), _rom.dataspace());
}
/***************************
** ROM session interface **
***************************/
Genode::Rom_dataspace_capability dataspace() {
return _rom.dataspace(); }
Genode::Rom_dataspace_capability dataspace() { return _rom.dataspace(); }
void sigh(Genode::Signal_context_capability) { }
};
class Rom_root : public Genode::Root_component<Rom_session_component>
class Rom_prefetcher::Rom_root : public Genode::Root_component<Rom_session_component>
{
private:
Genode::Env &_env;
Rom_session_component *_create_session(const char *args)
{
Genode::Session_label const label = Genode::label_from_args(args);
Genode::Session_label const name = label.last_element();
/* create new session for the requested file */
return new (md_alloc())
Rom_session_component(name.string());
Rom_session_component(_env, label.last_element());
}
public:
/**
* Constructor
*
* \param entrypoint entrypoint to be used for ROM sessions
* \param md_alloc meta-data allocator used for ROM sessions
*/
Rom_root(Genode::Rpc_entrypoint *entrypoint,
Genode::Allocator *md_alloc)
Rom_root(Genode::Env &env, Genode::Allocator &md_alloc)
:
Genode::Root_component<Rom_session_component>(entrypoint, md_alloc)
Genode::Root_component<Rom_session_component>(env.ep(), md_alloc),
_env(env)
{ }
};
int main(int argc, char **argv)
struct Rom_prefetcher::Main
{
using namespace Genode;
Genode::Env &_env;
/* connection to capability service needed to create capabilities */
static Cap_connection cap;
Genode::Attached_rom_dataspace _config { _env, "config" };
/*
* Prefetch ROM files specified in the config
*/
try {
Timer::Connection timer;
Genode::Xml_node entry = config()->xml_node().sub_node("rom");
for (;;) {
Genode::Sliced_heap _sliced_heap { _env.ram(), _env.rm() };
enum { NAME_MAX_LEN = 64 };
char name[NAME_MAX_LEN];
name[0] = 0;
entry.attribute("name").value(name, sizeof(name));
Rom_root _root { _env, _sliced_heap };
Main(Genode::Env &env) : _env(env)
{
Timer::Connection timer(_env);
_config.xml().for_each_sub_node("rom", [&] (Genode::Xml_node entry) {
typedef Genode::String<64> Name;
Name const name = entry.attribute_value("name", Name());
try {
Rom_connection rom(name);
log("prefetching ROM module ", Cstring(name));
prefetch_dataspace(rom.dataspace());
Genode::Rom_connection rom(_env, name.string());
log("prefetching ROM module ", name);
prefetch_dataspace(_env.rm(), rom.dataspace());
} catch (...) {
error("could not open ROM module ", Cstring(name));
error("could not open ROM module ", name);
}
/* proceed with next XML node */
entry = entry.next("rom");
/* yield */
timer.msleep(1);
}
} catch (...) { }
});
static Sliced_heap sliced_heap(env()->ram_session(),
env()->rm_session());
/* creation of the entrypoint and the root interface */
enum { STACK_SIZE = 8*1024 };
static Rpc_entrypoint ep(&cap, STACK_SIZE, "rom_pf_ep");
static Rom_root rom_root(&ep, &sliced_heap);
/* announce server */
env()->parent()->announce(ep.manage(&rom_root));
/* wait for activation through client */
sleep_forever();
return 0;
/* announce server */
_env.parent().announce(_env.ep().manage(_root));
}
};
void Component::construct(Genode::Env &env) { static Rom_prefetcher::Main main(env); }

View File

@ -1,3 +1,3 @@
TARGET = rom_prefetcher
SRC_CC = main.cc
LIBS += base config
LIBS += base

View File

@ -13,29 +13,35 @@
*/
/* Genode includes */
#include <rom_session/rom_session.h>
#include <root/component.h>
#include <cap_session/connection.h>
#include <util/arg_string.h>
#include <base/rpc_server.h>
#include <base/sleep.h>
#include <base/env.h>
#include <base/component.h>
#include <base/attached_rom_dataspace.h>
#include <base/heap.h>
#include <base/log.h>
#include <os/config.h>
#include <base/session_label.h>
#include <root/component.h>
namespace Tar_rom {
using namespace Genode;
class Rom_session_component;
class Rom_root;
struct Main;
}
/**
* A 'Rom_session_component' exports a single file of the tar archive
*/
class Rom_session_component : public Genode::Rpc_object<Genode::Rom_session>
class Tar_rom::Rom_session_component : public Rpc_object<Rom_session>
{
private:
const char *_tar_addr, *_filename, *_file_addr;
Genode::size_t _file_size, _tar_size;
Genode::Ram_dataspace_capability _file_ds;
Ram_session &_ram;
char const * const _tar_addr;
size_t const _tar_size;
Ram_dataspace_capability _file_ds;
enum {
/* length of on data block in tar */
@ -50,39 +56,34 @@ class Rom_session_component : public Genode::Rpc_object<Genode::Rom_session>
*
* \param dst destination dataspace
*/
void _copy_content_to_dataspace(Genode::Dataspace_capability dst)
void _copy_content_to_dataspace(Region_map &rm, Dataspace_capability dst,
char const *src, size_t len)
{
using namespace Genode;
/* map dataspace locally */
char *dst_addr = env()->rm_session()->attach(dst);
Dataspace_client dst_client(dst);
/* temporarily map dataspace */
Attached_dataspace ds(rm, dst);
/* copy content */
size_t dst_ds_size = Dataspace_client(dst).size();
size_t bytes_to_copy = min(_file_size, dst_ds_size);
memcpy(dst_addr, _file_addr, bytes_to_copy);
/* unmap dataspace */
env()->rm_session()->detach(dst_addr);
size_t bytes_to_copy = min(len, ds.size());
memcpy(ds.local_addr<char>(), src, bytes_to_copy);
}
/**
* Initialize dataspace containing the content of the archived file
*/
Genode::Ram_dataspace_capability _init_file_ds()
Ram_dataspace_capability _init_file_ds(Ram_session &ram, Region_map &rm,
Session_label const &name)
{
bool file_found = false;
/* measure size of archive in blocks */
unsigned block_id = 0, block_cnt = _tar_size/_BLOCK_LEN;
char const *file_content = nullptr;
unsigned long file_size = 0;
/* scan metablocks of archive */
while (block_id < block_cnt) {
unsigned long file_size = 0;
Genode::ascii_to_unsigned(_tar_addr + block_id*_BLOCK_LEN +
_FIELD_SIZE_LEN, file_size, 8);
ascii_to_unsigned(_tar_addr + block_id*_BLOCK_LEN +
_FIELD_SIZE_LEN, file_size, 8);
/* get name of tar record */
char const *record_filename = _tar_addr + block_id*_BLOCK_LEN;
@ -92,10 +93,8 @@ class Rom_session_component : public Genode::Rpc_object<Genode::Rom_session>
record_filename++;
/* get infos about current file */
if (Genode::strcmp(_filename, record_filename) == 0) {
_file_size = file_size;
_file_addr = _tar_addr + (block_id+1) * _BLOCK_LEN;
file_found = true;
if (name == record_filename) {
file_content = _tar_addr + (block_id+1) * _BLOCK_LEN;
break;
}
@ -115,20 +114,20 @@ class Rom_session_component : public Genode::Rpc_object<Genode::Rom_session>
break;
}
if (!file_found) {
Genode::error("couldn't find file '", _filename, "', empty result");
return Genode::Ram_dataspace_capability();
if (!file_content) {
error("couldn't find file '", name, "', empty result");
return Ram_dataspace_capability();
}
/* try to allocate memory for file */
Genode::Ram_dataspace_capability file_ds;
Ram_dataspace_capability file_ds;
try {
file_ds = Genode::env()->ram_session()->alloc(_file_size);
file_ds = ram.alloc(file_size);
/* get content of file copied into dataspace and return */
_copy_content_to_dataspace(file_ds);
_copy_content_to_dataspace(rm, file_ds, file_content, file_size);
} catch (...) {
Genode::error("couldn't allocate memory for file, empty result");
error("couldn't allocate memory for file, empty result");
return file_ds;
}
@ -142,55 +141,55 @@ class Rom_session_component : public Genode::Rpc_object<Genode::Rom_session>
*
* \param tar_addr local address to tar archive
* \param tar_size size of tar archive in bytes
* \param filename name of the requested file
* \param label name of the requested ROM module
*/
Rom_session_component(const char *tar_addr, unsigned tar_size,
const char *filename)
Rom_session_component(Ram_session &ram, Region_map &rm,
char const *tar_addr, unsigned tar_size,
Session_label const &label)
:
_tar_addr(tar_addr), _filename(filename), _file_addr(0), _file_size(0),
_tar_size(tar_size),
_file_ds(_init_file_ds())
_ram(ram), _tar_addr(tar_addr), _tar_size(tar_size),
_file_ds(_init_file_ds(ram, rm, label))
{
if (!_file_ds.valid())
throw Genode::Root::Invalid_args();
throw Root::Invalid_args();
}
/**
* Destructor
*/
~Rom_session_component() { Genode::env()->ram_session()->free(_file_ds); }
~Rom_session_component() { _ram.free(_file_ds); }
/**
* Return dataspace with content of file
*/
Genode::Rom_dataspace_capability dataspace()
Rom_dataspace_capability dataspace()
{
Genode::Dataspace_capability ds = _file_ds;
return Genode::static_cap_cast<Genode::Rom_dataspace>(ds);
Dataspace_capability ds = _file_ds;
return static_cap_cast<Rom_dataspace>(ds);
}
void sigh(Genode::Signal_context_capability) { }
void sigh(Signal_context_capability) { }
};
class Rom_root : public Genode::Root_component<Rom_session_component>
class Tar_rom::Rom_root : public Root_component<Rom_session_component>
{
private:
char *_tar_addr;
unsigned _tar_size;
Env &_env;
char const * const _tar_addr;
unsigned const _tar_size;
Rom_session_component *_create_session(const char *args)
{
using namespace Genode;
Session_label const label = label_from_args(args);
Session_label const module_name = label.last_element();
Genode::log("connection for module '", module_name, "' requested");
log("connection for module '", module_name, "' requested");
/* create new session for the requested file */
return new (md_alloc()) Rom_session_component(_tar_addr, _tar_size,
return new (md_alloc()) Rom_session_component(_env.ram(), _env.rm(),
_tar_addr, _tar_size,
module_name.string());
}
@ -199,67 +198,53 @@ class Rom_root : public Genode::Root_component<Rom_session_component>
/**
* Constructor
*
* \param entrypoint entrypoint to be used for ROM sessions
* \param md_alloc meta-data allocator used for ROM sessions
* \param tar_base local address of tar archive
* \param tar_size size of tar archive in bytes
* \param tar_base local address of tar archive
* \param tar_size size of tar archive in bytes
*/
Rom_root(Genode::Rpc_entrypoint *entrypoint,
Genode::Allocator *md_alloc,
char *tar_addr, Genode::size_t tar_size)
Rom_root(Env &env, Allocator &md_alloc,
char const *tar_addr, size_t tar_size)
:
Genode::Root_component<Rom_session_component>(entrypoint, md_alloc),
_tar_addr(tar_addr), _tar_size(tar_size)
Root_component<Rom_session_component>(env.ep(), md_alloc),
_env(env), _tar_addr(tar_addr), _tar_size(tar_size)
{ }
};
using namespace Genode;
int main(void)
struct Tar_rom::Main
{
/* read name of tar archive from config */
enum { TAR_FILENAME_MAX_LEN = 64 };
static char tar_filename[TAR_FILENAME_MAX_LEN];
try {
Xml_node archive_node =
config()->xml_node().sub_node("archive");
archive_node.attribute("name").value(tar_filename, sizeof(tar_filename));
} catch (...) {
Genode::error("could not read 'filename' argument from config");
return -1;
Env &_env;
Attached_rom_dataspace _config { _env, "config" };
typedef String<64> Name;
/**
* Read name of tar archive from config
*/
Name _tar_name()
{
try {
return _config.xml().sub_node("archive").attribute_value("name", Name());
} catch (...) {
error("could not read archive name argument from config");
throw;
}
}
/* obtain dataspace of tar archive from ROM service */
static char *tar_base = 0;
static size_t tar_size = 0;
try {
static Rom_connection tar_rom(tar_filename);
tar_base = env()->rm_session()->attach(tar_rom.dataspace());
tar_size = Dataspace_client(tar_rom.dataspace()).size();
} catch (...) {
Genode::error("could not obtain tar archive from ROM service");
return -2;
Attached_rom_dataspace _tar_ds { _env, _tar_name().string() };
Sliced_heap _sliced_heap { _env.ram(), _env.rm() };
Rom_root _root { _env, _sliced_heap, _tar_ds.local_addr<char>(), _tar_ds.size() };
Main(Env &env) : _env(env)
{
log("using tar archive '", _tar_name(), "' with size ", _tar_ds.size());
env.parent().announce(env.ep().manage(_root));
}
};
Genode::log("using tar archive '", Cstring(tar_filename), "' with size ", tar_size);
/* connection to capability service needed to create capabilities */
static Cap_connection cap;
void Component::construct(Genode::Env &env) { static Tar_rom::Main main(env); }
/* creation of the entrypoint and the root interface */
static Sliced_heap sliced_heap(env()->ram_session(),
env()->rm_session());
enum { STACK_SIZE = 8*1024 };
static Rpc_entrypoint ep(&cap, STACK_SIZE, "tar_rom_ep");
static Rom_root rom_root(&ep, &sliced_heap, tar_base, tar_size);
/* announce server*/
env()->parent()->announce(ep.manage(&rom_root));
/* wait for activation through client */
sleep_forever();
return 0;
}

View File

@ -1,3 +1,3 @@
TARGET = tar_rom
SRC_CC = main.cc
LIBS = base config
LIBS = base

View File

@ -12,8 +12,6 @@
*/
/* Genode includes */
#include <cap_session/connection.h>
#include <os/config.h>
#include <os/alarm.h>
#include <timer_session/connection.h>
@ -915,34 +913,30 @@ bool Noux::Child::syscall(Noux::Session::Syscall sc)
/**
* Return name of init process as specified in the config
*/
static char const *name_of_init_process()
static Genode::Child_policy::Name name_of_init_process(Genode::Xml_node config)
{
enum { INIT_NAME_LEN = 128 };
static char buf[INIT_NAME_LEN];
Genode::config()->xml_node().sub_node("start").attribute("name").value(buf, sizeof(buf));
return buf;
return config.sub_node("start").attribute_value("name", Genode::Child_policy::Name());
}
/**
* Read command-line arguments of init process from config
*/
static Noux::Args const &args_of_init_process()
static Noux::Args const &args_of_init_process(Genode::Xml_node config)
{
static char args_buf[4096];
static Noux::Args args(args_buf, sizeof(args_buf));
Genode::Xml_node start_node = Genode::config()->xml_node().sub_node("start");
Genode::Xml_node start_node = config.sub_node("start");
try {
/* the first argument is the program name */
args.append(name_of_init_process());
args.append(name_of_init_process(config).string());
Genode::Xml_node arg_node = start_node.sub_node("arg");
for (; ; arg_node = arg_node.next("arg")) {
static char buf[512];
arg_node.attribute("value").value(buf, sizeof(buf));
args.append(buf);
typedef Genode::String<512> Value;
args.append(arg_node.attribute_value("value", Value()).string());
}
}
catch (Genode::Xml_node::Nonexistent_sub_node) { }
@ -958,13 +952,13 @@ static Noux::Args const &args_of_init_process()
* The variable definitions are separated by zeros. The end of the string is
* marked with another zero.
*/
static Noux::Sysio::Env &env_string_of_init_process()
static Noux::Sysio::Env &env_string_of_init_process(Genode::Xml_node config)
{
static Noux::Sysio::Env env;
int index = 0;
/* read environment variables for init process from config */
Genode::Xml_node start_node = Genode::config()->xml_node().sub_node("start");
Genode::Xml_node start_node = config.sub_node("start");
try {
Genode::Xml_node arg_node = start_node.sub_node("env");
for (; ; arg_node = arg_node.next("env")) {
@ -1026,15 +1020,23 @@ Terminal::Connection *Noux::terminal()
}
static Noux::Io_channel *connect_stdio(Vfs::Dir_file_system &root,
class Stdio_unavailable : Genode::Exception { };
/*
* \throw Stdio_unavailable
*/
static Noux::Io_channel &connect_stdio(Genode::Xml_node config,
Vfs::Dir_file_system &root,
Noux::Terminal_io_channel::Type type,
Genode::Signal_receiver &sig_rec)
Genode::Signal_receiver &sig_rec,
Genode::Allocator &alloc)
{
using namespace Vfs;
using namespace Noux;
typedef Terminal_io_channel Tio; /* just a local abbreviation */
char path[MAX_PATH_LEN];
typedef Genode::String<MAX_PATH_LEN> Path;
Vfs_handle *vfs_handle = nullptr;
char const *stdio_name = "";
unsigned mode = 0;
@ -1054,26 +1056,22 @@ static Noux::Io_channel *connect_stdio(Vfs::Dir_file_system &root,
break;
};
try {
config()->xml_node().attribute(stdio_name).value(
path, sizeof(path));
if (root.open(path, mode, &vfs_handle, *Genode::env()->heap())
!= Directory_service::OPEN_OK)
{
error("failed to connect ", stdio_name, " to '", Cstring(path), "'");
Genode::env()->parent()->exit(1);
}
return new (Genode::env()->heap())
Vfs_io_channel(path, root.leaf_path(path), &root, vfs_handle, sig_rec);
} catch (Genode::Xml_node::Nonexistent_attribute) {
if (!config.has_attribute(stdio_name)) {
warning(stdio_name, " VFS path not defined, connecting to terminal session");
return *new (alloc) Tio(*Noux::terminal(), type, sig_rec);
}
return new (Genode::env()->heap())
Tio(*Noux::terminal(), type, sig_rec);
Path const path = config.attribute_value(stdio_name, Path());
if (root.open(path.string(), mode, &vfs_handle, alloc)
!= Directory_service::OPEN_OK)
{
error("failed to connect ", stdio_name, " to '", path, "'");
throw Stdio_unavailable();
}
return *new (alloc)
Vfs_io_channel(path.string(), root.leaf_path(path.string()), &root, vfs_handle, sig_rec);
}
@ -1138,9 +1136,13 @@ void Component::construct(Genode::Env &env)
for (unsigned i = 0; service_names[i]; i++)
new Noux::Parent_service(parent_services, service_names[i]);
static Genode::Attached_rom_dataspace config(env, "config");
static Genode::Heap heap(env.ram(), env.rm());
/* obtain global configuration */
trace_syscalls = config()->xml_node().attribute_value("trace_syscalls", trace_syscalls);
verbose = config()->xml_node().attribute_value("verbose", verbose);
trace_syscalls = config.xml().attribute_value("trace_syscalls", trace_syscalls);
verbose = config.xml().attribute_value("verbose", verbose);
/* register additional file systems to the VFS */
Vfs::Global_file_system_factory &fs_factory = Vfs::global_file_system_factory();
@ -1152,13 +1154,13 @@ void Component::construct(Genode::Env &env)
fs_factory.extend("random", random_file_system_factory);
/* initialize virtual file system */
static Vfs::Dir_file_system root_dir(env, *Genode::env()->heap(),
config()->xml_node().sub_node("fstab"),
static Vfs::Dir_file_system root_dir(env, heap,
config.xml().sub_node("fstab"),
fs_factory);
/* set user information */
try {
user_info()->set_info(config()->xml_node().sub_node("user"));
user_info()->set_info(config.xml().sub_node("user"));
}
catch (...) { }
@ -1170,7 +1172,7 @@ void Component::construct(Genode::Env &env)
*/
enum { STACK_SIZE = 2*1024*sizeof(long) };
static Genode::Rpc_entrypoint
resources_ep(Genode::env()->pd_session(), STACK_SIZE, "noux_rsc_ep");
resources_ep(&env.pd(), STACK_SIZE, "noux_rsc_ep");
/* create init process */
static Genode::Signal_receiver sig_rec;
@ -1191,22 +1193,22 @@ void Component::construct(Genode::Env &env)
static Kill_broadcaster_implementation kill_broadcaster;
init_child = new Noux::Child(name_of_init_process(),
init_child = new Noux::Child(name_of_init_process(config.xml()),
0,
kill_broadcaster,
*init_child,
pid_allocator()->alloc(),
sig_rec,
root_dir,
args_of_init_process(),
env_string_of_init_process(),
*Genode::env()->pd_session(),
args_of_init_process(config.xml()),
env_string_of_init_process(config.xml()),
env.pd(),
ref_ram,
Ram_session_capability(),
parent_services,
resources_ep,
false,
*Genode::env()->heap(),
heap,
destruct_queue,
verbose);
@ -1218,9 +1220,9 @@ void Component::construct(Genode::Env &env)
*/
typedef Terminal_io_channel Tio; /* just a local abbreviation */
Shared_pointer<Io_channel>
channel_0(connect_stdio(root_dir, Tio::STDIN, sig_rec), Genode::env()->heap()),
channel_1(connect_stdio(root_dir, Tio::STDOUT, sig_rec), Genode::env()->heap()),
channel_2(connect_stdio(root_dir, Tio::STDERR, sig_rec), Genode::env()->heap());
channel_0(&connect_stdio(config.xml(), root_dir, Tio::STDIN, sig_rec, heap), &heap),
channel_1(&connect_stdio(config.xml(), root_dir, Tio::STDOUT, sig_rec, heap), &heap),
channel_2(&connect_stdio(config.xml(), root_dir, Tio::STDERR, sig_rec, heap), &heap);
init_child->add_io_channel(channel_0, 0);
init_child->add_io_channel(channel_1, 1);

View File

@ -1,5 +1,5 @@
TARGET = noux
LIBS = alarm config vfs
LIBS = alarm vfs
SRC_CC = main.cc dummy_net.cc
INC_DIR += $(PRG_DIR)
INC_DIR += $(PRG_DIR)/../

View File

@ -1,5 +1,5 @@
TARGET = noux_net
LIBS += alarm libc libc_lwip_nic_dhcp config vfs
LIBS += alarm libc libc_lwip_nic_dhcp vfs
SRC_CC = main.cc net.cc