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, see <https://www.gnu.org/licenses/>. *
16 ***************************************************************************/
17
24#ifndef PLUGIN_HANDLER_H__
25#define PLUGIN_HANDLER_H__
26
27#include "config.h"
28
29#include <map>
30#include <memory>
31#include <string>
32#include <unordered_map>
33#include <vector>
34
35#include <wx/cmdline.h>
36
37#include <archive.h>
38
40#include "observable_evtvar.h"
41
42bool isRegularFile(const char* path);
43
45class CompatOs {
46public:
47 static CompatOs* GetInstance();
48 std::string name() const { return _name; }
49 std::string version() const { return _version; }
50
51private:
52 CompatOs();
53 std::string _name;
54 std::string _version;
55};
56
87public:
89 static PluginHandler* GetInstance();
90
91 PluginHandler(const PluginHandler&) = delete;
92 PluginHandler& operator=(const PluginHandler&) = delete;
93
99
102
104 static void Cleanup(const std::string& filelist, const std::string& plugname);
105
106 static void CleanupFiles(const std::string& manifestFile,
107 const std::string& plugname);
108
110 static std::string PluginsInstallDataPath();
111
113 static std::string FileListPath(std::string name);
114
116 static std::string VersionPath(std::string name);
117
119 static std::string ImportedMetadataPath(std::string name);
120
122 static std::vector<std::string> GetImportPaths();
123
125 static bool IsCompatible(const PluginMetadata& metadata,
126 const char* os = PKG_TARGET,
127 const char* os_version = PKG_TARGET_VERSION);
128
130 bool IsPluginWritable(std::string name);
131
133 const std::vector<PluginMetadata> GetInstalled();
134
139 std::vector<std::string> GetInstalldataPlugins();
140
142 void SetInstalledMetadata(const PluginMetadata& pm);
143
145 const std::vector<PluginMetadata> GetAvailable();
146
151 std::vector<PluginMetadata> getCompatiblePlugins();
152
154 const std::map<std::string, int> GetCountByTarget();
155
157 std::string GetPluginByLibrary(const std::string& filename);
158
160 std::string GetMetadataPath();
161
163 std::string GetUserMetadataPath();
164
166 void setMetadata(std::string path) { metadataPath = path; }
167
169 bool InstallPlugin(PluginMetadata plugin);
170
172 bool InstallPlugin(PluginMetadata plugin, std::string path);
173
175 bool ExtractMetadata(const std::string& path, PluginMetadata& metadata);
176
177 /* Install a new, downloaded but not installed plugin tarball. */
178 bool InstallPlugin(const std::string& path);
179
181 bool Uninstall(const std::string plugin);
182
184 bool ClearInstallData(const std::string plugin_name);
185
188
189 CatalogData* GetCatalogData() { return &catalogData; }
190
191protected:
193
194private:
195 std::string metadataPath;
196 std::vector<PluginMetadata> installed;
197 CatalogData catalogData;
198 std::string last_error_msg;
199 bool InstallPlugin(const std::string& path, std::string& filelist,
200 const std::string metadata_path, bool only_metadata);
201
215 bool ExplodeTarball(struct archive* src, struct archive* dest,
216 std::string& filelist, const std::string& metadata_path,
217 bool only_metadata);
230 bool ExtractTarball(const std::string path, std::string& filelist,
231 const std::string metadata_path = "",
232 bool only_metadata = false);
233 bool ArchiveCheck(int r, const char* msg, struct archive* a);
234
235 std::unordered_map<std::string, std::vector<std::string>> FilesByPlugin;
236
237 bool DoClearInstallData(const std::string plugin_name);
238};
239
240#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.
std::string GetUserMetadataPath()
Return path to user, writable metadata XML file.
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.
A common variable shared between producer and consumer which supports Listen() and Notify().
Overall metadata for the set of plugins used.
Plugin metadata, reflects the xml format directly.