OpenCPN Partial API docs
Loading...
Searching...
No Matches
plugin_handler.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2019 - 2025 Alec Leamas *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
19
25#ifndef PLUGIN_HANDLER_H__
26#define PLUGIN_HANDLER_H__
27
28#include "config.h"
29
30#include <map>
31#include <memory>
32#include <string>
33#include <unordered_map>
34#include <vector>
35
36#include <wx/cmdline.h>
37
38#include <archive.h>
39
41#include "observable_evtvar.h"
42
43bool isRegularFile(const char* path);
44
46class CompatOs {
47public:
48 static CompatOs* GetInstance();
49 std::string name() const { return _name; }
50 std::string version() const { return _version; }
51
52private:
53 CompatOs();
54 std::string _name;
55 std::string _version;
56};
57
88public:
90 static PluginHandler* GetInstance();
91
92 PluginHandler(const PluginHandler&) = delete;
93 PluginHandler& operator=(const PluginHandler&) = delete;
94
100
103
105 static void Cleanup(const std::string& filelist, const std::string& plugname);
106
107 static void CleanupFiles(const std::string& manifestFile,
108 const std::string& plugname);
109
111 static std::string PluginsInstallDataPath();
112
114 static std::string FileListPath(std::string name);
115
117 static std::string VersionPath(std::string name);
118
120 static std::string ImportedMetadataPath(std::string name);
121
123 static std::vector<std::string> GetImportPaths();
124
126 static bool IsCompatible(const PluginMetadata& metadata,
127 const char* os = PKG_TARGET,
128 const char* os_version = PKG_TARGET_VERSION);
129
131 bool IsPluginWritable(std::string name);
132
134 const std::vector<PluginMetadata> GetInstalled();
135
140 std::vector<std::string> GetInstalldataPlugins();
141
143 void SetInstalledMetadata(const PluginMetadata& pm);
144
146 const std::vector<PluginMetadata> GetAvailable();
147
152 std::vector<PluginMetadata> getCompatiblePlugins();
153
155 const std::map<std::string, int> GetCountByTarget();
156
158 std::string GetPluginByLibrary(const std::string& filename);
159
161 std::string GetMetadataPath();
162
164 void setMetadata(std::string path) { metadataPath = path; }
165
167 bool InstallPlugin(PluginMetadata plugin);
168
170 bool InstallPlugin(PluginMetadata plugin, std::string path);
171
173 bool ExtractMetadata(const std::string& path, PluginMetadata& metadata);
174
175 /* Install a new, downloaded but not installed plugin tarball. */
176 bool InstallPlugin(const std::string& path);
177
179 bool Uninstall(const std::string plugin);
180
182 bool ClearInstallData(const std::string plugin_name);
183
186
187 CatalogData* GetCatalogData() { return &catalogData; }
188
189protected:
191
192private:
193 std::string metadataPath;
194 std::vector<PluginMetadata> installed;
195 CatalogData catalogData;
196 std::string last_error_msg;
197 bool InstallPlugin(const std::string& path, std::string& filelist,
198 const std::string metadata_path, bool only_metadata);
199
213 bool ExplodeTarball(struct archive* src, struct archive* dest,
214 std::string& filelist, const std::string& metadata_path,
215 bool only_metadata);
228 bool ExtractTarball(const std::string path, std::string& filelist,
229 const std::string metadata_path = "",
230 bool only_metadata = false);
231 bool ArchiveCheck(int r, const char* msg, struct archive* a);
232
233 std::unordered_map<std::string, std::vector<std::string>> FilesByPlugin;
234
235 bool DoClearInstallData(const std::string plugin_name);
236};
237
238#endif // PLUGIN_HANDLER_H__
Datatypes and methods to parse ocpn-plugins.xml XML data, either complete catalog or a single plugin.
Internal helper wrapping host OS and version.
Generic event handling between MVC Model and Controller based on a shared EventVar variable.
Handle plugin install from remote repositories and local operations to Uninstall and list plugins.
void setMetadata(std::string path)
Set path to metadata XML file.
static std::vector< std::string > GetImportPaths()
List of paths for imported plugins metadata.
bool Uninstall(const std::string plugin)
Uninstall an installed and loaded plugin.
const std::vector< PluginMetadata > GetInstalled()
Return list of all installed and loaded plugins.
const std::map< std::string, int > GetCountByTarget()
Map of available plugin targets -> number of occurences.
static void Cleanup(const std::string &filelist, const std::string &plugname)
Cleanup failed installation attempt using filelist for plugin.
bool IsPluginWritable(std::string name)
Check if given plugin can be installed/updated.
std::vector< PluginMetadata > getCompatiblePlugins()
Return list of available, unique and compatible plugins from configured XML catalog.
static std::string ImportedMetadataPath(std::string name)
Return path to imported metadata for given plugin.
static std::string VersionPath(std::string name)
Return path to file containing version for given plugin.
std::string GetMetadataPath()
Return path to metadata XML file.
std::vector< std::string > GetInstalldataPlugins()
Return list of installed plugins lower case names, not necessarily loaded.
bool InstallPlugin(PluginMetadata plugin)
Download and install a new, not installed plugin.
const std::vector< PluginMetadata > GetAvailable()
Update catalog and return list of available, not installed plugins.
bool ClearInstallData(const std::string plugin_name)
Remove installation data for not loaded plugin.
static bool IsCompatible(const PluginMetadata &metadata, const char *os=PKG_TARGET, const char *os_version=PKG_TARGET_VERSION)
Return true if given plugin is loadable on given os/version.
static std::string FileListPath(std::string name)
Return path to installation manifest for given plugin.
EventVar evt_download_failed
Notified with plugin name after failed download attempt.
void SetInstalledMetadata(const PluginMetadata &pm)
Set metadata for an installed plugin.
bool ExtractMetadata(const std::string &path, PluginMetadata &metadata)
Extract metadata in given tarball path.
bool InstallPluginFromCache(PluginMetadata plugin)
Install plugin tarball from local cache.
std::string GetPluginByLibrary(const std::string &filename)
Return plugin containing given filename or "" if not found.
static PluginHandler * GetInstance()
Singleton factory.
static std::string PluginsInstallDataPath()
Return base directory for installation data.
EventVar evt_download_ok
Notified with plugin name + version string after successful download from repository.
Overall metadata for the set of plugins used.
Plugin metadata, reflects the xml format directly.