fixup! Added pong

This commit is contained in:
2025-12-19 11:54:07 +01:00
parent 66818ee499
commit 996b758d1f
3 changed files with 25 additions and 6 deletions

View File

@@ -174,6 +174,8 @@ main()
{
redirect_to_log(std::cout);
redirect_to_log(std::cerr);
redirect_to_log(L4::cout);
redirect_to_log(L4::cerr);
Main().run();
return 0;
};

View File

@@ -2,10 +2,16 @@
#pragma once
#include <l4/cxx/iostream>
#include <ostream>
void send_ipc(std::string const &msg);
void redirect_to_log(std::ostream &os);
static inline void
send_ipc(std::string const &msg);
static inline void
redirect_to_log(std::ostream &os);
static inline void
redirect_to_log(L4::BasicOStream &os);
void
send_ipc(std::string const &msg)
@@ -29,16 +35,14 @@ public:
Base::setp(&buffer.front(), &buffer.back());
}
int_type
overflow(int_type ch) override
int_type overflow(int_type ch) override
{
Log_Buffer::sync();
Base::sputc(ch);
return ch;
}
int
sync() override
int sync() override
{
send_ipc(buffer);
Base::setp(this->pbase(), this->epptr());
@@ -46,6 +50,11 @@ public:
}
};
class Log_Backend : public L4::IOBackend
{
void write(char const *str, unsigned len) override { send_ipc({str, len}); };
};
void
redirect_to_log(std::ostream &os)
{
@@ -55,3 +64,9 @@ redirect_to_log(std::ostream &os)
// We should not free the old buffer because it has not been allocated
// dynamically.
}
void
redirect_to_log(L4::BasicOStream &os)
{
os = {new Log_Backend{}};
}

View File

@@ -43,6 +43,8 @@ main()
{
redirect_to_log(std::cout);
redirect_to_log(std::cerr);
redirect_to_log(L4::cout);
redirect_to_log(L4::cerr);
L4::cout << "PS Hello here am I\n";