KiCad PCB EDA Suite
footprint_info_impl.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2011 Jean-Pierre Charras, <jp.charras@wanadoo.fr>
5  * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef FOOTPRINT_INFO_IMPL_H
22 #define FOOTPRINT_INFO_IMPL_H
23 
24 #include <atomic>
25 #include <functional>
26 #include <memory>
27 #include <thread>
28 #include <vector>
29 
30 #include <footprint_info.h>
31 #include <sync_queue.h>
32 
33 class LOCALE_IO;
34 
36 {
37 public:
39  FOOTPRINT_LIST* aOwner, const wxString& aNickname, const wxString& aFootprintName )
40  {
41  m_owner = aOwner;
42  m_loaded = false;
43  m_nickname = aNickname;
44  m_fpname = aFootprintName;
45  m_num = 0;
46  m_pad_count = 0;
48 #if !USE_FPI_LAZY
49  load();
50 #endif
51  }
52 
53 protected:
54  virtual void load() override;
55 };
56 
57 
59 {
61  std::vector<std::thread> m_threads;
64  std::atomic_size_t m_count_finished;
65  std::atomic_bool m_first_to_finish;
66 
72  bool CatchErrors( std::function<void()> aFunc );
73 
74 protected:
75  virtual void StartWorkers( FP_LIB_TABLE* aTable, wxString const* aNickname,
76  FOOTPRINT_ASYNC_LOADER* aLoader, unsigned aNThreads ) override;
77  virtual bool JoinWorkers() override;
78  virtual size_t CountFinished() override;
79 
84  void loader_job();
85 
86 public:
88  virtual ~FOOTPRINT_LIST_IMPL();
89 
90  virtual bool ReadFootprintFiles(
91  FP_LIB_TABLE* aTable, const wxString* aNickname = NULL ) override;
92 };
93 
94 #endif // FOOTPRINT_INFO_IMPL_H
FOOTPRINT_INFO_IMPL(FOOTPRINT_LIST *aOwner, const wxString &aNickname, const wxString &aFootprintName)
SYNC_QUEUE< wxString > m_queue_out
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
virtual void StartWorkers(FP_LIB_TABLE *aTable, wxString const *aNickname, FOOTPRINT_ASYNC_LOADER *aLoader, unsigned aNThreads) override
Launch worker threads to load footprints.
virtual size_t CountFinished() override
Return the number of libraries finished (successfully or otherwise).
void loader_job()
Function loader_job loads footprints from m_queue_in.
This class can be used to populate a FOOTPRINT_LIST asynchronously.
int m_unique_pad_count
Number of unique pads.
std::vector< std::thread > m_threads
int m_num
Order number in the display list.
FOOTPRINT_LIST * m_owner
provides access to FP_LIB_TABLE
SYNC_QUEUE< wxString > m_queue_in
virtual bool JoinWorkers() override
Join worker threads.
wxString m_fpname
Module name.
std::atomic_size_t m_count_finished
FOOTPRINT_ASYNC_LOADER * m_loader
int m_pad_count
Number of pads.
std::atomic_bool m_first_to_finish
Holds a list of FOOTPRINT_INFO objects, along with a list of IO_ERRORs or PARSE_ERRORs that were thro...
wxString m_nickname
library as known in FP_LIB_TABLE
virtual void load() override
lazily load stuff not filled in by constructor. This may throw IO_ERRORS.
virtual bool ReadFootprintFiles(FP_LIB_TABLE *aTable, const wxString *aNickname=NULL) override
Read all the footprints provided by the combination of aTable and aNickname.
bool CatchErrors(std::function< void()> aFunc)
Call aFunc, pushing any IO_ERRORs and std::exceptions it throws onto m_errors.