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, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 **************************************************************************/
19
26#ifndef CATALOG_HANDLER_H__
27#define CATALOG_HANDLER_H__
28
29#include <string>
30#include <memory>
31#include <ostream>
32#include <vector>
33
35
53public:
54 enum class ServerStatus {
55 UNKNOWN,
56 OK,
57 OK_MSG,
58 CURL_ERROR,
59 JSON_ERROR,
60 XML_ERROR,
61 OS_ERROR,
62 FILE_ERROR
63 };
64
65 static CatalogHandler* getInstance();
66
68 ServerStatus LoadChannels(std::ostream* json);
69
71 ServerStatus LoadChannels(const std::string& json);
72
74 std::vector<std::string> GetChannels();
75
77 bool SetActiveChannel(const char* channel);
78
80 std::string GetActiveChannel();
81
83 void SetCustomUrl(const char* url);
84
86 std::string GetCustomUrl();
87
89 std::string GetDefaultUrl();
90
92 ServerStatus DownloadCatalog(std::ostream* stream);
93
95 ServerStatus DownloadCatalog(std::string& path);
96
98 ServerStatus DownloadCatalog(std::ostream* stream, std::string url);
99
101 ServerStatus DownloadCatalog(std::string& filePath, std::string url);
102
104 ServerStatus ParseCatalog(const std::string xml, bool latest = false);
105
108
111
114
116 void ClearCatalogData();
117
120
122 ServerStatus GetCatalogStatus();
123
126
128 std::string LastErrorMsg();
129
134 ServerStatus DoParseCatalog(const std::string xml, CatalogCtx* ctx);
135
136protected:
139
140 void LoadCatalogData(const std::string& path, CatalogData& data);
141
142 const char* const GET_BRANCHES_PATH = "/repos/OpenCPN/plugins/branches";
143 const char* const GITHUB_API = "https://api.github.com";
144
145 const char* const REPO_URL = "https://raw.githubusercontent.com";
146 const char* const REPO_PATH = "/OpenCPN/plugins/@branch@/ocpn-plugins.xml";
147
148 const char* const DEFAULT_CHANNEL = "master";
149
150private:
151 std::vector<std::string> channels;
152 ServerStatus status;
153 std::ostream* stream;
154 std::string error_msg;
155 CatalogData latest_data;
156 CatalogData default_data;
157 CatalogData user_data;
158 ServerStatus m_catalog_status;
159 CatalogCtx m_catalogctx;
160};
161
162typedef CatalogHandler::ServerStatus catalog_status;
163
164#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.