From cde8163770f4d465caae066e676072ac2c8cbf06 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 23 Jan 2018 14:40:34 +0100 Subject: [PATCH] os: make 'Buffered_xml' util publicly available The 'Buffered_xml' utility is used by three components and a fourth is on the way. To avoid another duplication of the code, this patch makes it publicly available at 'os/buffered_xml.h'. --- repos/gems/src/app/decorator/config.h | 34 ++----------------- repos/gems/src/app/launcher/panel_dialog.h | 32 +---------------- .../{src/init => include/os}/buffered_xml.h | 10 +++--- repos/os/src/init/child.h | 2 +- repos/os/src/init/server.h | 2 +- 5 files changed, 10 insertions(+), 70 deletions(-) rename repos/os/{src/init => include/os}/buffered_xml.h (87%) diff --git a/repos/gems/src/app/decorator/config.h b/repos/gems/src/app/decorator/config.h index bc296d0281..0d7be2b15c 100644 --- a/repos/gems/src/app/decorator/config.h +++ b/repos/gems/src/app/decorator/config.h @@ -17,6 +17,7 @@ /* Genode includes */ #include #include +#include #include /* decorator includes */ @@ -81,40 +82,9 @@ class Decorator::Config private: - struct Buffered_xml - { - Allocator &_alloc; - char const * const _ptr; /* pointer to dynamically allocated buffer */ - Xml_node const _xml; /* referring to buffer of '_ptr' */ - - /** - * \throw Allocator::Out_of_memory - */ - static char const *_init_ptr(Allocator &alloc, Xml_node node) - { - char *ptr = (char *)alloc.alloc(node.size()); - Genode::memcpy(ptr, node.addr(), node.size()); - return ptr; - } - - /** - * Constructor - * - * \throw Allocator::Out_of_memory - */ - Buffered_xml(Allocator &alloc, Xml_node node) - : - _alloc(alloc), _ptr(_init_ptr(alloc, node)), _xml(_ptr, node.size()) - { } - - ~Buffered_xml() { _alloc.free(const_cast(_ptr), _xml.size()); } - - Xml_node xml() const { return _xml; } - }; - Genode::Allocator &_alloc; - Reconstructible _buffered_config; + Reconstructible _buffered_config; /** * Maximum number of configured window controls diff --git a/repos/gems/src/app/launcher/panel_dialog.h b/repos/gems/src/app/launcher/panel_dialog.h index 75cf9a1026..8ab3195bfb 100644 --- a/repos/gems/src/app/launcher/panel_dialog.h +++ b/repos/gems/src/app/launcher/panel_dialog.h @@ -16,6 +16,7 @@ /* Genode includes */ #include +#include /* local includes */ #include @@ -50,37 +51,6 @@ class Launcher::Panel_dialog : Input_event_handler, Dialog_generator, Genode::Allocator &_alloc; - struct Buffered_xml - { - Allocator &_alloc; - char const * const _ptr; /* pointer to dynamically allocated buffer */ - Xml_node const _xml; /* referring to buffer of '_ptr' */ - - /** - * \throw Allocator::Out_of_memory - */ - static char const *_init_ptr(Allocator &alloc, Xml_node node) - { - char *ptr = (char *)alloc.alloc(node.size()); - Genode::memcpy(ptr, node.addr(), node.size()); - return ptr; - } - - /** - * Constructor - * - * \throw Allocator::Out_of_memory - */ - Buffered_xml(Allocator &alloc, Xml_node node) - : - _alloc(alloc), _ptr(_init_ptr(alloc, node)), _xml(_ptr, node.size()) - { } - - ~Buffered_xml() { _alloc.free(const_cast(_ptr), _xml.size()); } - - Xml_node xml() const { return _xml; } - }; - Constructible _config; List _elements; diff --git a/repos/os/src/init/buffered_xml.h b/repos/os/include/os/buffered_xml.h similarity index 87% rename from repos/os/src/init/buffered_xml.h rename to repos/os/include/os/buffered_xml.h index 0b8d0e9c21..3b65be00ed 100644 --- a/repos/os/src/init/buffered_xml.h +++ b/repos/os/include/os/buffered_xml.h @@ -11,16 +11,16 @@ * under the terms of the GNU Affero General Public License version 3. */ -#ifndef _SRC__INIT__BUFFERED_XML_H_ -#define _SRC__INIT__BUFFERED_XML_H_ +#ifndef _OS__BUFFERED_XML_H_ +#define _OS__BUFFERED_XML_H_ /* Genode includes */ #include -namespace Init { class Buffered_xml; } +namespace Genode { class Buffered_xml; } -class Init::Buffered_xml +class Genode::Buffered_xml { private: @@ -61,4 +61,4 @@ class Init::Buffered_xml Xml_node xml() const { return _xml; } }; -#endif /* _SRC__INIT__BUFFERED_XML_H_ */ +#endif /* _OS__BUFFERED_XML_H_ */ diff --git a/repos/os/src/init/child.h b/repos/os/src/init/child.h index 91fc5454c5..888d8b49f9 100644 --- a/repos/os/src/init/child.h +++ b/repos/os/src/init/child.h @@ -19,12 +19,12 @@ #include #include #include +#include /* local includes */ #include #include #include -#include #include #include #include diff --git a/repos/os/src/init/server.h b/repos/os/src/init/server.h index a90a407961..26f8a032fb 100644 --- a/repos/os/src/init/server.h +++ b/repos/os/src/init/server.h @@ -16,11 +16,11 @@ /* Genode includes */ #include +#include /* local includes */ #include "types.h" #include "service.h" -#include "buffered_xml.h" #include "state_reporter.h" namespace Init { class Server; }