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 (C) 2024 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>
28#include <kicommon.h>
29
31wxDECLARE_EVENT( EDA_EVT_PLUGIN_MANAGER_JOB_FINISHED, wxCommandEvent );
32
34extern const KICOMMON_API wxEventTypeTag<wxCommandEvent> EDA_EVT_PLUGIN_AVAILABILITY_CHANGED;
35
40class KICOMMON_API API_PLUGIN_MANAGER : public wxEvtHandler
41{
42public:
43 API_PLUGIN_MANAGER( wxEvtHandler* aParent );
44
45 void ReloadPlugins();
46
47 void RecreatePluginEnvironment( const wxString& aIdentifier );
48
49 void InvokeAction( const wxString& aIdentifier );
50
51 std::optional<const PLUGIN_ACTION*> GetAction( const wxString& aIdentifier );
52
53 std::vector<const PLUGIN_ACTION*> GetActionsForScope( PLUGIN_ACTION_SCOPE aScope );
54
55 std::map<int, wxString>& ButtonBindings() { return m_buttonBindings; }
56
57 std::map<int, wxString>& MenuBindings() { return m_menuBindings; }
58
59private:
60 void processPluginDependencies();
61
62 void processNextJob( wxCommandEvent& aEvent );
63
64 wxEvtHandler* m_parent;
65
66 std::set<std::unique_ptr<API_PLUGIN>, CompareApiPluginIdentifiers> m_plugins;
67
68 std::map<wxString, const API_PLUGIN*> m_pluginsCache;
69
70 std::map<wxString, const PLUGIN_ACTION*> m_actionsCache;
71
73 std::map<wxString, wxString> m_environmentCache;
74
76 std::map<int, wxString> m_buttonBindings;
77
79 std::map<int, wxString> m_menuBindings;
80
81 std::set<wxString> m_readyPlugins;
82
83 std::set<wxString> m_busyPlugins;
84
85 enum class JOB_TYPE
86 {
87 CREATE_ENV,
88 SETUP_ENV,
89 INSTALL_REQUIREMENTS
90 };
91
92 struct JOB
93 {
95 wxString identifier;
96 wxString plugin_path;
97 wxString env_path;
98 };
99
100 std::deque<JOB> m_jobs;
101};
PLUGIN_ACTION_SCOPE
Definition: api_plugin.h:55
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::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:137