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:
parent
9259bce34e
commit
94a39db31d
1 changed files with 8 additions and 0 deletions
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue