From 29eeedf064872441412fdc1475b4646c1bf910de Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Thu, 19 Sep 2013 15:07:28 +0200 Subject: [PATCH] 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). --- demo/src/app/launchpad/README | 35 +++---------- demo/src/app/launchpad/main.cc | 23 +++----- demo/src/app/scout/genode/launcher.cc | 75 ++++++++++++++++++++++++++- gems/run/terminal_log.run | 3 ++ libports/run/eglgears.run | 2 +- os/run/demo.run | 21 +++++++- ports-foc/run/multi_linux.run | 4 +- ports/run/seoul.inc | 2 +- 8 files changed, 115 insertions(+), 50 deletions(-) diff --git a/demo/src/app/launchpad/README b/demo/src/app/launchpad/README index 8fb6b113c3..bba19e3501 100644 --- a/demo/src/app/launchpad/README +++ b/demo/src/app/launchpad/README @@ -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: ! -! -! sdl_pathfind -! 10M -! -! -! liquid_fb -! 10M -! -! -! init -! 10M -! -! -! hello -! 1M -! -! -! +! +! +! ! -To use this configuration for a Launchpad started via init, you can -simply insert the launchpad configuration into the '' node -of the launchpad entry in init's 'config' file. diff --git a/demo/src/app/launchpad/main.cc b/demo/src/app/launchpad/main.cc index b9bb7e7f7a..c69f4fa887 100644 --- a/demo/src/app/launchpad/main.cc +++ b/demo/src/app/launchpad/main.cc @@ -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); diff --git a/demo/src/app/scout/genode/launcher.cc b/demo/src/app/scout/genode/launcher.cc index 547efe5632..1dbcaf2b51 100644 --- a/demo/src/app/scout/genode/launcher.cc +++ b/demo/src/app/scout/genode/launcher.cc @@ -14,16 +14,89 @@ #include #include #include +#include +#include #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 _configs; + + public: + + /** + * Obtain configuration for specified program name from ROM module + * named '.config' + */ + Dataspace_capability config(char const *name); +}; + + +struct Config_registry::Entry : List::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())); } diff --git a/gems/run/terminal_log.run b/gems/run/terminal_log.run index 7f16df3554..a6764fa461 100644 --- a/gems/run/terminal_log.run +++ b/gems/run/terminal_log.run @@ -123,6 +123,9 @@ append config { + + + } diff --git a/libports/run/eglgears.run b/libports/run/eglgears.run index 0840dfbb9f..1caced8ec4 100644 --- a/libports/run/eglgears.run +++ b/libports/run/eglgears.run @@ -70,7 +70,7 @@ append config { - 100Minit + diff --git a/os/run/demo.run b/os/run/demo.run index 9d77626611..fe1b76c4c4 100644 --- a/os/run/demo.run +++ b/os/run/demo.run @@ -113,12 +113,28 @@ append config { - + + } install_config $config +# +# Create launchpad configuration +# +set launchpad_config_fd [open "bin/launchpad.config" w] +puts $launchpad_config_fd { + + + + + + +} +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 diff --git a/ports-foc/run/multi_linux.run b/ports-foc/run/multi_linux.run index d9ec079d4b..e0b2779b02 100644 --- a/ports-foc/run/multi_linux.run +++ b/ports-foc/run/multi_linux.run @@ -83,9 +83,7 @@ append config { - - init - 70M + diff --git a/ports/run/seoul.inc b/ports/run/seoul.inc index 17ae94bc3b..b930fd93b0 100644 --- a/ports/run/seoul.inc +++ b/ports/run/seoul.inc @@ -282,7 +282,7 @@ if {$use_fancy_stuff} { set launchpad_cfg_fd [open "bin/launchpad-config" w] puts $launchpad_cfg_fd " - $memory_initinit" + " puts $launchpad_cfg_fd {