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
37extern const KICOMMON_API wxChar* const traceApi;
38
40wxDECLARE_EVENT( EDA_EVT_PLUGIN_MANAGER_JOB_FINISHED, wxCommandEvent );
41
43extern const KICOMMON_API wxEventTypeTag<wxCommandEvent> EDA_EVT_PLUGIN_AVAILABILITY_CHANGED;
44
49class KICOMMON_API API_PLUGIN_MANAGER : public wxEvtHandler
50{
51public:
52 API_PLUGIN_MANAGER( wxEvtHandler* aParent );
53
54 void ReloadPlugins();
55
56 void InvokeAction( const wxString& aIdentifier );
57
58 std::vector<const PLUGIN_ACTION*> GetActionsForScope( PLUGIN_ACTION_SCOPE aScope );
59
60 std::map<int, wxString>& ButtonBindings() { return m_buttonBindings; }
61
62 std::map<int, wxString>& MenuBindings() { return m_menuBindings; }
63
64private:
65 void processPluginDependencies();
66
67 void processNextJob( wxCommandEvent& aEvent );
68
69 wxEvtHandler* m_parent;
70
71 std::set<std::unique_ptr<API_PLUGIN>, CompareApiPluginIdentifiers> m_plugins;
72
73 std::map<wxString, const API_PLUGIN*> m_pluginsCache;
74
75 std::map<wxString, const PLUGIN_ACTION*> m_actionsCache;
76
78 std::map<wxString, wxString> m_environmentCache;
79
81 std::map<int, wxString> m_buttonBindings;
82
84 std::map<int, wxString> m_menuBindings;
85
86 std::set<wxString> m_readyPlugins;
87
88 enum class JOB_TYPE
89 {
90 CREATE_ENV,
91 INSTALL_REQUIREMENTS
92 };
93
94 struct JOB
95 {
97 wxString identifier;
98 wxString plugin_path;
99 wxString env_path;
100 };
101
102 std::deque<JOB> m_jobs;
103};
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
wxEvtHandler * m_parent
const KICOMMON_API wxChar *const traceApi
Flag to enable debug output related to the API plugin system.
#define KICOMMON_API
Definition: kicommon.h:28
Comparison functor for ensuring API_PLUGINs have unique identifiers.
Definition: api_plugin.h:135