/* * 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&); RefPtr device() const { return m_device; } protected: explicit SysFSUSBDeviceInformation(USB::Device& device); virtual KResultOr read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, FileDescription*) const override; IntrusiveListNode> m_list_node; NonnullRefPtr m_device; private: KResult try_generate(KBufferBuilder&); virtual KResult refresh_data(FileDescription& description) const override; mutable Mutex m_lock { "SysFSUSBDeviceInformation" }; }; class SysFSUSBBusDirectory final : public SysFSDirectory { public: static void initialize(); static SysFSUSBBusDirectory& the(); void plug(USB::Device&); void unplug(USB::Device&); virtual KResult traverse_as_directory(unsigned, Function) 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; }; }