KiCad PCB EDA Suite
Loading...
Searching...
No Matches
background_jobs_monitor.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) 2023 Mark Roszko <[email protected]>
5 * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef BACKGROUND_JOBS_MONITOR_H
26#define BACKGROUND_JOBS_MONITOR_H
27
28#include <kicommon.h>
30#include <functional>
31#include <memory>
32#include <shared_mutex>
33#include <vector>
34
36class wxString;
37class KISTATUSBAR;
38struct BACKGROUND_JOB;
42class wxWindow;
43class wxCloseEvent;
44
46{
47public:
49 std::shared_ptr<BACKGROUND_JOB> aJob );
50
51 void SetTitle( const wxString& aTitle ) override
52 {
53 }
54
55 void Report( const wxString& aMessage ) override;
56
57 void Cancel() { m_cancelled.store( true ); }
58
59 void AdvancePhase() override;
60
61 void SetNumPhases( int aNumPhases ) override;
62
63private:
64 bool updateUI() override;
65
67 std::shared_ptr<BACKGROUND_JOB> m_job;
68 wxString m_title;
69 wxString m_report;
70};
71
72
74{
75public:
76 wxString m_name;
77 wxString m_status;
78 std::shared_ptr<BACKGROUND_JOB_REPORTER> m_reporter;
79
82};
83
84
86{
88 friend class BACKGROUND_JOB_LIST;
89
90public:
92
98 std::shared_ptr<BACKGROUND_JOB> Create( const wxString& aName );
99
103 void Remove( std::shared_ptr<BACKGROUND_JOB> job );
104
108 void ShowList( wxWindow* aParent, wxPoint aPos );
109
113 void RegisterStatusBar( KISTATUSBAR* aStatusBar );
114
118 void UnregisterStatusBar( KISTATUSBAR* aStatusBar );
119
120private:
124 void onListWindowClosed( wxCloseEvent& aEvent );
125
129 void jobUpdated( std::shared_ptr<BACKGROUND_JOB> aJob );
130
136 std::vector<std::shared_ptr<BACKGROUND_JOB>> m_jobs;
137 std::vector<BACKGROUND_JOB_LIST*> m_shownDialogs;
138
139 std::vector<KISTATUSBAR*> m_statusBars;
140
142 mutable std::shared_mutex m_mutex;
143};
144
145#endif
std::vector< std::shared_ptr< BACKGROUND_JOB > > m_jobs
Holds a reference to all active background jobs Access to this vector should be protected by locks si...
std::shared_mutex m_mutex
Mutex to protect access to the m_jobs vector.
std::vector< KISTATUSBAR * > m_statusBars
std::vector< BACKGROUND_JOB_LIST * > m_shownDialogs
std::shared_ptr< BACKGROUND_JOB > m_job
BACKGROUND_JOBS_MONITOR * m_monitor
void SetTitle(const wxString &aTitle) override
Change the title displayed on the window caption.
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
Definition: kistatusbar.h:45
This implements all the tricky bits for thread safety, but the GUI is left to derived classes.
virtual bool updateUI()=0
virtual void AdvancePhase() override
Use the next available virtual zone of the dialog progress bar.
virtual void Report(const wxString &aMessage) override
Display aMessage in the progress bar dialog.
void SetNumPhases(int aNumPhases) override
Set the number of phases.
A progress reporter interface for use in multi-threaded environments.
#define KICOMMON_API
Definition: kicommon.h:28
std::shared_ptr< BACKGROUND_JOB_REPORTER > m_reporter