diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-01-16 13:36:38 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-01-16 13:36:38 +0100 |
| commit | 7d6f0ed063790042a808f4bf07c50d308b3f2de4 (patch) | |
| tree | 1a2e1c4ed7e2f3d8e6cdcfb012e554d1a4eb1e5a /kernel/kapi/cio.cpp | |
| parent | 9750405757396d006ab6992fb93baf414b3e2ae8 (diff) | |
| download | teachos-7d6f0ed063790042a808f4bf07c50d308b3f2de4.tar.xz teachos-7d6f0ed063790042a808f4bf07c50d308b3f2de4.zip | |
chore: restructure namespaces
Diffstat (limited to 'kernel/kapi/cio.cpp')
| -rw-r--r-- | kernel/kapi/cio.cpp | 36 |
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 |
