diff options
| author | manuel <manuel@mausz.at> | 2020-07-02 23:09:26 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2020-07-02 23:09:26 +0200 |
| commit | 5f8335c1e49ce108ef3481863833c98efa00411b (patch) | |
| tree | f02b5c1c9765bb6a14c8eb42bb4f81b9face0b55 /xbmc/addons/kodi-addon-dev-kit/include/kodi/AddonBase.h | |
| parent | e317daf081a1048904fdf0b548946fa3ba6593a7 (diff) | |
| download | kodi-pvr-build-5f8335c1e49ce108ef3481863833c98efa00411b.tar.gz kodi-pvr-build-5f8335c1e49ce108ef3481863833c98efa00411b.tar.bz2 kodi-pvr-build-5f8335c1e49ce108ef3481863833c98efa00411b.zip | |
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/AddonBase.h')
| -rw-r--r-- | xbmc/addons/kodi-addon-dev-kit/include/kodi/AddonBase.h | 1374 |
1 files changed, 981 insertions, 393 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/AddonBase.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/AddonBase.h index db39f86..b0fddda 100644 --- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/AddonBase.h +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/AddonBase.h | |||
| @@ -8,230 +8,137 @@ | |||
| 8 | 8 | ||
| 9 | #pragma once | 9 | #pragma once |
| 10 | 10 | ||
| 11 | #include <stdarg.h> /* va_list, va_start, va_arg, va_end */ | 11 | #include "c-api/addon_base.h" |
| 12 | #include "versions.h" | ||
| 13 | |||
| 14 | #include <assert.h> /* assert */ | ||
| 12 | #include <cstdlib> | 15 | #include <cstdlib> |
| 13 | #include <cstring> | 16 | #include <cstring> |
| 17 | #include <ctime> | ||
| 18 | #include <memory> | ||
| 19 | #include <stdarg.h> /* va_list, va_start, va_arg, va_end */ | ||
| 14 | #include <stdexcept> | 20 | #include <stdexcept> |
| 15 | #include <string> | 21 | #include <string> |
| 16 | #include <vector> | 22 | #include <vector> |
| 17 | 23 | ||
| 18 | #ifndef TARGET_WINDOWS | 24 | namespace kodi |
| 19 | #ifndef __cdecl | ||
| 20 | #define __cdecl | ||
| 21 | #endif | ||
| 22 | #ifndef __declspec | ||
| 23 | #define __declspec(X) | ||
| 24 | #endif | ||
| 25 | #endif | ||
| 26 | |||
| 27 | #undef ATTRIBUTE_PACKED | ||
| 28 | #undef PRAGMA_PACK_BEGIN | ||
| 29 | #undef PRAGMA_PACK_END | ||
| 30 | |||
| 31 | #if defined(__GNUC__) | ||
| 32 | #define ATTRIBUTE_PACKED __attribute__ ((packed)) | ||
| 33 | #define PRAGMA_PACK 0 | ||
| 34 | #define ATTRIBUTE_HIDDEN __attribute__ ((visibility ("hidden"))) | ||
| 35 | #endif | ||
| 36 | |||
| 37 | #if !defined(ATTRIBUTE_PACKED) | ||
| 38 | #define ATTRIBUTE_PACKED | ||
| 39 | #define PRAGMA_PACK 1 | ||
| 40 | #endif | ||
| 41 | |||
| 42 | #if !defined(ATTRIBUTE_HIDDEN) | ||
| 43 | #define ATTRIBUTE_HIDDEN | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #ifdef _MSC_VER | ||
| 47 | #define ATTRIBUTE_FORCEINLINE __forceinline | ||
| 48 | #elif defined(__GNUC__) | ||
| 49 | #define ATTRIBUTE_FORCEINLINE inline __attribute__((__always_inline__)) | ||
| 50 | #elif defined(__CLANG__) | ||
| 51 | #if __has_attribute(__always_inline__) | ||
| 52 | #define ATTRIBUTE_FORCEINLINE inline __attribute__((__always_inline__)) | ||
| 53 | #else | ||
| 54 | #define ATTRIBUTE_FORCEINLINE inline | ||
| 55 | #endif | ||
| 56 | #else | ||
| 57 | #define ATTRIBUTE_FORCEINLINE inline | ||
| 58 | #endif | ||
| 59 | |||
| 60 | #include "versions.h" | ||
| 61 | |||
| 62 | namespace kodi { namespace addon { class CAddonBase; }} | ||
| 63 | namespace kodi { namespace addon { class IAddonInstance; }} | ||
| 64 | |||
| 65 | extern "C" { | ||
| 66 | |||
| 67 | //============================================================================== | ||
| 68 | /// Standard undefined pointer handle | ||
| 69 | typedef void* KODI_HANDLE; | ||
| 70 | //------------------------------------------------------------------------------ | ||
| 71 | |||
| 72 | //============================================================================== | ||
| 73 | /// | ||
| 74 | typedef enum ADDON_STATUS | ||
| 75 | { | 25 | { |
| 76 | /// | ||
| 77 | ADDON_STATUS_OK, | ||
| 78 | |||
| 79 | /// | ||
| 80 | ADDON_STATUS_LOST_CONNECTION, | ||
| 81 | |||
| 82 | /// | ||
| 83 | ADDON_STATUS_NEED_RESTART, | ||
| 84 | |||
| 85 | /// | ||
| 86 | ADDON_STATUS_NEED_SETTINGS, | ||
| 87 | 26 | ||
| 88 | /// | 27 | namespace gui |
| 89 | ADDON_STATUS_UNKNOWN, | 28 | { |
| 90 | 29 | struct IRenderHelper; | |
| 91 | /// permanent failure, like failing to resolve methods | 30 | } // namespace gui |
| 92 | ADDON_STATUS_PERMANENT_FAILURE, | ||
| 93 | |||
| 94 | /* internal used return error if function becomes not used from child on | ||
| 95 | * addon */ | ||
| 96 | ADDON_STATUS_NOT_IMPLEMENTED | ||
| 97 | } ADDON_STATUS; | ||
| 98 | //------------------------------------------------------------------------------ | ||
| 99 | 31 | ||
| 100 | //============================================================================== | 32 | //============================================================================== |
| 101 | /// @todo remove start with ADDON_* after old way on libXBMC_addon.h is removed | 33 | /// @ingroup cpp_kodi_addon_addonbase_Defs |
| 34 | /// @defgroup cpp_kodi_addon_addonbase_Defs_CSettingValue class CSettingValue | ||
| 35 | /// @brief Inside addon main instance used helper class to give settings value. | ||
| 36 | /// | ||
| 37 | /// This is used on @ref addon::CAddonBase::SetSetting() to inform addon about | ||
| 38 | /// settings change by used. This becomes then used to give the related value | ||
| 39 | /// name. | ||
| 40 | /// | ||
| 41 | /// ---------------------------------------------------------------------------- | ||
| 42 | /// | ||
| 43 | /// @copydetails cpp_kodi_addon_addonbase_Defs_CSettingValue_Help | ||
| 102 | /// | 44 | /// |
| 103 | typedef enum AddonLog | 45 | /// ---------------------------------------------------------------------------- |
| 46 | /// | ||
| 47 | /// **Here is a code example how this is used:** | ||
| 48 | /// | ||
| 49 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 50 | /// #include <kodi/AddonBase.h> | ||
| 51 | /// | ||
| 52 | /// enum myEnumValue | ||
| 53 | /// { | ||
| 54 | /// valueA, | ||
| 55 | /// valueB, | ||
| 56 | /// valueC | ||
| 57 | /// }; | ||
| 58 | /// | ||
| 59 | /// std::string m_myStringValue; | ||
| 60 | /// int m_myIntegerValue; | ||
| 61 | /// bool m_myBooleanValue; | ||
| 62 | /// float m_myFloatingPointValue; | ||
| 63 | /// myEnumValue m_myEnumValue; | ||
| 64 | /// | ||
| 65 | /// | ||
| 66 | /// ADDON_STATUS CMyAddon::SetSetting(const std::string& settingName, const kodi::CSettingValue& settingValue) | ||
| 67 | /// { | ||
| 68 | /// if (settingName == "my_string_value") | ||
| 69 | /// m_myStringValue = settingValue.GetString(); | ||
| 70 | /// else if (settingName == "my_integer_value") | ||
| 71 | /// m_myIntegerValue = settingValue.GetInt(); | ||
| 72 | /// else if (settingName == "my_boolean_value") | ||
| 73 | /// m_myBooleanValue = settingValue.GetBoolean(); | ||
| 74 | /// else if (settingName == "my_float_value") | ||
| 75 | /// m_myFloatingPointValue = settingValue.GetFloat(); | ||
| 76 | /// else if (settingName == "my_enum_value") | ||
| 77 | /// m_myEnumValue = settingValue.GetEnum<myEnumValue>(); | ||
| 78 | /// } | ||
| 79 | /// ~~~~~~~~~~~~~ | ||
| 80 | /// | ||
| 81 | /// @note The asked type should match the type used on settings.xml. | ||
| 82 | /// | ||
| 83 | ///@{ | ||
| 84 | class ATTRIBUTE_HIDDEN CSettingValue | ||
| 104 | { | 85 | { |
| 105 | /// | 86 | public: |
| 106 | ADDON_LOG_DEBUG = 0, | 87 | explicit CSettingValue(const void* settingValue) : m_settingValue(settingValue) {} |
| 107 | |||
| 108 | /// | ||
| 109 | ADDON_LOG_INFO = 1, | ||
| 110 | 88 | ||
| 111 | /// | 89 | bool empty() const { return (m_settingValue == nullptr) ? true : false; } |
| 112 | ADDON_LOG_NOTICE = 2, | ||
| 113 | 90 | ||
| 91 | /// @defgroup cpp_kodi_addon_addonbase_Defs_CSettingValue_Help Value Help | ||
| 92 | /// @ingroup cpp_kodi_addon_addonbase_Defs_CSettingValue | ||
| 114 | /// | 93 | /// |
| 115 | ADDON_LOG_WARNING = 3, | 94 | /// <b>The following table contains values that can be set with @ref cpp_kodi_addon_addonbase_Defs_CSettingValue :</b> |
| 95 | /// | Name | Type | Get call | ||
| 96 | /// |------|------|---------- | ||
| 97 | /// | **Settings value as string** | `std::string` | @ref CSettingValue::GetString "GetString" | ||
| 98 | /// | **Settings value as integer** | `int` | @ref CSettingValue::GetInt "GetInt" | ||
| 99 | /// | **Settings value as unsigned integer** | `unsigned int` | @ref CSettingValue::GetUInt "GetUInt" | ||
| 100 | /// | **Settings value as boolean** | `bool` | @ref CSettingValue::GetBoolean "GetBoolean" | ||
| 101 | /// | **Settings value as floating point** | `float` | @ref CSettingValue::GetFloat "GetFloat" | ||
| 102 | /// | **Settings value as enum** | `enum` | @ref CSettingValue::GetEnum "GetEnum" | ||
| 103 | |||
| 104 | /// @addtogroup cpp_kodi_addon_addonbase_Defs_CSettingValue | ||
| 105 | ///@{ | ||
| 106 | |||
| 107 | /// @brief To get settings value as string. | ||
| 108 | std::string GetString() const { return (const char*)m_settingValue; } | ||
| 116 | 109 | ||
| 117 | /// | 110 | /// @brief To get settings value as integer. |
| 118 | ADDON_LOG_ERROR = 4, | 111 | int GetInt() const { return *(const int*)m_settingValue; } |
| 119 | 112 | ||
| 120 | /// | 113 | /// @brief To get settings value as unsigned integer. |
| 121 | ADDON_LOG_SEVERE = 5, | 114 | unsigned int GetUInt() const { return *(const unsigned int*)m_settingValue; } |
| 122 | 115 | ||
| 123 | /// | 116 | /// @brief To get settings value as boolean. |
| 124 | ADDON_LOG_FATAL = 6 | 117 | bool GetBoolean() const { return *(const bool*)m_settingValue; } |
| 125 | } AddonLog; | ||
| 126 | //------------------------------------------------------------------------------ | ||
| 127 | 118 | ||
| 128 | /*! | 119 | /// @brief To get settings value as floating point. |
| 129 | * @brief Handle used to return data from the PVR add-on to CPVRClient | 120 | float GetFloat() const { return *(const float*)m_settingValue; } |
| 130 | */ | ||
| 131 | struct ADDON_HANDLE_STRUCT | ||
| 132 | { | ||
| 133 | void *callerAddress; /*!< address of the caller */ | ||
| 134 | void *dataAddress; /*!< address to store data in */ | ||
| 135 | int dataIdentifier; /*!< parameter to pass back when calling the callback */ | ||
| 136 | }; | ||
| 137 | typedef ADDON_HANDLE_STRUCT *ADDON_HANDLE; | ||
| 138 | 121 | ||
| 139 | /* | 122 | /// @brief To get settings value as enum. |
| 140 | * To have a on add-on and kodi itself handled string always on known size! | 123 | /// @note Inside settings.xml them stored as integer. |
| 141 | */ | 124 | template<typename enumType> |
| 142 | #define ADDON_STANDARD_STRING_LENGTH 1024 | 125 | enumType GetEnum() const |
| 143 | #define ADDON_STANDARD_STRING_LENGTH_SMALL 256 | 126 | { |
| 127 | return static_cast<enumType>(*(const int*)m_settingValue); | ||
| 128 | } | ||
| 144 | 129 | ||
| 145 | /* | 130 | ///@} |
| 146 | * Callback function tables from addon to Kodi | ||
| 147 | * Set complete from Kodi! | ||
| 148 | */ | ||
| 149 | struct AddonToKodiFuncTable_kodi; | ||
| 150 | struct AddonToKodiFuncTable_kodi_audioengine; | ||
| 151 | struct AddonToKodiFuncTable_kodi_filesystem; | ||
| 152 | struct AddonToKodiFuncTable_kodi_network; | ||
| 153 | struct AddonToKodiFuncTable_kodi_gui; | ||
| 154 | typedef struct AddonToKodiFuncTable_Addon | ||
| 155 | { | ||
| 156 | // Pointer inside Kodi, used on callback functions to give related handle | ||
| 157 | // class, for this ADDON::CAddonDll inside Kodi. | ||
| 158 | KODI_HANDLE kodiBase; | ||
| 159 | |||
| 160 | // Function addresses used for callbacks from addon to Kodi | ||
| 161 | void (*free_string)(void* kodiBase, char* str); | ||
| 162 | void (*free_string_array)(void* kodiBase, char** arr, int numElements); | ||
| 163 | char* (*get_addon_path)(void* kodiBase); | ||
| 164 | char* (*get_base_user_path)(void* kodiBase); | ||
| 165 | void (*addon_log_msg)(void* kodiBase, const int loglevel, const char *msg); | ||
| 166 | |||
| 167 | bool (*get_setting_bool)(void* kodiBase, const char* id, bool* value); | ||
| 168 | bool (*get_setting_int)(void* kodiBase, const char* id, int* value); | ||
| 169 | bool (*get_setting_float)(void* kodiBase, const char* id, float* value); | ||
| 170 | bool (*get_setting_string)(void* kodiBase, const char* id, char** value); | ||
| 171 | |||
| 172 | bool (*set_setting_bool)(void* kodiBase, const char* id, bool value); | ||
| 173 | bool (*set_setting_int)(void* kodiBase, const char* id, int value); | ||
| 174 | bool (*set_setting_float)(void* kodiBase, const char* id, float value); | ||
| 175 | bool (*set_setting_string)(void* kodiBase, const char* id, const char* value); | ||
| 176 | |||
| 177 | AddonToKodiFuncTable_kodi* kodi; | ||
| 178 | AddonToKodiFuncTable_kodi_audioengine* kodi_audioengine; | ||
| 179 | AddonToKodiFuncTable_kodi_filesystem* kodi_filesystem; | ||
| 180 | AddonToKodiFuncTable_kodi_gui* kodi_gui; | ||
| 181 | AddonToKodiFuncTable_kodi_network *kodi_network; | ||
| 182 | |||
| 183 | void* (*get_interface)(void* kodiBase, const char *name, const char *version); | ||
| 184 | } AddonToKodiFuncTable_Addon; | ||
| 185 | 131 | ||
| 186 | /* | 132 | private: |
| 187 | * Function tables from Kodi to addon | 133 | const void* m_settingValue; |
| 188 | */ | 134 | }; |
| 189 | typedef struct KodiToAddonFuncTable_Addon | 135 | ///@} |
| 190 | { | 136 | //------------------------------------------------------------------------------ |
| 191 | void (*destroy)(); | ||
| 192 | ADDON_STATUS (*get_status)(); | ||
| 193 | ADDON_STATUS (*create_instance)(int instanceType, const char* instanceID, KODI_HANDLE instance, KODI_HANDLE* addonInstance, KODI_HANDLE parent); | ||
| 194 | void (*destroy_instance)(int instanceType, KODI_HANDLE instance); | ||
| 195 | ADDON_STATUS (*set_setting)(const char *settingName, const void *settingValue); | ||
| 196 | ADDON_STATUS(*create_instance_ex)(int instanceType, const char* instanceID, KODI_HANDLE instance, KODI_HANDLE* addonInstance, KODI_HANDLE parent, const char* version); | ||
| 197 | } KodiToAddonFuncTable_Addon; | ||
| 198 | 137 | ||
| 199 | /* | 138 | namespace addon |
| 200 | * Main structure passed from kodi to addon with basic information needed to | ||
| 201 | * create add-on. | ||
| 202 | */ | ||
| 203 | typedef struct AddonGlobalInterface | ||
| 204 | { | 139 | { |
| 205 | // String with full path where add-on is installed (without his name on end) | ||
| 206 | // Set from Kodi! | ||
| 207 | const char* libBasePath; | ||
| 208 | |||
| 209 | // Pointer of first created instance, used in case this add-on goes with single way | ||
| 210 | // Set from Kodi! | ||
| 211 | KODI_HANDLE firstKodiInstance; | ||
| 212 | |||
| 213 | // Pointer to master base class inside add-on | ||
| 214 | // Set from addon header! | ||
| 215 | kodi::addon::CAddonBase* addonBase; | ||
| 216 | |||
| 217 | // Pointer to a instance used on single way (together with this class) | ||
| 218 | // Set from addon header! | ||
| 219 | kodi::addon::IAddonInstance* globalSingleInstance; | ||
| 220 | |||
| 221 | // Callback function tables from addon to Kodi | ||
| 222 | // Set from Kodi! | ||
| 223 | AddonToKodiFuncTable_Addon* toKodi; | ||
| 224 | |||
| 225 | // Function tables from Kodi to addon | ||
| 226 | // Set from addon header! | ||
| 227 | KodiToAddonFuncTable_Addon* toAddon; | ||
| 228 | } AddonGlobalInterface; | ||
| 229 | |||
| 230 | } /* extern "C" */ | ||
| 231 | 140 | ||
| 232 | //============================================================================== | 141 | //============================================================================== |
| 233 | namespace kodi { | ||
| 234 | namespace addon { | ||
| 235 | /* | 142 | /* |
| 236 | * Internal class to control various instance types with general parts defined | 143 | * Internal class to control various instance types with general parts defined |
| 237 | * here. | 144 | * here. |
| @@ -241,66 +148,147 @@ namespace addon { | |||
| 241 | * @note This class is not need to know during add-on development thats why | 148 | * @note This class is not need to know during add-on development thats why |
| 242 | * commented with "*". | 149 | * commented with "*". |
| 243 | */ | 150 | */ |
| 244 | class IAddonInstance | 151 | class ATTRIBUTE_HIDDEN IAddonInstance |
| 245 | { | 152 | { |
| 246 | public: | 153 | public: |
| 247 | explicit IAddonInstance(ADDON_TYPE type) : m_type(type) { } | 154 | explicit IAddonInstance(ADDON_TYPE type, const std::string& version) |
| 248 | virtual ~IAddonInstance() = default; | 155 | : m_type(type), m_kodiVersion(version) |
| 249 | |||
| 250 | virtual ADDON_STATUS CreateInstance(int instanceType, std::string instanceID, KODI_HANDLE instance, KODI_HANDLE& addonInstance) | ||
| 251 | { | 156 | { |
| 252 | return ADDON_STATUS_NOT_IMPLEMENTED; | ||
| 253 | } | 157 | } |
| 158 | virtual ~IAddonInstance() = default; | ||
| 254 | 159 | ||
| 255 | virtual ADDON_STATUS CreateInstanceEx(int instanceType, std::string instanceID, KODI_HANDLE instance, KODI_HANDLE& addonInstance, const std::string &version) | 160 | virtual ADDON_STATUS CreateInstance(int instanceType, |
| 161 | const std::string& instanceID, | ||
| 162 | KODI_HANDLE instance, | ||
| 163 | const std::string& version, | ||
| 164 | KODI_HANDLE& addonInstance) | ||
| 256 | { | 165 | { |
| 257 | return CreateInstance(instanceType, instanceID, instance, addonInstance); | 166 | return ADDON_STATUS_NOT_IMPLEMENTED; |
| 258 | } | 167 | } |
| 259 | 168 | ||
| 260 | const ADDON_TYPE m_type; | 169 | const ADDON_TYPE m_type; |
| 170 | const std::string m_kodiVersion; | ||
| 171 | std::string m_id; | ||
| 261 | }; | 172 | }; |
| 262 | } /* namespace addon */ | ||
| 263 | } /* namespace kodi */ | ||
| 264 | //------------------------------------------------------------------------------ | ||
| 265 | 173 | ||
| 266 | //============================================================================== | 174 | /* |
| 267 | namespace kodi { | 175 | * Internally used helper class to manage processing of a "C" structure in "CPP" |
| 268 | /// | 176 | * class. |
| 269 | class CSettingValue | 177 | * |
| 178 | * At constant, the "C" structure is copied, otherwise the given pointer is | ||
| 179 | * superseded and is changeable. | ||
| 180 | * | ||
| 181 | * ----------------------------------------------------------------------------- | ||
| 182 | * | ||
| 183 | * Example: | ||
| 184 | * | ||
| 185 | * ~~~~~~~~~~~~~{.cpp} | ||
| 186 | * extern "C" typedef struct C_SAMPLE_DATA | ||
| 187 | * { | ||
| 188 | * unsigned int iUniqueId; | ||
| 189 | * } C_SAMPLE_DATA; | ||
| 190 | * | ||
| 191 | * class CPPSampleData : public CStructHdl<CPPSampleData, C_SAMPLE_DATA> | ||
| 192 | * { | ||
| 193 | * public: | ||
| 194 | * CPPSampleData() = default; | ||
| 195 | * CPPSampleData(const CPPSampleData& sample) : CStructHdl(sample) { } | ||
| 196 | * CPPSampleData(const C_SAMPLE_DATA* sample) : CStructHdl(sample) { } | ||
| 197 | * CPPSampleData(C_SAMPLE_DATA* sample) : CStructHdl(sample) { } | ||
| 198 | * | ||
| 199 | * void SetUniqueId(unsigned int uniqueId) { m_cStructure->iUniqueId = uniqueId; } | ||
| 200 | * unsigned int GetUniqueId() const { return m_cStructure->iUniqueId; } | ||
| 201 | * }; | ||
| 202 | * | ||
| 203 | * ~~~~~~~~~~~~~ | ||
| 204 | * | ||
| 205 | * It also works with the following example: | ||
| 206 | * | ||
| 207 | * ~~~~~~~~~~~~~{.cpp} | ||
| 208 | * CPPSampleData test; | ||
| 209 | * // Some work | ||
| 210 | * C_SAMPLE_DATA* data = test; | ||
| 211 | * // Give "data" to Kodi | ||
| 212 | * ~~~~~~~~~~~~~ | ||
| 213 | */ | ||
| 214 | template<class CPP_CLASS, typename C_STRUCT> | ||
| 215 | class CStructHdl | ||
| 270 | { | 216 | { |
| 271 | public: | 217 | public: |
| 272 | explicit CSettingValue(const void *settingValue) : m_settingValue(settingValue) {} | 218 | CStructHdl() : m_cStructure(new C_STRUCT()), m_owner(true) {} |
| 273 | 219 | ||
| 274 | bool empty() const { return (m_settingValue == nullptr) ? true : false; } | 220 | CStructHdl(const CPP_CLASS& cppClass) |
| 275 | std::string GetString() const { return (const char*)m_settingValue; } | 221 | : m_cStructure(new C_STRUCT(*cppClass.m_cStructure)), m_owner(true) |
| 276 | int GetInt() const { return *(const int*)m_settingValue; } | 222 | { |
| 277 | unsigned int GetUInt() const { return *(const unsigned int*)m_settingValue; } | 223 | } |
| 278 | bool GetBoolean() const { return *(const bool*)m_settingValue; } | 224 | |
| 279 | float GetFloat() const { return *(const float*)m_settingValue; } | 225 | CStructHdl(const C_STRUCT* cStructure) : m_cStructure(new C_STRUCT(*cStructure)), m_owner(true) {} |
| 226 | |||
| 227 | CStructHdl(C_STRUCT* cStructure) : m_cStructure(cStructure) { assert(cStructure); } | ||
| 228 | |||
| 229 | const CStructHdl& operator=(const CStructHdl& right) | ||
| 230 | { | ||
| 231 | assert(&right.m_cStructure); | ||
| 232 | if (m_cStructure && !m_owner) | ||
| 233 | { | ||
| 234 | memcpy(m_cStructure, right.m_cStructure, sizeof(C_STRUCT)); | ||
| 235 | } | ||
| 236 | else | ||
| 237 | { | ||
| 238 | if (m_owner) | ||
| 239 | delete m_cStructure; | ||
| 240 | m_owner = true; | ||
| 241 | m_cStructure = new C_STRUCT(*right.m_cStructure); | ||
| 242 | } | ||
| 243 | return *this; | ||
| 244 | } | ||
| 245 | |||
| 246 | const CStructHdl& operator=(const C_STRUCT& right) | ||
| 247 | { | ||
| 248 | assert(&right); | ||
| 249 | if (m_cStructure && !m_owner) | ||
| 250 | { | ||
| 251 | memcpy(m_cStructure, &right, sizeof(C_STRUCT)); | ||
| 252 | } | ||
| 253 | else | ||
| 254 | { | ||
| 255 | if (m_owner) | ||
| 256 | delete m_cStructure; | ||
| 257 | m_owner = true; | ||
| 258 | m_cStructure = new C_STRUCT(*right); | ||
| 259 | } | ||
| 260 | return *this; | ||
| 261 | } | ||
| 262 | |||
| 263 | virtual ~CStructHdl() | ||
| 264 | { | ||
| 265 | if (m_owner) | ||
| 266 | delete m_cStructure; | ||
| 267 | } | ||
| 268 | |||
| 269 | operator C_STRUCT*() { return m_cStructure; } | ||
| 270 | operator const C_STRUCT*() const { return m_cStructure; } | ||
| 271 | |||
| 272 | const C_STRUCT* GetCStructure() const { return m_cStructure; } | ||
| 273 | |||
| 274 | protected: | ||
| 275 | C_STRUCT* m_cStructure = nullptr; | ||
| 280 | 276 | ||
| 281 | private: | 277 | private: |
| 282 | const void *m_settingValue; | 278 | bool m_owner = false; |
| 283 | }; | 279 | }; |
| 284 | } /* namespace kodi */ | ||
| 285 | //------------------------------------------------------------------------------ | ||
| 286 | 280 | ||
| 287 | //============================================================================== | ||
| 288 | namespace kodi { | ||
| 289 | namespace addon { | ||
| 290 | /// Add-on main instance class. | 281 | /// Add-on main instance class. |
| 291 | class ATTRIBUTE_HIDDEN CAddonBase | 282 | class ATTRIBUTE_HIDDEN CAddonBase |
| 292 | { | 283 | { |
| 293 | public: | 284 | public: |
| 294 | CAddonBase() | 285 | CAddonBase() |
| 295 | { | 286 | { |
| 296 | CAddonBase::m_interface->toAddon->destroy = ADDONBASE_Destroy; | 287 | m_interface->toAddon->destroy = ADDONBASE_Destroy; |
| 297 | CAddonBase::m_interface->toAddon->get_status = ADDONBASE_GetStatus; | 288 | m_interface->toAddon->get_status = ADDONBASE_GetStatus; |
| 298 | CAddonBase::m_interface->toAddon->create_instance = ADDONBASE_CreateInstance; | 289 | m_interface->toAddon->create_instance = ADDONBASE_CreateInstance; |
| 299 | CAddonBase::m_interface->toAddon->destroy_instance = ADDONBASE_DestroyInstance; | 290 | m_interface->toAddon->destroy_instance = ADDONBASE_DestroyInstance; |
| 300 | CAddonBase::m_interface->toAddon->set_setting = ADDONBASE_SetSetting; | 291 | m_interface->toAddon->set_setting = ADDONBASE_SetSetting; |
| 301 | // If version is present, we know that kodi has create_instance_ex implemented | ||
| 302 | if (!CAddonBase::m_strGlobalApiVersion.empty()) | ||
| 303 | CAddonBase::m_interface->toAddon->create_instance_ex = ADDONBASE_CreateInstanceEx; | ||
| 304 | } | 292 | } |
| 305 | 293 | ||
| 306 | virtual ~CAddonBase() = default; | 294 | virtual ~CAddonBase() = default; |
| @@ -309,97 +297,301 @@ public: | |||
| 309 | 297 | ||
| 310 | virtual ADDON_STATUS GetStatus() { return ADDON_STATUS_OK; } | 298 | virtual ADDON_STATUS GetStatus() { return ADDON_STATUS_OK; } |
| 311 | 299 | ||
| 312 | virtual ADDON_STATUS SetSetting(const std::string& settingName, const CSettingValue& settingValue) { return ADDON_STATUS_UNKNOWN; } | 300 | //============================================================================ |
| 313 | 301 | /// @ingroup cpp_kodi_addon_addonbase | |
| 314 | virtual ADDON_STATUS CreateInstance(int instanceType, std::string instanceID, KODI_HANDLE instance, KODI_HANDLE& addonInstance) | 302 | /// @brief To inform addon about changed settings values. |
| 303 | /// | ||
| 304 | /// This becomes called for every entry defined inside his settings.xml and | ||
| 305 | /// as **last** call the one where last in xml (to identify end of calls). | ||
| 306 | /// | ||
| 307 | /// -------------------------------------------------------------------------- | ||
| 308 | /// | ||
| 309 | /// @copydetails cpp_kodi_addon_addonbase_Defs_CSettingValue_Help | ||
| 310 | /// | ||
| 311 | /// | ||
| 312 | /// -------------------------------------------------------------------------- | ||
| 313 | /// | ||
| 314 | /// **Here is a code example how this is used:** | ||
| 315 | /// | ||
| 316 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 317 | /// #include <kodi/AddonBase.h> | ||
| 318 | /// | ||
| 319 | /// enum myEnumValue | ||
| 320 | /// { | ||
| 321 | /// valueA, | ||
| 322 | /// valueB, | ||
| 323 | /// valueC | ||
| 324 | /// }; | ||
| 325 | /// | ||
| 326 | /// std::string m_myStringValue; | ||
| 327 | /// int m_myIntegerValue; | ||
| 328 | /// bool m_myBooleanValue; | ||
| 329 | /// float m_myFloatingPointValue; | ||
| 330 | /// myEnumValue m_myEnumValue; | ||
| 331 | /// | ||
| 332 | /// | ||
| 333 | /// ADDON_STATUS CMyAddon::SetSetting(const std::string& settingName, const kodi::CSettingValue& settingValue) | ||
| 334 | /// { | ||
| 335 | /// if (settingName == "my_string_value") | ||
| 336 | /// m_myStringValue = settingValue.GetString(); | ||
| 337 | /// else if (settingName == "my_integer_value") | ||
| 338 | /// m_myIntegerValue = settingValue.GetInt(); | ||
| 339 | /// else if (settingName == "my_boolean_value") | ||
| 340 | /// m_myBooleanValue = settingValue.GetBoolean(); | ||
| 341 | /// else if (settingName == "my_float_value") | ||
| 342 | /// m_myFloatingPointValue = settingValue.GetFloat(); | ||
| 343 | /// else if (settingName == "my_enum_value") | ||
| 344 | /// m_myEnumValue = settingValue.GetEnum<myEnumValue>(); | ||
| 345 | /// } | ||
| 346 | /// ~~~~~~~~~~~~~ | ||
| 347 | /// | ||
| 348 | /// @note The asked type should match the type used on settings.xml. | ||
| 349 | /// | ||
| 350 | virtual ADDON_STATUS SetSetting(const std::string& settingName, | ||
| 351 | const kodi::CSettingValue& settingValue) | ||
| 315 | { | 352 | { |
| 316 | /* The handling below is intended for the case of the add-on only one | ||
| 317 | * instance and this is integrated in the add-on base class. | ||
| 318 | */ | ||
| 319 | |||
| 320 | /* Check about single instance usage */ | ||
| 321 | if (CAddonBase::m_interface->firstKodiInstance == instance && // the kodi side instance pointer must be equal to first one | ||
| 322 | CAddonBase::m_interface->globalSingleInstance && // the addon side instance pointer must be set | ||
| 323 | CAddonBase::m_interface->globalSingleInstance->m_type == instanceType) // and the requested type must be equal with used add-on class | ||
| 324 | { | ||
| 325 | addonInstance = CAddonBase::m_interface->globalSingleInstance; | ||
| 326 | return ADDON_STATUS_OK; | ||
| 327 | } | ||
| 328 | |||
| 329 | return ADDON_STATUS_UNKNOWN; | 353 | return ADDON_STATUS_UNKNOWN; |
| 330 | } | 354 | } |
| 355 | //---------------------------------------------------------------------------- | ||
| 331 | 356 | ||
| 332 | virtual ADDON_STATUS CreateInstanceEx(int instanceType, std::string instanceID, KODI_HANDLE instance, KODI_HANDLE& addonInstance, const std::string &version) | 357 | //========================================================================== |
| 358 | /// @ingroup cpp_kodi_addon_addonbase | ||
| 359 | /// @brief Instance created | ||
| 360 | /// | ||
| 361 | /// @param[in] instanceType The requested type of required instance, see \ref ADDON_TYPE. | ||
| 362 | /// @param[in] instanceID An individual identification key string given by Kodi. | ||
| 363 | /// @param[in] instance The instance handler used by Kodi must be passed to | ||
| 364 | /// the classes created here. See in the example. | ||
| 365 | /// @param[in] version The from Kodi used version of instance. This can be | ||
| 366 | /// used to allow compatibility to older versions of | ||
| 367 | /// them. Further is this given to the parent instance | ||
| 368 | /// that it can handle differences. | ||
| 369 | /// @param[out] addonInstance The pointer to instance class created in addon. | ||
| 370 | /// Needed to be able to identify them on calls. | ||
| 371 | /// @return \ref ADDON_STATUS_OK if correct, for possible errors | ||
| 372 | /// see \ref ADDON_STATUS | ||
| 373 | /// | ||
| 374 | /// | ||
| 375 | /// -------------------------------------------------------------------------- | ||
| 376 | /// | ||
| 377 | /// **Here is a code example how this is used:** | ||
| 378 | /// | ||
| 379 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 380 | /// #include <kodi/AddonBase.h> | ||
| 381 | /// | ||
| 382 | /// ... | ||
| 383 | /// | ||
| 384 | /// /* If you use only one instance in your add-on, can be instanceType and | ||
| 385 | /// * instanceID ignored */ | ||
| 386 | /// ADDON_STATUS CMyAddon::CreateInstance(int instanceType, | ||
| 387 | /// const std::string& instanceID, | ||
| 388 | /// KODI_HANDLE instance, | ||
| 389 | /// const std::string& version, | ||
| 390 | /// KODI_HANDLE& addonInstance) | ||
| 391 | /// { | ||
| 392 | /// if (instanceType == ADDON_INSTANCE_SCREENSAVER) | ||
| 393 | /// { | ||
| 394 | /// kodi::Log(ADDON_LOG_NOTICE, "Creating my Screensaver"); | ||
| 395 | /// addonInstance = new CMyScreensaver(instance); | ||
| 396 | /// return ADDON_STATUS_OK; | ||
| 397 | /// } | ||
| 398 | /// else if (instanceType == ADDON_INSTANCE_VISUALIZATION) | ||
| 399 | /// { | ||
| 400 | /// kodi::Log(ADDON_LOG_NOTICE, "Creating my Visualization"); | ||
| 401 | /// addonInstance = new CMyVisualization(instance); | ||
| 402 | /// return ADDON_STATUS_OK; | ||
| 403 | /// } | ||
| 404 | /// else if (...) | ||
| 405 | /// { | ||
| 406 | /// ... | ||
| 407 | /// } | ||
| 408 | /// return ADDON_STATUS_UNKNOWN; | ||
| 409 | /// } | ||
| 410 | /// | ||
| 411 | /// ... | ||
| 412 | /// | ||
| 413 | /// ~~~~~~~~~~~~~ | ||
| 414 | /// | ||
| 415 | virtual ADDON_STATUS CreateInstance(int instanceType, | ||
| 416 | const std::string& instanceID, | ||
| 417 | KODI_HANDLE instance, | ||
| 418 | const std::string& version, | ||
| 419 | KODI_HANDLE& addonInstance) | ||
| 333 | { | 420 | { |
| 334 | return CreateInstance(instanceType, instanceID, instance, addonInstance); | 421 | return ADDON_STATUS_NOT_IMPLEMENTED; |
| 335 | } | 422 | } |
| 423 | //-------------------------------------------------------------------------- | ||
| 424 | |||
| 425 | //========================================================================== | ||
| 426 | /// @ingroup cpp_kodi_addon_addonbase | ||
| 427 | /// @brief Instance destroy | ||
| 428 | /// | ||
| 429 | /// This function is optional and intended to notify addon that the instance | ||
| 430 | /// is terminating. | ||
| 431 | /// | ||
| 432 | /// @param[in] instanceType The requested type of required instance, see \ref ADDON_TYPE. | ||
| 433 | /// @param[in] instanceID An individual identification key string given by Kodi. | ||
| 434 | /// @param[in] addonInstance The pointer to instance class created in addon. | ||
| 435 | /// | ||
| 436 | /// @warning This call is only used to inform that the associated instance | ||
| 437 | /// is terminated. The deletion is carried out in the background. | ||
| 438 | /// | ||
| 439 | virtual void DestroyInstance(int instanceType, | ||
| 440 | const std::string& instanceID, | ||
| 441 | KODI_HANDLE addonInstance) | ||
| 442 | { | ||
| 443 | } | ||
| 444 | //-------------------------------------------------------------------------- | ||
| 445 | |||
| 446 | /* Background helper for GUI render systems, e.g. Screensaver or Visualization */ | ||
| 447 | std::shared_ptr<kodi::gui::IRenderHelper> m_renderHelper; | ||
| 336 | 448 | ||
| 337 | /* Global variables of class */ | 449 | /* Global variables of class */ |
| 338 | static AddonGlobalInterface* m_interface; // Interface function table to hold addresses on add-on and from kodi | 450 | static AddonGlobalInterface* |
| 339 | static std::string m_strGlobalApiVersion; | 451 | m_interface; // Interface function table to hold addresses on add-on and from kodi |
| 340 | 452 | ||
| 341 | /*private:*/ /* Needed public as long the old call functions becomes used! */ | 453 | /*private:*/ /* Needed public as long the old call functions becomes used! */ |
| 342 | static inline void ADDONBASE_Destroy() | 454 | static inline void ADDONBASE_Destroy() |
| 343 | { | 455 | { |
| 344 | delete CAddonBase::m_interface->addonBase; | 456 | delete static_cast<CAddonBase*>(m_interface->addonBase); |
| 345 | CAddonBase::m_interface->addonBase = nullptr; | 457 | m_interface->addonBase = nullptr; |
| 346 | } | 458 | } |
| 347 | 459 | ||
| 348 | static inline ADDON_STATUS ADDONBASE_GetStatus() { return CAddonBase::m_interface->addonBase->GetStatus(); } | 460 | static inline ADDON_STATUS ADDONBASE_GetStatus() |
| 349 | |||
| 350 | static inline ADDON_STATUS ADDONBASE_SetSetting(const char *settingName, const void *settingValue) | ||
| 351 | { | 461 | { |
| 352 | return CAddonBase::m_interface->addonBase->SetSetting(settingName, CSettingValue(settingValue)); | 462 | return static_cast<CAddonBase*>(m_interface->addonBase)->GetStatus(); |
| 353 | } | 463 | } |
| 354 | 464 | ||
| 355 | static inline ADDON_STATUS ADDONBASE_CreateInstance(int instanceType, const char* instanceID, KODI_HANDLE instance, KODI_HANDLE* addonInstance, KODI_HANDLE parent) | 465 | static inline ADDON_STATUS ADDONBASE_SetSetting(const char* settingName, const void* settingValue) |
| 356 | { | 466 | { |
| 357 | return ADDONBASE_CreateInstanceEx(instanceType, instanceID, instance, addonInstance, parent, ""); | 467 | return static_cast<CAddonBase*>(m_interface->addonBase) |
| 468 | ->SetSetting(settingName, CSettingValue(settingValue)); | ||
| 358 | } | 469 | } |
| 359 | 470 | ||
| 360 | static inline ADDON_STATUS ADDONBASE_CreateInstanceEx(int instanceType, const char* instanceID, KODI_HANDLE instance, KODI_HANDLE* addonInstance, KODI_HANDLE parent, const char* version) | 471 | private: |
| 472 | static inline ADDON_STATUS ADDONBASE_CreateInstance(int instanceType, | ||
| 473 | const char* instanceID, | ||
| 474 | KODI_HANDLE instance, | ||
| 475 | const char* version, | ||
| 476 | KODI_HANDLE* addonInstance, | ||
| 477 | KODI_HANDLE parent) | ||
| 361 | { | 478 | { |
| 479 | CAddonBase* base = static_cast<CAddonBase*>(m_interface->addonBase); | ||
| 480 | |||
| 362 | ADDON_STATUS status = ADDON_STATUS_NOT_IMPLEMENTED; | 481 | ADDON_STATUS status = ADDON_STATUS_NOT_IMPLEMENTED; |
| 363 | if (parent != nullptr) | 482 | |
| 364 | status = static_cast<IAddonInstance*>(parent)->CreateInstanceEx(instanceType, instanceID, instance, *addonInstance, version); | 483 | /* Check about single instance usage: |
| 365 | if (status == ADDON_STATUS_NOT_IMPLEMENTED) | 484 | * 1. The kodi side instance pointer must be equal to first one |
| 366 | status = CAddonBase::m_interface->addonBase->CreateInstanceEx(instanceType, instanceID, instance, *addonInstance, version); | 485 | * 2. The addon side instance pointer must be set |
| 486 | * 3. And the requested type must be equal with used add-on class | ||
| 487 | */ | ||
| 488 | if (m_interface->firstKodiInstance == instance && m_interface->globalSingleInstance && | ||
| 489 | static_cast<IAddonInstance*>(m_interface->globalSingleInstance)->m_type == instanceType) | ||
| 490 | { | ||
| 491 | /* The handling here is intended for the case of the add-on only one | ||
| 492 | * instance and this is integrated in the add-on base class. | ||
| 493 | */ | ||
| 494 | *addonInstance = m_interface->globalSingleInstance; | ||
| 495 | status = ADDON_STATUS_OK; | ||
| 496 | } | ||
| 497 | else | ||
| 498 | { | ||
| 499 | /* Here it should use the CreateInstance instance function to allow | ||
| 500 | * creation of several on one addon. | ||
| 501 | */ | ||
| 502 | |||
| 503 | /* Check first a parent is defined about (e.g. Codec within inputstream) */ | ||
| 504 | if (parent != nullptr) | ||
| 505 | status = static_cast<IAddonInstance*>(parent)->CreateInstance( | ||
| 506 | instanceType, instanceID, instance, version, *addonInstance); | ||
| 507 | |||
| 508 | /* if no parent call the main instance creation function to get it */ | ||
| 509 | if (status == ADDON_STATUS_NOT_IMPLEMENTED) | ||
| 510 | { | ||
| 511 | status = base->CreateInstance(instanceType, instanceID, instance, version, *addonInstance); | ||
| 512 | } | ||
| 513 | } | ||
| 514 | |||
| 367 | if (*addonInstance == nullptr) | 515 | if (*addonInstance == nullptr) |
| 368 | throw std::logic_error("kodi::addon::CAddonBase CreateInstanceEx returns a empty instance pointer!"); | 516 | { |
| 517 | if (status == ADDON_STATUS_OK) | ||
| 518 | { | ||
| 519 | m_interface->toKodi->addon_log_msg(m_interface->toKodi->kodiBase, ADDON_LOG_FATAL, | ||
| 520 | "kodi::addon::CAddonBase CreateInstance returned an " | ||
| 521 | "empty instance pointer, but reported OK!"); | ||
| 522 | return ADDON_STATUS_PERMANENT_FAILURE; | ||
| 523 | } | ||
| 524 | else | ||
| 525 | { | ||
| 526 | return status; | ||
| 527 | } | ||
| 528 | } | ||
| 529 | |||
| 530 | if (static_cast<IAddonInstance*>(*addonInstance)->m_type != instanceType) | ||
| 531 | { | ||
| 532 | m_interface->toKodi->addon_log_msg( | ||
| 533 | m_interface->toKodi->kodiBase, ADDON_LOG_FATAL, | ||
| 534 | "kodi::addon::CAddonBase CreateInstance difference between given and returned"); | ||
| 535 | delete static_cast<IAddonInstance*>(*addonInstance); | ||
| 536 | *addonInstance = nullptr; | ||
| 537 | return ADDON_STATUS_PERMANENT_FAILURE; | ||
| 538 | } | ||
| 369 | 539 | ||
| 370 | if (static_cast<::kodi::addon::IAddonInstance*>(*addonInstance)->m_type != instanceType) | 540 | // Store the used ID inside instance, to have on destroy calls by addon to identify |
| 371 | throw std::logic_error("kodi::addon::CAddonBase CreateInstanceEx with difference on given and returned instance type!"); | 541 | static_cast<IAddonInstance*>(*addonInstance)->m_id = instanceID; |
| 372 | 542 | ||
| 373 | return status; | 543 | return status; |
| 374 | } | 544 | } |
| 375 | 545 | ||
| 376 | static inline void ADDONBASE_DestroyInstance(int instanceType, KODI_HANDLE instance) | 546 | static inline void ADDONBASE_DestroyInstance(int instanceType, KODI_HANDLE instance) |
| 377 | { | 547 | { |
| 378 | if (CAddonBase::m_interface->globalSingleInstance == nullptr && instance != CAddonBase::m_interface->addonBase) | 548 | CAddonBase* base = static_cast<CAddonBase*>(m_interface->addonBase); |
| 549 | |||
| 550 | if (m_interface->globalSingleInstance == nullptr && instance != base) | ||
| 379 | { | 551 | { |
| 380 | if (static_cast<::kodi::addon::IAddonInstance*>(instance)->m_type == instanceType) | 552 | base->DestroyInstance(instanceType, static_cast<IAddonInstance*>(instance)->m_id, instance); |
| 381 | delete static_cast<::kodi::addon::IAddonInstance*>(instance); | 553 | delete static_cast<IAddonInstance*>(instance); |
| 382 | else | ||
| 383 | throw std::logic_error("kodi::addon::CAddonBase DestroyInstance called with difference on given and present instance type!"); | ||
| 384 | } | 554 | } |
| 385 | } | 555 | } |
| 386 | }; | 556 | }; |
| 557 | |||
| 387 | } /* namespace addon */ | 558 | } /* namespace addon */ |
| 388 | } /* namespace kodi */ | 559 | |
| 560 | //============================================================================== | ||
| 561 | /// @ingroup cpp_kodi_addon | ||
| 562 | /// @brief To get used version inside Kodi itself about asked type. | ||
| 563 | /// | ||
| 564 | /// This thought to allow a addon a handling of newer addon versions within | ||
| 565 | /// older Kodi until the type min version not changed. | ||
| 566 | /// | ||
| 567 | /// @param[in] type The wanted type of @ref ADDON_TYPE to ask | ||
| 568 | /// @return The version string about type in MAJOR.MINOR.PATCH style. | ||
| 569 | /// | ||
| 570 | inline std::string ATTRIBUTE_HIDDEN GetKodiTypeVersion(int type) | ||
| 571 | { | ||
| 572 | using namespace kodi::addon; | ||
| 573 | |||
| 574 | char* str = CAddonBase::m_interface->toKodi->get_type_version( | ||
| 575 | CAddonBase::m_interface->toKodi->kodiBase, type); | ||
| 576 | std::string ret = str; | ||
| 577 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, str); | ||
| 578 | return ret; | ||
| 579 | } | ||
| 389 | //------------------------------------------------------------------------------ | 580 | //------------------------------------------------------------------------------ |
| 390 | 581 | ||
| 391 | //============================================================================== | 582 | //============================================================================== |
| 392 | namespace kodi { | ||
| 393 | /// | 583 | /// |
| 394 | inline std::string GetAddonPath(const std::string& append = "") | 584 | inline std::string ATTRIBUTE_HIDDEN GetAddonPath(const std::string& append = "") |
| 395 | { | 585 | { |
| 396 | char* str = ::kodi::addon::CAddonBase::m_interface->toKodi->get_addon_path(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase); | 586 | using namespace kodi::addon; |
| 587 | |||
| 588 | char* str = | ||
| 589 | CAddonBase::m_interface->toKodi->get_addon_path(CAddonBase::m_interface->toKodi->kodiBase); | ||
| 397 | std::string ret = str; | 590 | std::string ret = str; |
| 398 | ::kodi::addon::CAddonBase::m_interface->toKodi->free_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, str); | 591 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, str); |
| 399 | if (!append.empty()) | 592 | if (!append.empty()) |
| 400 | { | 593 | { |
| 401 | if (append.at(0) != '\\' && | 594 | if (append.at(0) != '\\' && append.at(0) != '/') |
| 402 | append.at(0) != '/') | ||
| 403 | #ifdef TARGET_WINDOWS | 595 | #ifdef TARGET_WINDOWS |
| 404 | ret.append("\\"); | 596 | ret.append("\\"); |
| 405 | #else | 597 | #else |
| @@ -409,21 +601,21 @@ inline std::string GetAddonPath(const std::string& append = "") | |||
| 409 | } | 601 | } |
| 410 | return ret; | 602 | return ret; |
| 411 | } | 603 | } |
| 412 | } /* namespace kodi */ | ||
| 413 | //------------------------------------------------------------------------------ | 604 | //------------------------------------------------------------------------------ |
| 414 | 605 | ||
| 415 | //============================================================================== | 606 | //============================================================================== |
| 416 | namespace kodi { | ||
| 417 | /// | 607 | /// |
| 418 | inline std::string GetBaseUserPath(const std::string& append = "") | 608 | inline std::string ATTRIBUTE_HIDDEN GetBaseUserPath(const std::string& append = "") |
| 419 | { | 609 | { |
| 420 | char* str = ::kodi::addon::CAddonBase::m_interface->toKodi->get_base_user_path(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase); | 610 | using namespace kodi::addon; |
| 611 | |||
| 612 | char* str = CAddonBase::m_interface->toKodi->get_base_user_path( | ||
| 613 | CAddonBase::m_interface->toKodi->kodiBase); | ||
| 421 | std::string ret = str; | 614 | std::string ret = str; |
| 422 | ::kodi::addon::CAddonBase::m_interface->toKodi->free_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, str); | 615 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, str); |
| 423 | if (!append.empty()) | 616 | if (!append.empty()) |
| 424 | { | 617 | { |
| 425 | if (append.at(0) != '\\' && | 618 | if (append.at(0) != '\\' && append.at(0) != '/') |
| 426 | append.at(0) != '/') | ||
| 427 | #ifdef TARGET_WINDOWS | 619 | #ifdef TARGET_WINDOWS |
| 428 | ret.append("\\"); | 620 | ret.append("\\"); |
| 429 | #else | 621 | #else |
| @@ -433,174 +625,574 @@ inline std::string GetBaseUserPath(const std::string& append = "") | |||
| 433 | } | 625 | } |
| 434 | return ret; | 626 | return ret; |
| 435 | } | 627 | } |
| 436 | } /* namespace kodi */ | ||
| 437 | //------------------------------------------------------------------------------ | 628 | //------------------------------------------------------------------------------ |
| 438 | 629 | ||
| 439 | //============================================================================== | 630 | //============================================================================== |
| 440 | namespace kodi { | ||
| 441 | /// | 631 | /// |
| 442 | inline std::string GetLibPath() | 632 | inline std::string ATTRIBUTE_HIDDEN GetLibPath() |
| 443 | { | 633 | { |
| 444 | return ::kodi::addon::CAddonBase::m_interface->libBasePath; | 634 | using namespace kodi::addon; |
| 635 | |||
| 636 | return CAddonBase::m_interface->libBasePath; | ||
| 445 | } | 637 | } |
| 446 | } /* namespace kodi */ | ||
| 447 | //------------------------------------------------------------------------------ | 638 | //------------------------------------------------------------------------------ |
| 448 | 639 | ||
| 449 | //============================================================================== | 640 | //============================================================================== |
| 450 | namespace kodi { | 641 | /// @ingroup cpp_kodi |
| 642 | /// @brief Add a message to Kodi's log. | ||
| 643 | /// | ||
| 644 | /// @param[in] loglevel The log level of the message. | ||
| 645 | /// @param[in] format The format of the message to pass to Kodi. | ||
| 646 | /// @param[in] ... Additional text to insert in format text | ||
| 647 | /// | ||
| 648 | /// | ||
| 649 | /// @note This method uses limited buffer (16k) for the formatted output. | ||
| 650 | /// So data, which will not fit into it, will be silently discarded. | ||
| 451 | /// | 651 | /// |
| 452 | inline void Log(const AddonLog loglevel, const char* format, ...) | 652 | /// |
| 653 | /// ---------------------------------------------------------------------------- | ||
| 654 | /// | ||
| 655 | /// **Example:** | ||
| 656 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 657 | /// #include <kodi/General.h> | ||
| 658 | /// | ||
| 659 | /// kodi::Log(ADDON_LOG_ERROR, "%s: There is an error occurred!", __func__); | ||
| 660 | /// | ||
| 661 | /// ~~~~~~~~~~~~~ | ||
| 662 | /// | ||
| 663 | inline void ATTRIBUTE_HIDDEN Log(const AddonLog loglevel, const char* format, ...) | ||
| 453 | { | 664 | { |
| 665 | using namespace kodi::addon; | ||
| 666 | |||
| 454 | char buffer[16384]; | 667 | char buffer[16384]; |
| 455 | va_list args; | 668 | va_list args; |
| 456 | va_start(args, format); | 669 | va_start(args, format); |
| 457 | vsprintf(buffer, format, args); | 670 | vsnprintf(buffer, sizeof(buffer), format, args); |
| 458 | va_end(args); | 671 | va_end(args); |
| 459 | ::kodi::addon::CAddonBase::m_interface->toKodi->addon_log_msg(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, loglevel, buffer); | 672 | CAddonBase::m_interface->toKodi->addon_log_msg(CAddonBase::m_interface->toKodi->kodiBase, |
| 673 | loglevel, buffer); | ||
| 460 | } | 674 | } |
| 461 | } /* namespace kodi */ | ||
| 462 | //------------------------------------------------------------------------------ | 675 | //------------------------------------------------------------------------------ |
| 463 | 676 | ||
| 464 | //============================================================================ | 677 | //############################################################################## |
| 465 | namespace kodi { | 678 | /// @ingroup cpp_kodi |
| 679 | /// @defgroup cpp_kodi_settings 1. Setting control | ||
| 680 | /// @brief **Functions to handle settings access**\n | ||
| 681 | /// This can be used to get and set the addon related values inside his | ||
| 682 | /// settings.xml. | ||
| 683 | /// | ||
| 684 | /// The settings style is given with installed part on e.g. | ||
| 685 | /// <b>`$HOME/.kodi/addons/myspecial.addon/resources/settings.xml`</b>. The | ||
| 686 | /// related edit becomes then stored inside | ||
| 687 | /// <b>`$HOME/.kodi/userdata/addon_data/myspecial.addon/settings.xml`</b>. | ||
| 688 | /// | ||
| 689 | /*!@{*/ | ||
| 690 | |||
| 691 | //============================================================================== | ||
| 692 | /// @brief Check the given setting name is set to default value. | ||
| 466 | /// | 693 | /// |
| 467 | inline bool CheckSettingString(const std::string& settingName, std::string& settingValue) | 694 | /// The setting name relate to names used in his <b>settings.xml</b> file. |
| 695 | /// | ||
| 696 | /// @param[in] settingName The name of asked setting | ||
| 697 | /// @return true if setting is the default | ||
| 698 | /// | ||
| 699 | inline bool ATTRIBUTE_HIDDEN IsSettingUsingDefault(const std::string& settingName) | ||
| 468 | { | 700 | { |
| 701 | using namespace kodi::addon; | ||
| 702 | return CAddonBase::m_interface->toKodi->is_setting_using_default( | ||
| 703 | CAddonBase::m_interface->toKodi->kodiBase, settingName.c_str()); | ||
| 704 | } | ||
| 705 | //------------------------------------------------------------------------------ | ||
| 706 | |||
| 707 | //============================================================================== | ||
| 708 | /// @brief Check and get a string setting value. | ||
| 709 | /// | ||
| 710 | /// The setting name relate to names used in his <b>settings.xml</b> file. | ||
| 711 | /// | ||
| 712 | /// @param[in] settingName The name of asked setting | ||
| 713 | /// @param[out] settingValue The given setting value | ||
| 714 | /// @return true if setting was successfully found and "settingValue" is set | ||
| 715 | /// | ||
| 716 | /// @note If returns false, the "settingValue" is not changed. | ||
| 717 | /// | ||
| 718 | /// | ||
| 719 | /// ---------------------------------------------------------------------------- | ||
| 720 | /// | ||
| 721 | /// **Example:** | ||
| 722 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 723 | /// #include <kodi/General.h> | ||
| 724 | /// | ||
| 725 | /// std::string value; | ||
| 726 | /// if (!kodi::CheckSettingString("my_string_value", value)) | ||
| 727 | /// value = "my_default_if_setting_not_work"; | ||
| 728 | /// ~~~~~~~~~~~~~ | ||
| 729 | /// | ||
| 730 | inline bool ATTRIBUTE_HIDDEN CheckSettingString(const std::string& settingName, | ||
| 731 | std::string& settingValue) | ||
| 732 | { | ||
| 733 | using namespace kodi::addon; | ||
| 734 | |||
| 469 | char* buffer = nullptr; | 735 | char* buffer = nullptr; |
| 470 | bool ret = ::kodi::addon::CAddonBase::m_interface->toKodi->get_setting_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, settingName.c_str(), &buffer); | 736 | bool ret = CAddonBase::m_interface->toKodi->get_setting_string( |
| 737 | CAddonBase::m_interface->toKodi->kodiBase, settingName.c_str(), &buffer); | ||
| 471 | if (buffer) | 738 | if (buffer) |
| 472 | { | 739 | { |
| 473 | if (ret) | 740 | if (ret) |
| 474 | settingValue = buffer; | 741 | settingValue = buffer; |
| 475 | ::kodi::addon::CAddonBase::m_interface->toKodi->free_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, buffer); | 742 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, buffer); |
| 476 | } | 743 | } |
| 477 | return ret; | 744 | return ret; |
| 478 | } | 745 | } |
| 479 | } /* namespace kodi */ | 746 | //------------------------------------------------------------------------------ |
| 480 | //---------------------------------------------------------------------------- | ||
| 481 | 747 | ||
| 482 | //============================================================================ | 748 | //============================================================================== |
| 483 | namespace kodi { | 749 | /// @brief Get string setting value. |
| 750 | /// | ||
| 751 | /// The setting name relate to names used in his <b>settings.xml</b> file. | ||
| 752 | /// | ||
| 753 | /// @param[in] settingName The name of asked setting | ||
| 754 | /// @param[in] defaultValue [opt] Default value if not found | ||
| 755 | /// @return The value of setting, empty if not found; | ||
| 756 | /// | ||
| 757 | /// | ||
| 758 | /// ---------------------------------------------------------------------------- | ||
| 759 | /// | ||
| 760 | /// **Example:** | ||
| 761 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 762 | /// #include <kodi/General.h> | ||
| 763 | /// | ||
| 764 | /// std::string value = kodi::GetSettingString("my_string_value"); | ||
| 765 | /// ~~~~~~~~~~~~~ | ||
| 484 | /// | 766 | /// |
| 485 | inline std::string GetSettingString(const std::string& settingName) | 767 | inline std::string ATTRIBUTE_HIDDEN GetSettingString(const std::string& settingName, |
| 768 | const std::string& defaultValue = "") | ||
| 486 | { | 769 | { |
| 487 | std::string settingValue; | 770 | std::string settingValue = defaultValue; |
| 488 | CheckSettingString(settingName, settingValue); | 771 | CheckSettingString(settingName, settingValue); |
| 489 | return settingValue; | 772 | return settingValue; |
| 490 | } | 773 | } |
| 491 | } /* namespace kodi */ | 774 | //------------------------------------------------------------------------------ |
| 492 | //---------------------------------------------------------------------------- | ||
| 493 | 775 | ||
| 494 | //============================================================================ | 776 | //============================================================================== |
| 495 | namespace kodi { | 777 | /// @brief Set string setting of addon. |
| 778 | /// | ||
| 779 | /// The setting name relate to names used in his <b>settings.xml</b> file. | ||
| 780 | /// | ||
| 781 | /// @param[in] settingName The name of setting | ||
| 782 | /// @param[in] settingValue The setting value to write | ||
| 783 | /// | ||
| 496 | /// | 784 | /// |
| 497 | inline void SetSettingString(const std::string& settingName, const std::string& settingValue) | 785 | /// ---------------------------------------------------------------------------- |
| 786 | /// | ||
| 787 | /// **Example:** | ||
| 788 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 789 | /// #include <kodi/General.h> | ||
| 790 | /// | ||
| 791 | /// std::string value = "my_new_name for"; | ||
| 792 | /// kodi::SetSettingString("my_string_value", value); | ||
| 793 | /// ~~~~~~~~~~~~~ | ||
| 794 | /// | ||
| 795 | inline void ATTRIBUTE_HIDDEN SetSettingString(const std::string& settingName, | ||
| 796 | const std::string& settingValue) | ||
| 498 | { | 797 | { |
| 499 | ::kodi::addon::CAddonBase::m_interface->toKodi->set_setting_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, settingName.c_str(), settingValue.c_str()); | 798 | using namespace kodi::addon; |
| 799 | |||
| 800 | CAddonBase::m_interface->toKodi->set_setting_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 801 | settingName.c_str(), settingValue.c_str()); | ||
| 500 | } | 802 | } |
| 501 | } /* namespace kodi */ | 803 | //------------------------------------------------------------------------------ |
| 502 | //---------------------------------------------------------------------------- | ||
| 503 | 804 | ||
| 504 | //============================================================================ | 805 | //============================================================================== |
| 505 | namespace kodi { | 806 | /// @brief Check and get a integer setting value. |
| 807 | /// | ||
| 808 | /// The setting name relate to names used in his <b>settings.xml</b> file. | ||
| 809 | /// | ||
| 810 | /// @param[in] settingName The name of asked setting | ||
| 811 | /// @param[out] settingValue The given setting value | ||
| 812 | /// @return true if setting was successfully found and "settingValue" is set | ||
| 813 | /// | ||
| 814 | /// @note If returns false, the "settingValue" is not changed. | ||
| 506 | /// | 815 | /// |
| 507 | inline bool CheckSettingInt(const std::string& settingName, int& settingValue) | 816 | /// |
| 817 | /// ---------------------------------------------------------------------------- | ||
| 818 | /// | ||
| 819 | /// **Example:** | ||
| 820 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 821 | /// #include <kodi/General.h> | ||
| 822 | /// | ||
| 823 | /// int value = 0; | ||
| 824 | /// if (!kodi::CheckSettingInt("my_integer_value", value)) | ||
| 825 | /// value = 123; // My default of them | ||
| 826 | /// ~~~~~~~~~~~~~ | ||
| 827 | /// | ||
| 828 | inline bool ATTRIBUTE_HIDDEN CheckSettingInt(const std::string& settingName, int& settingValue) | ||
| 508 | { | 829 | { |
| 509 | return ::kodi::addon::CAddonBase::m_interface->toKodi->get_setting_int(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, settingName.c_str(), &settingValue); | 830 | using namespace kodi::addon; |
| 831 | |||
| 832 | return CAddonBase::m_interface->toKodi->get_setting_int(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 833 | settingName.c_str(), &settingValue); | ||
| 510 | } | 834 | } |
| 511 | } /* namespace kodi */ | 835 | //------------------------------------------------------------------------------ |
| 512 | //---------------------------------------------------------------------------- | ||
| 513 | 836 | ||
| 514 | //============================================================================ | 837 | //============================================================================== |
| 515 | namespace kodi { | 838 | /// @brief Get integer setting value. |
| 839 | /// | ||
| 840 | /// The setting name relate to names used in his <b>settings.xml</b> file. | ||
| 841 | /// | ||
| 842 | /// @param[in] settingName The name of asked setting | ||
| 843 | /// @param[in] defaultValue [opt] Default value if not found | ||
| 844 | /// @return The value of setting, <b>`0`</b> or defaultValue if not found | ||
| 516 | /// | 845 | /// |
| 517 | inline int GetSettingInt(const std::string& settingName) | 846 | /// |
| 847 | /// ---------------------------------------------------------------------------- | ||
| 848 | /// | ||
| 849 | /// **Example:** | ||
| 850 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 851 | /// #include <kodi/General.h> | ||
| 852 | /// | ||
| 853 | /// int value = kodi::GetSettingInt("my_integer_value"); | ||
| 854 | /// ~~~~~~~~~~~~~ | ||
| 855 | /// | ||
| 856 | inline int ATTRIBUTE_HIDDEN GetSettingInt(const std::string& settingName, int defaultValue = 0) | ||
| 518 | { | 857 | { |
| 519 | int settingValue = 0; | 858 | int settingValue = defaultValue; |
| 520 | CheckSettingInt(settingName, settingValue); | 859 | CheckSettingInt(settingName, settingValue); |
| 521 | return settingValue; | 860 | return settingValue; |
| 522 | } | 861 | } |
| 523 | } /* namespace kodi */ | 862 | //------------------------------------------------------------------------------ |
| 524 | //---------------------------------------------------------------------------- | ||
| 525 | 863 | ||
| 526 | //============================================================================ | 864 | //============================================================================== |
| 527 | namespace kodi { | 865 | /// @brief Set integer setting of addon. |
| 866 | /// | ||
| 867 | /// The setting name relate to names used in his <b>settings.xml</b> file. | ||
| 868 | /// | ||
| 869 | /// @param[in] settingName The name of setting | ||
| 870 | /// @param[in] settingValue The setting value to write | ||
| 528 | /// | 871 | /// |
| 529 | inline void SetSettingInt(const std::string& settingName, int settingValue) | 872 | /// |
| 873 | /// ---------------------------------------------------------------------------- | ||
| 874 | /// | ||
| 875 | /// **Example:** | ||
| 876 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 877 | /// #include <kodi/General.h> | ||
| 878 | /// | ||
| 879 | /// int value = 123; | ||
| 880 | /// kodi::SetSettingInt("my_integer_value", value); | ||
| 881 | /// ~~~~~~~~~~~~~ | ||
| 882 | /// | ||
| 883 | inline void ATTRIBUTE_HIDDEN SetSettingInt(const std::string& settingName, int settingValue) | ||
| 530 | { | 884 | { |
| 531 | ::kodi::addon::CAddonBase::m_interface->toKodi->set_setting_int(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, settingName.c_str(), settingValue); | 885 | using namespace kodi::addon; |
| 886 | |||
| 887 | CAddonBase::m_interface->toKodi->set_setting_int(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 888 | settingName.c_str(), settingValue); | ||
| 532 | } | 889 | } |
| 533 | } /* namespace kodi */ | 890 | //------------------------------------------------------------------------------ |
| 534 | //---------------------------------------------------------------------------- | ||
| 535 | 891 | ||
| 536 | //============================================================================ | 892 | //============================================================================== |
| 537 | namespace kodi { | 893 | /// @brief Check and get a boolean setting value. |
| 894 | /// | ||
| 895 | /// The setting name relate to names used in his <b>settings.xml</b> file. | ||
| 896 | /// | ||
| 897 | /// @param[in] settingName The name of asked setting | ||
| 898 | /// @param[out] settingValue The given setting value | ||
| 899 | /// @return true if setting was successfully found and "settingValue" is set | ||
| 900 | /// | ||
| 901 | /// @note If returns false, the "settingValue" is not changed. | ||
| 902 | /// | ||
| 903 | /// | ||
| 904 | /// ---------------------------------------------------------------------------- | ||
| 538 | /// | 905 | /// |
| 539 | inline bool CheckSettingBoolean(const std::string& settingName, bool& settingValue) | 906 | /// **Example:** |
| 907 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 908 | /// #include <kodi/General.h> | ||
| 909 | /// | ||
| 910 | /// bool value = false; | ||
| 911 | /// if (!kodi::CheckSettingBoolean("my_boolean_value", value)) | ||
| 912 | /// value = true; // My default of them | ||
| 913 | /// ~~~~~~~~~~~~~ | ||
| 914 | /// | ||
| 915 | inline bool ATTRIBUTE_HIDDEN CheckSettingBoolean(const std::string& settingName, bool& settingValue) | ||
| 540 | { | 916 | { |
| 541 | return ::kodi::addon::CAddonBase::m_interface->toKodi->get_setting_bool(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, settingName.c_str(), &settingValue); | 917 | using namespace kodi::addon; |
| 918 | |||
| 919 | return CAddonBase::m_interface->toKodi->get_setting_bool( | ||
| 920 | CAddonBase::m_interface->toKodi->kodiBase, settingName.c_str(), &settingValue); | ||
| 542 | } | 921 | } |
| 543 | } /* namespace kodi */ | 922 | //------------------------------------------------------------------------------ |
| 544 | //---------------------------------------------------------------------------- | ||
| 545 | 923 | ||
| 546 | //============================================================================ | 924 | //============================================================================== |
| 547 | namespace kodi { | 925 | /// @brief Get boolean setting value. |
| 926 | /// | ||
| 927 | /// The setting name relate to names used in his <b>settings.xml</b> file. | ||
| 928 | /// | ||
| 929 | /// @param[in] settingName The name of asked setting | ||
| 930 | /// @param[in] defaultValue [opt] Default value if not found | ||
| 931 | /// @return The value of setting, <b>`false`</b> or defaultValue if not found | ||
| 932 | /// | ||
| 933 | /// | ||
| 934 | /// ---------------------------------------------------------------------------- | ||
| 548 | /// | 935 | /// |
| 549 | inline bool GetSettingBoolean(const std::string& settingName) | 936 | /// **Example:** |
| 937 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 938 | /// #include <kodi/General.h> | ||
| 939 | /// | ||
| 940 | /// bool value = kodi::GetSettingBoolean("my_boolean_value"); | ||
| 941 | /// ~~~~~~~~~~~~~ | ||
| 942 | /// | ||
| 943 | inline bool ATTRIBUTE_HIDDEN GetSettingBoolean(const std::string& settingName, | ||
| 944 | bool defaultValue = false) | ||
| 550 | { | 945 | { |
| 551 | bool settingValue = false; | 946 | bool settingValue = defaultValue; |
| 552 | CheckSettingBoolean(settingName, settingValue); | 947 | CheckSettingBoolean(settingName, settingValue); |
| 553 | return settingValue; | 948 | return settingValue; |
| 554 | } | 949 | } |
| 555 | } /* namespace kodi */ | 950 | //------------------------------------------------------------------------------ |
| 556 | //---------------------------------------------------------------------------- | ||
| 557 | 951 | ||
| 558 | //============================================================================ | 952 | //============================================================================== |
| 559 | namespace kodi { | 953 | /// @brief Set boolean setting of addon. |
| 954 | /// | ||
| 955 | /// The setting name relate to names used in his <b>settings.xml</b> file. | ||
| 956 | /// | ||
| 957 | /// @param[in] settingName The name of setting | ||
| 958 | /// @param[in] settingValue The setting value to write | ||
| 959 | /// | ||
| 960 | /// | ||
| 961 | /// ---------------------------------------------------------------------------- | ||
| 560 | /// | 962 | /// |
| 561 | inline void SetSettingBoolean(const std::string& settingName, bool settingValue) | 963 | /// **Example:** |
| 964 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 965 | /// #include <kodi/General.h> | ||
| 966 | /// | ||
| 967 | /// bool value = true; | ||
| 968 | /// kodi::SetSettingBoolean("my_boolean_value", value); | ||
| 969 | /// ~~~~~~~~~~~~~ | ||
| 970 | /// | ||
| 971 | inline void ATTRIBUTE_HIDDEN SetSettingBoolean(const std::string& settingName, bool settingValue) | ||
| 562 | { | 972 | { |
| 563 | ::kodi::addon::CAddonBase::m_interface->toKodi->set_setting_bool(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, settingName.c_str(), settingValue); | 973 | using namespace kodi::addon; |
| 974 | |||
| 975 | CAddonBase::m_interface->toKodi->set_setting_bool(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 976 | settingName.c_str(), settingValue); | ||
| 564 | } | 977 | } |
| 565 | } /* namespace kodi */ | 978 | //------------------------------------------------------------------------------ |
| 566 | //---------------------------------------------------------------------------- | ||
| 567 | 979 | ||
| 568 | //============================================================================ | 980 | //============================================================================== |
| 569 | namespace kodi { | 981 | /// @brief Check and get a floating point setting value. |
| 982 | /// | ||
| 983 | /// The setting name relate to names used in his <b>settings.xml</b> file. | ||
| 984 | /// | ||
| 985 | /// @param[in] settingName The name of asked setting | ||
| 986 | /// @param[out] settingValue The given setting value | ||
| 987 | /// @return true if setting was successfully found and "settingValue" is set | ||
| 988 | /// | ||
| 989 | /// @note If returns false, the "settingValue" is not changed. | ||
| 990 | /// | ||
| 570 | /// | 991 | /// |
| 571 | inline bool CheckSettingFloat(const std::string& settingName, float& settingValue) | 992 | /// ---------------------------------------------------------------------------- |
| 993 | /// | ||
| 994 | /// **Example:** | ||
| 995 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 996 | /// #include <kodi/General.h> | ||
| 997 | /// | ||
| 998 | /// float value = 0.0f; | ||
| 999 | /// if (!kodi::CheckSettingBoolean("my_float_value", value)) | ||
| 1000 | /// value = 1.0f; // My default of them | ||
| 1001 | /// ~~~~~~~~~~~~~ | ||
| 1002 | /// | ||
| 1003 | inline bool ATTRIBUTE_HIDDEN CheckSettingFloat(const std::string& settingName, float& settingValue) | ||
| 572 | { | 1004 | { |
| 573 | return ::kodi::addon::CAddonBase::m_interface->toKodi->get_setting_float(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, settingName.c_str(), &settingValue); | 1005 | using namespace kodi::addon; |
| 1006 | |||
| 1007 | return CAddonBase::m_interface->toKodi->get_setting_float( | ||
| 1008 | CAddonBase::m_interface->toKodi->kodiBase, settingName.c_str(), &settingValue); | ||
| 574 | } | 1009 | } |
| 575 | } /* namespace kodi */ | 1010 | //------------------------------------------------------------------------------ |
| 576 | //---------------------------------------------------------------------------- | ||
| 577 | 1011 | ||
| 578 | //============================================================================ | 1012 | //============================================================================== |
| 579 | namespace kodi { | 1013 | /// @brief Get floating point setting value. |
| 1014 | /// | ||
| 1015 | /// The setting name relate to names used in his <b>settings.xml</b> file. | ||
| 1016 | /// | ||
| 1017 | /// @param[in] settingName The name of asked setting | ||
| 1018 | /// @param[in] defaultValue [opt] Default value if not found | ||
| 1019 | /// @return The value of setting, <b>`0.0`</b> or defaultValue if not found | ||
| 1020 | /// | ||
| 580 | /// | 1021 | /// |
| 581 | inline float GetSettingFloat(const std::string& settingName) | 1022 | /// ---------------------------------------------------------------------------- |
| 1023 | /// | ||
| 1024 | /// **Example:** | ||
| 1025 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 1026 | /// #include <kodi/General.h> | ||
| 1027 | /// | ||
| 1028 | /// float value = kodi::GetSettingFloat("my_float_value"); | ||
| 1029 | /// ~~~~~~~~~~~~~ | ||
| 1030 | /// | ||
| 1031 | inline float ATTRIBUTE_HIDDEN GetSettingFloat(const std::string& settingName, | ||
| 1032 | float defaultValue = 0.0f) | ||
| 582 | { | 1033 | { |
| 583 | float settingValue = 0.0f; | 1034 | float settingValue = defaultValue; |
| 584 | CheckSettingFloat(settingName, settingValue); | 1035 | CheckSettingFloat(settingName, settingValue); |
| 585 | return settingValue; | 1036 | return settingValue; |
| 586 | } | 1037 | } |
| 587 | } /* namespace kodi */ | 1038 | //------------------------------------------------------------------------------ |
| 588 | //---------------------------------------------------------------------------- | ||
| 589 | 1039 | ||
| 590 | //============================================================================ | 1040 | //============================================================================== |
| 591 | namespace kodi { | 1041 | /// @brief Set floating point setting of addon. |
| 1042 | /// | ||
| 1043 | /// The setting name relate to names used in his <b>settings.xml</b> file. | ||
| 1044 | /// | ||
| 1045 | /// @param[in] settingName The name of setting | ||
| 1046 | /// @param[in] settingValue The setting value to write | ||
| 1047 | /// | ||
| 1048 | /// | ||
| 1049 | /// ---------------------------------------------------------------------------- | ||
| 592 | /// | 1050 | /// |
| 593 | inline void SetSettingFloat(const std::string& settingName, float settingValue) | 1051 | /// **Example:** |
| 1052 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 1053 | /// #include <kodi/General.h> | ||
| 1054 | /// | ||
| 1055 | /// float value = 1.0f; | ||
| 1056 | /// kodi::SetSettingFloat("my_float_value", value); | ||
| 1057 | /// ~~~~~~~~~~~~~ | ||
| 1058 | /// | ||
| 1059 | inline void ATTRIBUTE_HIDDEN SetSettingFloat(const std::string& settingName, float settingValue) | ||
| 594 | { | 1060 | { |
| 595 | ::kodi::addon::CAddonBase::m_interface->toKodi->set_setting_float(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, settingName.c_str(), settingValue); | 1061 | using namespace kodi::addon; |
| 1062 | |||
| 1063 | CAddonBase::m_interface->toKodi->set_setting_float(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 1064 | settingName.c_str(), settingValue); | ||
| 596 | } | 1065 | } |
| 597 | } /* namespace kodi */ | 1066 | //------------------------------------------------------------------------------ |
| 598 | //---------------------------------------------------------------------------- | 1067 | |
| 1068 | //============================================================================== | ||
| 1069 | /// @brief Check and get a enum setting value. | ||
| 1070 | /// | ||
| 1071 | /// The setting name relate to names used in his <b>settings.xml</b> file. | ||
| 1072 | /// | ||
| 1073 | /// @param[in] settingName The name of asked setting | ||
| 1074 | /// @param[out] settingValue The given setting value | ||
| 1075 | /// @return true if setting was successfully found and "settingValue" is set | ||
| 1076 | /// | ||
| 1077 | /// @remark The enums are used as integer inside settings.xml. | ||
| 1078 | /// @note If returns false, the "settingValue" is not changed. | ||
| 1079 | /// | ||
| 1080 | /// | ||
| 1081 | /// ---------------------------------------------------------------------------- | ||
| 1082 | /// | ||
| 1083 | /// **Example:** | ||
| 1084 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 1085 | /// #include <kodi/General.h> | ||
| 1086 | /// | ||
| 1087 | /// enum myEnumValue | ||
| 1088 | /// { | ||
| 1089 | /// valueA, | ||
| 1090 | /// valueB, | ||
| 1091 | /// valueC | ||
| 1092 | /// }; | ||
| 1093 | /// | ||
| 1094 | /// myEnumValue value; | ||
| 1095 | /// if (!kodi::CheckSettingEnum<myEnumValue>("my_enum_value", value)) | ||
| 1096 | /// value = valueA; // My default of them | ||
| 1097 | /// ~~~~~~~~~~~~~ | ||
| 1098 | /// | ||
| 1099 | template<typename enumType> | ||
| 1100 | inline bool ATTRIBUTE_HIDDEN CheckSettingEnum(const std::string& settingName, | ||
| 1101 | enumType& settingValue) | ||
| 1102 | { | ||
| 1103 | using namespace kodi::addon; | ||
| 1104 | |||
| 1105 | int settingValueInt = static_cast<int>(settingValue); | ||
| 1106 | bool ret = CAddonBase::m_interface->toKodi->get_setting_int( | ||
| 1107 | CAddonBase::m_interface->toKodi->kodiBase, settingName.c_str(), &settingValueInt); | ||
| 1108 | if (ret) | ||
| 1109 | settingValue = static_cast<enumType>(settingValueInt); | ||
| 1110 | return ret; | ||
| 1111 | } | ||
| 1112 | //------------------------------------------------------------------------------ | ||
| 1113 | |||
| 1114 | //============================================================================== | ||
| 1115 | /// @brief Get enum setting value. | ||
| 1116 | /// | ||
| 1117 | /// The setting name relate to names used in his <b>settings.xml</b> file. | ||
| 1118 | /// | ||
| 1119 | /// @param[in] settingName The name of asked setting | ||
| 1120 | /// @param[in] defaultValue [opt] Default value if not found | ||
| 1121 | /// @return The value of setting, forced to <b>`0`</b> or defaultValue if not found | ||
| 1122 | /// | ||
| 1123 | /// @remark The enums are used as integer inside settings.xml. | ||
| 1124 | /// | ||
| 1125 | /// | ||
| 1126 | /// ---------------------------------------------------------------------------- | ||
| 1127 | /// | ||
| 1128 | /// **Example:** | ||
| 1129 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 1130 | /// #include <kodi/General.h> | ||
| 1131 | /// | ||
| 1132 | /// enum myEnumValue | ||
| 1133 | /// { | ||
| 1134 | /// valueA, | ||
| 1135 | /// valueB, | ||
| 1136 | /// valueC | ||
| 1137 | /// }; | ||
| 1138 | /// | ||
| 1139 | /// myEnumValue value = kodi::GetSettingEnum<myEnumValue>("my_enum_value"); | ||
| 1140 | /// ~~~~~~~~~~~~~ | ||
| 1141 | /// | ||
| 1142 | template<typename enumType> | ||
| 1143 | inline enumType ATTRIBUTE_HIDDEN GetSettingEnum(const std::string& settingName, | ||
| 1144 | enumType defaultValue = static_cast<enumType>(0)) | ||
| 1145 | { | ||
| 1146 | enumType settingValue = defaultValue; | ||
| 1147 | CheckSettingEnum(settingName, settingValue); | ||
| 1148 | return settingValue; | ||
| 1149 | } | ||
| 1150 | //------------------------------------------------------------------------------ | ||
| 1151 | |||
| 1152 | //============================================================================== | ||
| 1153 | /// @brief Set enum setting of addon. | ||
| 1154 | /// | ||
| 1155 | /// The setting name relate to names used in his <b>settings.xml</b> file. | ||
| 1156 | /// | ||
| 1157 | /// @param[in] settingName The name of setting | ||
| 1158 | /// @param[in] settingValue The setting value to write | ||
| 1159 | /// | ||
| 1160 | /// @remark The enums are used as integer inside settings.xml. | ||
| 1161 | /// | ||
| 1162 | /// | ||
| 1163 | /// ---------------------------------------------------------------------------- | ||
| 1164 | /// | ||
| 1165 | /// **Example:** | ||
| 1166 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 1167 | /// #include <kodi/General.h> | ||
| 1168 | /// | ||
| 1169 | /// enum myEnumValue | ||
| 1170 | /// { | ||
| 1171 | /// valueA, | ||
| 1172 | /// valueB, | ||
| 1173 | /// valueC | ||
| 1174 | /// }; | ||
| 1175 | /// | ||
| 1176 | /// myEnumValue value = valueA; | ||
| 1177 | /// kodi::SetSettingEnum<myEnumValue>("my_enum_value", value); | ||
| 1178 | /// ~~~~~~~~~~~~~ | ||
| 1179 | /// | ||
| 1180 | template<typename enumType> | ||
| 1181 | inline void ATTRIBUTE_HIDDEN SetSettingEnum(const std::string& settingName, enumType settingValue) | ||
| 1182 | { | ||
| 1183 | using namespace kodi::addon; | ||
| 1184 | |||
| 1185 | CAddonBase::m_interface->toKodi->set_setting_int(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 1186 | settingName.c_str(), | ||
| 1187 | static_cast<int>(settingValue)); | ||
| 1188 | } | ||
| 1189 | //------------------------------------------------------------------------------ | ||
| 1190 | |||
| 1191 | /*!@}*/ | ||
| 599 | 1192 | ||
| 600 | //============================================================================ | 1193 | //============================================================================ |
| 601 | namespace kodi { | ||
| 602 | /// | 1194 | /// |
| 603 | inline std::string TranslateAddonStatus(ADDON_STATUS status) | 1195 | inline std::string ATTRIBUTE_HIDDEN TranslateAddonStatus(ADDON_STATUS status) |
| 604 | { | 1196 | { |
| 605 | switch (status) | 1197 | switch (status) |
| 606 | { | 1198 | { |
| @@ -623,13 +1215,10 @@ inline std::string TranslateAddonStatus(ADDON_STATUS status) | |||
| 623 | } | 1215 | } |
| 624 | return "Unknown"; | 1216 | return "Unknown"; |
| 625 | } | 1217 | } |
| 626 | } /* namespace kodi */ | ||
| 627 | //---------------------------------------------------------------------------- | 1218 | //---------------------------------------------------------------------------- |
| 628 | 1219 | ||
| 629 | //============================================================================== | 1220 | //============================================================================== |
| 630 | namespace kodi { | 1221 | /// @ingroup cpp_kodi |
| 631 | /// | ||
| 632 | /// \ingroup cpp_kodi | ||
| 633 | /// @brief Returns a function table to a named interface | 1222 | /// @brief Returns a function table to a named interface |
| 634 | /// | 1223 | /// |
| 635 | /// @return pointer to struct containing interface functions | 1224 | /// @return pointer to struct containing interface functions |
| @@ -646,12 +1235,16 @@ namespace kodi { | |||
| 646 | /// ... | 1235 | /// ... |
| 647 | /// ~~~~~~~~~~~~~ | 1236 | /// ~~~~~~~~~~~~~ |
| 648 | /// | 1237 | /// |
| 649 | inline void* GetInterface(const std::string &name, const std::string &version) | 1238 | inline void* GetInterface(const std::string& name, const std::string& version) |
| 650 | { | 1239 | { |
| 651 | AddonToKodiFuncTable_Addon* toKodi = ::kodi::addon::CAddonBase::m_interface->toKodi; | 1240 | using namespace kodi::addon; |
| 1241 | |||
| 1242 | AddonToKodiFuncTable_Addon* toKodi = CAddonBase::m_interface->toKodi; | ||
| 652 | 1243 | ||
| 653 | return toKodi->get_interface(toKodi->kodiBase, name.c_str(), version.c_str()); | 1244 | return toKodi->get_interface(toKodi->kodiBase, name.c_str(), version.c_str()); |
| 654 | } | 1245 | } |
| 1246 | //---------------------------------------------------------------------------- | ||
| 1247 | |||
| 655 | } /* namespace kodi */ | 1248 | } /* namespace kodi */ |
| 656 | 1249 | ||
| 657 | /*! addon creation macro | 1250 | /*! addon creation macro |
| @@ -663,17 +1256,13 @@ inline void* GetInterface(const std::string &name, const std::string &version) | |||
| 663 | * Becomes really cleaned up soon :D | 1256 | * Becomes really cleaned up soon :D |
| 664 | */ | 1257 | */ |
| 665 | #define ADDONCREATOR(AddonClass) \ | 1258 | #define ADDONCREATOR(AddonClass) \ |
| 666 | extern "C" __declspec(dllexport) void get_addon(void* pAddon) {} \ | 1259 | extern "C" __declspec(dllexport) ADDON_STATUS ADDON_Create( \ |
| 667 | extern "C" __declspec(dllexport) ADDON_STATUS ADDON_Create(KODI_HANDLE addonInterface, void *unused) \ | 1260 | KODI_HANDLE addonInterface, const char* /*globalApiVersion*/, void* /*unused*/) \ |
| 668 | { \ | 1261 | { \ |
| 669 | kodi::addon::CAddonBase::m_interface = static_cast<AddonGlobalInterface*>(addonInterface); \ | 1262 | kodi::addon::CAddonBase::m_interface = static_cast<AddonGlobalInterface*>(addonInterface); \ |
| 670 | kodi::addon::CAddonBase::m_interface->addonBase = new AddonClass; \ | 1263 | kodi::addon::CAddonBase::m_interface->addonBase = new AddonClass; \ |
| 671 | return kodi::addon::CAddonBase::m_interface->addonBase->Create(); \ | 1264 | return static_cast<kodi::addon::CAddonBase*>(kodi::addon::CAddonBase::m_interface->addonBase) \ |
| 672 | } \ | 1265 | ->Create(); \ |
| 673 | extern "C" __declspec(dllexport) ADDON_STATUS ADDON_CreateEx(KODI_HANDLE addonInterface, const char* globalApiVersion, void *unused) \ | ||
| 674 | { \ | ||
| 675 | kodi::addon::CAddonBase::m_strGlobalApiVersion = globalApiVersion; \ | ||
| 676 | return ADDON_Create(addonInterface, unused); \ | ||
| 677 | } \ | 1266 | } \ |
| 678 | extern "C" __declspec(dllexport) void ADDON_Destroy() \ | 1267 | extern "C" __declspec(dllexport) void ADDON_Destroy() \ |
| 679 | { \ | 1268 | { \ |
| @@ -683,7 +1272,8 @@ inline void* GetInterface(const std::string &name, const std::string &version) | |||
| 683 | { \ | 1272 | { \ |
| 684 | return kodi::addon::CAddonBase::ADDONBASE_GetStatus(); \ | 1273 | return kodi::addon::CAddonBase::ADDONBASE_GetStatus(); \ |
| 685 | } \ | 1274 | } \ |
| 686 | extern "C" __declspec(dllexport) ADDON_STATUS ADDON_SetSetting(const char *settingName, const void *settingValue) \ | 1275 | extern "C" __declspec(dllexport) ADDON_STATUS ADDON_SetSetting(const char* settingName, \ |
| 1276 | const void* settingValue) \ | ||
| 687 | { \ | 1277 | { \ |
| 688 | return kodi::addon::CAddonBase::ADDONBASE_SetSetting(settingName, settingValue); \ | 1278 | return kodi::addon::CAddonBase::ADDONBASE_SetSetting(settingName, settingValue); \ |
| 689 | } \ | 1279 | } \ |
| @@ -695,6 +1285,4 @@ inline void* GetInterface(const std::string &name, const std::string &version) | |||
| 695 | { \ | 1285 | { \ |
| 696 | return kodi::addon::GetTypeMinVersion(type); \ | 1286 | return kodi::addon::GetTypeMinVersion(type); \ |
| 697 | } \ | 1287 | } \ |
| 698 | AddonGlobalInterface* kodi::addon::CAddonBase::m_interface = nullptr; \ | 1288 | AddonGlobalInterface* kodi::addon::CAddonBase::m_interface = nullptr; |
| 699 | std::string kodi::addon::CAddonBase::m_strGlobalApiVersion; | ||
| 700 | |||
