KiCad PCB EDA Suite
FP_THREAD_IFACE Class Reference

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

Public Member Functions

OPT< 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...
 
OPT< 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 = nullptr
 
MUTEX m_lock
 

Detailed Description

Threadsafe interface class between loader thread and panel class.

Definition at line 46 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 96 of file footprint_preview_panel.cpp.

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

97  {
98  MUTLOCK lock( m_lock );
99  m_cachedFootprints[aEntry.fpid] = aEntry;
100  }
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 67 of file footprint_preview_panel.cpp.

References FPS_LOADING, m_cachedFootprints, m_loaderQueue, and m_lock.

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

References m_current_fp, and m_lock.

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

Retrieve a cache entry by LIB_ID.

Definition at line 52 of file footprint_preview_panel.cpp.

References m_cachedFootprints, m_lock, and NULLOPT.

53  {
54  MUTLOCK lock( m_lock );
55  auto it = m_cachedFootprints.find( aFPID );
56 
57  if( it != m_cachedFootprints.end() )
58  return it->second;
59  else
60  return NULLOPT;
61  }
const auto NULLOPT
Definition: optional.h:9
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 132 of file footprint_preview_panel.cpp.

References m_lock, and m_panel.

133  {
134  MUTLOCK lock( m_lock );
135  return m_panel;
136  }
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 160 of file footprint_preview_panel.cpp.

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

161  {
162  MUTLOCK locK( m_lock );
163  return m_panel ? m_panel->Prj().PcbFootprintLibs() : nullptr;
164  }
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
OPT<CACHE_ENTRY> FP_THREAD_IFACE::PopFromQueue ( )
inline

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

Definition at line 79 of file footprint_preview_panel.cpp.

References m_loaderQueue, m_lock, and NULLOPT.

80  {
81  MUTLOCK lock( m_lock );
82 
83  if( m_loaderQueue.empty() )
84  {
85  return NULLOPT;
86  }
87  else
88  {
89  auto ent = m_loaderQueue.front();
90  m_loaderQueue.pop_front();
91  return ent;
92  }
93  }
const auto NULLOPT
Definition: optional.h:9
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 142 of file footprint_preview_panel.cpp.

References m_lock, and m_panel.

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

References m_current_fp, and m_lock.

106  {
107  MUTLOCK lock( m_lock );
108  m_current_fp = std::move( aFp );
109  }
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 123 of file footprint_preview_panel.cpp.

References m_lock, and m_panel.

124  {
125  MUTLOCK lock( m_lock );
126  m_panel = aPanel;
127  }
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 168 of file footprint_preview_panel.cpp.

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

LIB_ID FP_THREAD_IFACE::m_current_fp
private

Definition at line 169 of file footprint_preview_panel.cpp.

Referenced by GetCurrentFootprint(), and SetCurrentFootprint().

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

Definition at line 167 of file footprint_preview_panel.cpp.

Referenced by AddToQueue(), and PopFromQueue().

FOOTPRINT_PREVIEW_PANEL* FP_THREAD_IFACE::m_panel = nullptr
private

Definition at line 170 of file footprint_preview_panel.cpp.

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


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