KiCad PCB EDA Suite
Loading...
Searching...
No Matches
git_transfer_busy.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef GIT_TRANSFER_BUSY_H
21#define GIT_TRANSFER_BUSY_H
22
23#include <import_export.h>
24#include <core/observable.h>
25
26#include <cstdint>
27#include <functional>
28#include <map>
29#include <memory>
30
31#include <wx/string.h>
32
33class KIGIT_COMMON;
34
35
38{
39public:
40 virtual ~GIT_TRANSFER_WATCHER() = default;
41
42 virtual void OnGitTransfersChanged() = 0;
43};
44
45
52class APIEXPORT GIT_TRANSFER_BUSY : public UTIL::OBSERVABLE<GIT_TRANSFER_WATCHER>
53{
54public:
57 {
58 public:
59 HOLD() = default;
60 ~HOLD() { Release(); }
61
62 HOLD( const HOLD& ) = delete;
63 HOLD& operator=( const HOLD& ) = delete;
64
67 void Begin( const std::shared_ptr<KIGIT_COMMON>& aRepo, const wxString& aStatus,
68 std::function<void()> aCancel );
69
70 void Release();
71
72 private:
73 friend class GIT_TRANSFER_BUSY;
74
75 std::weak_ptr<KIGIT_COMMON> m_repo;
76 uint64_t m_id = 0;
77 };
78
80 bool IsBusy( const HOLD& aExcept ) const;
81
83 wxString Status( const HOLD& aExcept ) const;
84
86 bool CanCancel( const HOLD& aExcept ) const;
87
89 void CancelAll();
90
91private:
92 struct LIVE
93 {
94 wxString status;
95 std::function<void()> cancel;
96 };
97
99 std::map<uint64_t, LIVE> m_live;
100};
101
102#endif // GIT_TRANSFER_BUSY_H
One transfer's hold on its repository, released when reset, begun again or destroyed.
void Begin(const std::shared_ptr< KIGIT_COMMON > &aRepo, const wxString &aStatus, std::function< void()> aCancel)
Release any earlier hold, then hold aRepo busy for one transfer.
HOLD & operator=(const HOLD &)=delete
std::weak_ptr< KIGIT_COMMON > m_repo
HOLD(const HOLD &)=delete
The transfers running on one repository, so every window can show and cancel the others'.
wxString Status(const HOLD &aExcept) const
The status of the latest live transfer other than aExcept's, or empty when none is.
void CancelAll()
Call each live transfer's cancel once. They stay live until their owners end them.
bool CanCancel(const HOLD &aExcept) const
True while a live transfer other than aExcept's has a cancel that has not been called.
std::map< uint64_t, LIVE > m_live
Keyed by an id that only grows, so the last entry is the latest transfer.
bool IsBusy(const HOLD &aExcept) const
True while a transfer other than aExcept's is live.
Told whenever a transfer on the repository it subscribed to begins or ends.
virtual ~GIT_TRANSFER_WATCHER()=default
virtual void OnGitTransfersChanged()=0
The project's git session.
#define APIEXPORT
Macros which export functions from a DLL/DSO.
std::function< void()> cancel