/* * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2021 Jon Evans * Copyright The KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #ifndef KICAD_SYMBOL_ASYNC_LOADER_H #define KICAD_SYMBOL_ASYNC_LOADER_H #include #include #include #include #include #include class LIB_SYMBOL; class PROGRESS_REPORTER; class SYMBOL_LIB_TABLE; class SYMBOL_ASYNC_LOADER { public: /** * Construct a loader for symbol libraries. * * @param aNicknames is a list of library nicknames to load. * @param aTable is a pointer to the symbol library table to load libraries for. * @param aOnlyPowerSymbols, if true, will only return power symbols in the output map. * @param aOutput will be filled with the loaded parts. * @param aReporter will be used to report progress, of not null. */ SYMBOL_ASYNC_LOADER( const std::vector& aNicknames, SYMBOL_LIB_TABLE* aTable, bool aOnlyPowerSymbols = false, std::unordered_map>* aOutput = nullptr, PROGRESS_REPORTER* aReporter = nullptr ); ~SYMBOL_ASYNC_LOADER(); /** * Spin up threads to load all the libraries in m_nicknames. */ void Start(); /** * Finalize the threads and combines the output into the target output map. */ bool Join(); /// @return true if loading is done bool Done(); /// @return a string containing any errors generated during the load. const wxString& GetErrors() const { return m_errors; } /// Represent a pair of . typedef std::pair> LOADED_PAIR; private: /// Worker job that loads libraries and returns a list of pairs of . std::vector worker(); /// List of libraries to load. std::vector m_nicknames; /// Handle to the symbol library table being loaded into. SYMBOL_LIB_TABLE* m_table; /// True if we are loading only power symbols. bool m_onlyPowerSymbols; /// Handle to map that will be filled with the loaded parts per library. std::unordered_map>* m_output; /// Progress reporter (may be null). PROGRESS_REPORTER* m_reporter; size_t m_threadCount; std::atomic m_nextLibrary; wxString m_errors; std::mutex m_errorMutex; std::vector>> m_returns; }; #endif