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 REPORTER;
32class wxTimer;
33
35wxDECLARE_EVENT( EDA_EVT_PLUGIN_MANAGER_JOB_FINISHED, wxCommandEvent );
36
38extern const KICOMMON_API wxEventTypeTag<wxCommandEvent> EDA_EVT_PLUGIN_AVAILABILITY_CHANGED;
39
44class KICOMMON_API API_PLUGIN_MANAGER : public wxEvtHandler
45{
46public:
47 API_PLUGIN_MANAGER( wxEvtHandler* aParent );
48
54 void ReloadPlugins( std::optional<wxString> aDirectoryToScan = std::nullopt,
55 std::shared_ptr<REPORTER> aReporter = nullptr );
56
57 void RecreatePluginEnvironment( const wxString& aIdentifier );
58
59 void InvokeAction( const wxString& aIdentifier,
60 std::shared_ptr<REPORTER> aReporter = nullptr );
61
72 int InvokeActionSync( const wxString& aIdentifier, std::vector<wxString> aExtraArgs,
73 wxString* aStdout = nullptr, wxString* aStderr = nullptr,
74 std::shared_ptr<REPORTER> aReporter = nullptr );
75
76 bool Busy() const;
77
78 std::optional<const PLUGIN_ACTION*> GetAction( const wxString& aIdentifier );
79
80 std::vector<const PLUGIN_ACTION*> GetActionsForScope( PLUGIN_ACTION_SCOPE aScope );
81
82 std::map<int, wxString>& ButtonBindings() { return m_buttonBindings; }
83
84 std::map<int, wxString>& MenuBindings() { return m_menuBindings; }
85
86 std::shared_ptr<REPORTER> GetReporter() { return m_reloadReporter; }
87
88private:
89 void processPluginDependencies();
90
91 void processNextJob( wxCommandEvent& aEvent );
92
93 int doInvokeAction( const wxString& aIdentifier, std::vector<wxString> aExtraArgs,
94 bool aSync = false, wxString* aStdout = nullptr,
95 wxString* aStderr = nullptr,
96 std::shared_ptr<REPORTER> aReporter = nullptr );
97
98 wxEvtHandler* m_parent;
99
100 std::set<std::unique_ptr<API_PLUGIN>, CompareApiPluginIdentifiers> m_plugins;
101
102 std::map<wxString, const API_PLUGIN*> m_pluginsCache;
103
104 std::map<wxString, const PLUGIN_ACTION*> m_actionsCache;
105
107 std::map<wxString, wxString> m_environmentCache;
108
110 std::map<int, wxString> m_buttonBindings;
111
113 std::map<int, wxString> m_menuBindings;
114
115 std::set<wxString> m_readyPlugins;
116
117 std::set<wxString> m_busyPlugins;
118
125
126 struct JOB
127 {
129 wxString identifier;
130 wxString plugin_path;
131 wxString env_path;
132 };
133
134 std::deque<JOB> m_jobs;
135
136 std::unique_ptr<JSON_SCHEMA_VALIDATOR> m_schema_validator;
137
138 std::shared_ptr<REPORTER> m_reloadReporter;
139
140 [[maybe_unused]] long m_lastPid;
141 [[maybe_unused]] wxTimer* m_raiseTimer;
142};
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()
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.
std::map< int, wxString > & ButtonBindings()
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.
std::map< wxString, wxString > m_environmentCache
Map of plugin identifier to a path for the plugin's virtual environment, if it has one.
std::shared_ptr< REPORTER > m_reloadReporter
void InvokeAction(const wxString &aIdentifier, std::shared_ptr< REPORTER > aReporter=nullptr)
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::shared_ptr< REPORTER > GetReporter()
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
std::map< wxString, const PLUGIN_ACTION * > m_actionsCache
API_PLUGIN_MANAGER(wxEvtHandler *aParent)
std::set< wxString > m_busyPlugins
wxEvtHandler * m_parent
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:75
#define KICOMMON_API
Definition kicommon.h:27
PLUGIN_ACTION_SCOPE
Comparison functor for ensuring API_PLUGINs have unique identifiers.
Definition api_plugin.h:132