Compare commits
1 Commits
master
...
unlabeled-
Author | SHA1 | Date |
---|---|---|
Ehmry - | bf5803f7d8 |
|
@ -30,11 +30,7 @@ namespace Genode {
|
|||
*/
|
||||
Log_session_component *_create_session(const char *args) override
|
||||
{
|
||||
Session_label const label = label_from_args(args);
|
||||
if (label == "init -> platform")
|
||||
return new (md_alloc()) Platform_log_session_component();
|
||||
|
||||
return new (md_alloc()) Labeled_log_session_component(label);
|
||||
return new (md_alloc()) Log_session_component(label_from_args(args));
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
|
@ -24,10 +24,32 @@ namespace Genode {
|
|||
|
||||
class Log_session_component : public Rpc_object<Log_session>
|
||||
{
|
||||
protected:
|
||||
private:
|
||||
|
||||
template <typename PROC>
|
||||
size_t split_lines(String const &string_buf, PROC proc)
|
||||
Session_label const _label;
|
||||
|
||||
Session_label _expand_label(Session_label const &label)
|
||||
{
|
||||
if (label == "init -> unlabeled")
|
||||
return "";
|
||||
else
|
||||
return Session_label("[", _label, "] ");
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
Log_session_component(Session_label const &label)
|
||||
: _label(_expand_label(label)) { }
|
||||
|
||||
|
||||
/*****************
|
||||
** Log session **
|
||||
*****************/
|
||||
|
||||
size_t write(String const &string_buf) override
|
||||
{
|
||||
if (!(string_buf.valid_string())) {
|
||||
error("corrupted string");
|
||||
|
@ -37,64 +59,25 @@ namespace Genode {
|
|||
char const *string = string_buf.string();
|
||||
size_t len = strlen(string);
|
||||
|
||||
char buf[string_buf.MAX_SIZE];
|
||||
unsigned from_i = 0;
|
||||
|
||||
for (unsigned i = 0; i < len; i++) {
|
||||
if (string[i] == '\n') {
|
||||
proc(Cstring(string + from_i, i - from_i));
|
||||
memcpy(buf, string + from_i, i - from_i);
|
||||
buf[i - from_i] = 0;
|
||||
log(_label, Cstring(buf));
|
||||
from_i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* if last character of string was not a line break, add one */
|
||||
if (from_i < len)
|
||||
proc(Cstring(string + from_i));
|
||||
log(_label, Cstring(string + from_i));
|
||||
|
||||
return len;
|
||||
}
|
||||
};
|
||||
|
||||
class Labeled_log_session_component final : public Log_session_component
|
||||
{
|
||||
private:
|
||||
|
||||
Session_label const _label;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
Labeled_log_session_component(Session_label const &label) : _label(label) { }
|
||||
|
||||
|
||||
/*****************
|
||||
** Log session **
|
||||
*****************/
|
||||
|
||||
size_t write(String const &string_buf) override
|
||||
{
|
||||
return split_lines(string_buf, [&] (Cstring const &line) {
|
||||
log("[", _label, "] ", line); });
|
||||
}
|
||||
};
|
||||
|
||||
class Platform_log_session_component final : public Log_session_component
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
/*****************
|
||||
** Log session **
|
||||
*****************/
|
||||
|
||||
size_t write(String const &string_buf) override
|
||||
{
|
||||
return split_lines(string_buf, [&] (Cstring const &line) {
|
||||
log(line);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* _CORE__INCLUDE__LOG_SESSION_COMPONENT_H_ */
|
||||
|
|
Loading…
Reference in New Issue