KiCad PCB EDA Suite
Loading...
Searching...
No Matches
API_TASK_SCHEDULER Class Reference

For now, a single process-wide task runner, and one task at a time. More...

#include <api_task_scheduler.h>

Inheritance diagram for API_TASK_SCHEDULER:

Classes

struct  TASK_ENTRY
 

Public Member Functions

 ~API_TASK_SCHEDULER () override
 
 API_TASK_SCHEDULER (const API_TASK_SCHEDULER &)=delete
 
API_TASK_SCHEDULER & operator= (const API_TASK_SCHEDULER &)=delete
 
std::optional< std::string > StartTask (const std::shared_ptr< API_TASK > &aTask, const wxString &aDescription)
 Register a new task and begin running it.
 
std::optional< kiapi::common::tasks::TaskStatusResponse > GetStatus (const std::string &aToken) const
 Get a snapshot of the task's current status.
 
std::shared_ptr< API_TASK > GetFinishedTask (const std::string &aToken) const
 Look up a task that has finished, for result retrieval.
 
bool AnyTaskRunning () const
 
void Pump ()
 Run the current task to completion, synchronously.
 

Static Public Member Functions

static API_TASK_SCHEDULER & Instance ()
 

Static Public Attributes

static constexpr size_t MAX_FINISHED_TASKS = 32
 

Private Member Functions

 API_TASK_SCHEDULER ()
 
void onTaskRunEvent (wxCommandEvent &aEvent)
 
void runTask (const std::string &aToken)
 

Private Attributes

std::mutex m_mutex
 
std::map< std::string, std::shared_ptr< TASK_ENTRY > > m_tasks
 
std::deque< std::string > m_finishedTokens
 

Detailed Description

For now, a single process-wide task runner, and one task at a time.

Definition at line 59 of file api_task_scheduler.h.

Constructor & Destructor Documentation

◆ ~API_TASK_SCHEDULER()

API_TASK_SCHEDULER::~API_TASK_SCHEDULER ( )
override

Definition at line 56 of file api_task_scheduler.cpp.

References onTaskRunEvent().

◆ API_TASK_SCHEDULER() [1/2]

API_TASK_SCHEDULER::API_TASK_SCHEDULER ( const API_TASK_SCHEDULER & )
delete

◆ API_TASK_SCHEDULER() [2/2]

API_TASK_SCHEDULER::API_TASK_SCHEDULER ( )
private

Definition at line 50 of file api_task_scheduler.cpp.

References onTaskRunEvent().

Member Function Documentation

◆ AnyTaskRunning()

bool API_TASK_SCHEDULER::AnyTaskRunning ( ) const
Returns
true if a task is currently running

Definition at line 149 of file api_task_scheduler.cpp.

References m_mutex, and m_tasks.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and operator=().

◆ GetFinishedTask()

std::shared_ptr< API_TASK > API_TASK_SCHEDULER::GetFinishedTask ( const std::string & aToken) const

Look up a task that has finished, for result retrieval.

The most recent MAX_FINISHED_TASKS results are available.

Definition at line 136 of file api_task_scheduler.cpp.

References m_mutex, and m_tasks.

Referenced by BOOST_AUTO_TEST_CASE(), API_HANDLER_PCB::handleGetDrcTaskResult(), API_HANDLER_SCH::handleGetErcTaskResult(), and operator=().

◆ GetStatus()

std::optional< kiapi::common::tasks::TaskStatusResponse > API_TASK_SCHEDULER::GetStatus ( const std::string & aToken) const

◆ Instance()

◆ onTaskRunEvent()

void API_TASK_SCHEDULER::onTaskRunEvent ( wxCommandEvent & aEvent)
private

Definition at line 163 of file api_task_scheduler.cpp.

References runTask().

Referenced by API_TASK_SCHEDULER(), and ~API_TASK_SCHEDULER().

◆ operator=()

API_TASK_SCHEDULER & API_TASK_SCHEDULER::operator= ( const API_TASK_SCHEDULER & )
delete

◆ Pump()

void API_TASK_SCHEDULER::Pump ( )

◆ runTask()

void API_TASK_SCHEDULER::runTask ( const std::string & aToken)
private

Definition at line 172 of file api_task_scheduler.cpp.

References m_finishedTokens, m_mutex, m_tasks, MAX_FINISHED_TASKS, and traceApi.

Referenced by onTaskRunEvent(), and Pump().

◆ StartTask()

std::optional< std::string > API_TASK_SCHEDULER::StartTask ( const std::shared_ptr< API_TASK > & aTask,
const wxString & aDescription )

Register a new task and begin running it.

Parameters
aTaskis the task to run
aDescriptionis used for trace logging
Returns
the new task's token, or nullopt if another task is already running

Definition at line 62 of file api_task_scheduler.cpp.

References KIID::AsStdString(), m_mutex, m_tasks, makeRunEvent(), and traceApi.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), API_HANDLER_PCB::handleStartDrcTask(), API_HANDLER_SCH::handleStartErcTask(), API_HANDLER_PCB::handleStartRefillZonesTask(), and operator=().

Member Data Documentation

◆ m_finishedTokens

std::deque<std::string> API_TASK_SCHEDULER::m_finishedTokens
private

Definition at line 118 of file api_task_scheduler.h.

Referenced by runTask().

◆ m_mutex

std::mutex API_TASK_SCHEDULER::m_mutex
mutableprivate

◆ m_tasks

std::map<std::string, std::shared_ptr<TASK_ENTRY> > API_TASK_SCHEDULER::m_tasks
private

◆ MAX_FINISHED_TASKS

size_t API_TASK_SCHEDULER::MAX_FINISHED_TASKS = 32
staticconstexpr

Definition at line 62 of file api_task_scheduler.h.

Referenced by BOOST_AUTO_TEST_CASE(), and runTask().


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