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
32wxDECLARE_EVENT( EDA_EVT_PLUGIN_MANAGER_JOB_FINISHED, wxCommandEvent );
33
35extern const KICOMMON_API wxEventTypeTag<wxCommandEvent> EDA_EVT_PLUGIN_AVAILABILITY_CHANGED;
36
41class KICOMMON_API API_PLUGIN_MANAGER : public wxEvtHandler
42{
43public:
44 API_PLUGIN_MANAGER( wxEvtHandler* aParent );
45
46 void ReloadPlugins();
47
48 void RecreatePluginEnvironment( const wxString& aIdentifier );
49
50 void InvokeAction( const wxString& aIdentifier );
51
52 std::optional<const PLUGIN_ACTION*> GetAction( const wxString& aIdentifier );
53
54 std::vector<const PLUGIN_ACTION*> GetActionsForScope( PLUGIN_ACTION_SCOPE aScope );
55
56 std::map<int, wxString>& ButtonBindings() { return m_buttonBindings; }
57
58 std::map<int, wxString>& MenuBindings() { return m_menuBindings; }
59
60private:
61 void processPluginDependencies();
62
63 void processNextJob( wxCommandEvent& aEvent );
64
65 wxEvtHandler* m_parent;
66
67 std::set<std::unique_ptr<API_PLUGIN>, CompareApiPluginIdentifiers> m_plugins;
68
69 std::map<wxString, const API_PLUGIN*> m_pluginsCache;
70
71 std::map<wxString, const PLUGIN_ACTION*> m_actionsCache;
72
74 std::map<wxString, wxString> m_environmentCache;
75
77 std::map<int, wxString> m_buttonBindings;
78
80 std::map<int, wxString> m_menuBindings;
81
82 std::set<wxString> m_readyPlugins;
83
84 std::set<wxString> m_busyPlugins;
85
86 enum class JOB_TYPE
87 {
88 CREATE_ENV,
89 SETUP_ENV,
90 INSTALL_REQUIREMENTS
91 };
92
93 struct JOB
94 {
96 wxString identifier;
97 wxString plugin_path;
98 wxString env_path;
99 };
100
101 std::deque<JOB> m_jobs;
102
103 std::unique_ptr<JSON_SCHEMA_VALIDATOR> m_schema_validator;
104};
PLUGIN_ACTION_SCOPE
Definition: api_plugin.h:56
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.
Responsible for loading plugin definitions for API-based plugins (ones that do not run inside KiCad i...
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.
std::unique_ptr< JSON_SCHEMA_VALIDATOR > m_schema_validator
std::deque< JOB > m_jobs
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.
std::map< wxString, const API_PLUGIN * > m_pluginsCache
std::set< wxString > m_readyPlugins
std::map< wxString, const PLUGIN_ACTION * > m_actionsCache
std::set< wxString > m_busyPlugins
wxEvtHandler * m_parent
#define KICOMMON_API
Definition: kicommon.h:28
Comparison functor for ensuring API_PLUGINs have unique identifiers.
Definition: api_plugin.h:140