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#include <archive.h>
35
36#include <wx/cmdline.h>
37
38#include "observable/evtvar.h"
40
41bool isRegularFile(const char* path);
42
44class CompatOs {
45public:
46 static CompatOs* GetInstance();
47 std::string name() const { return _name; }
48 std::string version() const { return _version; }
49
50private:
51 CompatOs();
52 std::string _name;
53 std::string _version;
54};
55
86public:
88 static PluginHandler* GetInstance();
89
90 PluginHandler(const PluginHandler&) = delete;
91 PluginHandler& operator=(const PluginHandler&) = delete;
92
97 obs::EventVar evt_download_ok;
98
100 obs::EventVar evt_download_failed;
101
103 static void Cleanup(const std::string& filelist, const std::string& plugname);
104
105 static void CleanupFiles(const std::string& manifestFile,
106 const std::string& plugname);
107
109 static std::string PluginsInstallDataPath();
110
112 static std::string FileListPath(std::string name);
113
115 static std::string VersionPath(std::string name);
116
118 static std::string ImportedMetadataPath(std::string name);
119
121 static std::vector<std::string> GetImportPaths();
122
124 static bool IsCompatible(const PluginMetadata& metadata,
125 const char* os = PKG_TARGET,
126 const char* os_version = PKG_TARGET_VERSION);
127
129 bool IsPluginWritable(std::string name);
130
132 const std::vector<PluginMetadata> GetInstalled();
133
138 std::vector<std::string> GetInstalldataPlugins();
139
141 void SetInstalledMetadata(const PluginMetadata& pm);
142
144 const std::vector<PluginMetadata> GetAvailable();
145
150 std::vector<PluginMetadata> getCompatiblePlugins();
151
153 const std::map<std::string, int> GetCountByTarget();
154
156 std::string GetPluginByLibrary(const std::string& filename);
157
159 std::string GetMetadataPath();
160
162 std::string GetUserMetadataPath();
163
165 void setMetadata(std::string path) { metadataPath = path; }
166
168 bool InstallPlugin(PluginMetadata plugin);
169
171 bool InstallPlugin(PluginMetadata plugin, std::string path);
172
174 bool ExtractMetadata(const std::string& path, PluginMetadata& metadata);
175
176 /* Install a new, downloaded but not installed plugin tarball. */
177 bool InstallPlugin(const std::string& path);
178
180 bool Uninstall(const std::string plugin);
181
183 bool ClearInstallData(const std::string plugin_name);
184
187
188 CatalogData* GetCatalogData() { return &catalogData; }
189
190protected:
192
193private:
194 std::string metadataPath;
195 std::vector<PluginMetadata> installed;
196 CatalogData catalogData;
197 std::string last_error_msg;
198 bool InstallPlugin(const std::string& path, std::string& filelist,
199 const std::string metadata_path, bool only_metadata);
200
214 bool ExplodeTarball(struct archive* src, struct archive* dest,
215 std::string& filelist, const std::string& metadata_path,
216 bool only_metadata);
229 bool ExtractTarball(const std::string path, std::string& filelist,
230 const std::string metadata_path = "",
231 bool only_metadata = false);
232 bool ArchiveCheck(int r, const char* msg, struct archive* a);
233
234 std::unordered_map<std::string, std::vector<std::string>> FilesByPlugin;
235
236 bool DoClearInstallData(const std::string plugin_name);
237};
238
239#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.
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.
obs::EventVar evt_download_ok
Notified with plugin name + version string after successful download from repository.
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.
obs::EventVar evt_download_failed
Notified with plugin name after failed download attempt.
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.
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.
Overall metadata for the set of plugins used.
Plugin metadata, reflects the xml format directly.