OpenCPN Partial API docs
Loading...
Searching...
No Matches
plugin_handler.h
1/******************************************************************************
2 *
3 * Project: OpenCPN
4 *
5 ***************************************************************************
6 * Copyright (C) 2019 Alec Leamas *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
22 ***************************************************************************
23 */
24
56#ifndef PLUGIN_HANDLER_H__
57#define PLUGIN_HANDLER_H__
58
59#include "config.h"
60
61#include <string>
62#include <map>
63#include <memory>
64#include <vector>
65
66#include <wx/cmdline.h>
67
68#include <archive.h>
69
70#include "catalog_parser.h"
71#include "observable_evtvar.h"
72
73bool isRegularFile(const char* path);
74
75class CompatOs {
76public:
77 static CompatOs* getInstance();
78 std::string name() const { return _name; }
79 std::string version() const { return _version; }
80
81private:
82 CompatOs();
83 std::string _name;
84 std::string _version;
85};
86
88public:
89
90 EventVar evt_download_ok;
91 EventVar evt_download_failed;
92
93 static PluginHandler* getInstance();
94
96 static void cleanup(const std::string& filelist, const std::string& plugname);
97 static void cleanupFiles(const std::string& manifestFile,
98 const std::string& plugname);
99
101 static std::string fileListPath(std::string name);
102
104 static std::string versionPath(std::string name);
105
107 static bool isCompatible(const PluginMetadata& metadata,
108 const char* os = PKG_TARGET,
109 const char* os_version = PKG_TARGET_VERSION);
110
112 bool isPluginWritable(std::string name);
113
115 const std::vector<PluginMetadata> getInstalled();
116
118 const std::vector<PluginMetadata> getAvailable();
119
121 const std::map<std::string, int> getCountByTarget();
122
124 std::string getMetadataPath();
125
127 void setMetadata(std::string path) { metadataPath = path; }
128
130 bool installPlugin(PluginMetadata plugin);
131
133 bool installPlugin(PluginMetadata plugin, std::string path);
134
136 bool installPlugin(std::string path);
137
139 bool uninstall(const std::string plugin);
140
143
144 std::string getLastErrorMsg() { return last_error_msg; }
145
146 CatalogData* GetCatalogData() { return &catalogData; }
147
148protected:
150
151private:
152 std::string metadataPath;
153 std::vector<PluginMetadata> installed;
154 CatalogData catalogData;
155 std::string last_error_msg;
156 bool explodeTarball(struct archive* src, struct archive* dest,
157 std::string& filelist,
158 const std::string& metadata_path);
159 bool extractTarball(const std::string path, std::string& filelist,
160 const std::string metadata_path = "");
161 bool archive_check(int r, const char* msg, struct archive* a);
162};
163
164#endif // PLUGIN_HANDLER_H__
Generic event handling between between two parties like MVC Model and Controller using a shared Event...
const std::vector< PluginMetadata > getInstalled()
Return list of all installed plugins.
void setMetadata(std::string path)
Set path to metadata XML file.
static void cleanup(const std::string &filelist, const std::string &plugname)
Cleanup failed installation attempt using filelist for plugin.
bool installPluginFromCache(PluginMetadata plugin)
Install plugin tarball from local cache.
const std::map< std::string, int > getCountByTarget()
Map of available plugin targets -> number of occurences.
bool isPluginWritable(std::string name)
Check if given plugin can be installed/updated.
static std::string fileListPath(std::string name)
Return path to installation manifest for given plugin.
static std::string versionPath(std::string name)
Return path to file containing version for given plugin.
bool uninstall(const std::string plugin)
Uninstall an installed plugin.
bool installPlugin(PluginMetadata plugin)
Download and install a new, not installed plugin.
std::string getMetadataPath()
Return path to metadata XML file.
const std::vector< PluginMetadata > getAvailable()
Return list of available, not installed plugins.
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.
Datatypes and a single method to parse ocpn-plugins.xml XML data.
Plugin metadata, reflects the xml format directly.