mirror of
https://github.com/SerenityOS/serenity
synced 2026-05-14 19:06:55 +02:00
This change has many improvements: - We don't use `LockRefPtr` to hold instances of many base devices as with the DeviceManagement class. Instead, we have a saner pattern of holding them in a `NonnullRefPtr<T> const`, in a small-text footprint class definition in the `Device.cpp` file. - The awkwardness of using `::the()` each time we need to get references to mostly-static objects (like the Event queue) in runtime is now gone in the migration to using the `Device` class. - Acquiring a device feel more obvious because we use now the Device class for this method. The method name is improved as well.
40 lines
1.2 KiB
C++
40 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <Kernel/Devices/CharacterDevice.h>
|
|
|
|
namespace Kernel {
|
|
|
|
class AudioController;
|
|
class AudioChannel final
|
|
: public CharacterDevice {
|
|
friend class Device;
|
|
|
|
public:
|
|
static ErrorOr<NonnullRefPtr<AudioChannel>> create(AudioController const&, size_t channel_index);
|
|
virtual ~AudioChannel() override = default;
|
|
|
|
// ^CharacterDevice
|
|
virtual bool can_read(OpenFileDescription const&, u64) const override;
|
|
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
|
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t) override;
|
|
virtual bool can_write(OpenFileDescription const&, u64) const override { return true; }
|
|
|
|
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned, Userspace<void*>) override;
|
|
|
|
private:
|
|
AudioChannel(AudioController const&, size_t channel_index);
|
|
|
|
// ^CharacterDevice
|
|
virtual StringView class_name() const override { return "AudioChannel"sv; }
|
|
|
|
LockWeakPtr<AudioController> m_controller;
|
|
size_t const m_channel_index;
|
|
};
|
|
}
|