From 8da737acfdedcc7e46f05e0bf87570bd25294f3f Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Mon, 9 May 2016 17:09:43 +0200 Subject: [PATCH] base: add Attached_rom_dataspace::xml method Issue #1959 --- repos/base/include/base/attached_dataspace.h | 3 +++ .../include/base/attached_rom_dataspace.h | 24 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/repos/base/include/base/attached_dataspace.h b/repos/base/include/base/attached_dataspace.h index 84c5d64849..bbf157c4d2 100644 --- a/repos/base/include/base/attached_dataspace.h +++ b/repos/base/include/base/attached_dataspace.h @@ -89,6 +89,9 @@ class Genode::Attached_dataspace : Noncopyable template T *local_addr() { return static_cast(_local_addr); } + template + T const *local_addr() const { return static_cast(_local_addr); } + /** * Return size */ diff --git a/repos/base/include/base/attached_rom_dataspace.h b/repos/base/include/base/attached_rom_dataspace.h index 6a2f5ada29..430cce8bb9 100644 --- a/repos/base/include/base/attached_rom_dataspace.h +++ b/repos/base/include/base/attached_rom_dataspace.h @@ -15,6 +15,7 @@ #define _INCLUDE__BASE__ATTACHED_ROM_DATASPACE_H_ #include +#include #include #include @@ -85,7 +86,11 @@ class Genode::Attached_rom_dataspace */ Dataspace_capability cap() const { return _ds->cap(); } - template T *local_addr() { return _ds->local_addr(); } + template T *local_addr() { + return _ds->local_addr(); } + + template T const *local_addr() const { + return _ds->local_addr(); } size_t size() const { return _ds->size(); } @@ -119,6 +124,23 @@ class Genode::Attached_rom_dataspace * Return true of content is present */ bool is_valid() const { return _ds.is_constructed(); } + + /** + * Return dataspace content as XML node + * + * This method always returns a valid XML node. It never throws an + * exception. If the dataspace is invalid or does not contain properly + * formatted XML, the returned XML node has the form "". + */ + Xml_node xml() const + { + try { + if (is_valid() && local_addr()) + return Xml_node(local_addr(), size()); + } catch (Xml_node::Invalid_syntax) { } + + return Xml_node(""); + } }; #endif /* _INCLUDE__BASE__ATTACHED_ROM_DATASPACE_H_ */