diff options
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Screensaver.h')
| -rw-r--r-- | xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Screensaver.h | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Screensaver.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Screensaver.h new file mode 100644 index 0000000..39baae7 --- /dev/null +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Screensaver.h | |||
| @@ -0,0 +1,141 @@ | |||
| 1 | #pragma once | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2005-2017 Team Kodi | ||
| 4 | * http://kodi.tv | ||
| 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 Kodi; see the file COPYING. If not, see | ||
| 18 | * <http://www.gnu.org/licenses/>. | ||
| 19 | * | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include "../AddonBase.h" | ||
| 23 | |||
| 24 | namespace kodi { namespace addon { class CInstanceScreensaver; }} | ||
| 25 | |||
| 26 | extern "C" | ||
| 27 | { | ||
| 28 | |||
| 29 | struct AddonInstance_Screensaver; | ||
| 30 | |||
| 31 | typedef struct AddonProps_Screensaver | ||
| 32 | { | ||
| 33 | void *device; | ||
| 34 | int x; | ||
| 35 | int y; | ||
| 36 | int width; | ||
| 37 | int height; | ||
| 38 | float pixelRatio; | ||
| 39 | const char *name; | ||
| 40 | const char *presets; | ||
| 41 | const char *profile; | ||
| 42 | } AddonProps_Screensaver; | ||
| 43 | |||
| 44 | typedef struct AddonToKodiFuncTable_Screensaver | ||
| 45 | { | ||
| 46 | KODI_HANDLE kodiInstance; | ||
| 47 | } AddonToKodiFuncTable_Screensaver; | ||
| 48 | |||
| 49 | typedef struct KodiToAddonFuncTable_Screensaver | ||
| 50 | { | ||
| 51 | kodi::addon::CInstanceScreensaver* addonInstance; | ||
| 52 | bool (__cdecl* Start) (AddonInstance_Screensaver* instance); | ||
| 53 | void (__cdecl* Stop) (AddonInstance_Screensaver* instance); | ||
| 54 | void (__cdecl* Render) (AddonInstance_Screensaver* instance); | ||
| 55 | } KodiToAddonFuncTable_Screensaver; | ||
| 56 | |||
| 57 | typedef struct AddonInstance_Screensaver | ||
| 58 | { | ||
| 59 | AddonProps_Screensaver props; | ||
| 60 | AddonToKodiFuncTable_Screensaver toKodi; | ||
| 61 | KodiToAddonFuncTable_Screensaver toAddon; | ||
| 62 | } AddonInstance_Screensaver; | ||
| 63 | |||
| 64 | } /* extern "C" */ | ||
| 65 | |||
| 66 | namespace kodi | ||
| 67 | { | ||
| 68 | namespace addon | ||
| 69 | { | ||
| 70 | |||
| 71 | class CInstanceScreensaver : public IAddonInstance | ||
| 72 | { | ||
| 73 | public: | ||
| 74 | CInstanceScreensaver() | ||
| 75 | : IAddonInstance(ADDON_INSTANCE_SCREENSAVER) | ||
| 76 | { | ||
| 77 | if (CAddonBase::m_interface->globalSingleInstance != nullptr) | ||
| 78 | throw std::logic_error("kodi::addon::CInstanceScreensaver: Creation of more as one in single instance way is not allowed!"); | ||
| 79 | |||
| 80 | SetAddonStruct(CAddonBase::m_interface->firstKodiInstance); | ||
| 81 | CAddonBase::m_interface->globalSingleInstance = this; | ||
| 82 | } | ||
| 83 | |||
| 84 | CInstanceScreensaver(KODI_HANDLE instance) | ||
| 85 | : IAddonInstance(ADDON_INSTANCE_SCREENSAVER) | ||
| 86 | { | ||
| 87 | if (CAddonBase::m_interface->globalSingleInstance != nullptr) | ||
| 88 | throw std::logic_error("kodi::addon::CInstanceScreensaver: Creation of multiple together with single instance way is not allowed!"); | ||
| 89 | |||
| 90 | SetAddonStruct(instance); | ||
| 91 | } | ||
| 92 | |||
| 93 | virtual ~CInstanceScreensaver() { } | ||
| 94 | |||
| 95 | virtual bool Start() { return true; } | ||
| 96 | virtual void Stop() {} | ||
| 97 | virtual void Render() {} | ||
| 98 | |||
| 99 | inline void* Device() { return m_instanceData->props.device; } | ||
| 100 | inline int X() { return m_instanceData->props.x; } | ||
| 101 | inline int Y() { return m_instanceData->props.y; } | ||
| 102 | inline int Width() { return m_instanceData->props.width; } | ||
| 103 | inline int Height() { return m_instanceData->props.height; } | ||
| 104 | inline float PixelRatio() { return m_instanceData->props.pixelRatio; } | ||
| 105 | inline std::string Name() { return m_instanceData->props.name; } | ||
| 106 | inline std::string Presets() { return m_instanceData->props.presets; } | ||
| 107 | inline std::string Profile() { return m_instanceData->props.profile; } | ||
| 108 | |||
| 109 | private: | ||
| 110 | void SetAddonStruct(KODI_HANDLE instance) | ||
| 111 | { | ||
| 112 | if (instance == nullptr) | ||
| 113 | throw std::logic_error("kodi::addon::CInstanceScreensaver: Creation with empty addon structure not allowed, table must be given from Kodi!"); | ||
| 114 | |||
| 115 | m_instanceData = static_cast<AddonInstance_Screensaver*>(instance); | ||
| 116 | m_instanceData->toAddon.addonInstance = this; | ||
| 117 | m_instanceData->toAddon.Start = ADDON_Start; | ||
| 118 | m_instanceData->toAddon.Stop = ADDON_Stop; | ||
| 119 | m_instanceData->toAddon.Render = ADDON_Render; | ||
| 120 | } | ||
| 121 | |||
| 122 | inline static bool ADDON_Start(AddonInstance_Screensaver* instance) | ||
| 123 | { | ||
| 124 | return instance->toAddon.addonInstance->Start(); | ||
| 125 | } | ||
| 126 | |||
| 127 | inline static void ADDON_Stop(AddonInstance_Screensaver* instance) | ||
| 128 | { | ||
| 129 | instance->toAddon.addonInstance->Stop(); | ||
| 130 | } | ||
| 131 | |||
| 132 | inline static void ADDON_Render(AddonInstance_Screensaver* instance) | ||
| 133 | { | ||
| 134 | instance->toAddon.addonInstance->Render(); | ||
| 135 | } | ||
| 136 | |||
| 137 | AddonInstance_Screensaver* m_instanceData; | ||
| 138 | }; | ||
| 139 | |||
| 140 | } /* namespace addon */ | ||
| 141 | } /* namespace kodi */ | ||
