KiCad PCB EDA Suite
FP_THREAD_IFACE Class Reference

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

Public Member Functions

 FP_THREAD_IFACE ()
 
OPT< CACHE_ENTRYGetFromCache (const LIB_ID &aFPID)
 Retrieve a cache entry by LIB_ID. More...
 
CACHE_ENTRY AddToQueue (const LIB_ID &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 (const CACHE_ENTRY &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 (const wxEvent &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
 
std::mutex m_lock
 

Detailed Description

Threadsafe interface class between loader thread and panel class.

Definition at line 47 of file footprint_preview_panel.cpp.

Member Typedef Documentation

◆ CACHE_ENTRY

Constructor & Destructor Documentation

◆ FP_THREAD_IFACE()

FP_THREAD_IFACE::FP_THREAD_IFACE ( )
inline

Definition at line 52 of file footprint_preview_panel.cpp.

52  : m_panel( nullptr )
53  {
54  }
FOOTPRINT_PREVIEW_PANEL * m_panel

Member Function Documentation

◆ AddToCache()

void FP_THREAD_IFACE::AddToCache ( const CACHE_ENTRY aEntry)
inline

Add an entry to the cache.

Definition at line 101 of file footprint_preview_panel.cpp.

102  {
103  std::lock_guard<std::mutex> lock( m_lock );
104  m_cachedFootprints[aEntry.fpid] = aEntry;
105  }
std::map< LIB_ID, CACHE_ENTRY > m_cachedFootprints

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

◆ AddToQueue()

CACHE_ENTRY FP_THREAD_IFACE::AddToQueue ( const LIB_ID aEntry)
inline

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

Definition at line 72 of file footprint_preview_panel.cpp.

73  {
74  std::lock_guard<std::mutex> lock( m_lock );
75 
76  CACHE_ENTRY ent = { aEntry, nullptr, FPS_LOADING };
77  m_cachedFootprints[aEntry] = ent;
78  m_loaderQueue.push_back( ent );
79 
80  return ent;
81  }
FOOTPRINT_PREVIEW_PANEL::CACHE_ENTRY CACHE_ENTRY
std::map< LIB_ID, CACHE_ENTRY > m_cachedFootprints
std::deque< CACHE_ENTRY > m_loaderQueue

References FPS_LOADING, m_cachedFootprints, m_loaderQueue, and m_lock.

◆ GetCurrentFootprint()

LIB_ID FP_THREAD_IFACE::GetCurrentFootprint ( )
inline

Threadsafe accessor to get the current footprint.

Definition at line 119 of file footprint_preview_panel.cpp.

120  {
121  std::lock_guard<std::mutex> lock( m_lock );
122  return m_current_fp;
123  }

References m_current_fp, and m_lock.

◆ GetFromCache()

OPT<CACHE_ENTRY> FP_THREAD_IFACE::GetFromCache ( const LIB_ID aFPID)
inline

Retrieve a cache entry by LIB_ID.

Definition at line 57 of file footprint_preview_panel.cpp.

58  {
59  std::lock_guard<std::mutex> lock( m_lock );
60  auto it = m_cachedFootprints.find( aFPID );
61 
62  if( it != m_cachedFootprints.end() )
63  return it->second;
64  else
65  return NULLOPT;
66  }
const auto NULLOPT
Definition: optional.h:9
std::map< LIB_ID, CACHE_ENTRY > m_cachedFootprints

References m_cachedFootprints, m_lock, and NULLOPT.

◆ GetPanel()

FOOTPRINT_PREVIEW_PANEL* FP_THREAD_IFACE::GetPanel ( )
inline

Get the associated panel.

Definition at line 137 of file footprint_preview_panel.cpp.

138  {
139  std::lock_guard<std::mutex> lock( m_lock );
140  return m_panel;
141  }
FOOTPRINT_PREVIEW_PANEL * m_panel

References m_lock, and m_panel.

◆ GetTable()

FP_LIB_TABLE* FP_THREAD_IFACE::GetTable ( )
inline

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

Definition at line 165 of file footprint_preview_panel.cpp.

166  {
167  std::lock_guard<std::mutex> lock( m_lock );
168  return m_panel ? m_panel->Prj().PcbFootprintLibs() : nullptr;
169  }
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.
Definition: project.cpp:286
FOOTPRINT_PREVIEW_PANEL * m_panel

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

◆ PopFromQueue()

OPT<CACHE_ENTRY> FP_THREAD_IFACE::PopFromQueue ( )
inline

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

Definition at line 84 of file footprint_preview_panel.cpp.

85  {
86  std::lock_guard<std::mutex> lock( m_lock );
87 
88  if( m_loaderQueue.empty() )
89  {
90  return NULLOPT;
91  }
92  else
93  {
94  auto ent = m_loaderQueue.front();
95  m_loaderQueue.pop_front();
96  return ent;
97  }
98  }
const auto NULLOPT
Definition: optional.h:9
std::deque< CACHE_ENTRY > m_loaderQueue

References m_loaderQueue, m_lock, and NULLOPT.

◆ QueueEvent()

bool FP_THREAD_IFACE::QueueEvent ( const wxEvent &  aEvent)
inline

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

Return whether the event was posted.

Definition at line 147 of file footprint_preview_panel.cpp.

148  {
149  std::lock_guard<std::mutex> lock( m_lock );
150 
151  if( m_panel )
152  {
153  m_panel->GetEventHandler()->QueueEvent( aEvent.Clone() );
154  return true;
155  }
156  else
157  {
158  return false;
159  }
160  }
FOOTPRINT_PREVIEW_PANEL * m_panel

References m_lock, and m_panel.

◆ SetCurrentFootprint()

void FP_THREAD_IFACE::SetCurrentFootprint ( LIB_ID  aFp)
inline

Threadsafe accessor to set the current footprint.

Definition at line 110 of file footprint_preview_panel.cpp.

111  {
112  std::lock_guard<std::mutex> lock( m_lock );
113  m_current_fp = std::move( aFp );
114  }

References m_current_fp, and m_lock.

◆ SetPanel()

void FP_THREAD_IFACE::SetPanel ( FOOTPRINT_PREVIEW_PANEL aPanel)
inline

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

Definition at line 128 of file footprint_preview_panel.cpp.

129  {
130  std::lock_guard<std::mutex> lock( m_lock );
131  m_panel = aPanel;
132  }
FOOTPRINT_PREVIEW_PANEL * m_panel

References m_lock, and m_panel.

Member Data Documentation

◆ m_cachedFootprints

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

Definition at line 173 of file footprint_preview_panel.cpp.

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

◆ m_current_fp

LIB_ID FP_THREAD_IFACE::m_current_fp
private

Definition at line 174 of file footprint_preview_panel.cpp.

Referenced by GetCurrentFootprint(), and SetCurrentFootprint().

◆ m_loaderQueue

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

Definition at line 172 of file footprint_preview_panel.cpp.

Referenced by AddToQueue(), and PopFromQueue().

◆ m_lock

std::mutex FP_THREAD_IFACE::m_lock
private

◆ m_panel

FOOTPRINT_PREVIEW_PANEL* FP_THREAD_IFACE::m_panel
private

Definition at line 175 of file footprint_preview_panel.cpp.

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


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