2018-10-21 22:59:43 +03:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-29 00:40:55 +03:00
|
|
|
#include <AK/CircularQueue.h>
|
2018-10-26 23:32:35 +03:00
|
|
|
#include <AK/Compiler.h>
|
2018-10-28 00:42:20 +03:00
|
|
|
#include <AK/Vector.h>
|
2019-01-23 07:13:17 +03:00
|
|
|
#include <Kernel/CharacterDevice.h>
|
2018-10-21 22:59:43 +03:00
|
|
|
|
2018-10-30 15:59:29 +03:00
|
|
|
class ConsoleImplementation {
|
|
|
|
public:
|
|
|
|
virtual ~ConsoleImplementation();
|
2018-12-03 02:39:25 +03:00
|
|
|
virtual void on_sysconsole_receive(byte) = 0;
|
2018-10-30 15:59:29 +03:00
|
|
|
};
|
|
|
|
|
2018-10-21 22:59:43 +03:00
|
|
|
class Console final : public CharacterDevice {
|
2018-11-01 01:19:15 +03:00
|
|
|
AK_MAKE_ETERNAL
|
2018-10-21 22:59:43 +03:00
|
|
|
public:
|
2018-10-26 19:43:25 +03:00
|
|
|
static Console& the() PURE;
|
2018-10-21 22:59:43 +03:00
|
|
|
|
|
|
|
Console();
|
|
|
|
virtual ~Console() override;
|
|
|
|
|
2019-01-21 04:33:01 +03:00
|
|
|
// ^CharacterDevice
|
2019-01-16 02:10:13 +03:00
|
|
|
virtual bool can_read(Process&) const override;
|
2019-01-15 11:17:22 +03:00
|
|
|
virtual bool can_write(Process&) const override { return true; }
|
2019-01-16 02:20:38 +03:00
|
|
|
virtual ssize_t read(Process&, byte* buffer, size_t size) override;
|
|
|
|
virtual ssize_t write(Process&, const byte* data, size_t size) override;
|
2019-01-21 04:33:01 +03:00
|
|
|
virtual const char* class_name() const override { return "Console"; }
|
2018-10-21 22:59:43 +03:00
|
|
|
|
2018-10-30 15:59:29 +03:00
|
|
|
void setImplementation(ConsoleImplementation* implementation) { m_implementation = implementation; }
|
|
|
|
|
2018-12-03 03:38:22 +03:00
|
|
|
void put_char(char);
|
2018-10-21 23:11:46 +03:00
|
|
|
|
2019-01-29 00:40:55 +03:00
|
|
|
const CircularQueue<char, 16384>& logbuffer() const { return m_logbuffer; }
|
|
|
|
|
2018-10-23 16:19:02 +03:00
|
|
|
private:
|
2018-10-30 15:59:29 +03:00
|
|
|
ConsoleImplementation* m_implementation { nullptr };
|
2019-01-29 00:40:55 +03:00
|
|
|
CircularQueue<char, 16384> m_logbuffer;
|
2018-10-21 22:59:43 +03:00
|
|
|
};
|
|
|
|
|