KiCad PCB EDA Suite
Loading...
Searching...
No Matches
api_plugin_manager.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2024 Jon Evans <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <deque>
22#include <memory>
23#include <set>
24
25#include <wx/event.h>
26
27#include <api/api_plugin.h>
29#include <kicommon.h>
30
31class wxTimer;
32
34wxDECLARE_EVENT( EDA_EVT_PLUGIN_MANAGER_JOB_FINISHED, wxCommandEvent );
35
37extern const KICOMMON_API wxEventTypeTag<wxCommandEvent> EDA_EVT_PLUGIN_AVAILABILITY_CHANGED;
38
43class KICOMMON_API API_PLUGIN_MANAGER : public wxEvtHandler
44{
45public:
46 API_PLUGIN_MANAGER( wxEvtHandler* aParent );
47
53 void ReloadPlugins( std::optional<wxString> aDirectoryToScan = std::nullopt );
54
55 void RecreatePluginEnvironment( const wxString& aIdentifier );
56
57 void InvokeAction( const wxString& aIdentifier );
58
69 int InvokeActionSync( const wxString& aIdentifier, std::vector<wxString> aExtraArgs,
70 wxString* aStdout = nullptr, wxString* aStderr = nullptr );
71
72 bool Busy() const;
73
74 std::optional<const PLUGIN_ACTION*> GetAction( const wxString& aIdentifier );
75
76 std::vector<const PLUGIN_ACTION*> GetActionsForScope( PLUGIN_ACTION_SCOPE aScope );
77
78 std::map<int, wxString>& ButtonBindings() { return m_buttonBindings; }
79
80 std::map<int, wxString>& MenuBindings() { return m_menuBindings; }
81
82private:
83 void processPluginDependencies();
84
85 void processNextJob( wxCommandEvent& aEvent );
86
87 int doInvokeAction( const wxString& aIdentifier, std::vector<wxString> aExtraArgs,
88 bool aSync = false, wxString* aStdout = nullptr,
89 wxString* aStderr = nullptr );
90
91 wxEvtHandler* m_parent;
92
93 std::set<std::unique_ptr<API_PLUGIN>, CompareApiPluginIdentifiers> m_plugins;
94
95 std::map<wxString, const API_PLUGIN*> m_pluginsCache;
96
97 std::map<wxString, const PLUGIN_ACTION*> m_actionsCache;
98
100 std::map<wxString, wxString> m_environmentCache;
101
103 std::map<int, wxString> m_buttonBindings;
104
106 std::map<int, wxString> m_menuBindings;
107
108 std::set<wxString> m_readyPlugins;
109
110 std::set<wxString> m_busyPlugins;
111
118
119 struct JOB
120 {
122 wxString identifier;
123 wxString plugin_path;
124 wxString env_path;
125 };
126
127 std::deque<JOB> m_jobs;
128
129 std::unique_ptr<JSON_SCHEMA_VALIDATOR> m_schema_validator;
130
131 [[maybe_unused]] long m_lastPid;
132 [[maybe_unused]] wxTimer* m_raiseTimer;
133};
wxDECLARE_EVENT(EDA_EVT_PLUGIN_MANAGER_JOB_FINISHED, wxCommandEvent)
Internal event used for handling async tasks.
const KICOMMON_API wxEventTypeTag< wxCommandEvent > EDA_EVT_PLUGIN_AVAILABILITY_CHANGED
Notifies other parts of KiCad when plugin availability changes.
std::set< std::unique_ptr< API_PLUGIN >, CompareApiPluginIdentifiers > m_plugins
std::map< int, wxString > & MenuBindings()
std::map< int, wxString > & ButtonBindings()
std::map< wxString, wxString > m_environmentCache
Map of plugin identifier to a path for the plugin's virtual environment, if it has one.
int InvokeActionSync(const wxString &aIdentifier, std::vector< wxString > aExtraArgs, wxString *aStdout=nullptr, wxString *aStderr=nullptr)
Invokes an action synchronously, capturing its output.
std::unique_ptr< JSON_SCHEMA_VALIDATOR > m_schema_validator
std::deque< JOB > m_jobs
std::vector< const PLUGIN_ACTION * > GetActionsForScope(PLUGIN_ACTION_SCOPE aScope)
std::map< int, wxString > m_menuBindings
Map of menu wx item id to action identifier.
std::map< int, wxString > m_buttonBindings
Map of button wx item id to action identifier.
void RecreatePluginEnvironment(const wxString &aIdentifier)
std::map< wxString, const API_PLUGIN * > m_pluginsCache
std::optional< const PLUGIN_ACTION * > GetAction(const wxString &aIdentifier)
std::set< wxString > m_readyPlugins
void ReloadPlugins(std::optional< wxString > aDirectoryToScan=std::nullopt)
Clears the loaded plugins and actions and re-scans the filesystem to register new ones.
std::map< wxString, const PLUGIN_ACTION * > m_actionsCache
void InvokeAction(const wxString &aIdentifier)
API_PLUGIN_MANAGER(wxEvtHandler *aParent)
std::set< wxString > m_busyPlugins
wxEvtHandler * m_parent
#define KICOMMON_API
Definition kicommon.h:27
PLUGIN_ACTION_SCOPE
Comparison functor for ensuring API_PLUGINs have unique identifiers.
Definition api_plugin.h:129