|
KiCad PCB EDA Suite
|
Responsible for loading plugin definitions for API-based plugins (ones that do not run inside KiCad itself, but instead are launched as external processes by KiCad) More...
#include <api_plugin_manager.h>
Classes | |
| struct | JOB |
Public Member Functions | |
| API_PLUGIN_MANAGER (wxEvtHandler *aParent) | |
| void | ReloadPlugins (std::optional< wxString > aDirectoryToScan=std::nullopt, std::shared_ptr< REPORTER > aReporter=nullptr) |
| Clears the loaded plugins and actions and re-scans the filesystem to register new ones. | |
| bool | RecreatePluginEnvironment (const wxString &aIdentifier) |
| Removes the given plugin's virtual environment (if any) and schedules a new one to be created with the currently-configured interpreter. | |
| void | HandlePythonInterpreterChanged () |
| void | InvokeAction (const wxString &aIdentifier, std::shared_ptr< REPORTER > aReporter=nullptr) |
| int | InvokeActionSync (const wxString &aIdentifier, std::vector< wxString > aExtraArgs, wxString *aStdout=nullptr, wxString *aStderr=nullptr, std::shared_ptr< REPORTER > aReporter=nullptr) |
| Invokes an action synchronously, capturing its output. | |
| bool | Busy () const |
| std::optional< const PLUGIN_ACTION * > | GetAction (const wxString &aIdentifier) |
| std::vector< const PLUGIN_ACTION * > | GetActionsForScope (PLUGIN_ACTION_SCOPE aScope) |
| std::map< int, wxString > & | ButtonBindings (FRAME_T aFrame) |
| std::map< int, wxString > & | MenuBindings (FRAME_T aFrame) |
| std::shared_ptr< REPORTER > | GetReporter () |
Private Types | |
| enum class | JOB_TYPE { CREATE_ENV , SETUP_ENV , INSTALL_REQUIREMENTS } |
Private Member Functions | |
| wxString | pluginName (const wxString &aIdentifier) const |
| void | processPluginDependencies () |
| void | processNextJob (wxCommandEvent &aEvent) |
| bool | cancelPluginJobs (const wxString &aIdentifier) |
| void | recreateCancelledPlugin (const wxString &aIdentifier) |
| int | doInvokeAction (const wxString &aIdentifier, std::vector< wxString > aExtraArgs, bool aSync=false, wxString *aStdout=nullptr, wxString *aStderr=nullptr, std::shared_ptr< REPORTER > aReporter=nullptr) |
Private Attributes | |
| wxEvtHandler * | m_parent |
| std::set< std::unique_ptr< API_PLUGIN >, CompareApiPluginIdentifiers > | m_plugins |
| std::map< wxString, const API_PLUGIN * > | m_pluginsCache |
| std::map< wxString, const PLUGIN_ACTION * > | m_actionsCache |
| std::map< wxString, wxString > | m_environmentCache |
| Map of plugin identifier to a path for the plugin's virtual environment, if it has one. | |
| std::map< FRAME_T, std::map< int, wxString > > | m_buttonBindings |
| Map of button wx item id to action identifier, per frame. | |
| std::map< FRAME_T, std::map< int, wxString > > | m_menuBindings |
| Map of menu wx item id to action identifier, per frame. | |
| std::set< wxString > | m_readyPlugins |
| std::set< wxString > | m_busyPlugins |
| std::map< wxString, long > | m_runningPids |
| Map of plugin identifier to the pid of its currently-running setup process, if any. | |
| std::set< wxString > | m_cancelledPlugins |
| Plugins whose setup jobs were cancelled and need their environment recreated. | |
| std::deque< JOB > | m_jobs |
| std::unique_ptr< JSON_SCHEMA_VALIDATOR > | m_schema_validator |
| std::shared_ptr< REPORTER > | m_reloadReporter |
| long | m_lastPid |
| wxTimer * | m_raiseTimer |
Responsible for loading plugin definitions for API-based plugins (ones that do not run inside KiCad itself, but instead are launched as external processes by KiCad)
Definition at line 45 of file api_plugin_manager.h.
|
strongprivate |
| Enumerator | |
|---|---|
| CREATE_ENV | |
| SETUP_ENV | |
| INSTALL_REQUIREMENTS | |
Definition at line 135 of file api_plugin_manager.h.
| API_PLUGIN_MANAGER::API_PLUGIN_MANAGER | ( | wxEvtHandler * | aParent | ) |
Definition at line 164 of file api_plugin_manager.cpp.
References EDA_EVT_PLUGIN_MANAGER_JOB_FINISHED, FN_NORMALIZE_FLAGS, PATHS::GetStockDataPath(), m_lastPid, m_parent, m_raiseTimer, m_schema_validator, and processNextJob().
| bool API_PLUGIN_MANAGER::Busy | ( | ) | const |
Definition at line 1187 of file api_plugin_manager.cpp.
References m_busyPlugins, and m_jobs.
Referenced by BOOST_AUTO_TEST_CASE(), processNextJob(), and ReloadPlugins().
| std::map< int, wxString > & API_PLUGIN_MANAGER::ButtonBindings | ( | FRAME_T | aFrame | ) |
Definition at line 316 of file api_plugin_manager.cpp.
References m_buttonBindings.
Referenced by EDA_DRAW_FRAME::AddApiPluginTools(), and EDA_DRAW_FRAME::OnApiPluginInvoke().
|
private |
Definition at line 758 of file api_plugin_manager.cpp.
References API_PLUGIN_MANAGER::JOB::identifier, m_cancelledPlugins, m_jobs, and m_runningPids.
Referenced by HandlePythonInterpreterChanged().
|
private |
Definition at line 447 of file api_plugin_manager.cpp.
References _, PLUGIN_ACTION::args, API_PLUGIN::BasePath(), PLUGIN_ACTION::entrypoint, EXEC, PYTHON_MANAGER::Execute(), PYTHON_MANAGER::ExecuteSync(), FindKicadFile(), PGM_BASE::GetApiServer(), PYTHON_MANAGER::GetPythonEnvironment(), PYTHON_MANAGER::GetVirtualPython(), API_PLUGIN::Identifier(), PLUGIN_ACTION::identifier, m_actionsCache, m_lastPid, m_raiseTimer, m_readyPlugins, PLUGIN_ACTION::name, Pgm(), PLUGIN_ACTION::plugin, process, PYTHON, reportPluginActionMessage(), reportPluginActionResult(), API_PLUGIN::Runtime(), KICAD_API_SERVER::SocketPath(), KICAD_API_SERVER::Token(), traceApi, and PLUGIN_RUNTIME::type.
Referenced by InvokeAction(), and InvokeActionSync().
| std::optional< const PLUGIN_ACTION * > API_PLUGIN_MANAGER::GetAction | ( | const wxString & | aIdentifier | ) |
Definition at line 370 of file api_plugin_manager.cpp.
References m_actionsCache.
Referenced by PLUGINS_GRID_TRICKS::doPopupSelection(), PLUGINS_GRID_TRICKS::showPopupMenu(), and PANEL_PCBNEW_ACTION_PLUGINS::TransferDataFromWindow().
| std::vector< const PLUGIN_ACTION * > API_PLUGIN_MANAGER::GetActionsForScope | ( | PLUGIN_ACTION_SCOPE | aScope | ) |
Definition at line 732 of file api_plugin_manager.cpp.
References m_actionsCache, and m_readyPlugins.
Referenced by BOOST_AUTO_TEST_CASE(), FOOTPRINT_EDIT_FRAME::configureToolbars(), PCB_EDIT_FRAME::configureToolbars(), SCH_EDIT_FRAME::configureToolbars(), SYMBOL_EDIT_FRAME::configureToolbars(), EDA_DRAW_FRAME::GetOrderedPluginActions(), and FOOTPRINT_WIZARD_MANAGER::ReloadWizards().
|
inline |
Definition at line 96 of file api_plugin_manager.h.
References m_reloadReporter.
| void API_PLUGIN_MANAGER::HandlePythonInterpreterChanged | ( | ) |
Definition at line 394 of file api_plugin_manager.cpp.
References cancelPluginJobs(), EDA_EVT_PLUGIN_MANAGER_JOB_FINISHED, PYTHON_MANAGER::GetPythonEnvironment(), PYTHON_MANAGER::IsVenvStale(), m_busyPlugins, m_plugins, m_readyPlugins, Pgm(), PYTHON, recreateCancelledPlugin(), RecreatePluginEnvironment(), and traceApi.
Referenced by PANEL_PLUGIN_SETTINGS::TransferDataFromWindow().
| void API_PLUGIN_MANAGER::InvokeAction | ( | const wxString & | aIdentifier, |
| std::shared_ptr< REPORTER > | aReporter = nullptr ) |
Definition at line 716 of file api_plugin_manager.cpp.
References doInvokeAction().
Referenced by EDA_DRAW_FRAME::OnApiPluginInvoke().
| int API_PLUGIN_MANAGER::InvokeActionSync | ( | const wxString & | aIdentifier, |
| std::vector< wxString > | aExtraArgs, | ||
| wxString * | aStdout = nullptr, | ||
| wxString * | aStderr = nullptr, | ||
| std::shared_ptr< REPORTER > | aReporter = nullptr ) |
Invokes an action synchronously, capturing its output.
Mainly used for things like wizards that have actions that return quickly and pass data to KiCad via stdout.
| aIdentifier | is the plugin action to invoke |
| aExtraArgs | are extra arguments to pass to the action beyond the ones specified in the plugin configuration file |
| aStdout | is a pointer to a string to fill with the stdout output of the action |
| aStderr | is a pointer to a string to fill with the stderr output of the action |
| aReporter | is a REPORTER object to write status information to. |
Definition at line 723 of file api_plugin_manager.cpp.
References doInvokeAction().
Referenced by FOOTPRINT_WIZARD_MANAGER::Generate(), and FOOTPRINT_WIZARD_MANAGER::RefreshInfo().
| std::map< int, wxString > & API_PLUGIN_MANAGER::MenuBindings | ( | FRAME_T | aFrame | ) |
Definition at line 322 of file api_plugin_manager.cpp.
References m_menuBindings.
Referenced by EDA_DRAW_FRAME::AddApiPluginMenuItems(), and EDA_DRAW_FRAME::OnApiPluginInvoke().
|
private |
Definition at line 749 of file api_plugin_manager.cpp.
References m_pluginsCache.
Referenced by processNextJob().
|
private |
Definition at line 869 of file api_plugin_manager.cpp.
References _, Busy(), CREATE_ENV, EDA_EVT_PLUGIN_AVAILABILITY_CHANGED, EDA_EVT_PLUGIN_MANAGER_JOB_FINISHED, API_PLUGIN_MANAGER::JOB::env_path, PYTHON_MANAGER::Execute(), FindKicadFile(), PYTHON_MANAGER::GetPythonEnvironment(), PYTHON_MANAGER::GetVirtualPython(), API_PLUGIN_MANAGER::JOB::identifier, INSTALL_REQUIREMENTS, m_busyPlugins, m_cancelledPlugins, m_jobs, m_readyPlugins, m_reloadReporter, m_runningPids, Pgm(), API_PLUGIN_MANAGER::JOB::plugin_path, pluginName(), recreateCancelledPlugin(), reportPluginLoadMessage(), SETUP_ENV, traceApi, and API_PLUGIN_MANAGER::JOB::type.
Referenced by API_PLUGIN_MANAGER().
|
private |
Definition at line 778 of file api_plugin_manager.cpp.
References CREATE_ENV, EDA_EVT_PLUGIN_MANAGER_JOB_FINISHED, API_PLUGIN_MANAGER::JOB::env_path, PYTHON_MANAGER::GetPythonEnvironment(), API_PLUGIN_MANAGER::JOB::identifier, INSTALL_REQUIREMENTS, PYTHON_MANAGER::IsVenvStale(), PYTHON_MANAGER::IsVenvUsable(), m_busyPlugins, m_environmentCache, m_jobs, m_plugins, m_readyPlugins, Pgm(), API_PLUGIN_MANAGER::JOB::plugin_path, PYTHON, RecreatePluginEnvironment(), traceApi, and API_PLUGIN_MANAGER::JOB::type.
Referenced by ReloadPlugins().
|
private |
Definition at line 379 of file api_plugin_manager.cpp.
References EDA_EVT_PLUGIN_MANAGER_JOB_FINISHED, m_busyPlugins, m_cancelledPlugins, and RecreatePluginEnvironment().
Referenced by HandlePythonInterpreterChanged(), and processNextJob().
| bool API_PLUGIN_MANAGER::RecreatePluginEnvironment | ( | const wxString & | aIdentifier | ) |
Removes the given plugin's virtual environment (if any) and schedules a new one to be created with the currently-configured interpreter.
Definition at line 328 of file api_plugin_manager.cpp.
References API_PLUGIN::BasePath(), CREATE_ENV, API_PLUGIN_MANAGER::JOB::env_path, PYTHON_MANAGER::GetPythonEnvironment(), API_PLUGIN::Identifier(), API_PLUGIN_MANAGER::JOB::identifier, m_jobs, m_pluginsCache, API_PLUGIN_MANAGER::JOB::plugin_path, PYTHON, API_PLUGIN::Runtime(), traceApi, API_PLUGIN_MANAGER::JOB::type, and PLUGIN_RUNTIME::type.
Referenced by PLUGINS_GRID_TRICKS::doPopupSelection(), HandlePythonInterpreterChanged(), processPluginDependencies(), and recreateCancelledPlugin().
| void API_PLUGIN_MANAGER::ReloadPlugins | ( | std::optional< wxString > | aDirectoryToScan = std::nullopt, |
| std::shared_ptr< REPORTER > | aReporter = nullptr ) |
Clears the loaded plugins and actions and re-scans the filesystem to register new ones.
| aDirectoryToScan | can be provided to scan an arbitrary directory instead of the stock paths; provided for QA testing. |
| aReporter | is a REPORTER object to write status information to. |
Definition at line 209 of file api_plugin_manager.cpp.
References Busy(), EDA_EVT_PLUGIN_AVAILABILITY_CHANGED, PATHS::GetDefault3rdPartyPath(), PGM_BASE::GetLocalEnvVariables(), PATHS::GetStockPluginsPath(), PATHS::GetUserPluginsPath(), ENV_VAR::GetVersionedEnvVarValue(), m_actionsCache, m_buttonBindings, m_environmentCache, m_menuBindings, m_parent, m_plugins, m_pluginsCache, m_readyPlugins, m_reloadReporter, m_schema_validator, Pgm(), processPluginDependencies(), reportPluginLoadMessage(), and traceApi.
Referenced by BOOST_AUTO_TEST_CASE(), EDA_BASE_FRAME::CommonSettingsChanged(), PANEL_PCBNEW_ACTION_PLUGINS::OnReloadButtonClick(), and COMMON_CONTROL::ReloadPlugins().
|
private |
Definition at line 120 of file api_plugin_manager.h.
Referenced by doInvokeAction(), GetAction(), GetActionsForScope(), and ReloadPlugins().
|
private |
Definition at line 133 of file api_plugin_manager.h.
Referenced by Busy(), HandlePythonInterpreterChanged(), processNextJob(), processPluginDependencies(), and recreateCancelledPlugin().
|
private |
Map of button wx item id to action identifier, per frame.
Definition at line 126 of file api_plugin_manager.h.
Referenced by ButtonBindings(), and ReloadPlugins().
|
private |
Plugins whose setup jobs were cancelled and need their environment recreated.
Definition at line 146 of file api_plugin_manager.h.
Referenced by cancelPluginJobs(), processNextJob(), and recreateCancelledPlugin().
|
private |
Map of plugin identifier to a path for the plugin's virtual environment, if it has one.
Definition at line 123 of file api_plugin_manager.h.
Referenced by processPluginDependencies(), and ReloadPlugins().
|
private |
Definition at line 156 of file api_plugin_manager.h.
Referenced by Busy(), cancelPluginJobs(), processNextJob(), processPluginDependencies(), and RecreatePluginEnvironment().
|
private |
Definition at line 162 of file api_plugin_manager.h.
Referenced by API_PLUGIN_MANAGER(), and doInvokeAction().
|
private |
Map of menu wx item id to action identifier, per frame.
Definition at line 129 of file api_plugin_manager.h.
Referenced by MenuBindings(), and ReloadPlugins().
|
private |
Definition at line 114 of file api_plugin_manager.h.
Referenced by API_PLUGIN_MANAGER(), and ReloadPlugins().
|
private |
Definition at line 116 of file api_plugin_manager.h.
Referenced by HandlePythonInterpreterChanged(), processPluginDependencies(), and ReloadPlugins().
|
private |
Definition at line 118 of file api_plugin_manager.h.
Referenced by pluginName(), RecreatePluginEnvironment(), and ReloadPlugins().
|
private |
Definition at line 163 of file api_plugin_manager.h.
Referenced by API_PLUGIN_MANAGER(), and doInvokeAction().
|
private |
Definition at line 131 of file api_plugin_manager.h.
Referenced by doInvokeAction(), GetActionsForScope(), HandlePythonInterpreterChanged(), processNextJob(), processPluginDependencies(), and ReloadPlugins().
|
private |
Definition at line 160 of file api_plugin_manager.h.
Referenced by GetReporter(), processNextJob(), and ReloadPlugins().
|
private |
Map of plugin identifier to the pid of its currently-running setup process, if any.
Definition at line 143 of file api_plugin_manager.h.
Referenced by cancelPluginJobs(), and processNextJob().
|
private |
Definition at line 158 of file api_plugin_manager.h.
Referenced by API_PLUGIN_MANAGER(), and ReloadPlugins().