aboutsummaryrefslogtreecommitdiff
path: root/kernel/kapi/cio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/kapi/cio.cpp')
-rw-r--r--kernel/kapi/cio.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/kernel/kapi/cio.cpp b/kernel/kapi/cio.cpp
new file mode 100644
index 0000000..d447a6a
--- /dev/null
+++ b/kernel/kapi/cio.cpp
@@ -0,0 +1,36 @@
+#include "kapi/cio.hpp"
+
+#include <optional>
+#include <string_view>
+#include <utility>
+
+namespace kapi::cio
+{
+ namespace
+ {
+ struct null_device final : public output_device
+ {
+ null_device static instance;
+ auto write(output_stream, std::string_view) -> void override {}
+ };
+
+ constinit null_device null_device::instance;
+ } // namespace
+
+ constinit auto static active_device = static_cast<output_device *>(&null_device::instance);
+
+ auto set_output_device(output_device & device) -> std::optional<output_device *>
+ {
+ if (&device == active_device)
+ {
+ return {};
+ }
+ return std::exchange(active_device, &device);
+ }
+
+ auto write(output_stream stream, std::string_view text) -> void
+ {
+ active_device->write(stream, text);
+ }
+
+} // namespace kapi::cio