xbmc
AddonDll.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "addons/Addon.h"
12 #include "addons/kodi-dev-kit/include/kodi/c-api/addon_base.h"
13 
14 #include <map>
15 #include <memory>
16 #include <string>
17 
18 class DllAddon;
19 
20 namespace ADDON
21 {
22 
23 class CBinaryAddonBase;
24 using BinaryAddonBasePtr = std::shared_ptr<CBinaryAddonBase>;
25 
35 using ADDON_INSTANCE_HANDLER = void*;
36 
44 {
45 public:
46  virtual ~CAddonDllInformer() = default;
47 
48  virtual bool IsInUse(const std::string& id) = 0;
49 };
50 
51 class CAddonDll : public CAddon
52 {
53 public:
54  CAddonDll(const AddonInfoPtr& addonInfo, BinaryAddonBasePtr addonBase);
55  CAddonDll(const AddonInfoPtr& addonInfo, AddonType addonType);
56  ~CAddonDll() override;
57 
58  // Implementation of IAddon via CAddon
59  std::string LibPath() const override;
60 
61  // addon settings
62  void SaveSettings(AddonInstanceId id = ADDON_SETTINGS_ID) override;
63 
64  bool DllLoaded(void) const;
65 
75  CAddonVersion GetTypeVersionDll(int type) const;
76 
86  CAddonVersion GetTypeMinVersionDll(int type) const;
87 
95 
101  void DestroyInstance(KODI_ADDON_INSTANCE_STRUCT* instance);
102 
103  bool IsInUse() const override;
104  void RegisterInformer(CAddonDllInformer* informer);
105  AddonPtr GetRunningInstance() const override;
106 
107  void OnPreInstall() override;
108  void OnPostInstall(bool update, bool modal) override;
109  void OnPreUnInstall() override;
110  void OnPostUnInstall() override;
111 
112  bool Initialized() const { return m_initialized; }
113 
114 protected:
115  static std::string GetDllPath(const std::string& strFileName);
116 
117  std::string m_parentLib;
118 
119 private:
134  ADDON_STATUS Create(KODI_ADDON_INSTANCE_STRUCT* firstKodiInstance);
135 
141  void Destroy();
142 
143  bool CheckAPIVersion(int type);
144 
145  BinaryAddonBasePtr m_binaryAddonBase = nullptr;
146  DllAddon* m_pDll = nullptr;
147  bool m_initialized = false;
148  bool LoadDll();
149  std::map<ADDON_INSTANCE_HANDLER, KODI_ADDON_INSTANCE_STRUCT*> m_usedInstances;
150  CAddonDllInformer* m_informer = nullptr;
151 
152  virtual ADDON_STATUS TransferSettings(AddonInstanceId instanceId);
153 
160  AddonGlobalInterface m_interface = {};
161 };
162 
163 } /* namespace ADDON */
Definition: AddonDll.h:51
Definition: AddonVersion.h:27
Information class for use on addon type managers.
Definition: AddonDll.h:43
Main structure passed from kodi to addon with basic information needed to create add-on.
Definition: addon_base.h:378
Definition: addon_base.h:267
ADDON_STATUS
Definition: addon_base.h:137
Definition: DllAddon.h:22
Definition: Addon.cpp:39
Definition: Addon.h:34