KiCad PCB EDA Suite
FP_THREAD_IFACE Class Reference

Threadsafe interface class between loader thread and panel class. More...

Public Member Functions

boost::optional< CACHE_ENTRYGetFromCache (LIB_ID const &aFPID)
 Retrieve a cache entry by LIB_ID. More...
 
CACHE_ENTRY AddToQueue (LIB_ID const &aEntry)
 Push an entry to the loading queue and a placeholder to the cache; return the placeholder. More...
 
boost::optional< CACHE_ENTRYPopFromQueue ()
 Pop an entry from the queue, or empty option if none is available. More...
 
void AddToCache (CACHE_ENTRY const &aEntry)
 Add an entry to the cache. More...
 
void SetCurrentFootprint (LIB_ID aFp)
 Threadsafe accessor to set the current footprint. More...
 
LIB_ID GetCurrentFootprint ()
 Threadsafe accessor to get the current footprint. More...
 
void SetPanel (FOOTPRINT_PREVIEW_PANEL *aPanel)
 Set the associated panel, for QueueEvent() and GetTable(). More...
 
FOOTPRINT_PREVIEW_PANELGetPanel ()
 Get the associated panel. More...
 
bool QueueEvent (wxEvent const &aEvent)
 Post an event to the panel, if the panel still exists. More...
 
FP_LIB_TABLEGetTable ()
 Get an FP_LIB_TABLE, or null if the panel is dead. More...
 

Private Types

using CACHE_ENTRY = FOOTPRINT_PREVIEW_PANEL::CACHE_ENTRY
 

Private Attributes

std::deque< CACHE_ENTRYm_loaderQueue
 
std::map< LIB_ID, CACHE_ENTRYm_cachedFootprints
 
LIB_ID m_current_fp
 
FOOTPRINT_PREVIEW_PANELm_panel
 
MUTEX m_lock
 

Detailed Description

Threadsafe interface class between loader thread and panel class.

Definition at line 44 of file footprint_preview_panel.cpp.

Member Typedef Documentation

Member Function Documentation

void FP_THREAD_IFACE::AddToCache ( CACHE_ENTRY const &  aEntry)
inline

Add an entry to the cache.

Definition at line 94 of file footprint_preview_panel.cpp.

References FOOTPRINT_PREVIEW_PANEL::CACHE_ENTRY::fpid, m_cachedFootprints, and m_lock.

95  {
96  MUTLOCK lock( m_lock );
97  m_cachedFootprints[aEntry.fpid] = aEntry;
98  }
std::map< LIB_ID, CACHE_ENTRY > m_cachedFootprints
boost::interprocess::scoped_lock< MUTEX > MUTLOCK
Definition: ki_mutex.h:43
CACHE_ENTRY FP_THREAD_IFACE::AddToQueue ( LIB_ID const &  aEntry)
inline

Push an entry to the loading queue and a placeholder to the cache; return the placeholder.

Definition at line 65 of file footprint_preview_panel.cpp.

References FPS_LOADING, m_cachedFootprints, m_loaderQueue, and m_lock.

66  {
67  MUTLOCK lock( m_lock );
68 
69  CACHE_ENTRY ent = { aEntry, NULL, FPS_LOADING };
70  m_cachedFootprints[aEntry] = ent;
71  m_loaderQueue.push_back( ent );
72 
73  return ent;
74  }
FOOTPRINT_PREVIEW_PANEL::CACHE_ENTRY CACHE_ENTRY
std::map< LIB_ID, CACHE_ENTRY > m_cachedFootprints
boost::interprocess::scoped_lock< MUTEX > MUTLOCK
Definition: ki_mutex.h:43
std::deque< CACHE_ENTRY > m_loaderQueue
LIB_ID FP_THREAD_IFACE::GetCurrentFootprint ( )
inline

Threadsafe accessor to get the current footprint.

Definition at line 112 of file footprint_preview_panel.cpp.

References m_current_fp, and m_lock.

113  {
114  MUTLOCK lock( m_lock );
115  return m_current_fp;
116  }
boost::interprocess::scoped_lock< MUTEX > MUTLOCK
Definition: ki_mutex.h:43
boost::optional<CACHE_ENTRY> FP_THREAD_IFACE::GetFromCache ( LIB_ID const &  aFPID)
inline

Retrieve a cache entry by LIB_ID.

Definition at line 50 of file footprint_preview_panel.cpp.

References m_cachedFootprints, and m_lock.

51  {
52  MUTLOCK lock( m_lock );
53  auto it = m_cachedFootprints.find( aFPID );
54 
55  if( it != m_cachedFootprints.end() )
56  return it->second;
57  else
58  return boost::none;
59  }
std::map< LIB_ID, CACHE_ENTRY > m_cachedFootprints
boost::interprocess::scoped_lock< MUTEX > MUTLOCK
Definition: ki_mutex.h:43
FOOTPRINT_PREVIEW_PANEL* FP_THREAD_IFACE::GetPanel ( )
inline

Get the associated panel.

Definition at line 130 of file footprint_preview_panel.cpp.

References m_lock, and m_panel.

131  {
132  MUTLOCK lock( m_lock );
133  return m_panel;
134  }
boost::interprocess::scoped_lock< MUTEX > MUTLOCK
Definition: ki_mutex.h:43
FOOTPRINT_PREVIEW_PANEL * m_panel
FP_LIB_TABLE* FP_THREAD_IFACE::GetTable ( )
inline

Get an FP_LIB_TABLE, or null if the panel is dead.

Definition at line 158 of file footprint_preview_panel.cpp.

References m_lock, m_panel, PROJECT::PcbFootprintLibs(), and KIWAY_HOLDER::Prj().

159  {
160  MUTLOCK locK( m_lock );
161  return m_panel ? m_panel->Prj().PcbFootprintLibs() : nullptr;
162  }
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
boost::interprocess::scoped_lock< MUTEX > MUTLOCK
Definition: ki_mutex.h:43
FOOTPRINT_PREVIEW_PANEL * m_panel
boost::optional<CACHE_ENTRY> FP_THREAD_IFACE::PopFromQueue ( )
inline

Pop an entry from the queue, or empty option if none is available.

Definition at line 77 of file footprint_preview_panel.cpp.

References m_loaderQueue, and m_lock.

78  {
79  MUTLOCK lock( m_lock );
80 
81  if( m_loaderQueue.empty() )
82  {
83  return boost::none;
84  }
85  else
86  {
87  auto ent = m_loaderQueue.front();
88  m_loaderQueue.pop_front();
89  return ent;
90  }
91  }
boost::interprocess::scoped_lock< MUTEX > MUTLOCK
Definition: ki_mutex.h:43
std::deque< CACHE_ENTRY > m_loaderQueue
bool FP_THREAD_IFACE::QueueEvent ( wxEvent const &  aEvent)
inline

Post an event to the panel, if the panel still exists.

Return whether the event was posted.

Definition at line 140 of file footprint_preview_panel.cpp.

References m_lock, and m_panel.

141  {
142  MUTLOCK lock( m_lock );
143 
144  if( m_panel )
145  {
146  m_panel->GetEventHandler()->QueueEvent( aEvent.Clone() );
147  return true;
148  }
149  else
150  {
151  return false;
152  }
153  }
boost::interprocess::scoped_lock< MUTEX > MUTLOCK
Definition: ki_mutex.h:43
FOOTPRINT_PREVIEW_PANEL * m_panel
void FP_THREAD_IFACE::SetCurrentFootprint ( LIB_ID  aFp)
inline

Threadsafe accessor to set the current footprint.

Definition at line 103 of file footprint_preview_panel.cpp.

References m_current_fp, and m_lock.

104  {
105  MUTLOCK lock( m_lock );
106  m_current_fp = aFp;
107  }
boost::interprocess::scoped_lock< MUTEX > MUTLOCK
Definition: ki_mutex.h:43
void FP_THREAD_IFACE::SetPanel ( FOOTPRINT_PREVIEW_PANEL aPanel)
inline

Set the associated panel, for QueueEvent() and GetTable().

Definition at line 121 of file footprint_preview_panel.cpp.

References m_lock, and m_panel.

122  {
123  MUTLOCK lock( m_lock );
124  m_panel = aPanel;
125  }
boost::interprocess::scoped_lock< MUTEX > MUTLOCK
Definition: ki_mutex.h:43
FOOTPRINT_PREVIEW_PANEL * m_panel

Member Data Documentation

std::map<LIB_ID, CACHE_ENTRY> FP_THREAD_IFACE::m_cachedFootprints
private

Definition at line 166 of file footprint_preview_panel.cpp.

Referenced by AddToCache(), AddToQueue(), and GetFromCache().

LIB_ID FP_THREAD_IFACE::m_current_fp
private

Definition at line 167 of file footprint_preview_panel.cpp.

Referenced by GetCurrentFootprint(), and SetCurrentFootprint().

std::deque<CACHE_ENTRY> FP_THREAD_IFACE::m_loaderQueue
private

Definition at line 165 of file footprint_preview_panel.cpp.

Referenced by AddToQueue(), and PopFromQueue().

FOOTPRINT_PREVIEW_PANEL* FP_THREAD_IFACE::m_panel
private

Definition at line 168 of file footprint_preview_panel.cpp.

Referenced by GetPanel(), GetTable(), QueueEvent(), and SetPanel().


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