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 The 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 const 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
63 void SetCurrentProgress( double aProgress ) override;
64
65private:
66 bool updateUI() override;
67
69 std::shared_ptr<BACKGROUND_JOB> m_job;
70 wxString m_title;
71 wxString m_report;
72};
73
74
76{
77public:
78 wxString m_name;
79 wxString m_status;
80 std::shared_ptr<BACKGROUND_JOB_REPORTER> m_reporter;
81
84};
85
86
88{
90 friend class BACKGROUND_JOB_LIST;
91
92public:
94
100 std::shared_ptr<BACKGROUND_JOB> Create( const wxString& aName );
101
105 void Remove( std::shared_ptr<BACKGROUND_JOB> job );
106
110 void ShowList( wxWindow* aParent, wxPoint aPos );
111
115 void RegisterStatusBar( KISTATUSBAR* aStatusBar );
116
120 void UnregisterStatusBar( KISTATUSBAR* aStatusBar );
121
122private:
126 void onListWindowClosed( wxCloseEvent& aEvent );
127
131 void jobUpdated( std::shared_ptr<BACKGROUND_JOB> aJob );
132
138 std::vector<std::shared_ptr<BACKGROUND_JOB>> m_jobs;
139 std::vector<BACKGROUND_JOB_LIST*> m_shownDialogs;
140
141 std::vector<KISTATUSBAR*> m_statusBars;
142
144 mutable std::shared_mutex m_mutex;
145};
146
147#endif
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.
std::shared_ptr< BACKGROUND_JOB > m_job
BACKGROUND_JOBS_MONITOR * m_monitor
BACKGROUND_JOB_REPORTER(BACKGROUND_JOBS_MONITOR *aMonitor, const std::shared_ptr< BACKGROUND_JOB > &aJob)
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:46
virtual bool updateUI()=0
virtual void AdvancePhase() override
Use the next available virtual zone of the dialog progress bar.
virtual void SetCurrentProgress(double aProgress) override
Set the progress value to aProgress (0..1).
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