launchpad: Update config syntax, remove defaults

This patch updates the launchpad config to use XML attributes and
removes the built-in default configuration (which is only meaningful
for demo.run anyway).
This commit is contained in:
Norman Feske 2013-09-19 15:07:28 +02:00
parent 6cd5407ed9
commit 29eeedf064
8 changed files with 115 additions and 50 deletions

View File

@ -1,34 +1,15 @@
Launchpad is a graphical application for interactively starting and
killing programs.
By default, launchpad displays a preconfigured list of programs and their
respective default memory quotas. The user can tweak the memory quota
for each entry with mouse and then start a program by clicking on its
name. As an alternative to using the default list, you can define the list
manually by supplying a configuration to Launchpad. The following example
configuration tells launchpad to display a list of two launcher entries:
By default, launchpad displays a onfigured list of programs and their
respective default memory quotas. The user can tweak the memory quota for each
entry with mouse and then start a program by clicking on its name. The
following example configuration tells launchpad to display a list of three
launcher entries:
!<config>
! <launcher>
! <filename>sdl_pathfind</filename>
! <ram_quota>10M</ram_quota>
! </launcher>
! <launcher>
! <filename>liquid_fb</filename>
! <ram_quota>10M</ram_quota>
! </launcher>
! <launcher>
! <filename>init</filename>
! <ram_quota>10M</ram_quota>
! <config>
! <start>
! <filename>hello</filename>
! <ram_quota>1M</ram_quota>
! </start>
! </config>
! </launcher>
! <launcher name="sdl_pathfind" ram_quota="10M" />
! <launcher name="liquid_fb" ram_quota="10M" />
! <launcher name="hello" ram_quota="1M" />
!</config>
To use this configuration for a Launchpad started via init, you can
simply insert the launchpad configuration into the '<start>' node
of the launchpad entry in init's 'config' file.

View File

@ -99,18 +99,18 @@ static void process_config(Launchpad *launchpad)
/* catch XML syntax errors within launcher node */
try {
/* read file name and default quote from launcher node */
Xml_node filename_node = node.sub_node("filename");
Xml_node::Attribute filename_attr = node.attribute("name");
size_t filename_len = filename_node.content_size();
char *filename = (char *)env()->heap()->alloc(filename_len + 1);
enum { MAX_NAME_LEN = 128 };
char *filename = (char *)env()->heap()->alloc(MAX_NAME_LEN);
if (!filename) {
::printf("Error: Out of memory while processing configuration\n");
return;
}
filename_node.value(filename, filename_len + 1);
Xml_node ram_quota_node = node.sub_node("ram_quota");
filename_attr.value(filename, MAX_NAME_LEN);
Xml_node::Attribute ram_quota_attr = node.attribute("ram_quota");
Number_of_bytes default_ram_quota = 0;
ram_quota_node.value(&default_ram_quota);
ram_quota_attr.value(&default_ram_quota);
/* obtain configuration for the child */
Init::Child_config *config = new (env()->heap())
@ -187,16 +187,7 @@ int main(int argc, char **argv)
/* request config file from ROM service */
try {
process_config(&launchpad);
/* if there exists no configuration, use defaults */
} catch (...) {
launchpad.add_launcher("testnit", 768*1024);
launchpad.add_launcher("scout", 11*1024*1024);
launchpad.add_launcher("launchpad", 6*1024*1024);
launchpad.add_launcher("nitlog", 1*1024*1024);
launchpad.add_launcher("liquid_fb", 7*1024*1024);
launchpad.add_launcher("nitpicker", 1*1024*1024);
}
} catch (...) { }
Avail_quota_update avail_quota_update(&launchpad);

View File

@ -14,16 +14,89 @@
#include <base/env.h>
#include <launchpad/launchpad.h>
#include <dataspace/capability.h>
#include <rom_session/connection.h>
#include <base/snprintf.h>
#include "elements.h"
static Launchpad launchpad(Genode::env()->ram_session()->quota());
using namespace Genode;
/**********************************************
** Registry containing child configurations **
**********************************************/
/**
* The registry contains config dataspaces for given program names. It is
* filled lazily as a side effect of 'Launcher::launch()'.
*/
class Config_registry
{
private:
struct Entry;
List<Entry> _configs;
public:
/**
* Obtain configuration for specified program name from ROM module
* named '<prg_name>.config'
*/
Dataspace_capability config(char const *name);
};
struct Config_registry::Entry : List<Config_registry::Entry>::Element
{
Dataspace_capability _init_dataspace(char const *name)
{
char buf[256];
snprintf(buf, sizeof(buf), "%s.config", name);
Rom_connection *config = 0;
try {
config = new (env()->heap()) Rom_connection(buf);
return config->dataspace();
}
catch (...) { }
return Dataspace_capability();
}
Dataspace_capability const dataspace;
char name[128];
Entry(char const *prg_name) : dataspace(_init_dataspace(prg_name))
{
strncpy(name, prg_name, sizeof(name));
}
};
Dataspace_capability Config_registry::config(char const *name)
{
/* lookup existing configuration */
for (Entry *e = _configs.first(); e; e = e->next())
if (strcmp(name, e->name) == 0)
return e->dataspace;
/* if lookup failed, create and register new config */
Entry *entry = new (env()->heap()) Entry(name);
_configs.insert(entry);
return entry->dataspace;
}
/************************
** Launcher interface **
************************/
void Launcher::launch()
{
launchpad.start_child(prg_name(), quota(), Genode::Dataspace_capability());
static Config_registry config_registry;
launchpad.start_child(prg_name(), quota(),
config_registry.config(prg_name()));
}

View File

@ -123,6 +123,9 @@ append config {
<service name="LOG"> <child name="terminal_log"/> </service>
<any-service> <any-child/> <parent/></any-service>
</route>
<config>
<launcher name="testnit" ram_quota="768K" />
</config>
</start>
</config>
}

View File

@ -70,7 +70,7 @@ append config {
<start name="launchpad">
<resource name="RAM" quantum="1G"/>
<config>
<launcher><ram_quota>100M</ram_quota><filename>init</filename>
<launcher name="init" ram_quota="100M">
<config>
<parent-provides>
<service name="ROM"/>

View File

@ -113,12 +113,28 @@ append config {
</config>
</start>
<start name="launchpad">
<resource name="RAM" quantum="32M"/>
<resource name="RAM" quantum="64M" />
<configfile name="launchpad.config" />
</start>
</config>}
install_config $config
#
# Create launchpad configuration
#
set launchpad_config_fd [open "bin/launchpad.config" w]
puts $launchpad_config_fd {<config>
<launcher name="testnit" ram_quota="768K" />
<launcher name="scout" ram_quota="41M" />
<launcher name="launchpad" ram_quota="6M" />
<launcher name="nitlog" ram_quota="1M" />
<launcher name="liquid_fb" ram_quota="7M" />
<launcher name="nitpicker" ram_quota="1M" />
</config>}
close $launchpad_config_fd
#
# Boot modules
#
@ -129,6 +145,7 @@ set boot_modules {
timer
nitpicker liquid_fb launchpad scout
testnit nitlog
launchpad.config
}
# platform-specific modules
@ -143,6 +160,8 @@ lappend_if [have_spec imx53] boot_modules input_drv
build_boot_image $boot_modules
file delete -force bin/launchpad.config
append qemu_args " -m 256 "
run_genode_until forever

View File

@ -83,9 +83,7 @@ append config {
<start name="launchpad">
<resource name="RAM" quantum="1G"/>
<config>
<launcher>
<filename>init</filename>
<ram_quota>70M</ram_quota>
<launcher name="init" ram_quota="70M">
<config prio_levels="2">
<parent-provides>
<service name="ROM"/>

View File

@ -282,7 +282,7 @@ if {$use_fancy_stuff} {
set launchpad_cfg_fd [open "bin/launchpad-config" w]
puts $launchpad_cfg_fd "<config>
<launcher><ram_quota>$memory_init</ram_quota><filename>init</filename>"
<launcher ram_quota=\"$memory_init\" name=\"init\">"
puts $launchpad_cfg_fd {
<config>