OpenCPN Partial API docs
Loading...
Searching...
No Matches
catalog_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
30#ifndef CATALOG_HANDLER_H__
31#define CATALOG_HANDLER_H__
32
33#include <string>
34#include <memory>
35#include <ostream>
36#include <vector>
37
38#include "catalog_parser.h"
39
51public:
52 enum class ServerStatus {
53 UNKNOWN,
54 OK,
55 OK_MSG,
56 CURL_ERROR,
57 JSON_ERROR,
58 XML_ERROR,
59 OS_ERROR
60 };
61
62 static CatalogHandler* getInstance();
63
65 ServerStatus LoadChannels(std::ostream* json);
66
68 ServerStatus LoadChannels(const std::string& json);
69
71 std::vector<std::string> GetChannels();
72
74 bool SetActiveChannel(const char* channel);
75
77 std::string GetActiveChannel();
78
80 void SetCustomUrl(const char* url);
81
83 std::string GetCustomUrl();
84
86 std::string GetDefaultUrl();
87
89 ServerStatus DownloadCatalog(std::ostream* stream);
90
92 ServerStatus DownloadCatalog(std::string& path);
93
95 ServerStatus DownloadCatalog(std::ostream* stream, std::string url);
96
98 ServerStatus DownloadCatalog(std::string& filePath, std::string url);
99
101 ServerStatus ParseCatalog(const std::string xml, bool latest = false);
102
105
108
111
113 void ClearCatalogData();
114
116 std::string LastErrorMsg();
117
118 ServerStatus DoParseCatalog(const std::string xml, CatalogCtx* ctx);
119
120protected:
123
124 void LoadCatalogData(const std::string& path, CatalogData& data);
125
126 const char* const GET_BRANCHES_PATH = "/repos/OpenCPN/plugins/branches";
127 const char* const GITHUB_API = "https://api.github.com";
128
129 const char* const REPO_URL = "https://raw.githubusercontent.com";
130 const char* const REPO_PATH = "/OpenCPN/plugins/@branch@/ocpn-plugins.xml";
131
132 const char* const DEFAULT_CHANNEL = "master";
133
134private:
135 std::vector<std::string> channels;
136 ServerStatus status;
137 std::ostream* stream;
138 std::string error_msg;
139 CatalogData latest_data;
140 CatalogData default_data;
141 CatalogData user_data;
142};
143
144typedef CatalogHandler::ServerStatus catalog_status;
145
146#endif // CATALOG_HANDLER_H__
Plugin catalog management: Check for available versions and branches, download as required.
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.
std::string LastErrorMsg()
Last error message, free format.
CatalogData UserCatalogData()
Data for user catalog which overrides the default one.
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()
Set a custom url, overrides also channel settings.
bool SetActiveChannel(const char *channel)
Set the active channel used when downloading catalog.
The result from parsing the xml catalog i.
Datatypes and a single method to parse ocpn-plugins.xml XML data.