2021-08-14 04:31:00 +01:00
|
|
|
/*
|
2022-04-22 10:04:37 +03:00
|
|
|
* Copyright (c) 2021-2022, Liav A. <liavalb@hotmail.co.il>
|
2021-08-14 04:31:00 +01:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <Kernel/Bus/USB/USBDevice.h>
|
2022-04-22 12:46:19 +03:00
|
|
|
#include <Kernel/FileSystem/SysFS/Component.h>
|
2021-09-04 16:23:45 +03:00
|
|
|
#include <Kernel/KBufferBuilder.h>
|
2022-04-22 10:04:37 +03:00
|
|
|
#include <Kernel/KString.h>
|
2021-09-04 16:23:45 +03:00
|
|
|
#include <Kernel/Locking/Mutex.h>
|
2021-08-14 04:31:00 +01:00
|
|
|
|
2022-04-22 10:04:37 +03:00
|
|
|
namespace Kernel {
|
2021-08-14 04:31:00 +01:00
|
|
|
|
|
|
|
|
class SysFSUSBDeviceInformation : public SysFSComponent {
|
|
|
|
|
friend class SysFSUSBBusDirectory;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
virtual ~SysFSUSBDeviceInformation() override;
|
|
|
|
|
|
2022-01-03 00:48:46 +11:00
|
|
|
static ErrorOr<NonnullRefPtr<SysFSUSBDeviceInformation>> create(USB::Device&);
|
2021-12-12 16:33:08 +02:00
|
|
|
virtual StringView name() const override { return m_device_name->view(); }
|
2021-08-14 04:31:00 +01:00
|
|
|
|
|
|
|
|
protected:
|
2021-12-12 16:33:08 +02:00
|
|
|
SysFSUSBDeviceInformation(NonnullOwnPtr<KString> device_name, USB::Device& device);
|
2021-08-14 04:31:00 +01:00
|
|
|
|
2021-11-08 00:51:39 +01:00
|
|
|
virtual ErrorOr<size_t> read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
|
2021-08-14 04:31:00 +01:00
|
|
|
|
|
|
|
|
NonnullRefPtr<USB::Device> m_device;
|
2021-09-04 16:23:45 +03:00
|
|
|
|
|
|
|
|
private:
|
2021-11-08 00:51:39 +01:00
|
|
|
ErrorOr<void> try_generate(KBufferBuilder&);
|
|
|
|
|
virtual ErrorOr<void> refresh_data(OpenFileDescription& description) const override;
|
2022-07-11 17:32:29 +00:00
|
|
|
mutable Mutex m_lock { "SysFSUSBDeviceInformation"sv };
|
2021-12-12 16:33:08 +02:00
|
|
|
NonnullOwnPtr<KString> m_device_name;
|
2021-08-14 04:31:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|