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 43 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 93 of file footprint_preview_panel.cpp.

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

94  {
95  MUTLOCK lock( m_lock );
96  m_cachedFootprints[aEntry.fpid] = aEntry;
97  }
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 64 of file footprint_preview_panel.cpp.

References FPS_LOADING, m_cachedFootprints, m_loaderQueue, and m_lock.

65  {
66  MUTLOCK lock( m_lock );
67 
68  CACHE_ENTRY ent = { aEntry, NULL, FPS_LOADING };
69  m_cachedFootprints[aEntry] = ent;
70  m_loaderQueue.push_back( ent );
71 
72  return ent;
73  }
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 111 of file footprint_preview_panel.cpp.

References m_current_fp, and m_lock.

112  {
113  MUTLOCK lock( m_lock );
114  return m_current_fp;
115  }
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 49 of file footprint_preview_panel.cpp.

References m_cachedFootprints, and m_lock.

50  {
51  MUTLOCK lock( m_lock );
52  auto it = m_cachedFootprints.find( aFPID );
53 
54  if( it != m_cachedFootprints.end() )
55  return it->second;
56  else
57  return boost::none;
58  }
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 129 of file footprint_preview_panel.cpp.

References m_lock, and m_panel.

130  {
131  MUTLOCK lock( m_lock );
132  return m_panel;
133  }
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 157 of file footprint_preview_panel.cpp.

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

158  {
159  MUTLOCK locK( m_lock );
160  return m_panel ? m_panel->Prj().PcbFootprintLibs() : nullptr;
161  }
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 76 of file footprint_preview_panel.cpp.

References m_loaderQueue, and m_lock.

77  {
78  MUTLOCK lock( m_lock );
79 
80  if( m_loaderQueue.empty() )
81  {
82  return boost::none;
83  }
84  else
85  {
86  auto ent = m_loaderQueue.front();
87  m_loaderQueue.pop_front();
88  return ent;
89  }
90  }
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 139 of file footprint_preview_panel.cpp.

References m_lock, and m_panel.

140  {
141  MUTLOCK lock( m_lock );
142 
143  if( m_panel )
144  {
145  m_panel->GetEventHandler()->QueueEvent( aEvent.Clone() );
146  return true;
147  }
148  else
149  {
150  return false;
151  }
152  }
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 102 of file footprint_preview_panel.cpp.

References m_current_fp, and m_lock.

103  {
104  MUTLOCK lock( m_lock );
105  m_current_fp = aFp;
106  }
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 120 of file footprint_preview_panel.cpp.

References m_lock, and m_panel.

121  {
122  MUTLOCK lock( m_lock );
123  m_panel = aPanel;
124  }
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 165 of file footprint_preview_panel.cpp.

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

LIB_ID FP_THREAD_IFACE::m_current_fp
private

Definition at line 166 of file footprint_preview_panel.cpp.

Referenced by GetCurrentFootprint(), and SetCurrentFootprint().

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

Definition at line 164 of file footprint_preview_panel.cpp.

Referenced by AddToQueue(), and PopFromQueue().

FOOTPRINT_PREVIEW_PANEL* FP_THREAD_IFACE::m_panel
private

Definition at line 167 of file footprint_preview_panel.cpp.

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


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