2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Log output service for Core
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2006-09-15
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2006-2017 Genode Labs GmbH
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CORE__INCLUDE__LOG_SESSION_COMPONENT_H_
|
|
|
|
#define _CORE__INCLUDE__LOG_SESSION_COMPONENT_H_
|
|
|
|
|
|
|
|
#include <util/string.h>
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
#include <base/log.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <base/rpc_server.h>
|
|
|
|
#include <log_session/log_session.h>
|
|
|
|
|
|
|
|
namespace Genode {
|
|
|
|
|
|
|
|
class Log_session_component : public Rpc_object<Log_session>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2016-08-17 17:23:23 +02:00
|
|
|
enum { LABEL_LEN = 128 };
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
char _label[LABEL_LEN];
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
Log_session_component(const char *label) {
|
|
|
|
strncpy(_label, label, sizeof(_label)); }
|
|
|
|
|
|
|
|
|
|
|
|
/*****************
|
|
|
|
** Log session **
|
|
|
|
*****************/
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
size_t write(String const &string_buf) override
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2016-05-11 18:21:47 +02:00
|
|
|
if (!(string_buf.valid_string())) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
error("corrupted string");
|
2011-12-22 16:19:25 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char const *string = string_buf.string();
|
2014-12-18 15:55:30 +01:00
|
|
|
size_t len = strlen(string);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2014-12-18 15:55:30 +01:00
|
|
|
char buf[string_buf.MAX_SIZE];
|
|
|
|
unsigned from_i = 0;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < len; i++) {
|
|
|
|
if (string[i] == '\n') {
|
|
|
|
memcpy(buf, string + from_i, i - from_i);
|
|
|
|
buf[i - from_i] = 0;
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
log("[", Cstring(_label), "] ", Cstring(buf));
|
2014-12-18 15:55:30 +01:00
|
|
|
from_i = i + 1;
|
|
|
|
}
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/* if last character of string was not a line break, add one */
|
2014-12-18 15:55:30 +01:00
|
|
|
if (from_i < len)
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
log("[", Cstring(_label), "] ", Cstring(string + from_i));
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _CORE__INCLUDE__LOG_SESSION_COMPONENT_H_ */
|