mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-22 20:38:09 +00:00
Qt launchpad: use XML configuration
With this patch, Qt launchpad entries are configured the same way as with the Scout launchpad. Fixes #1222.
This commit is contained in:
parent
2e64a01ea5
commit
e851b98806
@ -187,6 +187,10 @@ class Launchpad
|
|||||||
|
|
||||||
virtual ~Launchpad() { }
|
virtual ~Launchpad() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process launchpad XML configuration
|
||||||
|
*/
|
||||||
|
void process_config();
|
||||||
|
|
||||||
/*************************
|
/*************************
|
||||||
** Configuring the GUI **
|
** Configuring the GUI **
|
||||||
|
@ -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)
|
static long read_int_attr_from_config(const char *attr, long default_value)
|
||||||
{
|
{
|
||||||
long result = default_value;
|
long result = default_value;
|
||||||
@ -204,7 +122,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
/* request config file from ROM service */
|
/* request config file from ROM service */
|
||||||
try {
|
try {
|
||||||
process_config(&launchpad);
|
launchpad.process_config();
|
||||||
} catch (...) { }
|
} catch (...) { }
|
||||||
|
|
||||||
Avail_quota_update avail_quota_update(&launchpad);
|
Avail_quota_update avail_quota_update(&launchpad);
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <rom_session/connection.h>
|
#include <rom_session/connection.h>
|
||||||
#include <ram_session/connection.h>
|
#include <ram_session/connection.h>
|
||||||
#include <cpu_session/connection.h>
|
#include <cpu_session/connection.h>
|
||||||
|
#include <os/config.h>
|
||||||
#include <timer_session/connection.h>
|
#include <timer_session/connection.h>
|
||||||
#include <launchpad/launchpad.h>
|
#include <launchpad/launchpad.h>
|
||||||
|
|
||||||
@ -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,
|
Launchpad_child *Launchpad::start_child(const char *filename,
|
||||||
unsigned long ram_quota,
|
unsigned long ram_quota,
|
||||||
Genode::Dataspace_capability config_ds)
|
Genode::Dataspace_capability config_ds)
|
||||||
|
@ -35,6 +35,31 @@ append config [qt5_start_nodes feature]
|
|||||||
append config {
|
append config {
|
||||||
<start name="qt_launchpad">
|
<start name="qt_launchpad">
|
||||||
<resource name="RAM" quantum="80M"/>
|
<resource name="RAM" quantum="80M"/>
|
||||||
|
<config>
|
||||||
|
<libc stdout="/dev/log" stderr="/dev/log">
|
||||||
|
<vfs>
|
||||||
|
<dir name="dev"> <log/> </dir>
|
||||||
|
</vfs>
|
||||||
|
</libc>
|
||||||
|
<launcher name="calculatorform" ram_quota="30M">
|
||||||
|
<config>
|
||||||
|
<libc stdout="/dev/log" stderr="/dev/log">
|
||||||
|
<vfs>
|
||||||
|
<dir name="dev"> <log/> </dir>
|
||||||
|
</vfs>
|
||||||
|
</libc>
|
||||||
|
</config>
|
||||||
|
</launcher>
|
||||||
|
<launcher name="tetrix" ram_quota="40M">
|
||||||
|
<config>
|
||||||
|
<libc stdout="/dev/log" stderr="/dev/log">
|
||||||
|
<vfs>
|
||||||
|
<dir name="dev"> <log/> </dir>
|
||||||
|
</vfs>
|
||||||
|
</libc>
|
||||||
|
</config>
|
||||||
|
</launcher>
|
||||||
|
</config>
|
||||||
</start>
|
</start>
|
||||||
</config>
|
</config>
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
static Qt_launchpad launchpad(Genode::env()->ram_session()->quota());
|
static Qt_launchpad launchpad(Genode::env()->ram_session()->quota());
|
||||||
|
|
||||||
launchpad.add_launcher("calculatorform",
|
try {
|
||||||
30*1024*1024,
|
launchpad.process_config();
|
||||||
Genode::Dataspace_capability());
|
} catch (...) { }
|
||||||
|
|
||||||
launchpad.add_launcher("tetrix",
|
|
||||||
40*1024*1024,
|
|
||||||
Genode::Dataspace_capability());
|
|
||||||
|
|
||||||
launchpad.move(300,100);
|
launchpad.move(300,100);
|
||||||
launchpad.show();
|
launchpad.show();
|
||||||
|
Loading…
Reference in New Issue
Block a user