KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 <jon@craftyjon.com>
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
48 void ReloadPlugins();
49
50 void RecreatePluginEnvironment( const wxString& aIdentifier );
51
52 void InvokeAction( const wxString& aIdentifier );
53
54 std::optional<const PLUGIN_ACTION*> GetAction( const wxString& aIdentifier );
55
56 std::vector<const PLUGIN_ACTION*> GetActionsForScope( PLUGIN_ACTION_SCOPE aScope );
57
58 std::map<int, wxString>& ButtonBindings() { return m_buttonBindings; }
59
60 std::map<int, wxString>& MenuBindings() { return m_menuBindings; }
61
62private:
63 void processPluginDependencies();
64
65 void processNextJob( wxCommandEvent& aEvent );
66
67 wxEvtHandler* m_parent;
68
69 std::set<std::unique_ptr<API_PLUGIN>, CompareApiPluginIdentifiers> m_plugins;
70
71 std::map<wxString, const API_PLUGIN*> m_pluginsCache;
72
73 std::map<wxString, const PLUGIN_ACTION*> m_actionsCache;
74
76 std::map<wxString, wxString> m_environmentCache;
77
79 std::map<int, wxString> m_buttonBindings;
80
82 std::map<int, wxString> m_menuBindings;
83
84 std::set<wxString> m_readyPlugins;
85
86 std::set<wxString> m_busyPlugins;
87
88 enum class JOB_TYPE
89 {
90 CREATE_ENV,
91 SETUP_ENV,
92 INSTALL_REQUIREMENTS
93 };
94
95 struct JOB
96 {
98 wxString identifier;
99 wxString plugin_path;
100 wxString env_path;
101 };
102
103 std::deque<JOB> m_jobs;
104
105 std::unique_ptr<JSON_SCHEMA_VALIDATOR> m_schema_validator;
106
108 wxTimer* m_raiseTimer;
109};
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