/* * Copyright (c) 2021, Liav A. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Kernel::USB { class SysFSUSBDeviceInformation : public SysFSComponent { friend class SysFSUSBBusDirectory; public: virtual ~SysFSUSBDeviceInformation() override; static NonnullRefPtr create(USB::Device&); virtual StringView name() const override { return m_device_name->view(); } RefPtr device() const { return m_device; } protected: SysFSUSBDeviceInformation(NonnullOwnPtr device_name, USB::Device& device); virtual ErrorOr read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription*) const override; IntrusiveListNode> m_list_node; NonnullRefPtr m_device; private: ErrorOr try_generate(KBufferBuilder&); virtual ErrorOr refresh_data(OpenFileDescription& description) const override; mutable Mutex m_lock { "SysFSUSBDeviceInformation" }; NonnullOwnPtr m_device_name; }; class SysFSUSBBusDirectory final : public SysFSDirectory { public: static void initialize(); static SysFSUSBBusDirectory& the(); virtual StringView name() const override { return "usb"sv; } void plug(USB::Device&); void unplug(USB::Device&); virtual ErrorOr traverse_as_directory(FileSystemID, Function(FileSystem::DirectoryEntryView const&)>) const override; virtual RefPtr lookup(StringView name) override; private: explicit SysFSUSBBusDirectory(SysFSBusDirectory&); RefPtr device_node_for(USB::Device& device); IntrusiveList<&SysFSUSBDeviceInformation::m_list_node> m_device_nodes; mutable Spinlock m_lock; }; }