summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/AddonManager.h
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/addons/AddonManager.h')
-rw-r--r--xbmc/addons/AddonManager.h253
1 files changed, 0 insertions, 253 deletions
diff --git a/xbmc/addons/AddonManager.h b/xbmc/addons/AddonManager.h
deleted file mode 100644
index 8bc058d..0000000
--- a/xbmc/addons/AddonManager.h
+++ /dev/null
@@ -1,253 +0,0 @@
1#pragma once
2/*
3 * Copyright (C) 2005-2013 Team XBMC
4 * http://xbmc.org
5 *
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 *
20 */
21#include "Addon.h"
22#include "threads/CriticalSection.h"
23#include "utils/Observer.h"
24#include <string>
25#include <vector>
26#include <map>
27#include <deque>
28#include "AddonDatabase.h"
29
30class DllLibCPluff;
31extern "C"
32{
33#include "lib/cpluff/libcpluff/cpluff.h"
34}
35
36namespace ADDON
37{
38 typedef std::map<TYPE, VECADDONS> MAPADDONS;
39 typedef std::map<TYPE, VECADDONS>::iterator IMAPADDONS;
40 typedef std::vector<cp_cfg_element_t*> ELEMENTS;
41
42 const std::string ADDON_METAFILE = "description.xml";
43 const std::string ADDON_VIS_EXT = "*.vis";
44 const std::string ADDON_PYTHON_EXT = "*.py";
45 const std::string ADDON_SCRAPER_EXT = "*.xml";
46 const std::string ADDON_SCREENSAVER_EXT = "*.xbs";
47 const std::string ADDON_PVRDLL_EXT = "*.pvr";
48 const std::string ADDON_DSP_AUDIO_EXT = "*.adsp";
49 const std::string ADDON_VERSION_RE = "(?<Major>\\d*)\\.?(?<Minor>\\d*)?\\.?(?<Build>\\d*)?\\.?(?<Revision>\\d*)?";
50
51 /**
52 * Class - IAddonMgrCallback
53 * This callback should be inherited by any class which manages
54 * specific addon types. Could be mostly used for Dll addon types to handle
55 * cleanup before restart/removal
56 */
57 class IAddonMgrCallback
58 {
59 public:
60 virtual ~IAddonMgrCallback() {};
61 virtual bool RequestRestart(AddonPtr addon, bool datachanged)=0;
62 virtual bool RequestRemoval(AddonPtr addon)=0;
63 };
64
65 /**
66 * Class - CAddonMgr
67 * Holds references to all addons, enabled or
68 * otherwise. Services the generic callbacks available
69 * to all addon variants.
70 */
71 class CAddonMgr : public Observable
72 {
73 public:
74 static CAddonMgr &Get();
75 bool ReInit() { DeInit(); return Init(); }
76 bool Init();
77 void DeInit();
78
79 IAddonMgrCallback* GetCallbackForType(TYPE type);
80 bool RegisterAddonMgrCallback(TYPE type, IAddonMgrCallback* cb);
81 void UnregisterAddonMgrCallback(TYPE type);
82
83 /* Addon access */
84 bool GetDefault(const TYPE &type, AddonPtr &addon);
85 bool SetDefault(const TYPE &type, const std::string &addonID);
86 /*! \brief Retrieve a specific addon (of a specific type)
87 \param id the id of the addon to retrieve.
88 \param addon [out] the retrieved addon pointer - only use if the function returns true.
89 \param type type of addon to retrieve - defaults to any type.
90 \param enabledOnly whether we only want enabled addons - set to false to allow both enabled and disabled addons - defaults to true.
91 \return true if an addon matching the id of the given type is available and is enabled (if enabledOnly is true).
92 */
93 bool GetAddon(const std::string &id, AddonPtr &addon, const TYPE &type = ADDON_UNKNOWN, bool enabledOnly = true);
94 bool HasAddons(const TYPE &type, bool enabled = true);
95 bool GetAddons(const TYPE &type, VECADDONS &addons, bool enabled = true);
96 bool GetAllAddons(VECADDONS &addons, bool enabled = true, bool allowRepos = false);
97 void AddToUpdateableAddons(AddonPtr &pAddon);
98 void RemoveFromUpdateableAddons(AddonPtr &pAddon);
99 bool ReloadSettings(const std::string &id);
100 /*! \brief Get all addons with available updates
101 \param addons List to fill with all outdated addons
102 \param getLocalVersion Whether to get the local addon version or the addon verion from the repository
103 \return True if there are outdated addons otherwise false
104 */
105 bool GetAllOutdatedAddons(VECADDONS &addons, bool getLocalVersion = false);
106 /*! \brief Checks if there is any addon with available updates
107 \return True if there are outdated addons otherwise false
108 */
109 bool HasOutdatedAddons();
110 std::string GetString(const std::string &id, const int number);
111
112 std::string GetTranslatedString(const cp_cfg_element_t *root, const char *tag);
113 static AddonPtr AddonFromProps(AddonProps& props);
114 void FindAddons();
115 void RemoveAddon(const std::string& ID);
116
117 /* \brief Disable an addon
118 Triggers the database routine and saves the current addon state to cache.
119 \param ID id of the addon
120 \param disable whether to enable or disable. Defaults to true (disable)
121 \sa IsAddonDisabled,
122 */
123 bool DisableAddon(const std::string& ID, bool disable = true);
124
125 /* \brief Check whether an addon has been disabled via DisableAddon.
126 In case the disabled cache does not know about the current state the database routine will be used.
127 \param ID id of the addon
128 \sa DisableAddon
129 */
130 bool IsAddonDisabled(const std::string& ID);
131
132 /* \brief Checks whether an addon can be disabled via DisableAddon.
133 \param ID id of the addon
134 \sa DisableAddon
135 */
136 bool CanAddonBeDisabled(const std::string& ID);
137
138 /* \brief Checks whether an addon is installed.
139 \param ID id of the addon
140 */
141 bool IsAddonInstalled(const std::string& ID);
142
143 /* \brief Checks whether an addon is installed.
144 \param ID id of the addon
145 \param addon Installed addon
146 */
147 bool IsAddonInstalled(const std::string& ID, AddonPtr& addon);
148
149 /* \brief Checks whether an addon can be installed. Broken addons can't be installed.
150 \param ID id of the addon
151 */
152 bool CanAddonBeInstalled(const std::string& ID);
153
154 /* \brief Checks whether an addon can be installed. Broken addons can't be installed.
155 \param addon addon to be checked
156 */
157 bool CanAddonBeInstalled(const AddonPtr& addon);
158
159 /* libcpluff */
160 std::string GetExtValue(cp_cfg_element_t *base, const char *path);
161
162 /*! \brief Retrieve a vector of repeated elements from a given configuration element
163 \param base the base configuration element.
164 \param path the path to the configuration element from the base element.
165 \param result [out] returned list of elements.
166 \return true if the configuration element is present and the list of elements is non-empty
167 */
168 bool GetExtElements(cp_cfg_element_t *base, const char *path, ELEMENTS &result);
169
170 /*! \brief Retrieve a list of strings from a given configuration element
171 Assumes the configuration element or attribute contains a whitespace separated list of values (eg xs:list schema).
172 \param base the base configuration element.
173 \param path the path to the configuration element or attribute from the base element.
174 \param result [out] returned list of strings.
175 \return true if the configuration element is present and the list of strings is non-empty
176 */
177 bool GetExtList(cp_cfg_element_t *base, const char *path, std::vector<std::string> &result) const;
178
179 const cp_extension_t *GetExtension(const cp_plugin_info_t *props, const char *extension) const;
180
181 /*! \brief Load the addon in the given path
182 This loads the addon using c-pluff which parses the addon descriptor file.
183 \param path folder that contains the addon.
184 \param addon [out] returned addon.
185 \return true if addon is set, false otherwise.
186 */
187 bool LoadAddonDescription(const std::string &path, AddonPtr &addon);
188
189 /*! \brief Load the addon in the given in-memory xml
190 This loads the addon using c-pluff which parses the addon descriptor file.
191 \param root Root element of an XML document.
192 \param addon [out] returned addon.
193 \return true if addon is set, false otherwise.
194 */
195 bool LoadAddonDescriptionFromMemory(const TiXmlElement *root, AddonPtr &addon);
196
197 /*! \brief Parse a repository XML file for addons and load their descriptors
198 A repository XML is essentially a concatenated list of addon descriptors.
199 \param root Root element of an XML document.
200 \param addons [out] returned list of addons.
201 \return true if the repository XML file is parsed, false otherwise.
202 */
203 bool AddonsFromRepoXML(const TiXmlElement *root, VECADDONS &addons);
204
205 /*! \brief Start all services addons.
206 \return True is all addons are started, false otherwise
207 */
208 bool StartServices(const bool beforelogin);
209 /*! \brief Stop all services addons.
210 */
211 void StopServices(const bool onlylogin);
212
213 private:
214 void LoadAddons(const std::string &path,
215 std::map<std::string, AddonPtr>& unresolved);
216
217 /* libcpluff */
218 const cp_cfg_element_t *GetExtElement(cp_cfg_element_t *base, const char *path);
219 cp_context_t *m_cp_context;
220 DllLibCPluff *m_cpluff;
221 VECADDONS m_updateableAddons;
222
223 /*! \brief Fetch a (single) addon from a plugin descriptor.
224 Assumes that there is a single (non-trivial) extension point per addon.
225 \param info the plugin descriptor
226 \param type the extension point we want
227 \return an AddonPtr based on the descriptor. May be NULL if no suitable extension point is found.
228 */
229 AddonPtr GetAddonFromDescriptor(const cp_plugin_info_t *info,
230 const std::string& type="");
231
232 /*! \brief Check whether this addon is supported on the current platform
233 \param info the plugin descriptor
234 \return true if the addon is supported, false otherwise.
235 */
236 bool PlatformSupportsAddon(const cp_plugin_info_t *info) const;
237
238 AddonPtr Factory(const cp_extension_t *props);
239 bool CheckUserDirs(const cp_cfg_element_t *element);
240
241 // private construction, and no assignements; use the provided singleton methods
242 CAddonMgr();
243 CAddonMgr(const CAddonMgr&);
244 CAddonMgr const& operator=(CAddonMgr const&);
245 virtual ~CAddonMgr();
246
247 std::map<std::string, bool> m_disabled;
248 static std::map<TYPE, IAddonMgrCallback*> m_managers;
249 CCriticalSection m_critSection;
250 CAddonDatabase m_database;
251 };
252
253}; /* namespace ADDON */