OpenCPN Partial API docs
Loading...
Searching...
No Matches
catalog_handler.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2019 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
25#ifndef CATALOG_HANDLER_H__
26#define CATALOG_HANDLER_H__
27
28#include <string>
29#include <memory>
30#include <ostream>
31#include <vector>
32
34
52public:
53 enum class ServerStatus {
54 UNKNOWN,
55 OK,
56 OK_MSG,
57 CURL_ERROR,
58 JSON_ERROR,
59 XML_ERROR,
60 OS_ERROR,
61 FILE_ERROR
62 };
63
64 static CatalogHandler* GetInstance();
65
67 ServerStatus LoadChannels(std::ostream* json);
68
70 ServerStatus LoadChannels(const std::string& json);
71
73 std::vector<std::string> GetChannels();
74
76 bool SetActiveChannel(const char* channel);
77
79 std::string GetActiveChannel();
80
82 void SetCustomUrl(const char* url);
83
85 std::string GetCustomUrl();
86
88 std::string GetDefaultUrl();
89
91 ServerStatus DownloadCatalog(std::ostream* stream);
92
94 ServerStatus DownloadCatalog(std::string& path);
95
97 ServerStatus DownloadCatalog(std::ostream* stream, std::string url);
98
100 ServerStatus DownloadCatalog(std::string& filePath, std::string url);
101
103 ServerStatus ParseCatalog(const std::string xml, bool latest = false);
104
107
110
113
115 void ClearCatalogData();
116
119
121 ServerStatus GetCatalogStatus();
122
125
127 std::string LastErrorMsg();
128
133 ServerStatus DoParseCatalog(const std::string xml, CatalogCtx* ctx);
134
135protected:
138
139 void LoadCatalogData(const std::string& path, CatalogData& data);
140
141 const char* const GET_BRANCHES_PATH = "/repos/OpenCPN/plugins/branches";
142 const char* const GITHUB_API = "https://api.github.com";
143
144 const char* const REPO_URL = "https://raw.githubusercontent.com";
145 const char* const REPO_PATH = "/OpenCPN/plugins/@branch@/ocpn-plugins.xml";
146
147 const char* const DEFAULT_CHANNEL = "master";
148
149private:
150 std::vector<std::string> channels;
151 ServerStatus status;
152 std::ostream* stream;
153 std::string error_msg;
154 CatalogData latest_data;
155 CatalogData default_data;
156 CatalogData user_data;
157 ServerStatus m_catalog_status;
158 CatalogCtx m_catalogctx;
159};
160
161typedef CatalogHandler::ServerStatus catalog_status;
162
163#endif // CATALOG_HANDLER_H__
Datatypes and methods to parse ocpn-plugins.xml XML data, either complete catalog or a single plugin.
Local proxy for the catalog server and other catalog sources.
std::vector< std::string > GetChannels()
Get the downloaded list of channels, empty on errors.
ServerStatus LoadChannels(std::ostream *json)
Download channel json data, possibly return error code.
CatalogHandler()
Initiate the handler.
CatalogData DefaultCatalogData()
Data for default version, installed with main opencpn.
std::string GetDefaultUrl()
Get the default URL, with actual channel included.
CatalogData LatestCatalogData()
Data for latest parsed data marked as latest.
CatalogCtx * GetActiveCatalogContext()
Return a pointer to the currently active plugin catalog context.
std::string LastErrorMsg()
Last error message, free format.
ServerStatus DoParseCatalog(const std::string xml, CatalogCtx *ctx)
Parse the catalog by merging data from imported metadata, meta-urls and the standard url.
CatalogData UserCatalogData()
Data for user catalog which overrides the default one.
bool AddMetadataToActiveContext(PluginMetadata metadata)
Add an abritrary stub metadata netry to the active catalog context.
ServerStatus ParseCatalog(const std::string xml, bool latest=false)
Parse XML contents, save as latest data if latest is true.
std::string GetActiveChannel()
Get the branch (a.
void SetCustomUrl(const char *url)
Set a custom url, overrides also channel settings.
ServerStatus DownloadCatalog(std::ostream *stream)
Download the latest catalog to given stream.
void ClearCatalogData()
Invalidate *CatalogData caches.
std::string GetCustomUrl()
Get the custom url set by SetCustomUrl.
ServerStatus GetCatalogStatus()
Retrieve status of currently active plugin catalog
bool SetActiveChannel(const char *channel)
Set the active channel used when downloading catalog.
The result from parsing the xml catalog i.
Overall metadata for the set of plugins used.
Plugin metadata, reflects the xml format directly.