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
29#include <functional>
30#include <memory>
31#include <shared_mutex>
32#include <vector>
33
35class wxString;
36class KISTATUSBAR;
37struct BACKGROUND_JOB;
41class wxWindow;
42class wxCloseEvent;
43
45{
46public:
48 std::shared_ptr<BACKGROUND_JOB> aJob );
49
50 void SetTitle( const wxString& aTitle ) override
51 {
52 }
53
54 void Report( const wxString& aMessage ) override;
55
56 void Cancel() { m_cancelled.store( true ); }
57
58 void AdvancePhase() override;
59
60 void SetNumPhases( int aNumPhases ) override;
61
62private:
63 bool updateUI() override;
64
66 std::shared_ptr<BACKGROUND_JOB> m_job;
67 wxString m_title;
68 wxString m_report;
69};
70
71
73{
74public:
75 wxString m_name;
76 wxString m_status;
77 std::shared_ptr<BACKGROUND_JOB_REPORTER> m_reporter;
78
81};
82
83
85{
87 friend class BACKGROUND_JOB_LIST;
88
89public:
91
97 std::shared_ptr<BACKGROUND_JOB> Create( const wxString& aName );
98
102 void Remove( std::shared_ptr<BACKGROUND_JOB> job );
103
107 void ShowList( wxWindow* aParent, wxPoint aPos );
108
112 void RegisterStatusBar( KISTATUSBAR* aStatusBar );
113
117 void UnregisterStatusBar( KISTATUSBAR* aStatusBar );
118
119private:
123 void onListWindowClosed( wxCloseEvent& aEvent );
124
128 void jobUpdated( std::shared_ptr<BACKGROUND_JOB> aJob );
129
131
137 std::vector<std::shared_ptr<BACKGROUND_JOB>> m_jobs;
138 std::vector<BACKGROUND_JOB_LIST*> m_shownDialogs;
139
140 std::vector<KISTATUSBAR*> m_statusBars;
141
143 mutable std::shared_mutex m_mutex;
144};
145
146#endif
BACKGROUND_JOB_LIST * m_jobListDialog
void UnregisterStatusBar(KISTATUSBAR *aStatusBar)
Removes status bar from handling.
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...
void ShowList(wxWindow *aParent, wxPoint aPos)
Shows the background job list.
std::shared_mutex m_mutex
Mutex to protect access to the m_jobs vector.
std::shared_ptr< BACKGROUND_JOB > Create(const wxString &aName)
Creates a background job with the given name.
void jobUpdated(std::shared_ptr< BACKGROUND_JOB > aJob)
Handles job status updates, intended to be called by BACKGROUND_JOB_REPORTER only.
void Remove(std::shared_ptr< BACKGROUND_JOB > job)
Removes the given background job from any lists and frees it.
void onListWindowClosed(wxCloseEvent &aEvent)
Handles removing the shown list window from our list of shown windows.
std::vector< KISTATUSBAR * > m_statusBars
std::vector< BACKGROUND_JOB_LIST * > m_shownDialogs
void RegisterStatusBar(KISTATUSBAR *aStatusBar)
Add a status bar for handling.
void SetNumPhases(int aNumPhases) override
Set the number of phases.
void AdvancePhase() override
Use the next available virtual zone of the dialog progress bar.
std::shared_ptr< BACKGROUND_JOB > m_job
void Report(const wxString &aMessage) override
Display aMessage in the progress bar dialog.
BACKGROUND_JOBS_MONITOR * m_monitor
void SetTitle(const wxString &aTitle) override
Change the title displayed on the window caption.
This implements all the tricky bits for thread safety, but the GUI is left to derived classes.
A progress reporter interface for use in multi-threaded environments.
std::shared_ptr< BACKGROUND_JOB_REPORTER > m_reporter