| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include "core/idatasource.h" |
| 7 | #include "ihwidtranslator.h" |
| 8 | #include "vendor.h" |
| 9 | #include <memory> |
| 10 | #include <string> |
| 11 | #include <unordered_map> |
| 12 | #include <vector> |
| 13 | |
| 14 | class HWIDTranslator final : public IHWIDTranslator |
| 15 | { |
| 16 | public: |
| 17 | HWIDTranslator( |
| 18 | std::vector<Vendor> vendors, |
| 19 | std::unique_ptr<IDataSource<std::vector<char>>> &&dataSource) noexcept; |
| 20 | |
| 21 | // clang-format off |
| 22 | std::string vendor(std::string const& vendorID) const override; |
| 23 | |
| 24 | std::string device(std::string const& vendorID, |
| 25 | std::string const& deviceID) const override; |
| 26 | |
| 27 | std::string subdevice(std::string const& vendorID, |
| 28 | std::string const& deviceID, |
| 29 | std::string const& subvendorID, |
| 30 | std::string const& subdeviceID) const override; |
| 31 | // clang-format on |
| 32 | private: |
| 33 | /// Extracts a name from a line, skipping all information between |
| 34 | /// the first ocurrence of " (" or " [" and the end of the line. |
| 35 | /// @returns name |
| 36 | std::string extractName(std::string const &line, size_t start) const; |
| 37 | |
| 38 | void parseHWIDSFileData(std::vector<char> &data, std::vector<Vendor> &&vendors); |
| 39 | |
| 40 | private: |
| 41 | std::unordered_map<std::string, std::string> vendors_; |
| 42 | std::unordered_map<std::string, std::string> devices_; |
| 43 | std::unordered_map<std::string, std::string> subdevices_; |
| 44 | }; |