Files
serenity/Kernel/Devices/Audio/Channel.h
Liav A. 96e1391c23 Kernel/Devices: Remove the DeviceManagement singleton
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.
2024-10-05 12:26:48 +02:00

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;
};
}