From 5f8335c1e49ce108ef3481863833c98efa00411b Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 2 Jul 2020 23:09:26 +0200 Subject: sync with upstream --- .../include/kodi/tools/CMakeLists.txt | 3 +- .../include/kodi/tools/DllHelper.h | 143 +++++++++++++++++---- .../kodi-addon-dev-kit/include/kodi/tools/Time.h | 91 ------------- 3 files changed, 119 insertions(+), 118 deletions(-) delete mode 100644 xbmc/addons/kodi-addon-dev-kit/include/kodi/tools/Time.h (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/tools') 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 @@ -set(HEADERS DllHelper.h - Time.h) +set(HEADERS DllHelper.h ) if(NOT ENABLE_STATIC_LIBS) 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 @@ #pragma once +#ifdef __cplusplus + #include -#include -#ifdef _WIN32 // windows -#include -#else -#include // linux+osx -#endif +#include +#include +#include +//============================================================================== +/// @ingroup cpp_kodi_tools_CDllHelper +/// @brief Macro to translate the given pointer value name of functions to +/// requested function name. +/// +/// @note This should always be used and does the work of +/// @ref kodi::tools::CDllHelper::RegisterSymbol(). +/// #define REGISTER_DLL_SYMBOL(functionPtr) \ - CDllHelper::RegisterSymbol(functionPtr, #functionPtr) + kodi::tools::CDllHelper::RegisterSymbol(functionPtr, #functionPtr) +//------------------------------------------------------------------------------ -/// @brief Class to help with load of shared library functions -/// +namespace kodi +{ +namespace tools +{ + +//============================================================================== +/// @defgroup cpp_kodi_tools_CDllHelper class CDllHelper +/// @ingroup cpp_kodi_tools +/// @brief **Class to help with load of shared library functions**\n /// You can add them as parent to your class and to help with load of shared /// library functions. /// -/// @note To use on Windows must you also include p8-platform on your addon! +/// @note To use on Windows must you also include [dlfcn-win32](https://github.com/dlfcn-win32/dlfcn-win32) +/// on your addon!\n\n +/// Furthermore, this allows the use of Android where the required library is +/// copied to an EXE useable folder. /// /// /// ---------------------------------------------------------------------------- @@ -37,22 +55,22 @@ /// /// ... /// class CMyInstance : public kodi::addon::CInstanceAudioDecoder, -/// private CDllHelper +/// private kodi::tools::CDllHelper /// { /// public: -/// CMyInstance(KODI_HANDLE instance); +/// CMyInstance(KODI_HANDLE instance, const std::string& kodiVersion); /// bool Start(); /// /// ... /// -/// /* The pointers for on shared library exported functions */ +/// // The pointers for on shared library exported functions /// int (*Init)(); /// void (*Cleanup)(); /// int (*GetLength)(); /// }; /// -/// CMyInstance::CMyInstance(KODI_HANDLE instance) -/// : CInstanceAudioDecoder(instance) +/// CMyInstance::CMyInstance(KODI_HANDLE instance, const std::string& kodiVersion) +/// : CInstanceAudioDecoder(instance, kodiVersion) /// { /// } /// @@ -70,23 +88,80 @@ /// ... /// ~~~~~~~~~~~~~ /// -class CDllHelper +///@{ +class ATTRIBUTE_HIDDEN CDllHelper { public: - CDllHelper() : m_dll(nullptr) { } + //============================================================================ + /// @ingroup cpp_kodi_tools_CDllHelper + /// @brief Class constructor. + /// + CDllHelper() = default; + //---------------------------------------------------------------------------- + + //============================================================================ + /// @ingroup cpp_kodi_tools_CDllHelper + /// @brief Class destructor. + /// virtual ~CDllHelper() { if (m_dll) dlclose(m_dll); } + //---------------------------------------------------------------------------- - /// @brief Function to load requested library + //============================================================================ + /// @ingroup cpp_kodi_tools_CDllHelper + /// @brief Function to load requested library. /// - /// @param[in] path The path with filename of shared library to load - /// @return true if load was successful done + /// @param[in] path The path with filename of shared library to load + /// @return true if load was successful done /// - bool LoadDll(const std::string& path) + bool LoadDll(std::string path) { +#if defined(TARGET_ANDROID) + if (kodi::vfs::FileExists(path)) + { + // Check already defined for "xbmcaltbinaddons", if yes no copy necassary. + std::string xbmcaltbinaddons = + kodi::vfs::TranslateSpecialProtocol("special://xbmcaltbinaddons/"); + if (path.compare(0, xbmcaltbinaddons.length(), xbmcaltbinaddons) != 0) + { + bool doCopy = true; + std::string dstfile = xbmcaltbinaddons + kodi::vfs::GetFileName(path); + + kodi::vfs::FileStatus dstFileStat; + if (kodi::vfs::StatFile(dstfile, dstFileStat)) + { + kodi::vfs::FileStatus srcFileStat; + if (kodi::vfs::StatFile(path, srcFileStat)) + { + if (dstFileStat.GetSize() == srcFileStat.GetSize() && + dstFileStat.GetModificationTime() > srcFileStat.GetModificationTime()) + doCopy = false; + } + } + + if (doCopy) + { + kodi::Log(ADDON_LOG_DEBUG, "Caching '%s' to '%s'", path.c_str(), dstfile.c_str()); + if (!kodi::vfs::CopyFile(path, dstfile)) + { + kodi::Log(ADDON_LOG_ERROR, "Failed to cache '%s' to '%s'", path.c_str(), + dstfile.c_str()); + return false; + } + } + + path = dstfile; + } + } + else + { + return false; + } +#endif + m_dll = dlopen(path.c_str(), RTLD_LAZY); if (m_dll == nullptr) { @@ -95,11 +170,21 @@ public: } return true; } + //---------------------------------------------------------------------------- - /// @brief Function to register requested library symbol + //============================================================================ + /// @ingroup cpp_kodi_tools_CDllHelper + /// @brief Function to register requested library symbol. + /// + /// @warning This function should not be used, use instead the macro + /// @ref REGISTER_DLL_SYMBOL to register the symbol pointer. /// - /// @note This function should not be used, use instead the macro - /// REGISTER_DLL_SYMBOL to register the symbol pointer. + /// + /// Use this always via Macro, e.g.: + /// ~~~~~~~~~~~~~{.cpp} + /// if (!REGISTER_DLL_SYMBOL(Init)) + /// return false; + /// ~~~~~~~~~~~~~ /// template bool RegisterSymbol(T& functionPtr, const char* strFunctionPtr) @@ -112,7 +197,15 @@ public: } return true; } + //---------------------------------------------------------------------------- private: - void* m_dll; + void* m_dll = nullptr; }; +///@} +//------------------------------------------------------------------------------ + +} /* namespace tools */ +} /* namespace kodi */ + +#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 @@ -#pragma once -/* - * Copyright (C) 2005-2019 Team Kodi - * Copyright (C) 2011-2012 Pulse-Eight Limited. - * This file is part of Kodi - https://kodi.tv - * - * SPDX-License-Identifier: GPL-2.0-or-later - * See LICENSES/README.md for more information. - */ - -#if defined(TARGET_DARWIN) -#include -#include -#elif defined(TARGET_WINDOWS) -#include -#include -#else -#include -#endif - -namespace kodi -{ -namespace time -{ - -//=============================================================================== -/// @brief Function to get current time in milliseconds -/// -/// @return Current time in milliseconds as a double value -/// -/// -/// ----------------------------------------------------------------------------- -/// -/// **Example:** -/// ~~~~~~~~~~~~~{.cpp} -/// -/// #include -/// -/// ... -/// double time = kodi::time::GetTimeMs(); -/// ... -/// ~~~~~~~~~~~~~ -/// -inline double GetTimeMs() -{ -#if defined(TARGET_DARWIN) - return static_cast(CVGetCurrentHostTime() / static_cast(CVGetHostClockFrequency() * 0.001)); -#elif defined(TARGET_WINDOWS) - LARGE_INTEGER tickPerSecond; - LARGE_INTEGER tick; - if (QueryPerformanceFrequency(&tickPerSecond)) - { - QueryPerformanceCounter(&tick); - return static_cast(tick.QuadPart) / (tickPerSecond.QuadPart / 1000.0); - } - return 0.0; -#else - timespec time; - clock_gettime(CLOCK_MONOTONIC, &time); - return static_cast(time.tv_sec) * 1000.0 + time.tv_nsec / 1000000.0; -#endif -} -//------------------------------------------------------------------------------- - -//=============================================================================== -/// @brief Function to get current time in seconds -/// -/// @return Current time in seconds with the value type defined in the template -/// -/// -/// ----------------------------------------------------------------------------- -/// -/// **Example:** -/// ~~~~~~~~~~~~~{.cpp} -/// -/// #include -/// -/// ... -/// double time = kodi::time::GetTimeSec(); -/// ... -/// ~~~~~~~~~~~~~ -/// -template -inline T GetTimeSec() -{ - return static_cast(GetTimeMs()) / static_cast(1000.0); -} -//------------------------------------------------------------------------------- - -} /* namespace time */ -} /* namespace kodi */ -- cgit v1.2.3