Adapt high-level components to new parent API

This patch adjusts the various users of the 'Child' API to the changes
on the account of the new non-blocking parent interface. It also removes
the use of the no-longer-available 'Connection::KEEP_OPEN' feature.

With the adjustment, we took the opportunity to redesign several
components to fit the non-blocking execution model much better, in
particular the demo applications.

Issue #2120
This commit is contained in:
Norman Feske
2016-11-23 17:07:49 +01:00
committed by Christian Helmuth
parent 8bafb9d41b
commit b44f0554bd
146 changed files with 3026 additions and 3484 deletions

View File

@ -32,18 +32,18 @@ class Kill_event_handler : public Scout::Event_handler
{
private:
Launchpad *_launchpad;
Launchpad_child *_launchpad_child;
Launchpad &_launchpad;
Launchpad_child &_launchpad_child;
public:
Kill_event_handler(Launchpad *launchpad, Launchpad_child *launchpad_child):
Kill_event_handler(Launchpad &launchpad, Launchpad_child &launchpad_child):
_launchpad(launchpad), _launchpad_child(launchpad_child) { }
/**
* Event handler interface
*/
void handle(Scout::Event &ev)
void handle_event(Scout::Event const &ev) override
{
static int key_cnt;
@ -53,7 +53,7 @@ class Kill_event_handler : public Scout::Event_handler
if (ev.type == Event::RELEASE) key_cnt--;
if (ev.type == Event::RELEASE && key_cnt == 0)
_launchpad->exit_child(_launchpad_child);
_launchpad.exit_child(_launchpad_child);
}
};
@ -73,7 +73,7 @@ class Child_entry : public Scout::Parent_element,
Scout::Block _block;
Kbyte_loadbar<PT> _loadbar;
char _name[_NAME_LEN];
Launchpad_child::Name const _name;
Scout::Fade_icon<PT, _IW, _IH> _kill_icon;
Scout::Fade_icon<PT, _IW, _IH> _fold_icon;
@ -85,14 +85,14 @@ class Child_entry : public Scout::Parent_element,
/**
* Constructor
*/
Child_entry(const char *name, int quota_kb, int max_quota_kb,
Launchpad *launchpad, Launchpad_child *launchpad_child)
Child_entry(Launchpad_child::Name const &name, int quota_kb, int max_quota_kb,
Launchpad &launchpad, Launchpad_child &launchpad_child)
:
_block(Scout::Block::RIGHT), _loadbar(0, &Scout::label_font),
_name(name),
_kill_event_handler(launchpad, launchpad_child)
{
Genode::strncpy(_name, name, sizeof(_name));
_block.append_plaintext(_name, &Scout::plain_style);
_block.append_plaintext(_name.string(), &Scout::plain_style);
_loadbar.max_value(max_quota_kb);
_loadbar.value(quota_kb);
@ -118,7 +118,7 @@ class Child_entry : public Scout::Parent_element,
/**
* Accessors
*/
const char *name() { return _name; }
Launchpad_child::Name name() { return _name; }
/******************************

View File

@ -22,6 +22,7 @@ class Launch_entry : public Scout::Parent_element, public Loadbar_listener
{
private:
Scout::Launcher::Name _prg_name;
Scout::Block _block;
Kbyte_loadbar<PT> _loadbar;
Scout::Launcher_config _config;
@ -37,15 +38,16 @@ class Launch_entry : public Scout::Parent_element, public Loadbar_listener
/**
* Constructor
*/
Launch_entry(const char *prg_name, unsigned long initial_quota,
Launch_entry(Scout::Launcher::Name const &prg_name, unsigned long initial_quota,
unsigned long max_quota, Launchpad *launchpad,
Genode::Dataspace_capability config_ds)
:
_prg_name(prg_name),
_block(Scout::Block::RIGHT), _loadbar(this, &Scout::label_font),
_config(config_ds),
_launcher(prg_name, launchpad, initial_quota * 1024UL, &_config)
{
_block.append_launchertext(prg_name, &Scout::link_style, &_launcher);
_block.append_launchertext(_prg_name.string(), &Scout::link_style, &_launcher);
_loadbar.max_value(max_quota);
_loadbar.value(initial_quota);

View File

@ -35,11 +35,12 @@ extern unsigned char TITLEBAR_RGBA[];
********************************/
template <typename PT>
Launchpad_window<PT>::Launchpad_window(Graphics_backend &gfx_backend,
Launchpad_window<PT>::Launchpad_window(Genode::Env &env,
Graphics_backend &gfx_backend,
Point position, Area size, Area max_size,
unsigned long initial_quota)
:
Launchpad(initial_quota),
Launchpad(env, initial_quota),
Window(gfx_backend, position, size, max_size, false),
_docview(0),
_spacer(1, _TH),

View File

@ -14,6 +14,9 @@
#ifndef _LAUNCHPAD_WINDOW_H_
#define _LAUNCHPAD_WINDOW_H_
#include <base/env.h>
#include <dataspace/capability.h>
#include <scout/platform.h>
#include <scout/window.h>
@ -73,7 +76,8 @@ class Launchpad_window : public Scout::Scrollbar_listener,
*
* \param initial_quota maximum value of quota displays
*/
Launchpad_window(Scout::Graphics_backend &gfx_backend,
Launchpad_window(Genode::Env &env,
Scout::Graphics_backend &gfx_backend,
Scout::Point position, Scout::Area size,
Scout::Area max_size, unsigned long inital_quota);
@ -123,39 +127,40 @@ class Launchpad_window : public Scout::Scrollbar_listener,
_status_entry.refresh();
}
void add_launcher(const char *filename,
void add_launcher(Launchpad_child::Name const &name,
unsigned long default_quota,
Genode::Dataspace_capability config_ds = Genode::Dataspace_capability())
Genode::Dataspace_capability config_ds = Genode::Dataspace_capability()) override
{
Launch_entry<PT> *le;
le = new Launch_entry<PT>(filename, default_quota / 1024,
le = new Launch_entry<PT>(name, default_quota / 1024,
initial_quota() / 1024,
this, config_ds);
_launch_section.append(le);
refresh();
}
void add_child(const char *unique_name,
void add_child(Launchpad_child::Name const &name,
unsigned long quota,
Launchpad_child *launchpad_child,
Genode::Allocator *alloc)
Launchpad_child &launchpad_child,
Genode::Allocator &alloc) override
{
Child_entry<PT> *ce;
ce = new (alloc) Child_entry<PT>(unique_name, quota / 1024,
ce = new (alloc) Child_entry<PT>(name, quota / 1024,
initial_quota() / 1024,
this, launchpad_child);
*this, launchpad_child);
_child_entry_list.insert(ce);
_kiddy_section.append(ce);
format(_size);
refresh();
}
void remove_child(const char *name, Genode::Allocator *alloc)
void remove_child(Launchpad_child::Name const &name,
Genode::Allocator &alloc) override
{
/* lookup child entry by its name */
Child_entry<PT> *ce = _child_entry_list.first();
for ( ; ce; ce = ce->Genode::List<Child_entry<PT> >::Element::next())
if (Genode::strcmp(ce->name(), name) == 0)
if (name == ce->name())
break;
if (!ce) {

View File

@ -53,7 +53,7 @@ class Loadbar_event_handler : public Scout::Event_handler
/**
* Event handler interface
*/
void handle(Scout::Event &ev)
void handle_event(Scout::Event const &ev) override
{
static int key_cnt;
using Scout::Event;

View File

@ -11,6 +11,8 @@
* under the terms of the GNU General Public License version 2.
*/
#include <base/component.h>
#include <scout/platform.h>
#include <scout/tick.h>
#include <scout/user_state.h>
@ -85,15 +87,52 @@ static long read_int_attr_from_config(const char *attr, long default_value)
}
/**
* Main program
*/
int main(int argc, char **argv)
struct Main : Scout::Event_handler
{
Scout::Platform &_pf;
Scout::Window &_launchpad;
Scout::User_state &_user_state;
unsigned long _old_time = _pf.timer_ticks();
Main(Scout::Platform &pf, Scout::Window &launchpad, Scout::User_state &user_state)
: _pf(pf), _launchpad(launchpad), _user_state(user_state) { }
void handle_event(Scout::Event const &event) override
{
using namespace Scout;
Event ev = event;
if (ev.type != Event::WHEEL)
ev.mouse_position = ev.mouse_position - _user_state.view_position();
_user_state.handle_event(ev);
if (ev.type == Event::TIMER)
Tick::handle(_pf.timer_ticks());
/* perform periodic redraw */
unsigned long const curr_time = _pf.timer_ticks();
if (!_pf.event_pending() && ((curr_time - _old_time > 20)
|| (curr_time < _old_time))) {
_old_time = curr_time;
_launchpad.process_redraw();
}
}
};
/***************
** Component **
***************/
void Component::construct(Genode::Env &env)
{
using namespace Scout;
static Nitpicker::Connection nitpicker;
static Platform pf(*nitpicker.input());
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);
@ -109,17 +148,13 @@ int main(int argc, char **argv)
/* create instance of launchpad window */
static Launchpad_window<Pixel_rgb565>
launchpad(
graphics_backend, initial_position, initial_size, max_size,
Genode::env()->ram_session()->avail()
);
launchpad(env, graphics_backend, initial_position, initial_size,
max_size, env.ram().avail());
/* request config file from ROM service */
try {
launchpad.process_config();
} catch (...) { }
try { launchpad.process_config(); } catch (...) { }
Avail_quota_update avail_quota_update(&launchpad);
static Avail_quota_update avail_quota_update(&launchpad);
/* create user state manager */
static User_state user_state(&launchpad, &launchpad,
@ -129,36 +164,6 @@ int main(int argc, char **argv)
launchpad.format(initial_size);
launchpad.ypos(0);
Genode::printf("--- entering main loop ---\n");
/* enter main loop */
unsigned long curr_time, old_time;
curr_time = old_time = pf.timer_ticks();
for (;;) {
Event ev = pf.get_event();
launchpad.gui_lock.lock();
if (ev.type != Event::WHEEL)
ev.mouse_position = ev.mouse_position - user_state.view_position();
user_state.handle_event(ev);
if (ev.type == Event::TIMER)
Tick::handle(pf.timer_ticks());
/* perform periodic redraw */
curr_time = pf.timer_ticks();
if (!pf.event_pending() && ((curr_time - old_time > 20) || (curr_time < old_time))) {
old_time = curr_time;
launchpad.process_redraw();
}
launchpad.gui_lock.unlock();
if (ev.type == Event::QUIT)
break;
}
return 0;
static Main main(pf, launchpad, user_state);
pf.event_handler(main);
}