File: api_plugin_manager.h

package info (click to toggle)
kicad 9.0.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 771,448 kB
  • sloc: cpp: 969,355; ansic: 121,001; xml: 66,428; python: 18,387; sh: 1,010; awk: 301; asm: 292; makefile: 228; javascript: 167; perl: 10
file content (109 lines) | stat: -rw-r--r-- 3,235 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2024 Jon Evans <jon@craftyjon.com>
 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <deque>
#include <memory>
#include <set>

#include <wx/event.h>

#include <api/api_plugin.h>
#include <json_schema_validator.h>
#include <kicommon.h>

class wxTimer;

/// Internal event used for handling async tasks
wxDECLARE_EVENT( EDA_EVT_PLUGIN_MANAGER_JOB_FINISHED, wxCommandEvent );

/// Notifies other parts of KiCad when plugin availability changes
extern const KICOMMON_API wxEventTypeTag<wxCommandEvent> EDA_EVT_PLUGIN_AVAILABILITY_CHANGED;

/**
 * Responsible for loading plugin definitions for API-based plugins (ones that do not run inside
 * KiCad itself, but instead are launched as external processes by KiCad)
 */
class KICOMMON_API API_PLUGIN_MANAGER : public wxEvtHandler
{
public:
    API_PLUGIN_MANAGER( wxEvtHandler* aParent );

    void ReloadPlugins();

    void RecreatePluginEnvironment( const wxString& aIdentifier );

    void InvokeAction( const wxString& aIdentifier );

    std::optional<const PLUGIN_ACTION*> GetAction( const wxString& aIdentifier );

    std::vector<const PLUGIN_ACTION*> GetActionsForScope( PLUGIN_ACTION_SCOPE aScope );

    std::map<int, wxString>& ButtonBindings() { return m_buttonBindings; }

    std::map<int, wxString>& MenuBindings() { return m_menuBindings; }

private:
    void processPluginDependencies();

    void processNextJob( wxCommandEvent& aEvent );

    wxEvtHandler* m_parent;

    std::set<std::unique_ptr<API_PLUGIN>, CompareApiPluginIdentifiers> m_plugins;

    std::map<wxString, const API_PLUGIN*> m_pluginsCache;

    std::map<wxString, const PLUGIN_ACTION*> m_actionsCache;

    /// Map of plugin identifier to a path for the plugin's virtual environment, if it has one
    std::map<wxString, wxString> m_environmentCache;

    /// Map of button wx item id to action identifier
    std::map<int, wxString> m_buttonBindings;

    /// Map of menu wx item id to action identifier
    std::map<int, wxString> m_menuBindings;

    std::set<wxString> m_readyPlugins;

    std::set<wxString> m_busyPlugins;

    enum class JOB_TYPE
    {
        CREATE_ENV,
        SETUP_ENV,
        INSTALL_REQUIREMENTS
    };

    struct JOB
    {
        JOB_TYPE type;
        wxString identifier;
        wxString plugin_path;
        wxString env_path;
    };

    std::deque<JOB> m_jobs;

    std::unique_ptr<JSON_SCHEMA_VALIDATOR> m_schema_validator;

    long m_lastPid;
    wxTimer* m_raiseTimer;
};