diff options
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/tools')
3 files changed, 119 insertions, 118 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/tools/CMakeLists.txt b/xbmc/addons/kodi-addon-dev-kit/include/kodi/tools/CMakeLists.txt index ef2fa25..939585c 100644 --- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/tools/CMakeLists.txt +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/tools/CMakeLists.txt | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | set(HEADERS DllHelper.h | 1 | set(HEADERS DllHelper.h ) |
| 2 | Time.h) | ||
| 3 | 2 | ||
| 4 | if(NOT ENABLE_STATIC_LIBS) | 3 | if(NOT ENABLE_STATIC_LIBS) |
| 5 | core_add_library(addons_kodi-addon-dev-kit_include_kodi_tools) | 4 | core_add_library(addons_kodi-addon-dev-kit_include_kodi_tools) |
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/tools/DllHelper.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/tools/DllHelper.h index 1ae1a0e..3cc9eea 100644 --- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/tools/DllHelper.h +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/tools/DllHelper.h | |||
| @@ -8,24 +8,42 @@ | |||
| 8 | 8 | ||
| 9 | #pragma once | 9 | #pragma once |
| 10 | 10 | ||
| 11 | #ifdef __cplusplus | ||
| 12 | |||
| 11 | #include <string> | 13 | #include <string> |
| 12 | #include <kodi/AddonBase.h> | ||
| 13 | 14 | ||
| 14 | #ifdef _WIN32 // windows | 15 | #include <dlfcn.h> |
| 15 | #include <p8-platform/windows/dlfcn-win32.h> | 16 | #include <kodi/AddonBase.h> |
| 16 | #else | 17 | #include <kodi/Filesystem.h> |
| 17 | #include <dlfcn.h> // linux+osx | ||
| 18 | #endif | ||
| 19 | 18 | ||
| 19 | //============================================================================== | ||
| 20 | /// @ingroup cpp_kodi_tools_CDllHelper | ||
| 21 | /// @brief Macro to translate the given pointer value name of functions to | ||
| 22 | /// requested function name. | ||
| 23 | /// | ||
| 24 | /// @note This should always be used and does the work of | ||
| 25 | /// @ref kodi::tools::CDllHelper::RegisterSymbol(). | ||
| 26 | /// | ||
| 20 | #define REGISTER_DLL_SYMBOL(functionPtr) \ | 27 | #define REGISTER_DLL_SYMBOL(functionPtr) \ |
| 21 | CDllHelper::RegisterSymbol(functionPtr, #functionPtr) | 28 | kodi::tools::CDllHelper::RegisterSymbol(functionPtr, #functionPtr) |
| 29 | //------------------------------------------------------------------------------ | ||
| 22 | 30 | ||
| 23 | /// @brief Class to help with load of shared library functions | 31 | namespace kodi |
| 24 | /// | 32 | { |
| 33 | namespace tools | ||
| 34 | { | ||
| 35 | |||
| 36 | //============================================================================== | ||
| 37 | /// @defgroup cpp_kodi_tools_CDllHelper class CDllHelper | ||
| 38 | /// @ingroup cpp_kodi_tools | ||
| 39 | /// @brief **Class to help with load of shared library functions**\n | ||
| 25 | /// You can add them as parent to your class and to help with load of shared | 40 | /// You can add them as parent to your class and to help with load of shared |
| 26 | /// library functions. | 41 | /// library functions. |
| 27 | /// | 42 | /// |
| 28 | /// @note To use on Windows must you also include p8-platform on your addon! | 43 | /// @note To use on Windows must you also include [dlfcn-win32](https://github.com/dlfcn-win32/dlfcn-win32) |
| 44 | /// on your addon!\n\n | ||
| 45 | /// Furthermore, this allows the use of Android where the required library is | ||
| 46 | /// copied to an EXE useable folder. | ||
| 29 | /// | 47 | /// |
| 30 | /// | 48 | /// |
| 31 | /// ---------------------------------------------------------------------------- | 49 | /// ---------------------------------------------------------------------------- |
| @@ -37,22 +55,22 @@ | |||
| 37 | /// | 55 | /// |
| 38 | /// ... | 56 | /// ... |
| 39 | /// class CMyInstance : public kodi::addon::CInstanceAudioDecoder, | 57 | /// class CMyInstance : public kodi::addon::CInstanceAudioDecoder, |
| 40 | /// private CDllHelper | 58 | /// private kodi::tools::CDllHelper |
| 41 | /// { | 59 | /// { |
| 42 | /// public: | 60 | /// public: |
| 43 | /// CMyInstance(KODI_HANDLE instance); | 61 | /// CMyInstance(KODI_HANDLE instance, const std::string& kodiVersion); |
| 44 | /// bool Start(); | 62 | /// bool Start(); |
| 45 | /// | 63 | /// |
| 46 | /// ... | 64 | /// ... |
| 47 | /// | 65 | /// |
| 48 | /// /* The pointers for on shared library exported functions */ | 66 | /// // The pointers for on shared library exported functions |
| 49 | /// int (*Init)(); | 67 | /// int (*Init)(); |
| 50 | /// void (*Cleanup)(); | 68 | /// void (*Cleanup)(); |
| 51 | /// int (*GetLength)(); | 69 | /// int (*GetLength)(); |
| 52 | /// }; | 70 | /// }; |
| 53 | /// | 71 | /// |
| 54 | /// CMyInstance::CMyInstance(KODI_HANDLE instance) | 72 | /// CMyInstance::CMyInstance(KODI_HANDLE instance, const std::string& kodiVersion) |
| 55 | /// : CInstanceAudioDecoder(instance) | 73 | /// : CInstanceAudioDecoder(instance, kodiVersion) |
| 56 | /// { | 74 | /// { |
| 57 | /// } | 75 | /// } |
| 58 | /// | 76 | /// |
| @@ -70,23 +88,80 @@ | |||
| 70 | /// ... | 88 | /// ... |
| 71 | /// ~~~~~~~~~~~~~ | 89 | /// ~~~~~~~~~~~~~ |
| 72 | /// | 90 | /// |
| 73 | class CDllHelper | 91 | ///@{ |
| 92 | class ATTRIBUTE_HIDDEN CDllHelper | ||
| 74 | { | 93 | { |
| 75 | public: | 94 | public: |
| 76 | CDllHelper() : m_dll(nullptr) { } | 95 | //============================================================================ |
| 96 | /// @ingroup cpp_kodi_tools_CDllHelper | ||
| 97 | /// @brief Class constructor. | ||
| 98 | /// | ||
| 99 | CDllHelper() = default; | ||
| 100 | //---------------------------------------------------------------------------- | ||
| 101 | |||
| 102 | //============================================================================ | ||
| 103 | /// @ingroup cpp_kodi_tools_CDllHelper | ||
| 104 | /// @brief Class destructor. | ||
| 105 | /// | ||
| 77 | virtual ~CDllHelper() | 106 | virtual ~CDllHelper() |
| 78 | { | 107 | { |
| 79 | if (m_dll) | 108 | if (m_dll) |
| 80 | dlclose(m_dll); | 109 | dlclose(m_dll); |
| 81 | } | 110 | } |
| 111 | //---------------------------------------------------------------------------- | ||
| 82 | 112 | ||
| 83 | /// @brief Function to load requested library | 113 | //============================================================================ |
| 114 | /// @ingroup cpp_kodi_tools_CDllHelper | ||
| 115 | /// @brief Function to load requested library. | ||
| 84 | /// | 116 | /// |
| 85 | /// @param[in] path The path with filename of shared library to load | 117 | /// @param[in] path The path with filename of shared library to load |
| 86 | /// @return true if load was successful done | 118 | /// @return true if load was successful done |
| 87 | /// | 119 | /// |
| 88 | bool LoadDll(const std::string& path) | 120 | bool LoadDll(std::string path) |
| 89 | { | 121 | { |
| 122 | #if defined(TARGET_ANDROID) | ||
| 123 | if (kodi::vfs::FileExists(path)) | ||
| 124 | { | ||
| 125 | // Check already defined for "xbmcaltbinaddons", if yes no copy necassary. | ||
| 126 | std::string xbmcaltbinaddons = | ||
| 127 | kodi::vfs::TranslateSpecialProtocol("special://xbmcaltbinaddons/"); | ||
| 128 | if (path.compare(0, xbmcaltbinaddons.length(), xbmcaltbinaddons) != 0) | ||
| 129 | { | ||
| 130 | bool doCopy = true; | ||
| 131 | std::string dstfile = xbmcaltbinaddons + kodi::vfs::GetFileName(path); | ||
| 132 | |||
| 133 | kodi::vfs::FileStatus dstFileStat; | ||
| 134 | if (kodi::vfs::StatFile(dstfile, dstFileStat)) | ||
| 135 | { | ||
| 136 | kodi::vfs::FileStatus srcFileStat; | ||
| 137 | if (kodi::vfs::StatFile(path, srcFileStat)) | ||
| 138 | { | ||
| 139 | if (dstFileStat.GetSize() == srcFileStat.GetSize() && | ||
| 140 | dstFileStat.GetModificationTime() > srcFileStat.GetModificationTime()) | ||
| 141 | doCopy = false; | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | if (doCopy) | ||
| 146 | { | ||
| 147 | kodi::Log(ADDON_LOG_DEBUG, "Caching '%s' to '%s'", path.c_str(), dstfile.c_str()); | ||
| 148 | if (!kodi::vfs::CopyFile(path, dstfile)) | ||
| 149 | { | ||
| 150 | kodi::Log(ADDON_LOG_ERROR, "Failed to cache '%s' to '%s'", path.c_str(), | ||
| 151 | dstfile.c_str()); | ||
| 152 | return false; | ||
| 153 | } | ||
| 154 | } | ||
| 155 | |||
| 156 | path = dstfile; | ||
| 157 | } | ||
| 158 | } | ||
| 159 | else | ||
| 160 | { | ||
| 161 | return false; | ||
| 162 | } | ||
| 163 | #endif | ||
| 164 | |||
| 90 | m_dll = dlopen(path.c_str(), RTLD_LAZY); | 165 | m_dll = dlopen(path.c_str(), RTLD_LAZY); |
| 91 | if (m_dll == nullptr) | 166 | if (m_dll == nullptr) |
| 92 | { | 167 | { |
| @@ -95,11 +170,21 @@ public: | |||
| 95 | } | 170 | } |
| 96 | return true; | 171 | return true; |
| 97 | } | 172 | } |
| 173 | //---------------------------------------------------------------------------- | ||
| 98 | 174 | ||
| 99 | /// @brief Function to register requested library symbol | 175 | //============================================================================ |
| 176 | /// @ingroup cpp_kodi_tools_CDllHelper | ||
| 177 | /// @brief Function to register requested library symbol. | ||
| 178 | /// | ||
| 179 | /// @warning This function should not be used, use instead the macro | ||
| 180 | /// @ref REGISTER_DLL_SYMBOL to register the symbol pointer. | ||
| 100 | /// | 181 | /// |
| 101 | /// @note This function should not be used, use instead the macro | 182 | /// |
| 102 | /// REGISTER_DLL_SYMBOL to register the symbol pointer. | 183 | /// Use this always via Macro, e.g.: |
| 184 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 185 | /// if (!REGISTER_DLL_SYMBOL(Init)) | ||
| 186 | /// return false; | ||
| 187 | /// ~~~~~~~~~~~~~ | ||
| 103 | /// | 188 | /// |
| 104 | template <typename T> | 189 | template <typename T> |
| 105 | bool RegisterSymbol(T& functionPtr, const char* strFunctionPtr) | 190 | bool RegisterSymbol(T& functionPtr, const char* strFunctionPtr) |
| @@ -112,7 +197,15 @@ public: | |||
| 112 | } | 197 | } |
| 113 | return true; | 198 | return true; |
| 114 | } | 199 | } |
| 200 | //---------------------------------------------------------------------------- | ||
| 115 | 201 | ||
| 116 | private: | 202 | private: |
| 117 | void* m_dll; | 203 | void* m_dll = nullptr; |
| 118 | }; | 204 | }; |
| 205 | ///@} | ||
| 206 | //------------------------------------------------------------------------------ | ||
| 207 | |||
| 208 | } /* namespace tools */ | ||
| 209 | } /* namespace kodi */ | ||
| 210 | |||
| 211 | #endif /* __cplusplus */ | ||
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/tools/Time.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/tools/Time.h deleted file mode 100644 index 31c29fd..0000000 --- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/tools/Time.h +++ /dev/null | |||
| @@ -1,91 +0,0 @@ | |||
| 1 | #pragma once | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2005-2019 Team Kodi | ||
| 4 | * Copyright (C) 2011-2012 Pulse-Eight Limited. | ||
| 5 | * This file is part of Kodi - https://kodi.tv | ||
| 6 | * | ||
| 7 | * SPDX-License-Identifier: GPL-2.0-or-later | ||
| 8 | * See LICENSES/README.md for more information. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #if defined(TARGET_DARWIN) | ||
| 12 | #include <mach/mach_time.h> | ||
| 13 | #include <CoreVideo/CVHostTime.h> | ||
| 14 | #elif defined(TARGET_WINDOWS) | ||
| 15 | #include <Windows.h> | ||
| 16 | #include <time.h> | ||
| 17 | #else | ||
| 18 | #include <time.h> | ||
| 19 | #endif | ||
| 20 | |||
| 21 | namespace kodi | ||
| 22 | { | ||
| 23 | namespace time | ||
| 24 | { | ||
| 25 | |||
| 26 | //=============================================================================== | ||
| 27 | /// @brief Function to get current time in milliseconds | ||
| 28 | /// | ||
| 29 | /// @return Current time in milliseconds as a double value | ||
| 30 | /// | ||
| 31 | /// | ||
| 32 | /// ----------------------------------------------------------------------------- | ||
| 33 | /// | ||
| 34 | /// **Example:** | ||
| 35 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 36 | /// | ||
| 37 | /// #include <kodi/tools/Time.h> | ||
| 38 | /// | ||
| 39 | /// ... | ||
| 40 | /// double time = kodi::time::GetTimeMs(); | ||
| 41 | /// ... | ||
| 42 | /// ~~~~~~~~~~~~~ | ||
| 43 | /// | ||
| 44 | inline double GetTimeMs() | ||
| 45 | { | ||
| 46 | #if defined(TARGET_DARWIN) | ||
| 47 | return static_cast<double>(CVGetCurrentHostTime() / static_cast<double>(CVGetHostClockFrequency() * 0.001)); | ||
| 48 | #elif defined(TARGET_WINDOWS) | ||
| 49 | LARGE_INTEGER tickPerSecond; | ||
| 50 | LARGE_INTEGER tick; | ||
| 51 | if (QueryPerformanceFrequency(&tickPerSecond)) | ||
| 52 | { | ||
| 53 | QueryPerformanceCounter(&tick); | ||
| 54 | return static_cast<double>(tick.QuadPart) / (tickPerSecond.QuadPart / 1000.0); | ||
| 55 | } | ||
| 56 | return 0.0; | ||
| 57 | #else | ||
| 58 | timespec time; | ||
| 59 | clock_gettime(CLOCK_MONOTONIC, &time); | ||
| 60 | return static_cast<double>(time.tv_sec) * 1000.0 + time.tv_nsec / 1000000.0; | ||
| 61 | #endif | ||
| 62 | } | ||
| 63 | //------------------------------------------------------------------------------- | ||
| 64 | |||
| 65 | //=============================================================================== | ||
| 66 | /// @brief Function to get current time in seconds | ||
| 67 | /// | ||
| 68 | /// @return Current time in seconds with the value type defined in the template | ||
| 69 | /// | ||
| 70 | /// | ||
| 71 | /// ----------------------------------------------------------------------------- | ||
| 72 | /// | ||
| 73 | /// **Example:** | ||
| 74 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 75 | /// | ||
| 76 | /// #include <kodi/tools/Time.h> | ||
| 77 | /// | ||
| 78 | /// ... | ||
| 79 | /// double time = kodi::time::GetTimeSec<double>(); | ||
| 80 | /// ... | ||
| 81 | /// ~~~~~~~~~~~~~ | ||
| 82 | /// | ||
| 83 | template <class T> | ||
| 84 | inline T GetTimeSec() | ||
| 85 | { | ||
| 86 | return static_cast<T>(GetTimeMs()) / static_cast<T>(1000.0); | ||
| 87 | } | ||
| 88 | //------------------------------------------------------------------------------- | ||
| 89 | |||
| 90 | } /* namespace time */ | ||
| 91 | } /* namespace kodi */ | ||
