1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 08:28:11 +00:00

Kernel: Add try_create_device overload for static factory functions

This makes sure DeviceManagement::try_create_device will call the
static factory function (if available) instead of directly calling the
constructor, which will allow us to move OOM-fallible calls out of
Device constructors.
This commit is contained in:
Idan Horowitz 2022-01-26 22:00:45 +02:00 committed by Linus Groh
parent 9259bce34e
commit 94a39db31d

View file

@ -55,6 +55,14 @@ public:
ConsoleDevice const& console_device() const;
ConsoleDevice& console_device();
template<typename DeviceType, typename... Args>
static inline ErrorOr<NonnullRefPtr<DeviceType>> try_create_device(Args&&... args) requires(requires(Args... args) { DeviceType::try_create(args...); })
{
auto device = TRY(DeviceType::try_create(forward<Args>(args)...));
device->after_inserting();
return device;
}
template<typename DeviceType, typename... Args>
static inline ErrorOr<NonnullRefPtr<DeviceType>> try_create_device(Args&&... args)
{