OpenCPN Partial API docs
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 "model/catalog_parser.h"
39 
51 public:
52  enum class ServerStatus {
53  UNKNOWN,
54  OK,
55  OK_MSG,
56  CURL_ERROR,
57  JSON_ERROR,
58  XML_ERROR,
59  OS_ERROR,
60  FILE_ERROR
61  };
62 
63  static CatalogHandler* getInstance();
64 
66  ServerStatus LoadChannels(std::ostream* json);
67 
69  ServerStatus LoadChannels(const std::string& json);
70 
72  std::vector<std::string> GetChannels();
73 
75  bool SetActiveChannel(const char* channel);
76 
78  std::string GetActiveChannel();
79 
81  void SetCustomUrl(const char* url);
82 
84  std::string GetCustomUrl();
85 
87  std::string GetDefaultUrl();
88 
90  ServerStatus DownloadCatalog(std::ostream* stream);
91 
93  ServerStatus DownloadCatalog(std::string& path);
94 
96  ServerStatus DownloadCatalog(std::ostream* stream, std::string url);
97 
99  ServerStatus DownloadCatalog(std::string& filePath, std::string url);
100 
102  ServerStatus ParseCatalog(const std::string xml, bool latest = false);
103 
106 
109 
112 
114  void ClearCatalogData();
115 
118 
120  ServerStatus GetCatalogStatus();
121 
124 
126  std::string LastErrorMsg();
127 
128  ServerStatus DoParseCatalog(const std::string xml, CatalogCtx* ctx);
129 
130 protected:
132  CatalogHandler();
133 
134  void LoadCatalogData(const std::string& path, CatalogData& data);
135 
136  const char* const GET_BRANCHES_PATH = "/repos/OpenCPN/plugins/branches";
137  const char* const GITHUB_API = "https://api.github.com";
138 
139  const char* const REPO_URL = "https://raw.githubusercontent.com";
140  const char* const REPO_PATH = "/OpenCPN/plugins/@branch@/ocpn-plugins.xml";
141 
142  const char* const DEFAULT_CHANNEL = "master";
143 
144 private:
145  std::vector<std::string> channels;
146  ServerStatus status;
147  std::ostream* stream;
148  std::string error_msg;
149  CatalogData latest_data;
150  CatalogData default_data;
151  CatalogData user_data;
152  ServerStatus m_catalog_status;
153  CatalogCtx m_catalogctx;
154 };
155 
156 typedef CatalogHandler::ServerStatus catalog_status;
157 
158 #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.
CatalogCtx * GetActiveCatalogContext()
Return a pointer to the currently active plugin catalog context.
std::string LastErrorMsg()
Last error message, free format.
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()
Set a custom url, overrides also channel settings.
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.
Datatypes and methods to parse ocpn-plugins.xml XML data, either complete catalog or a single plugin.
Plugin metadata, reflects the xml format directly.