1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:47:45 +00:00

Kernel/Devices: Use try_create_device helper for ConsoleDevice

This commit is contained in:
Liav A 2021-09-16 22:23:25 +03:00 committed by Idan Horowitz
parent 5e8dcb9ca7
commit fd4397a430
8 changed files with 43 additions and 26 deletions

View file

@ -15,6 +15,7 @@
#include <Kernel/API/KResult.h>
#include <Kernel/API/TimePage.h>
#include <Kernel/Arch/x86/RegisterState.h>
#include <Kernel/Devices/ConsoleDevice.h>
#include <Kernel/Devices/Device.h>
#include <Kernel/Devices/NullDevice.h>
#include <Kernel/UnixTypes.h>
@ -30,14 +31,21 @@ public:
static DeviceManagement& the();
void attach_null_device(NullDevice const&);
bool is_console_device_attached() const { return !m_console_device.is_null(); }
void attach_console_device(ConsoleDevice const&);
void after_inserting_device(Badge<Device>, Device&);
void before_device_removal(Badge<Device>, Device&);
void for_each(Function<void(Device&)>);
Device* get_device(unsigned major, unsigned minor);
NullDevice const& null_device() const;
NullDevice& null_device();
ConsoleDevice const& console_device() const;
ConsoleDevice& console_device();
template<typename DeviceType, typename... Args>
static inline KResultOr<NonnullRefPtr<DeviceType>> try_create_device(Args&&... args)
{
@ -48,6 +56,7 @@ public:
private:
RefPtr<NullDevice> m_null_device;
RefPtr<ConsoleDevice> m_console_device;
MutexProtected<HashMap<u32, Device*>> m_devices;
};