KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcm_task_manager.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) 2021 Andrew Lutsenko, anlutsenko at gmail dot com
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef PCM_TASK_MANAGER_H_
22#define PCM_TASK_MANAGER_H_
23
25#include "pcm.h"
26#include "pcm_data.h"
27#include <core/sync_queue.h>
28#include <atomic>
29#include <condition_variable>
30#include <functional>
31#include <memory>
32#include <mutex>
33#include <nlohmann/json-schema.hpp>
35#include <wx/regex.h>
36#include <wx/string.h>
37
38
48{
49public:
50 enum class STATUS
51 {
52 FAILED = -1,
55 };
56
57 typedef std::function<STATUS()> PCM_TASK;
58
59 PCM_TASK_MANAGER( std::shared_ptr<PLUGIN_CONTENT_MANAGER> pcm ) : m_pcm( pcm ){};
60
79 PCM_TASK_MANAGER::STATUS DownloadAndInstall( const PCM_PACKAGE& aPackage, const wxString& aVersion,
80 const wxString& aRepositoryId, const bool isUpdate );
81
93
105 void RunQueue( wxWindow* aParent );
106
118 PCM_TASK_MANAGER::STATUS InstallFromFile( wxWindow* aParent, const wxString& aFilePath );
119
123 std::unordered_set<PCM_PACKAGE_TYPE>& GetChangedPackageTypes()
124 {
126 };
127
128private:
136 int downloadFile( const wxString& aFilePath, const wxString& aUrl );
137
149 const wxString& aVersion,
150 const wxString& aRepositoryId,
151 const wxFileName& aFilePath,
152 const bool isUpdate );
153
162 bool extract( const wxString& aFilePath, const wxString& aPackageId, bool isMultiThreaded );
163
170 void deletePackageDirectories( const wxString& aPackageId,
171 const std::forward_list<wxRegEx>& aKeep = {} );
172
173 std::unique_ptr<DIALOG_PCM_PROGRESS> m_reporter;
176 std::shared_ptr<PLUGIN_CONTENT_MANAGER> m_pcm;
178 std::unordered_set<PCM_PACKAGE_TYPE> m_changed_package_types;
179};
180
181
182#endif // PCM_TASK_MANAGER_H_
void deletePackageDirectories(const wxString &aPackageId, const std::forward_list< wxRegEx > &aKeep={})
Delete all package files.
SYNC_QUEUE< PCM_TASK > m_install_queue
std::shared_ptr< PLUGIN_CONTENT_MANAGER > m_pcm
SYNC_QUEUE< PCM_TASK > m_download_queue
std::function< STATUS()> PCM_TASK
std::unordered_set< PCM_PACKAGE_TYPE > & GetChangedPackageTypes()
int downloadFile(const wxString &aFilePath, const wxString &aUrl)
Download URL to a file.
PCM_TASK_MANAGER::STATUS DownloadAndInstall(const PCM_PACKAGE &aPackage, const wxString &aVersion, const wxString &aRepositoryId, const bool isUpdate)
Enqueue package download and installation.
bool extract(const wxString &aFilePath, const wxString &aPackageId, bool isMultiThreaded)
Extract package archive.
void RunQueue(wxWindow *aParent)
Run queue of pending actions.
PCM_TASK_MANAGER(std::shared_ptr< PLUGIN_CONTENT_MANAGER > pcm)
std::mutex m_changed_package_types_guard
PCM_TASK_MANAGER::STATUS installDownloadedPackage(const PCM_PACKAGE &aPackage, const wxString &aVersion, const wxString &aRepositoryId, const wxFileName &aFilePath, const bool isUpdate)
Installs downloaded package archive.
std::unique_ptr< DIALOG_PCM_PROGRESS > m_reporter
PCM_TASK_MANAGER::STATUS Uninstall(const PCM_PACKAGE &aPackage)
Enqueue package uninstallation.
PCM_TASK_MANAGER::STATUS InstallFromFile(wxWindow *aParent, const wxString &aFilePath)
Installs package from an archive file on disk.
std::unordered_set< PCM_PACKAGE_TYPE > m_changed_package_types
Synchronized, locking queue.
Definition sync_queue.h:32
Package metadata.
Definition pcm_data.h:114