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 (C) 1992-2021 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 along
18 * with this program. If not, see <http://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,
53 INITIALIZED = 0,
54 SUCCESS = 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
78 PCM_TASK_MANAGER::STATUS DownloadAndInstall( const PCM_PACKAGE& aPackage, const wxString& aVersion,
79 const wxString& aRepositoryId, const bool isUpdate );
80
92
104 void RunQueue( wxWindow* aParent );
105
117 PCM_TASK_MANAGER::STATUS InstallFromFile( wxWindow* aParent, const wxString& aFilePath );
118
122 std::unordered_set<PCM_PACKAGE_TYPE>& GetChangedPackageTypes()
123 {
125 };
126
127private:
135 int downloadFile( const wxString& aFilePath, const wxString& aUrl );
136
148 const wxString& aVersion,
149 const wxString& aRepositoryId,
150 const wxFileName& aFilePath,
151 const bool isUpdate );
152
161 bool extract( const wxString& aFilePath, const wxString& aPackageId, bool isMultiThreaded );
162
169 void deletePackageDirectories( const wxString& aPackageId,
170 const std::forward_list<wxRegEx>& aKeep = {} );
171
172 std::unique_ptr<DIALOG_PCM_PROGRESS> m_reporter;
175 std::shared_ptr<PLUGIN_CONTENT_MANAGER> m_pcm;
177 std::unordered_set<PCM_PACKAGE_TYPE> m_changed_package_types;
178};
179
180
181#endif // PCM_TASK_MANAGER_H_
Helper class that handles package (un)installation.
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
Repository reference to a resource.
Definition: pcm_data.h:105