diff --git a/run/python3.run b/run/python3.run
index 093c14e..ad11dc6 100644
--- a/run/python3.run
+++ b/run/python3.run
@@ -21,7 +21,6 @@ import_from_depot [depot_user]/pkg/python3
build {
core init
timer
- drivers/rtc
server/dynamic_rom
}
@@ -51,10 +50,6 @@ install_config {
-
-
-
-
@@ -95,7 +90,7 @@ print("Hello again")
-
+ 2018-01-01 00:01
@@ -116,9 +111,8 @@ print("Hello again")
# generic modules
append boot_modules {
core init
- ld.lib.so
+ ld.lib.so
timer
- rtc_drv
dynamic_rom
}
diff --git a/src/app/python3/main.cc b/src/app/python3/main.cc
index 55500f0..c2b66b8 100644
--- a/src/app/python3/main.cc
+++ b/src/app/python3/main.cc
@@ -39,44 +39,58 @@ struct Python::Main
int _execute()
{
- enum {
- MAX_NAME_LEN = 128
- };
+ using namespace Genode;
- char filename[MAX_NAME_LEN];
+ typedef String<128> File_name;
- Genode::Xml_node script = _config.xml().sub_node("file");
- script.attribute("name").value(filename, sizeof(filename));
+ int res = 0;
- FILE * fp = fopen(filename, "r");
+ Xml_node const config = _config.xml();
- Genode::log("Starting python ...");
- int res = PyRun_SimpleFile(fp, filename);
- Genode::log("Executed '", Genode::Cstring(filename), "'");
+ if (!config.has_sub_node("file"))
+ warning("config lacks sub node");
+
+ config.with_sub_node("file", [&] (Xml_node const &script) {
+
+ if (!script.has_attribute("name")) {
+ warning(" node lacks 'name' attribute");
+ return;
+ }
+
+ File_name const file_name = script.attribute_value("name", File_name());
+
+ FILE * fp = fopen(file_name.string(), "r");
+
+ log("Starting python ...");
+ res = PyRun_SimpleFile(fp, file_name.string());
+ log("Executed '", file_name, "'");
+
+ fclose(fp);
+ });
- fclose(fp);
return res;
}
void _initialize()
{
- enum {
- MAX_NAME_LEN = 128
- };
+ using namespace Genode;
+ Xml_node const config = _config.xml();
+
+ enum { MAX_NAME_LEN = 128 };
wchar_t wbuf[MAX_NAME_LEN];
- if (_config.xml().has_sub_node("pythonpath")) {
- char pythonpath[MAX_NAME_LEN];
- Genode::Xml_node path = _config.xml().sub_node("pythonpath");
+ config.with_sub_node("pythonpath", [&] (Xml_node const &pythonpath) {
- path.attribute("name").value(pythonpath, sizeof(pythonpath));
- mbstowcs(wbuf, pythonpath, strlen(pythonpath));
+ typedef String Path;
+ Path const path = pythonpath.attribute_value("name", Path());
+
+ mbstowcs(wbuf, path.string(), ::strlen(path.string()));
Py_SetPath(wbuf);
- }
+ });
- if (_config.xml().attribute_value("verbose", false))
+ if (config.attribute_value("verbose", false))
Py_VerboseFlag = 1;
//don't need the 'site' module
@@ -95,30 +109,32 @@ struct Python::Main
{
_initialize();
- if (_config.xml().has_sub_node("file")) {
- Genode::Xml_node filenode = _config.xml().sub_node("file");
- if (filenode.has_attribute("on-rom-update")) {
- char rom_name[128];
- filenode.attribute("on-rom-update").value(rom_name, sizeof(rom_name));
+ _config.update();
+ Genode::Xml_node const config = _config.xml();
- _update.construct(_env, rom_name);
+ if (!config.has_sub_node("file"))
+ Genode::error("Need as argument!");
+
+ config.with_sub_node("file", [&] (Genode::Xml_node const &file) {
+
+ if (file.has_attribute("on-rom-update")) {
+
+ typedef Genode::String<128> Rom_name;
+
+ Rom_name const rom_name =
+ file.attribute_value("on-rom-update", Rom_name());
+
+ _update.construct(_env, rom_name.string());
_update->sigh(_trigger_handler);
if (_update->dataspace().valid())
_execute();
- return;
- }
- else {
+ } else {
_execute();
+ _finalize();
}
- }
- else {
- Genode::error("Need as argument!");
- }
-
- /* if there was a on-rom-update attribute, we finalize and wait for next config update */
- _finalize();
+ });
}
void _handle_trigger()