KiCad PCB EDA Suite
FOOTPRINT_LIST_IMPL Class Reference

#include <footprint_info_impl.h>

Inheritance diagram for FOOTPRINT_LIST_IMPL:
FOOTPRINT_LIST

Public Member Functions

 FOOTPRINT_LIST_IMPL ()
 
virtual ~FOOTPRINT_LIST_IMPL ()
 
virtual bool ReadFootprintFiles (FP_LIB_TABLE *aTable, const wxString *aNickname=nullptr, WX_PROGRESS_REPORTER *aProgressReporter=nullptr) override
 Read all the footprints provided by the combination of aTable and aNickname. More...
 
unsigned GetCount () const
 
const FPILISTGetList () const
 Was forced to add this by modview_frame.cpp. More...
 
FOOTPRINT_INFOGetModuleInfo (const wxString &aFootprintName)
 Get info for a module by name. More...
 
FOOTPRINT_INFOGetItem (unsigned aIdx)
 Get info for a module by index. More...
 
void AddItem (FOOTPRINT_INFO *aItem)
 Add aItem to list. More...
 
unsigned GetErrorCount () const
 
std::unique_ptr< IO_ERRORPopError ()
 
void DisplayErrors (wxTopLevelWindow *aCaller=NULL)
 
FP_LIB_TABLEGetTable () const
 

Static Public Member Functions

static std::unique_ptr< FOOTPRINT_LISTGetInstance (KIWAY &aKiway)
 Factory function to return a new FOOTPRINT_LIST via Kiway. More...
 

Protected Types

typedef std::vector< std::unique_ptr< FOOTPRINT_INFO > > FPILIST
 
typedef SYNC_QUEUE< std::unique_ptr< IO_ERROR > > ERRLIST
 

Protected Member Functions

virtual void StartWorkers (FP_LIB_TABLE *aTable, wxString const *aNickname, FOOTPRINT_ASYNC_LOADER *aLoader, unsigned aNThreads) override
 Launch worker threads to load footprints. More...
 
virtual bool JoinWorkers () override
 Join worker threads. More...
 
virtual size_t CountFinished () override
 Return the number of libraries finished (successfully or otherwise). More...
 
void loader_job ()
 Function loader_job loads footprints from m_queue_in. More...
 

Protected Attributes

FP_LIB_TABLEm_lib_table
 no ownership More...
 
FPILIST m_list
 
ERRLIST m_errors
 some can be PARSE_ERRORs also More...
 
MUTEX m_list_lock
 

Private Member Functions

bool CatchErrors (const std::function< void()> &aFunc)
 Call aFunc, pushing any IO_ERRORs and std::exceptions it throws onto m_errors. More...
 

Private Attributes

FOOTPRINT_ASYNC_LOADERm_loader
 
std::vector< std::thread > m_threads
 
SYNC_QUEUE< wxString > m_queue_in
 
SYNC_QUEUE< wxString > m_queue_out
 
std::atomic_size_t m_count_finished
 
long long m_libraries_last_mod_checksum
 
WX_PROGRESS_REPORTERm_progress_reporter
 
std::atomic_bool m_cancelled
 

Detailed Description

Definition at line 58 of file footprint_info_impl.h.

Member Typedef Documentation

typedef SYNC_QUEUE<std::unique_ptr<IO_ERROR> > FOOTPRINT_LIST::ERRLIST
protectedinherited

Definition at line 178 of file footprint_info.h.

typedef std::vector<std::unique_ptr<FOOTPRINT_INFO> > FOOTPRINT_LIST::FPILIST
protectedinherited

Definition at line 177 of file footprint_info.h.

Constructor & Destructor Documentation

FOOTPRINT_LIST_IMPL::FOOTPRINT_LIST_IMPL ( )

Definition at line 306 of file footprint_info_impl.cpp.

306  :
307  m_loader( nullptr ),
308  m_count_finished( 0 ),
310  m_progress_reporter( nullptr ),
311  m_cancelled( false )
312 {
313 }
long long m_libraries_last_mod_checksum
std::atomic_bool m_cancelled
WX_PROGRESS_REPORTER * m_progress_reporter
std::atomic_size_t m_count_finished
FOOTPRINT_ASYNC_LOADER * m_loader
FOOTPRINT_LIST_IMPL::~FOOTPRINT_LIST_IMPL ( )
virtual

Definition at line 316 of file footprint_info_impl.cpp.

References m_threads.

317 {
318  for( auto& i : m_threads )
319  i.join();
320 }
std::vector< std::thread > m_threads

Member Function Documentation

void FOOTPRINT_LIST::AddItem ( FOOTPRINT_INFO aItem)
inherited

Add aItem to list.

Parameters
aItem= item to add
bool FOOTPRINT_LIST_IMPL::CatchErrors ( const std::function< void()> &  aFunc)
private

Call aFunc, pushing any IO_ERRORs and std::exceptions it throws onto m_errors.

Returns
true if no error occurred.

Definition at line 70 of file footprint_info_impl.cpp.

References FOOTPRINT_LIST::m_errors, SYNC_QUEUE< T >::move_push(), and THROW_IO_ERROR.

Referenced by loader_job().

71 {
72  try
73  {
74  aFunc();
75  }
76  catch( const IO_ERROR& ioe )
77  {
78  m_errors.move_push( std::make_unique<IO_ERROR>( ioe ) );
79  return false;
80  }
81  catch( const std::exception& se )
82  {
83  // This is a round about way to do this, but who knows what THROW_IO_ERROR()
84  // may be tricked out to do someday, keep it in the game.
85  try
86  {
87  THROW_IO_ERROR( se.what() );
88  }
89  catch( const IO_ERROR& ioe )
90  {
91  m_errors.move_push( std::make_unique<IO_ERROR>( ioe ) );
92  }
93  return false;
94  }
95 
96  return true;
97 }
ERRLIST m_errors
some can be PARSE_ERRORs also
void move_push(T &&aValue)
Move a value onto the queue.
Definition: sync_queue.h:54
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
size_t FOOTPRINT_LIST_IMPL::CountFinished ( )
overrideprotectedvirtual

Return the number of libraries finished (successfully or otherwise).

Implements FOOTPRINT_LIST.

Definition at line 300 of file footprint_info_impl.cpp.

References m_count_finished.

301 {
302  return m_count_finished.load();
303 }
std::atomic_size_t m_count_finished
void FOOTPRINT_LIST::DisplayErrors ( wxTopLevelWindow *  aCaller = NULL)
inherited

Definition at line 84 of file footprint_info.cpp.

References HTML_MESSAGE_BOX::AddHTML_Text(), HTML_MESSAGE_BOX::MessageSet(), and FOOTPRINT_LIST::PopError().

Referenced by PCB_BASE_FRAME::LoadModuleFromLibrary(), and PCB_BASE_FRAME::SelectFootprint().

85 {
86  // @todo: go to a more HTML !<table>! ? centric output, possibly with
87  // recommendations for remedy of errors. Add numeric error codes
88  // to PARSE_ERROR, and switch on them for remedies, etc. Full
89  // access is provided to everything in every exception!
90 
91  HTML_MESSAGE_BOX dlg( aWindow, _( "Load Error" ) );
92 
93  dlg.MessageSet( _( "Errors were encountered loading footprints:" ) );
94 
95  wxString msg;
96 
97  while( auto error = PopError() )
98  {
99  wxString tmp = error->Problem();
100 
101  // Preserve new lines in error messages so queued errors don't run together.
102  tmp.Replace( "\n", "<BR>" );
103  msg += wxT( "<p>" ) + tmp + wxT( "</p>" );
104  }
105 
106  dlg.AddHTML_Text( msg );
107 
108  dlg.ShowModal();
109 }
Class HTML_MESSAGE_BOX.
std::unique_ptr< IO_ERROR > PopError()
unsigned FOOTPRINT_LIST::GetCount ( ) const
inlineinherited
Returns
the number of items stored in list

Definition at line 198 of file footprint_info.h.

Referenced by FOOTPRINT_FILTER::ITERATOR::dereference(), FOOTPRINT_FILTER::end(), FOOTPRINT_FILTER::ITERATOR::increment(), and PCB_BASE_FRAME::SelectFootprint().

199  {
200  return m_list.size();
201  }
unsigned FOOTPRINT_LIST::GetErrorCount ( ) const
inlineinherited

Definition at line 232 of file footprint_info.h.

References SYNC_QUEUE< T >::size().

Referenced by PCB_BASE_FRAME::LoadModuleFromLibrary(), and PCB_BASE_FRAME::SelectFootprint().

233  {
234  return m_errors.size();
235  }
size_t size() const
Return the size of the queue.
Definition: sync_queue.h:94
ERRLIST m_errors
some can be PARSE_ERRORs also
std::unique_ptr< FOOTPRINT_LIST > FOOTPRINT_LIST::GetInstance ( KIWAY aKiway)
staticinherited

Factory function to return a new FOOTPRINT_LIST via Kiway.

NOT guaranteed to succeed; will return null if the kiface is not available.

Parameters
aKiway- active kiway instance

Definition at line 137 of file footprint_info.cpp.

References get_instance_from_id(), and KIFACE_NEW_FOOTPRINT_LIST.

Referenced by CVPCB_MAINFRAME::CVPCB_MAINFRAME(), FOOTPRINT_SELECT_WIDGET::Load(), and FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList().

138 {
140 }
Return a new instance of FOOTPRINT_LIST from pcbnew.
Definition: kiface_ids.h:39
static std::unique_ptr< FOOTPRINT_LIST > get_instance_from_id(KIWAY &aKiway, int aId)
FOOTPRINT_INFO& FOOTPRINT_LIST::GetItem ( unsigned  aIdx)
inlineinherited

Get info for a module by index.

Parameters
aIdx= index of the given item
Returns
the aIdx item in list

Definition at line 221 of file footprint_info.h.

Referenced by FOOTPRINT_FILTER::ITERATOR::dereference(), and PCB_BASE_FRAME::SelectFootprint().

222  {
223  return *m_list[aIdx];
224  }
const FPILIST& FOOTPRINT_LIST::GetList ( ) const
inlineinherited

Was forced to add this by modview_frame.cpp.

Definition at line 204 of file footprint_info.h.

References FOOTPRINT_ASYNC_LOADER::m_list.

205  {
206  return m_list;
207  }
FOOTPRINT_INFO * FOOTPRINT_LIST::GetModuleInfo ( const wxString &  aFootprintName)
inherited

Get info for a module by name.

Parameters
aFootprintName= the footprint name inside the FOOTPRINT_INFO of interest.
Returns
FOOTPRINT_INF* - the item stored in list if found

Definition at line 54 of file footprint_info.cpp.

References Format(), GetChars(), LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), FOOTPRINT_LIST::m_list, and LIB_ID::Parse().

Referenced by DisplayCmpDoc().

55 {
56  if( aFootprintName.IsEmpty() )
57  return NULL;
58 
59  for( auto& fp : m_list )
60  {
61  LIB_ID fpid;
62 
63  wxCHECK_MSG( fpid.Parse( aFootprintName ) < 0, NULL,
65  wxT( "\"%s\" is not a valid LIB_ID." ), GetChars( aFootprintName ) ) );
66 
67  wxString libNickname = fpid.GetLibNickname();
68  wxString footprintName = fpid.GetLibItemName();
69 
70  if( libNickname == fp->GetNickname() && footprintName == fp->GetFootprintName() )
71  return &*fp;
72  }
73 
74  return NULL;
75 }
int Parse(const UTF8 &aId)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
const UTF8 & GetLibItemName() const
Definition: lib_id.h:115
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:98
FP_LIB_TABLE* FOOTPRINT_LIST::GetTable ( ) const
inlineinherited

Definition at line 262 of file footprint_info.h.

Referenced by FOOTPRINT_INFO_IMPL::load().

263  {
264  return m_lib_table;
265  }
FP_LIB_TABLE * m_lib_table
no ownership
bool FOOTPRINT_LIST_IMPL::JoinWorkers ( )
overrideprotectedvirtual

Join worker threads.

Part of the FOOTPRINT_ASYNC_LOADER implementation.

Implements FOOTPRINT_LIST.

Definition at line 207 of file footprint_info_impl.cpp.

References PROGRESS_REPORTER::AdvanceProgress(), SYNC_QUEUE< T >::clear(), SYNC_QUEUE< T >::empty(), FOOTPRINT_INFO_IMPL::FOOTPRINT_INFO_IMPL(), FP_LIB_TABLE::FootprintEnumerate(), PROGRESS_REPORTER::KeepRefreshing(), numEval::lhs, m_cancelled, m_count_finished, FOOTPRINT_LIST::m_errors, FOOTPRINT_LIST::m_lib_table, FOOTPRINT_LIST::m_list, m_progress_reporter, m_queue_in, m_queue_out, m_threads, SYNC_QUEUE< T >::move_push(), SYNC_QUEUE< T >::pop(), SYNC_QUEUE< T >::size(), and THROW_IO_ERROR.

208 {
209  for( auto& i : m_threads )
210  i.join();
211 
212  m_threads.clear();
213  m_queue_in.clear();
214  m_count_finished.store( 0 );
215 
216  size_t total_count = m_queue_out.size();
217 
218  LOCALE_IO toggle_locale;
219 
220  // Parse the footprints in parallel. WARNING! This requires changing the locale, which is
221  // GLOBAL. It is only threadsafe to construct the LOCALE_IO before the threads are created,
222  // destroy it after they finish, and block the main (GUI) thread while they work. Any deviation
223  // from this will cause nasal demons.
224  //
225  // TODO: blast LOCALE_IO into the sun
226 
228  std::vector<std::thread> threads;
229 
230  for( size_t ii = 0; ii < std::thread::hardware_concurrency() + 1; ++ii )
231  {
232  threads.push_back( std::thread( [this, &queue_parsed]() {
233  wxString nickname;
234 
235  while( this->m_queue_out.pop( nickname ) && !m_cancelled )
236  {
237  wxArrayString fpnames;
238 
239  try
240  {
241  this->m_lib_table->FootprintEnumerate( fpnames, nickname );
242  }
243  catch( const IO_ERROR& ioe )
244  {
245  m_errors.move_push( std::make_unique<IO_ERROR>( ioe ) );
246  }
247  catch( const std::exception& se )
248  {
249  // This is a round about way to do this, but who knows what THROW_IO_ERROR()
250  // may be tricked out to do someday, keep it in the game.
251  try
252  {
253  THROW_IO_ERROR( se.what() );
254  }
255  catch( const IO_ERROR& ioe )
256  {
257  m_errors.move_push( std::make_unique<IO_ERROR>( ioe ) );
258  }
259  }
260 
261  for( unsigned jj = 0; jj < fpnames.size() && !m_cancelled; ++jj )
262  {
263  wxString fpname = fpnames[jj];
264  FOOTPRINT_INFO* fpinfo = new FOOTPRINT_INFO_IMPL( this, nickname, fpname );
265  queue_parsed.move_push( std::unique_ptr<FOOTPRINT_INFO>( fpinfo ) );
266  }
267 
268  if( m_progress_reporter )
270 
271  m_count_finished.fetch_add( 1 );
272  }
273  } ) );
274  }
275 
276  while( !m_cancelled && m_count_finished.load() < total_count )
277  {
278  if( m_progress_reporter )
280  else
281  wxMilliSleep( 20 );
282  }
283 
284  for( auto& thr : threads )
285  thr.join();
286 
287  std::unique_ptr<FOOTPRINT_INFO> fpi;
288 
289  while( queue_parsed.pop( fpi ) )
290  m_list.push_back( std::move( fpi ) );
291 
292  std::sort( m_list.begin(), m_list.end(),
293  []( std::unique_ptr<FOOTPRINT_INFO> const& lhs,
294  std::unique_ptr<FOOTPRINT_INFO> const& rhs ) -> bool { return *lhs < *rhs; } );
295 
296  return m_errors.empty();
297 }
SYNC_QUEUE< wxString > m_queue_out
size_t size() const
Return the size of the queue.
Definition: sync_queue.h:94
bool pop(T &aReceiver)
Pop a value off the queue into the provided variable.
Definition: sync_queue.h:66
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
std::atomic_bool m_cancelled
ERRLIST m_errors
some can be PARSE_ERRORs also
FP_LIB_TABLE * m_lib_table
no ownership
Synchronized, locking queue.
Definition: sync_queue.h:30
bool empty() const
Return true iff the queue is empty.
Definition: sync_queue.h:85
std::vector< std::thread > m_threads
void move_push(T &&aValue)
Move a value onto the queue.
Definition: sync_queue.h:54
SYNC_QUEUE< wxString > m_queue_in
WX_PROGRESS_REPORTER * m_progress_reporter
std::atomic_size_t m_count_finished
YYCODETYPE lhs
bool KeepRefreshing(bool aWait=false)
Update the UI dialog.
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aNickname)
Return a list of footprint names contained within the library given by aNickname. ...
void AdvanceProgress()
Increment the progress bar length (inside the current virtual zone)
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
void clear()
Clear the queue.
Definition: sync_queue.h:103
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void FOOTPRINT_LIST_IMPL::loader_job ( )
protected

Function loader_job loads footprints from m_queue_in.

Definition at line 100 of file footprint_info_impl.cpp.

References PROGRESS_REPORTER::AdvanceProgress(), CatchErrors(), m_cancelled, m_count_finished, FOOTPRINT_LIST::m_lib_table, m_progress_reporter, m_queue_in, m_queue_out, SYNC_QUEUE< T >::pop(), FP_LIB_TABLE::PrefetchLib(), and SYNC_QUEUE< T >::push().

Referenced by StartWorkers().

101 {
102  wxString nickname;
103 
104  while( m_queue_in.pop( nickname ) && !m_cancelled )
105  {
106  CatchErrors( [this, &nickname]() {
107  m_lib_table->PrefetchLib( nickname );
108  m_queue_out.push( nickname );
109  } );
110 
111  m_count_finished.fetch_add( 1 );
112 
113  if( m_progress_reporter )
115  }
116 }
void push(T const &aValue)
Push a value onto the queue.
Definition: sync_queue.h:45
SYNC_QUEUE< wxString > m_queue_out
bool pop(T &aReceiver)
Pop a value off the queue into the provided variable.
Definition: sync_queue.h:66
std::atomic_bool m_cancelled
FP_LIB_TABLE * m_lib_table
no ownership
SYNC_QUEUE< wxString > m_queue_in
WX_PROGRESS_REPORTER * m_progress_reporter
void PrefetchLib(const wxString &aNickname)
Function PrefetchLib If possible, prefetches the specified library (e.g.
std::atomic_size_t m_count_finished
bool CatchErrors(const std::function< void()> &aFunc)
Call aFunc, pushing any IO_ERRORs and std::exceptions it throws onto m_errors.
void AdvanceProgress()
Increment the progress bar length (inside the current virtual zone)
std::unique_ptr<IO_ERROR> FOOTPRINT_LIST::PopError ( )
inlineinherited

Definition at line 237 of file footprint_info.h.

References SYNC_QUEUE< T >::pop().

Referenced by FOOTPRINT_LIST::DisplayErrors().

238  {
239  std::unique_ptr<IO_ERROR> error;
240 
241  m_errors.pop( error );
242  return error;
243  }
bool pop(T &aReceiver)
Pop a value off the queue into the provided variable.
Definition: sync_queue.h:66
ERRLIST m_errors
some can be PARSE_ERRORs also
bool FOOTPRINT_LIST_IMPL::ReadFootprintFiles ( FP_LIB_TABLE aTable,
const wxString *  aNickname = nullptr,
WX_PROGRESS_REPORTER aProgressReporter = nullptr 
)
overridevirtual

Read all the footprints provided by the combination of aTable and aNickname.

Parameters
aTabledefines all the libraries.
aNicknameis the library to read from, or if NULL means read all footprints from all known libraries in aTable.
aProgressReporteris an optional progress reporter. ReadFootprintFiles() will use 2 phases within the reporter.
Returns
bool - true if it ran to completion, else false if it aborted after some number of errors. If true, it does not mean there were no errors, check GetErrorCount() for that, should be zero to indicate success.

Implements FOOTPRINT_LIST.

Definition at line 119 of file footprint_info_impl.cpp.

References PROGRESS_REPORTER::AdvancePhase(), SYNC_QUEUE< T >::empty(), FP_LIB_TABLE::GenLastModifiedChecksum(), FOOTPRINT_ASYNC_LOADER::GetProgress(), FOOTPRINT_ASYNC_LOADER::Join(), PROGRESS_REPORTER::KeepRefreshing(), m_cancelled, FOOTPRINT_LIST::m_errors, m_libraries_last_mod_checksum, m_progress_reporter, m_queue_in, m_queue_out, SYNC_QUEUE< T >::move_push(), PROGRESS_REPORTER::Report(), FOOTPRINT_ASYNC_LOADER::SetList(), PROGRESS_REPORTER::SetMaxProgress(), SYNC_QUEUE< T >::size(), and FOOTPRINT_ASYNC_LOADER::Start().

Referenced by PCB_BASE_FRAME::LoadModuleFromLibrary(), and PCB_BASE_FRAME::SelectFootprint().

121 {
122  if( aTable->GenLastModifiedChecksum( aNickname ) == m_libraries_last_mod_checksum )
123  return true;
124 
125  m_progress_reporter = aProgressReporter;
126  m_cancelled = false;
127 
128  FOOTPRINT_ASYNC_LOADER loader;
129 
130  loader.SetList( this );
131  loader.Start( aTable, aNickname );
132 
133  if( m_progress_reporter )
134  {
136  m_progress_reporter->Report( _( "Fetching Footprint Libraries" ) );
137  }
138 
139  while( !m_cancelled && loader.GetProgress() < 100 )
140  {
141  if( m_progress_reporter )
143  else
144  wxMilliSleep( 20 );
145  }
146 
147  if( m_progress_reporter )
149 
150  if( !m_cancelled )
151  {
152  if( m_progress_reporter )
153  {
155  m_progress_reporter->Report( _( "Loading Footprints" ) );
156  }
157 
158  loader.Join();
159  }
160 
161  if( m_progress_reporter )
163 
164  if( m_cancelled )
165  {
166  m_errors.move_push( std::make_unique<IO_ERROR>
167  ( _( "Loading incomplete; cancelled by user." ), nullptr, nullptr, 0 ) );
168  }
169 
171  m_progress_reporter = nullptr;
172 
173  return m_errors.empty();
174 }
void AdvancePhase()
Uses the next vailable virtual zone of the dialog progress bar.
SYNC_QUEUE< wxString > m_queue_out
size_t size() const
Return the size of the queue.
Definition: sync_queue.h:94
long long m_libraries_last_mod_checksum
std::atomic_bool m_cancelled
ERRLIST m_errors
some can be PARSE_ERRORs also
void Report(const wxString &aMessage)
Display aMessage in the progress bar dialog.
This class can be used to populate a FOOTPRINT_LIST asynchronously.
bool empty() const
Return true iff the queue is empty.
Definition: sync_queue.h:85
void move_push(T &&aValue)
Move a value onto the queue.
Definition: sync_queue.h:54
SYNC_QUEUE< wxString > m_queue_in
long long GenLastModifiedChecksum(const wxString *aNickname)
Generate a checksum of the last-mod-date of aNickname&#39;s directory, or a checksum of all the libraries...
void Start(FP_LIB_TABLE *aTable, wxString const *aNickname=nullptr, unsigned aNThreads=DEFAULT_THREADS)
Launch the worker threads.
WX_PROGRESS_REPORTER * m_progress_reporter
bool Join()
Wait until the worker threads are finished, and then perform any required single-threaded finishing o...
int GetProgress() const
Get the current completion percentage.
bool KeepRefreshing(bool aWait=false)
Update the UI dialog.
void SetMaxProgress(int aMaxProgress)
Fix the value thar gives the 100 precent progress bar length (inside the current virtual zone) ...
void SetList(FOOTPRINT_LIST *aList)
Assign a FOOTPRINT_LIST to the loader.
void FOOTPRINT_LIST_IMPL::StartWorkers ( FP_LIB_TABLE aTable,
wxString const *  aNickname,
FOOTPRINT_ASYNC_LOADER aLoader,
unsigned  aNThreads 
)
overrideprotectedvirtual

Launch worker threads to load footprints.

Part of the FOOTPRINT_ASYNC_LOADER implementation.

Implements FOOTPRINT_LIST.

Definition at line 177 of file footprint_info_impl.cpp.

References SYNC_QUEUE< T >::clear(), LIB_TABLE::GetLogicalLibs(), loader_job(), m_count_finished, FOOTPRINT_LIST::m_errors, FOOTPRINT_LIST::m_lib_table, FOOTPRINT_LIST::m_list, m_loader, m_queue_in, m_queue_out, m_threads, FOOTPRINT_ASYNC_LOADER::m_total_libs, SYNC_QUEUE< T >::push(), and SYNC_QUEUE< T >::size().

179 {
180  m_loader = aLoader;
181  m_lib_table = aTable;
182 
183  // Clear data before reading files
184  m_count_finished.store( 0 );
185  m_errors.clear();
186  m_list.clear();
187  m_threads.clear();
188  m_queue_in.clear();
189  m_queue_out.clear();
190 
191  if( aNickname )
192  m_queue_in.push( *aNickname );
193  else
194  {
195  for( auto const& nickname : aTable->GetLogicalLibs() )
196  m_queue_in.push( nickname );
197  }
198 
200 
201  for( unsigned i = 0; i < aNThreads; ++i )
202  {
203  m_threads.push_back( std::thread( &FOOTPRINT_LIST_IMPL::loader_job, this ) );
204  }
205 }
void push(T const &aValue)
Push a value onto the queue.
Definition: sync_queue.h:45
SYNC_QUEUE< wxString > m_queue_out
size_t size() const
Return the size of the queue.
Definition: sync_queue.h:94
ERRLIST m_errors
some can be PARSE_ERRORs also
void loader_job()
Function loader_job loads footprints from m_queue_in.
FP_LIB_TABLE * m_lib_table
no ownership
std::vector< std::thread > m_threads
SYNC_QUEUE< wxString > m_queue_in
std::atomic_size_t m_count_finished
FOOTPRINT_ASYNC_LOADER * m_loader
void clear()
Clear the queue.
Definition: sync_queue.h:103
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE...

Member Data Documentation

std::atomic_bool FOOTPRINT_LIST_IMPL::m_cancelled
private

Definition at line 67 of file footprint_info_impl.h.

Referenced by JoinWorkers(), loader_job(), and ReadFootprintFiles().

std::atomic_size_t FOOTPRINT_LIST_IMPL::m_count_finished
private

Definition at line 64 of file footprint_info_impl.h.

Referenced by CountFinished(), JoinWorkers(), loader_job(), and StartWorkers().

ERRLIST FOOTPRINT_LIST::m_errors
protectedinherited

some can be PARSE_ERRORs also

Definition at line 181 of file footprint_info.h.

Referenced by CatchErrors(), JoinWorkers(), ReadFootprintFiles(), and StartWorkers().

FP_LIB_TABLE* FOOTPRINT_LIST::m_lib_table
protectedinherited

no ownership

Definition at line 175 of file footprint_info.h.

Referenced by JoinWorkers(), loader_job(), and StartWorkers().

long long FOOTPRINT_LIST_IMPL::m_libraries_last_mod_checksum
private

Definition at line 65 of file footprint_info_impl.h.

Referenced by ReadFootprintFiles().

FPILIST FOOTPRINT_LIST::m_list
protectedinherited

Definition at line 180 of file footprint_info.h.

Referenced by FOOTPRINT_LIST::GetModuleInfo(), JoinWorkers(), and StartWorkers().

MUTEX FOOTPRINT_LIST::m_list_lock
protectedinherited

Definition at line 183 of file footprint_info.h.

FOOTPRINT_ASYNC_LOADER* FOOTPRINT_LIST_IMPL::m_loader
private

Definition at line 60 of file footprint_info_impl.h.

Referenced by StartWorkers().

WX_PROGRESS_REPORTER* FOOTPRINT_LIST_IMPL::m_progress_reporter
private

Definition at line 66 of file footprint_info_impl.h.

Referenced by JoinWorkers(), loader_job(), and ReadFootprintFiles().

SYNC_QUEUE<wxString> FOOTPRINT_LIST_IMPL::m_queue_in
private

Definition at line 62 of file footprint_info_impl.h.

Referenced by JoinWorkers(), loader_job(), ReadFootprintFiles(), and StartWorkers().

SYNC_QUEUE<wxString> FOOTPRINT_LIST_IMPL::m_queue_out
private

Definition at line 63 of file footprint_info_impl.h.

Referenced by JoinWorkers(), loader_job(), ReadFootprintFiles(), and StartWorkers().

std::vector<std::thread> FOOTPRINT_LIST_IMPL::m_threads
private

Definition at line 61 of file footprint_info_impl.h.

Referenced by JoinWorkers(), StartWorkers(), and ~FOOTPRINT_LIST_IMPL().


The documentation for this class was generated from the following files: