diff --git a/repos/base-hw/src/bootstrap/log.cc b/repos/base-hw/src/bootstrap/log.cc index 7887fd59d..2f77fa32a 100644 --- a/repos/base-hw/src/bootstrap/log.cc +++ b/repos/base-hw/src/bootstrap/log.cc @@ -14,6 +14,7 @@ /* Genode includes */ #include +#include /* base-internal includes */ #include diff --git a/repos/base/include/base/buffered_output.h b/repos/base/include/base/buffered_output.h new file mode 100644 index 000000000..774a25180 --- /dev/null +++ b/repos/base/include/base/buffered_output.h @@ -0,0 +1,68 @@ +/* + * \brief Implementation of the output interface that buffers characters + * \author Norman Feske + * \date 2016-05-03 + */ + +/* + * Copyright (C) 2016-2019 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +#ifndef _INCLUDE__BASE__BUFFERED_OUTPUT_H_ +#define _INCLUDE__BASE__BUFFERED_OUTPUT_H_ + +#include + +namespace Genode { template class Buffered_output; } + + +/** + * Implementation of the output interface that buffers characters + * + * \param BUF_SIZE maximum number of characters to buffer before writing + * \param WRITE_FN functor called to writing the buffered characters to a + * backend. + * + * The 'WRITE_FN' functor is called with a null-terminated 'char const *' + * as argument. + */ +template +class Genode::Buffered_output : public Output +{ + private: + + BACKEND_WRITE_FN _write_fn; + char _buf[BUF_SIZE]; + unsigned _num_chars = 0; + + void _flush() + { + /* null-terminate string */ + _buf[_num_chars] = 0; + _write_fn(_buf); + + /* restart with empty buffer */ + _num_chars = 0; + } + + public: + + Buffered_output(BACKEND_WRITE_FN const &write_fn) : _write_fn(write_fn) { } + + void out_char(char c) override + { + /* ensure enough buffer space for complete escape sequence */ + if ((c == 27) && (_num_chars + 8 > BUF_SIZE)) _flush(); + + _buf[_num_chars++] = c; + + /* flush immediately on line break */ + if (c == '\n' || _num_chars >= sizeof(_buf) - 1) + _flush(); + } +}; + +#endif /* _INCLUDE__BASE__BUFFERED_OUTPUT_H_ */ diff --git a/repos/base/src/core/default_log.cc b/repos/base/src/core/default_log.cc index 7e0e76eda..aed0fc910 100644 --- a/repos/base/src/core/default_log.cc +++ b/repos/base/src/core/default_log.cc @@ -14,10 +14,10 @@ /* Genode includes */ #include +#include /* base-internal includes */ #include -#include #include /* core includes */ diff --git a/repos/base/src/include/base/internal/output.h b/repos/base/src/include/base/internal/output.h index efbe551b8..28d31f072 100644 --- a/repos/base/src/include/base/internal/output.h +++ b/repos/base/src/include/base/internal/output.h @@ -14,7 +14,6 @@ #ifndef _INCLUDE__BASE__INTERNAL__OUTPUT_H_ #define _INCLUDE__BASE__INTERNAL__OUTPUT_H_ - #include @@ -155,53 +154,4 @@ static inline void out_float(T value, unsigned base, unsigned length, OUT_CHAR_F } } -namespace Genode { template class Buffered_output; } - - -/** - * Implementation of the output interface that buffers characters - * - * \param BUF_SIZE maximum number of characters to buffer before writing - * \param WRITE_FN functor called to writing the buffered characters to a - * backend. - * - * The 'WRITE_FN' functor is called with a null-terminated 'char const *' - * as argument. - */ -template -class Genode::Buffered_output : public Output -{ - private: - - BACKEND_WRITE_FN _write_fn; - char _buf[BUF_SIZE]; - unsigned _num_chars = 0; - - void _flush() - { - /* null-terminate string */ - _buf[_num_chars] = 0; - _write_fn(_buf); - - /* restart with empty buffer */ - _num_chars = 0; - } - - public: - - Buffered_output(BACKEND_WRITE_FN const &write_fn) : _write_fn(write_fn) { } - - void out_char(char c) override - { - /* ensure enough buffer space for complete escape sequence */ - if ((c == 27) && (_num_chars + 8 > BUF_SIZE)) _flush(); - - _buf[_num_chars++] = c; - - /* flush immediately on line break */ - if (c == '\n' || _num_chars >= sizeof(_buf) - 1) - _flush(); - } -}; - #endif /* _INCLUDE__BASE__INTERNAL__OUTPUT_H_ */ diff --git a/repos/base/src/lib/base/default_log.cc b/repos/base/src/lib/base/default_log.cc index 3ce9c8e24..ba3f2ea52 100644 --- a/repos/base/src/lib/base/default_log.cc +++ b/repos/base/src/lib/base/default_log.cc @@ -14,10 +14,10 @@ /* Genode includes */ #include #include +#include /* base-internal includes */ #include -#include #include using namespace Genode; diff --git a/repos/base/src/lib/base/raw_output.cc b/repos/base/src/lib/base/raw_output.cc index 3230ad188..a9744e450 100644 --- a/repos/base/src/lib/base/raw_output.cc +++ b/repos/base/src/lib/base/raw_output.cc @@ -13,10 +13,10 @@ /* Genode includes */ #include +#include /* base-internal includes */ #include -#include #include