diff --git a/repos/demo/include/launchpad/launchpad.h b/repos/demo/include/launchpad/launchpad.h index e312b16b2..0dfb76622 100644 --- a/repos/demo/include/launchpad/launchpad.h +++ b/repos/demo/include/launchpad/launchpad.h @@ -187,6 +187,10 @@ class Launchpad virtual ~Launchpad() { } + /** + * Process launchpad XML configuration + */ + void process_config(); /************************* ** Configuring the GUI ** diff --git a/repos/demo/src/app/launchpad/main.cc b/repos/demo/src/app/launchpad/main.cc index 74c5e7ae5..39cfac8b2 100644 --- a/repos/demo/src/app/launchpad/main.cc +++ b/repos/demo/src/app/launchpad/main.cc @@ -75,88 +75,6 @@ class Avail_quota_update : public Scout::Tick }; -/** - * Process launchpad XML configuration - */ -static void process_config(Launchpad *launchpad) -{ - using namespace Genode; - - Xml_node config_node = config()->xml_node(); - - /* - * Iterate through all entries of the config file and create - * launchpad entries as specified. - */ - int launcher_cnt = 0; - for (unsigned i = 0; i < config_node.num_sub_nodes(); i++) { - Xml_node node = config_node.sub_node(i); - if (node.has_type("launcher")) - - /* catch XML syntax errors within launcher node */ - try { - /* read file name and default quote from launcher node */ - Xml_node::Attribute filename_attr = node.attribute("name"); - - 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_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_attr.value(&default_ram_quota); - - /* - * Obtain configuration for the child - */ - Dataspace_capability config_ds; - - if (node.has_sub_node("configfile") - && node.sub_node("configfile").has_attribute("name")) { - - char name[128]; - node.sub_node("configfile").attribute("name").value(name, sizeof(name)); - - Rom_connection config_rom(name); - config_rom.on_destruction(Rom_connection::KEEP_OPEN); - - config_ds = config_rom.dataspace(); - } - - if (node.has_sub_node("config")) { - - Xml_node config_node = node.sub_node("config"); - - /* allocate dataspace for config */ - size_t const config_size = config_node.size(); - config_ds = env()->ram_session()->alloc(config_size); - - /* copy configuration into new dataspace */ - char * const ptr = env()->rm_session()->attach(config_ds); - Genode::memcpy(ptr, config_node.addr(), config_size); - env()->rm_session()->detach(ptr); - } - - /* add launchpad entry */ - launchpad->add_launcher(filename, default_ram_quota, config_ds); - launcher_cnt++; - - } catch (...) { - printf("Warning: Launcher entry %d is malformed.\n", - launcher_cnt + 1); - } - else { - char buf[32]; - node.type_name(buf, sizeof(buf)); - printf("Warning: Ignoring unsupported tag <%s>.\n", buf); - } - } -} - - static long read_int_attr_from_config(const char *attr, long default_value) { long result = default_value; @@ -204,7 +122,7 @@ int main(int argc, char **argv) /* request config file from ROM service */ try { - process_config(&launchpad); + launchpad.process_config(); } catch (...) { } Avail_quota_update avail_quota_update(&launchpad); diff --git a/repos/demo/src/lib/launchpad/launchpad.cc b/repos/demo/src/lib/launchpad/launchpad.cc index dbf504a6b..0c91fe904 100644 --- a/repos/demo/src/lib/launchpad/launchpad.cc +++ b/repos/demo/src/lib/launchpad/launchpad.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -101,6 +102,88 @@ void Launchpad::_get_unique_child_name(const char *filename, char *dst, int dst_ } +/** + * Process launchpad XML configuration + */ +void Launchpad::process_config() +{ + using namespace Genode; + + Xml_node config_node = config()->xml_node(); + + /* + * Iterate through all entries of the config file and create + * launchpad entries as specified. + */ + int launcher_cnt = 0; + for (unsigned i = 0; i < config_node.num_sub_nodes(); i++) { + Xml_node node = config_node.sub_node(i); + if (node.has_type("launcher")) + + /* catch XML syntax errors within launcher node */ + try { + /* read file name and default quote from launcher node */ + Xml_node::Attribute filename_attr = node.attribute("name"); + + 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_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_attr.value(&default_ram_quota); + + /* + * Obtain configuration for the child + */ + Dataspace_capability config_ds; + + if (node.has_sub_node("configfile") + && node.sub_node("configfile").has_attribute("name")) { + + char name[128]; + node.sub_node("configfile").attribute("name").value(name, sizeof(name)); + + Rom_connection config_rom(name); + config_rom.on_destruction(Rom_connection::KEEP_OPEN); + + config_ds = config_rom.dataspace(); + } + + if (node.has_sub_node("config")) { + + Xml_node config_node = node.sub_node("config"); + + /* allocate dataspace for config */ + size_t const config_size = config_node.size(); + config_ds = env()->ram_session()->alloc(config_size); + + /* copy configuration into new dataspace */ + char * const ptr = env()->rm_session()->attach(config_ds); + Genode::memcpy(ptr, config_node.addr(), config_size); + env()->rm_session()->detach(ptr); + } + + /* add launchpad entry */ + add_launcher(filename, default_ram_quota, config_ds); + launcher_cnt++; + + } catch (...) { + printf("Warning: Launcher entry %d is malformed.\n", + launcher_cnt + 1); + } + else { + char buf[32]; + node.type_name(buf, sizeof(buf)); + printf("Warning: Ignoring unsupported tag <%s>.\n", buf); + } + } +} + + Launchpad_child *Launchpad::start_child(const char *filename, unsigned long ram_quota, Genode::Dataspace_capability config_ds) diff --git a/repos/libports/run/qt5.run b/repos/libports/run/qt5.run index 4b77f37f9..88fec5199 100644 --- a/repos/libports/run/qt5.run +++ b/repos/libports/run/qt5.run @@ -35,6 +35,31 @@ append config [qt5_start_nodes feature] append config { + + + + + + + + + + + + + + + + + + + + + + + + + } diff --git a/repos/libports/src/app/qt5/qt_launchpad/main.cpp b/repos/libports/src/app/qt5/qt_launchpad/main.cpp index e85adcae7..2462a2248 100644 --- a/repos/libports/src/app/qt5/qt_launchpad/main.cpp +++ b/repos/libports/src/app/qt5/qt_launchpad/main.cpp @@ -29,13 +29,9 @@ int main(int argc, char *argv[]) static Qt_launchpad launchpad(Genode::env()->ram_session()->quota()); - launchpad.add_launcher("calculatorform", - 30*1024*1024, - Genode::Dataspace_capability()); - - launchpad.add_launcher("tetrix", - 40*1024*1024, - Genode::Dataspace_capability()); + try { + launchpad.process_config(); + } catch (...) { } launchpad.move(300,100); launchpad.show();