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 ()
 
bool ReadFootprintFiles (FP_LIB_TABLE *aTable, const wxString *aNickname=nullptr, 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 FOOTPRINT_LISTGetInstance (KIWAY &aKiway)
 Factory function to return a 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

void StartWorkers (FP_LIB_TABLE *aTable, wxString const *aNickname, FOOTPRINT_ASYNC_LOADER *aLoader, unsigned aNThreads) override
 Launch worker threads to load footprints. More...
 
bool JoinWorkers () override
 Join worker threads. 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
 
const wxString * m_library
 
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_list_timestamp
 
PROGRESS_REPORTERm_progress_reporter
 
std::atomic_bool m_cancelled
 

Detailed Description

Definition at line 57 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 304 of file footprint_info_impl.cpp.

304  :
305  m_loader( nullptr ),
306  m_count_finished( 0 ),
307  m_list_timestamp( 0 ),
308  m_progress_reporter( nullptr ),
309  m_cancelled( false )
310 {
311 }
std::atomic_bool m_cancelled
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 314 of file footprint_info_impl.cpp.

References i, and m_threads.

315 {
316  for( auto& i : m_threads )
317  i.join();
318 }
std::vector< std::thread > m_threads
size_t i
Definition: json11.cpp:597

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 69 of file footprint_info_impl.cpp.

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

Referenced by loader_job().

70 {
71  try
72  {
73  aFunc();
74  }
75  catch( const IO_ERROR& ioe )
76  {
77  m_errors.move_push( std::make_unique<IO_ERROR>( ioe ) );
78  return false;
79  }
80  catch( const std::exception& se )
81  {
82  // This is a round about way to do this, but who knows what THROW_IO_ERROR()
83  // may be tricked out to do someday, keep it in the game.
84  try
85  {
86  THROW_IO_ERROR( se.what() );
87  }
88  catch( const IO_ERROR& ioe )
89  {
90  m_errors.move_push( std::make_unique<IO_ERROR>( ioe ) );
91  }
92  return false;
93  }
94 
95  return true;
96 }
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
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 CVPCB_MAINFRAME::LoadFootprintFiles(), 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 CVPCB_MAINFRAME::LoadFootprintFiles(), 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
FOOTPRINT_LIST * FOOTPRINT_LIST::GetInstance ( KIWAY aKiway)
staticinherited

Factory function to return a 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(), DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT(), 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 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 CVPCB_MAINFRAME::AutomaticFootprintMatching(), DisplayCmpDoc(), CVPCB_MAINFRAME::DisplayStatus(), and DISPLAY_FOOTPRINTS_FRAME::InitDisplay().

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:118
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:101
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 206 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(), FP_LIB_TABLE::GenerateTimestamp(), i, PROGRESS_REPORTER::KeepRefreshing(), numEval::lhs, m_cancelled, m_count_finished, FOOTPRINT_LIST::m_errors, FOOTPRINT_LIST::m_lib_table, m_library, FOOTPRINT_LIST::m_list, m_list_timestamp, 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.

207 {
208  for( auto& i : m_threads )
209  i.join();
210 
211  m_threads.clear();
212  m_queue_in.clear();
213  m_count_finished.store( 0 );
214 
215  size_t total_count = m_queue_out.size();
216 
217  LOCALE_IO toggle_locale;
218 
219  // Parse the footprints in parallel. WARNING! This requires changing the locale, which is
220  // GLOBAL. It is only threadsafe to construct the LOCALE_IO before the threads are created,
221  // destroy it after they finish, and block the main (GUI) thread while they work. Any deviation
222  // from this will cause nasal demons.
223  //
224  // TODO: blast LOCALE_IO into the sun
225 
227  std::vector<std::thread> threads;
228 
229  for( size_t ii = 0; ii < std::thread::hardware_concurrency() + 1; ++ii )
230  {
231  threads.push_back( std::thread( [this, &queue_parsed]() {
232  wxString nickname;
233 
234  while( this->m_queue_out.pop( nickname ) && !m_cancelled )
235  {
236  wxArrayString fpnames;
237 
238  try
239  {
240  m_lib_table->FootprintEnumerate( fpnames, nickname );
241  }
242  catch( const IO_ERROR& ioe )
243  {
244  m_errors.move_push( std::make_unique<IO_ERROR>( ioe ) );
245  }
246  catch( const std::exception& se )
247  {
248  // This is a round about way to do this, but who knows what THROW_IO_ERROR()
249  // may be tricked out to do someday, keep it in the game.
250  try
251  {
252  THROW_IO_ERROR( se.what() );
253  }
254  catch( const IO_ERROR& ioe )
255  {
256  m_errors.move_push( std::make_unique<IO_ERROR>( ioe ) );
257  }
258  }
259 
260  for( unsigned jj = 0; jj < fpnames.size() && !m_cancelled; ++jj )
261  {
262  wxString fpname = fpnames[jj];
263  FOOTPRINT_INFO* fpinfo = new FOOTPRINT_INFO_IMPL( this, nickname, fpname );
264  queue_parsed.move_push( std::unique_ptr<FOOTPRINT_INFO>( fpinfo ) );
265  }
266 
267  if( m_progress_reporter )
269 
270  m_count_finished.fetch_add( 1 );
271  }
272  } ) );
273  }
274 
275  while( !m_cancelled && (size_t)m_count_finished.load() < total_count )
276  {
277  if( m_progress_reporter )
279  else
280  wxMilliSleep( 20 );
281  }
282 
283  for( auto& thr : threads )
284  thr.join();
285 
286  std::unique_ptr<FOOTPRINT_INFO> fpi;
287 
288  while( queue_parsed.pop( fpi ) )
289  m_list.push_back( std::move( fpi ) );
290 
291  std::sort( m_list.begin(), m_list.end(),
292  []( std::unique_ptr<FOOTPRINT_INFO> const& lhs,
293  std::unique_ptr<FOOTPRINT_INFO> const& rhs ) -> bool { return *lhs < *rhs; } );
294 
295  if( m_cancelled )
296  m_list_timestamp = 0; // God knows what we got before we were cancelled
297  else
299 
300  return m_errors.empty();
301 }
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
long long GenerateTimestamp(const wxString *aNickname)
Generate a hashed timestamp representing the last-mod-times of the library indicated by aNickname...
PROGRESS_REPORTER * m_progress_reporter
std::atomic_size_t m_count_finished
const wxString * m_library
YYCODETYPE lhs
size_t i
Definition: json11.cpp:597
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 99 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().

100 {
101  wxString nickname;
102 
103  while( m_queue_in.pop( nickname ) && !m_cancelled )
104  {
105  CatchErrors( [this, &nickname]() {
106  m_lib_table->PrefetchLib( nickname );
107  m_queue_out.push( nickname );
108  } );
109 
110  m_count_finished.fetch_add( 1 );
111 
112  if( m_progress_reporter )
114  }
115 }
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
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,
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 118 of file footprint_info_impl.cpp.

References PROGRESS_REPORTER::AdvancePhase(), SYNC_QUEUE< T >::empty(), FP_LIB_TABLE::GenerateTimestamp(), FOOTPRINT_ASYNC_LOADER::Join(), PROGRESS_REPORTER::KeepRefreshing(), m_cancelled, m_count_finished, FOOTPRINT_LIST::m_errors, m_list_timestamp, m_loader, m_progress_reporter, m_queue_in, m_queue_out, FOOTPRINT_ASYNC_LOADER::m_total_libs, 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().

120 {
121  if( m_list_timestamp == aTable->GenerateTimestamp( aNickname ) )
122  return true;
123 
124  m_progress_reporter = aProgressReporter;
125  m_cancelled = false;
126 
127  FOOTPRINT_ASYNC_LOADER loader;
128 
129  loader.SetList( this );
130  loader.Start( aTable, aNickname );
131 
132  if( m_progress_reporter )
133  {
135  m_progress_reporter->Report( _( "Fetching Footprint Libraries" ) );
136  }
137 
138  while( !m_cancelled && (int)m_count_finished.load() < m_loader->m_total_libs )
139  {
140  if( m_progress_reporter )
142  else
143  wxMilliSleep( 20 );
144  }
145 
146  if( m_progress_reporter )
148 
149  if( !m_cancelled )
150  {
151  if( m_progress_reporter )
152  {
154  m_progress_reporter->Report( _( "Loading Footprints" ) );
155  }
156 
157  loader.Join();
158  }
159 
160  if( m_progress_reporter )
162 
163  if( m_cancelled )
164  {
165  m_errors.move_push( std::make_unique<IO_ERROR>
166  ( _( "Loading incomplete; cancelled by user." ), nullptr, nullptr, 0 ) );
167  }
168 
169  m_progress_reporter = nullptr;
170 
171  return m_errors.empty();
172 }
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
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 GenerateTimestamp(const wxString *aNickname)
Generate a hashed timestamp representing the last-mod-times of the library indicated by aNickname...
PROGRESS_REPORTER * m_progress_reporter
void Start(FP_LIB_TABLE *aTable, wxString const *aNickname=nullptr, unsigned aNThreads=DEFAULT_THREADS)
Launch the worker threads.
std::atomic_size_t m_count_finished
bool Join()
Wait until the worker threads are finished, and then perform any required single-threaded finishing o...
FOOTPRINT_ASYNC_LOADER * m_loader
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 175 of file footprint_info_impl.cpp.

References SYNC_QUEUE< T >::clear(), LIB_TABLE::GetLogicalLibs(), i, loader_job(), m_count_finished, FOOTPRINT_LIST::m_errors, FOOTPRINT_LIST::m_lib_table, m_library, 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().

177 {
178  m_loader = aLoader;
179  m_lib_table = aTable;
180  m_library = aNickname;
181 
182  // Clear data before reading files
183  m_count_finished.store( 0 );
184  m_errors.clear();
185  m_list.clear();
186  m_threads.clear();
187  m_queue_in.clear();
188  m_queue_out.clear();
189 
190  if( aNickname )
191  m_queue_in.push( *aNickname );
192  else
193  {
194  for( auto const& nickname : aTable->GetLogicalLibs() )
195  m_queue_in.push( nickname );
196  }
197 
199 
200  for( unsigned i = 0; i < aNThreads; ++i )
201  {
202  m_threads.push_back( std::thread( &FOOTPRINT_LIST_IMPL::loader_job, this ) );
203  }
204 }
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
const wxString * m_library
size_t i
Definition: json11.cpp:597
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 JoinWorkers(), loader_job(), ReadFootprintFiles(), 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().

const wxString* FOOTPRINT_LIST_IMPL::m_library
private

Definition at line 60 of file footprint_info_impl.h.

Referenced by JoinWorkers(), and StartWorkers().

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.

long long FOOTPRINT_LIST_IMPL::m_list_timestamp
private

Definition at line 65 of file footprint_info_impl.h.

Referenced by JoinWorkers(), and ReadFootprintFiles().

FOOTPRINT_ASYNC_LOADER* FOOTPRINT_LIST_IMPL::m_loader
private

Definition at line 59 of file footprint_info_impl.h.

Referenced by ReadFootprintFiles(), and StartWorkers().

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: