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 45 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 95 of file footprint_preview_panel.cpp.

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

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

References FPS_LOADING, m_cachedFootprints, m_loaderQueue, and m_lock.

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

References m_current_fp, and m_lock.

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

References m_cachedFootprints, m_lock, and NULLOPT.

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

References m_lock, and m_panel.

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

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

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

References m_loaderQueue, m_lock, and NULLOPT.

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

References m_lock, and m_panel.

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

References m_current_fp, and m_lock.

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

References m_lock, and m_panel.

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

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

LIB_ID FP_THREAD_IFACE::m_current_fp
private

Definition at line 168 of file footprint_preview_panel.cpp.

Referenced by GetCurrentFootprint(), and SetCurrentFootprint().

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

Definition at line 166 of file footprint_preview_panel.cpp.

Referenced by AddToQueue(), and PopFromQueue().

FOOTPRINT_PREVIEW_PANEL* FP_THREAD_IFACE::m_panel = nullptr
private

Definition at line 169 of file footprint_preview_panel.cpp.

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


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